summaryrefslogtreecommitdiffstats
path: root/tests/tapl/com/android/launcher3/tapl/Overview.java
blob: 3c0ae2daf6b90294979b6a7dfefbc20d5975c922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3.tapl;

import static org.junit.Assert.assertNotEquals;

import android.graphics.Point;
import android.support.test.uiautomator.Direction;
import android.support.test.uiautomator.UiObject2;

import java.util.Collections;
import java.util.List;

import androidx.annotation.NonNull;

/**
 * Overview pane.
 */
public final class Overview extends LauncherInstrumentation.VisibleContainer {
    private static final int DEFAULT_FLING_SPEED = 15000;

    Overview(LauncherInstrumentation launcher) {
        super(launcher);
        verifyActiveContainer();
    }

    @Override
    protected LauncherInstrumentation.ContainerType getContainerType() {
        return LauncherInstrumentation.ContainerType.OVERVIEW;
    }

    /**
     * Flings forward (left) and waits the fling's end.
     */
    public void flingForward() {
        final UiObject2 overview = verifyActiveContainer();
        overview.fling(Direction.LEFT, DEFAULT_FLING_SPEED);
        mLauncher.waitForIdle();
        verifyActiveContainer();
    }

    /**
     * Flings backward (right) and waits the fling's end.
     */
    public void flingBackward() {
        final UiObject2 overview = verifyActiveContainer();
        overview.fling(Direction.RIGHT, DEFAULT_FLING_SPEED);
        mLauncher.waitForIdle();
        verifyActiveContainer();
    }

    /**
     * Gets the current task in the carousel, or fails if the carousel is empty.
     *
     * @return the task in the middle of the visible tasks list.
     */
    @NonNull
    public OverviewTask getCurrentTask() {
        verifyActiveContainer();
        final List<UiObject2> taskViews = mLauncher.getDevice().findObjects(
                LauncherInstrumentation.getLauncherObjectSelector("snapshot"));
        assertNotEquals("Unable to find a task", 0, taskViews.size());

        // taskViews contains up to 3 task views: the 'main' (having the widest visible
        // part) one in the center, and parts of its right and left siblings. Find the
        // main task view by its width.
        final UiObject2 widestTask = Collections.max(taskViews,
                (t1, t2) -> Integer.compare(t1.getVisibleBounds().width(),
                        t2.getVisibleBounds().width()));

        return new OverviewTask(mLauncher, widestTask, this);
    }

    /**
     * Swipes up to All Apps.
     *
     * @return the App Apps object.
     */
    @NonNull
    public AllAppsFromOverview switchToAllApps() {
        verifyActiveContainer();

        // Swipe from navbar to the top.
        final UiObject2 navBar = mLauncher.getSystemUiObject("navigation_bar_frame");
        final Point start = navBar.getVisibleCenter();
        mLauncher.swipe(start.x, start.y, start.x, 0);

        return new AllAppsFromOverview(mLauncher);
    }
}