• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.launcher3.allapps;
17 
18 import static com.android.launcher3.util.TestUtil.expectFail;
19 
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assume.assumeTrue;
24 
25 import android.content.Intent;
26 import android.platform.test.annotations.PlatinumTest;
27 
28 import androidx.test.platform.app.InstrumentationRegistry;
29 
30 import com.android.launcher3.Launcher;
31 import com.android.launcher3.LauncherState;
32 import com.android.launcher3.tapl.AllApps;
33 import com.android.launcher3.ui.AbstractLauncherUiTest;
34 import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
35 
36 import org.junit.Test;
37 
38 /**
39  * Test that we can open and close the all apps in multiple situations.
40  * The test runs in Out of process (Oop) and in process.
41  */
42 public class TaplOpenCloseAllAppsTest extends AbstractLauncherUiTest<Launcher> {
43 
44     public static final String READ_DEVICE_CONFIG_PERMISSION =
45             "android.permission.READ_DEVICE_CONFIG";
46 
47     /**
48      * Make sure we can go home after pressing the context menu on an Icon on the AllApps.
49      */
50     @Test
testPressHomeOnAllAppsContextMenu()51     public void testPressHomeOnAllAppsContextMenu() {
52         final AllApps allApps = mLauncher.getWorkspace().switchToAllApps();
53         allApps.freeze();
54         try {
55             allApps.getAppIcon("TestActivity7").openMenu();
56         } finally {
57             allApps.unfreeze();
58         }
59         mLauncher.goHome();
60     }
61 
62     /**
63      * Make sure we can open AllApps from the Workspace.
64      */
65     @Test
66     @PortraitLandscape
testWorkspaceSwitchToAllApps()67     public void testWorkspaceSwitchToAllApps() {
68         assertNotNull("switchToAllApps() returned null",
69                 mLauncher.getWorkspace().switchToAllApps());
70         assertTrue("Launcher internal state is not All Apps",
71                 isInState(() -> LauncherState.ALL_APPS));
72     }
73 
74     /**
75      * Make sure we can go to Workspace from AllApps
76      */
77     @Test
78     @PortraitLandscape
testAllAppsSwitchToWorkspace()79     public void testAllAppsSwitchToWorkspace() {
80         assertNotNull("switchToWorkspace() returned null",
81                 mLauncher.getWorkspace().switchToAllApps()
82                         .switchToWorkspace(/* swipeDown= */ true));
83         assertTrue("Launcher internal state is not Workspace",
84                 isInState(() -> LauncherState.NORMAL));
85     }
86 
87     /**
88      * Make sure the swipe up gesture can take us back to the workspace from AllApps
89      */
90     @PlatinumTest(focusArea = "launcher")
91     @Test
92     @PortraitLandscape
testAllAppsSwipeUpToWorkspace()93     public void testAllAppsSwipeUpToWorkspace() {
94         assertNotNull("testAllAppsSwipeUpToWorkspace() returned null",
95                 mLauncher.getWorkspace().switchToAllApps()
96                         .switchToWorkspace(/* swipeDown= */ false));
97         assertTrue("Launcher internal state is not Workspace",
98                 isInState(() -> LauncherState.NORMAL));
99     }
100 
101     /**
102      * Make sure we can go to the Workspace from AllApps on tablets by tapping on the background.
103      */
104     @Test
105     @PortraitLandscape
testAllAppsDeadzoneForTablet()106     public void testAllAppsDeadzoneForTablet() {
107         assumeTrue(mLauncher.isTablet());
108 
109         mLauncher.getWorkspace().switchToAllApps().dismissByTappingOutsideForTablet(
110                 true /* tapRight */);
111         mLauncher.getWorkspace().switchToAllApps().dismissByTappingOutsideForTablet(
112                 false /* tapRight */);
113     }
114 
115     /**
116      * Make sure that AllApps closes when pressing the home button
117      */
118     @Test
119     @PortraitLandscape
120     @PlatinumTest(focusArea = "launcher")
testAllAppsFromHome()121     public void testAllAppsFromHome() {
122         // Test opening all apps
123         assertNotNull("switchToAllApps() returned null",
124                 mLauncher.getWorkspace().switchToAllApps());
125 
126         runAllAppsTest(mLauncher.getAllApps());
127 
128         // Testing pressHome.
129         assertTrue("Launcher internal state is not All Apps",
130                 isInState(() -> LauncherState.ALL_APPS));
131         assertNotNull("pressHome returned null", mLauncher.goHome());
132         assertTrue("Launcher internal state is not Home",
133                 isInState(() -> LauncherState.NORMAL));
134         assertNotNull("getHome returned null", mLauncher.getWorkspace());
135     }
136 
137     /**
138      * Makes sure the state of AllApps is correct.
139      */
runAllAppsTest(AllApps allApps)140     public void runAllAppsTest(AllApps allApps) {
141         allApps.freeze();
142         try {
143             assertNotNull("allApps parameter is null", allApps);
144 
145             assertTrue(
146                     "Launcher internal state is not All Apps",
147                     isInState(() -> LauncherState.ALL_APPS));
148 
149             // Test flinging forward and backward.
150             executeOnLauncher(launcher -> assertEquals(
151                     "All Apps started in already scrolled state", 0,
152                     getAllAppsScroll(launcher)));
153 
154             allApps.flingForward();
155             assertTrue("Launcher internal state is not All Apps",
156                     isInState(() -> LauncherState.ALL_APPS));
157             final Integer flingForwardY = getFromLauncher(
158                     launcher -> getAllAppsScroll(launcher));
159             executeOnLauncher(
160                     launcher -> assertTrue("flingForward() didn't scroll App Apps",
161                             flingForwardY > 0));
162 
163             allApps.flingBackward();
164             assertTrue(
165                     "Launcher internal state is not All Apps",
166                     isInState(() -> LauncherState.ALL_APPS));
167             final Integer flingBackwardY = getFromLauncher(
168                     launcher -> getAllAppsScroll(launcher));
169             executeOnLauncher(launcher -> assertTrue("flingBackward() didn't scroll App Apps",
170                     flingBackwardY < flingForwardY));
171 
172             // Test scrolling down to the end of the app list.
173             assertNotNull("All apps: can't find YouTube", allApps.getAppIcon("ZZZ"));
174             // Test scrolling up to the beginning oof the app list.
175             assertNotNull("All apps: can't find Camera", allApps.getAppIcon("AAA"));
176             // Test failing to find a non-existing app.
177             final AllApps allAppsFinal = allApps;
178             expectFail("All apps: could find a non-existing app",
179                     () -> allAppsFinal.getAppIcon("NO APP"));
180 
181             assertTrue(
182                     "Launcher internal state is not All Apps",
183                     isInState(() -> LauncherState.ALL_APPS));
184         } finally {
185             allApps.unfreeze();
186         }
187     }
188 
189     /**
190      * Makes sure that when pressing back when AllApps is open we go back to the Home screen.
191      */
192     @Test
193     @PortraitLandscape
testPressBackFromAllAppsToHome()194     public void testPressBackFromAllAppsToHome() {
195         InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(
196                 READ_DEVICE_CONFIG_PERMISSION);
197         mLauncher
198                 .getWorkspace()
199                 .switchToAllApps()
200                 .pressBackToWorkspace();
201         waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
202         startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
203         mLauncher.getLaunchedAppState().pressBackToWorkspace();
204         waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
205     }
206 
207     @Test
testDismissAllAppsWithEscKey()208     public void testDismissAllAppsWithEscKey() {
209         mLauncher.goHome().switchToAllApps().dismissByEscKey();
210         waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
211     }
212 }
213