• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.android.quickstep;
18 
19 import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName;
20 
21 import static org.junit.Assert.assertTrue;
22 
23 import android.os.SystemProperties;
24 
25 import androidx.test.uiautomator.By;
26 import androidx.test.uiautomator.Until;
27 
28 import com.android.launcher3.Launcher;
29 import com.android.launcher3.tapl.LaunchedAppState;
30 import com.android.launcher3.tapl.LauncherInstrumentation;
31 import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
32 import com.android.launcher3.ui.AbstractLauncherUiTest;
33 import com.android.quickstep.views.RecentsView;
34 
35 import org.junit.rules.RuleChain;
36 import org.junit.rules.TestRule;
37 
38 /**
39  * Base class for all instrumentation tests that deal with Quickstep.
40  */
41 public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest {
42     public static final boolean ENABLE_SHELL_TRANSITIONS =
43             SystemProperties.getBoolean("persist.wm.debug.shell_transit", true);
44     @Override
getRulesInsideActivityMonitor()45     protected TestRule getRulesInsideActivityMonitor() {
46         return RuleChain.
47                 outerRule(new NavigationModeSwitchRule(mLauncher)).
48                 around(new TaskbarModeSwitchRule(mLauncher)).
49                 around(super.getRulesInsideActivityMonitor());
50     }
51 
52     @Override
onLauncherActivityClose(Launcher launcher)53     protected void onLauncherActivityClose(Launcher launcher) {
54         RecentsView recentsView = launcher.getOverviewPanel();
55         if (recentsView != null) {
56             recentsView.finishRecentsAnimation(false /* toRecents */, null);
57         }
58     }
59 
60     @Override
checkLauncherState(Launcher launcher, ContainerType expectedContainerType, boolean isResumed, boolean isStarted)61     protected void checkLauncherState(Launcher launcher, ContainerType expectedContainerType,
62             boolean isResumed, boolean isStarted) {
63         if (ENABLE_SHELL_TRANSITIONS || !isInLiveTileMode(launcher, expectedContainerType)) {
64             super.checkLauncherState(launcher, expectedContainerType, isResumed, isStarted);
65         } else {
66             assertTrue("[Live Tile] hasBeenResumed() == isStarted(), hasBeenResumed(): "
67                             + isResumed, isResumed != isStarted);
68         }
69     }
70 
71     @Override
checkLauncherStateInOverview(Launcher launcher, ContainerType expectedContainerType, boolean isStarted, boolean isResumed)72     protected void checkLauncherStateInOverview(Launcher launcher,
73             ContainerType expectedContainerType, boolean isStarted, boolean isResumed) {
74         if (ENABLE_SHELL_TRANSITIONS || !isInLiveTileMode(launcher, expectedContainerType)) {
75             super.checkLauncherStateInOverview(launcher, expectedContainerType, isStarted,
76                     isResumed);
77         } else {
78             assertTrue(
79                     "[Live Tile] Launcher is not started or has been resumed in state: "
80                             + expectedContainerType,
81                     isStarted && !isResumed);
82         }
83     }
84 
assertTestActivityIsRunning(int activityNumber, String message)85     protected void assertTestActivityIsRunning(int activityNumber, String message) {
86         assertTrue(message, mDevice.wait(
87                 Until.hasObject(By.pkg(getAppPackageName()).text("TestActivity" + activityNumber)),
88                 DEFAULT_UI_TIMEOUT));
89     }
90 
getAndAssertLaunchedApp()91     protected LaunchedAppState getAndAssertLaunchedApp() {
92         final LaunchedAppState launchedAppState = mLauncher.getLaunchedAppState();
93         executeOnLauncher(launcher -> assertTrue(
94                 "Launcher activity is the top activity; expecting another activity to be the top "
95                         + "one",
96                 isInLaunchedApp(launcher)));
97         return launchedAppState;
98     }
99 
isInLiveTileMode(Launcher launcher, LauncherInstrumentation.ContainerType expectedContainerType)100     private boolean isInLiveTileMode(Launcher launcher,
101             LauncherInstrumentation.ContainerType expectedContainerType) {
102         if (expectedContainerType != LauncherInstrumentation.ContainerType.OVERVIEW) {
103             return false;
104         }
105 
106         RecentsView recentsView = launcher.getOverviewPanel();
107         return recentsView.getSizeStrategy().isInLiveTileMode()
108                 && recentsView.getRunningTaskViewId() != -1;
109     }
110 }
111