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 org.junit.Assert.assertTrue;
20 
21 import android.os.SystemProperties;
22 
23 import androidx.test.uiautomator.By;
24 import androidx.test.uiautomator.Until;
25 
26 import com.android.launcher3.tapl.LaunchedAppState;
27 import com.android.launcher3.ui.AbstractLauncherUiTest;
28 import com.android.launcher3.uioverrides.QuickstepLauncher;
29 import com.android.quickstep.views.RecentsView;
30 
31 import org.junit.rules.RuleChain;
32 import org.junit.rules.TestRule;
33 
34 /**
35  * Base class for all instrumentation tests that deal with Quickstep.
36  */
37 public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest<QuickstepLauncher> {
38     public static final boolean ENABLE_SHELL_TRANSITIONS =
39             SystemProperties.getBoolean("persist.wm.debug.shell_transit", true);
40     @Override
getRulesInsideActivityMonitor()41     protected TestRule getRulesInsideActivityMonitor() {
42         return RuleChain.
43                 outerRule(new NavigationModeSwitchRule(mLauncher)).
44                 around(new TaskbarModeSwitchRule(mLauncher)).
45                 around(super.getRulesInsideActivityMonitor());
46     }
47 
48     @Override
onLauncherActivityClose(QuickstepLauncher launcher)49     protected void onLauncherActivityClose(QuickstepLauncher launcher) {
50         RecentsView recentsView = launcher.getOverviewPanel();
51         if (recentsView != null) {
52             recentsView.finishRecentsAnimation(false /* toRecents */, null);
53         }
54     }
55 
assertTestActivityIsRunning(int activityNumber, String message)56     protected void assertTestActivityIsRunning(int activityNumber, String message) {
57         assertTrue(message, mDevice.wait(
58                 Until.hasObject(By.pkg(getAppPackageName()).text("TestActivity" + activityNumber)),
59                 DEFAULT_UI_TIMEOUT));
60     }
61 
getAndAssertLaunchedApp()62     protected LaunchedAppState getAndAssertLaunchedApp() {
63         final LaunchedAppState launchedAppState = mLauncher.getLaunchedAppState();
64         executeOnLauncher(launcher -> assertTrue(
65                 "Launcher activity is the top activity; expecting another activity to be the top "
66                         + "one",
67                 isInLaunchedApp(launcher)));
68         return launchedAppState;
69     }
70 }
71