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.appiconmenu;
17 
18 import static com.android.launcher3.util.TestConstants.AppNames.TEST_APP_NAME;
19 
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 
23 import android.platform.test.annotations.PlatinumTest;
24 
25 import com.android.launcher3.Launcher;
26 import com.android.launcher3.popup.ArrowPopup;
27 import com.android.launcher3.tapl.AllApps;
28 import com.android.launcher3.tapl.AppIconMenu;
29 import com.android.launcher3.tapl.AppIconMenuItem;
30 import com.android.launcher3.tapl.HomeAllApps;
31 import com.android.launcher3.ui.AbstractLauncherUiTest;
32 import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
33 
34 import org.junit.Test;
35 
36 /**
37  * This test run in both Out of process (Oop) and in-process (Ipc).
38  * Tests the AppIconMenu (the menu that appears when you long press an app icon) and also make sure
39  * we can launch a shortcut from it.
40  */
41 public class TaplAppIconMenuTest extends AbstractLauncherUiTest<Launcher> {
42 
isOptionsPopupVisible(Launcher launcher)43     private boolean isOptionsPopupVisible(Launcher launcher) {
44         final ArrowPopup<?> popup = launcher.getOptionsPopup();
45         return popup != null && popup.isShown();
46     }
47 
48     /**
49      * Open All apps then open the AppIconMenu then launch a shortcut from the menu and make sure it
50      * launches.
51      */
52     @Test
53     @PortraitLandscape
54     @PlatinumTest(focusArea = "launcher")
testLaunchMenuItem()55     public void testLaunchMenuItem() {
56         final AllApps allApps = mLauncher.getWorkspace().switchToAllApps();
57         allApps.freeze();
58         try {
59             final AppIconMenu menu = allApps.getAppIcon(TEST_APP_NAME).openDeepShortcutMenu();
60 
61             executeOnLauncher(
62                     launcher -> assertTrue("Launcher internal state didn't switch to Showing Menu",
63                             isOptionsPopupVisible(launcher)));
64 
65             final AppIconMenuItem menuItem = menu.getMenuItem(1);
66             assertEquals("Wrong menu item", "Shortcut 2", menuItem.getText());
67             menuItem.launch(getAppPackageName());
68         } finally {
69             allApps.unfreeze();
70         }
71     }
72 
73     /**
74      * Drag icon from AllApps to the workspace and then open the AppIconMenu and launch a shortcut
75      * from it.
76      */
77     @PlatinumTest(focusArea = "launcher")
78     @Test
testLaunchHomeScreenMenuItem()79     public void testLaunchHomeScreenMenuItem() {
80         // Drag the test app icon to home screen and open short cut menu from the icon
81         final HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
82         allApps.freeze();
83         try {
84             allApps.getAppIcon(TEST_APP_NAME).dragToWorkspace(false, false);
85             final AppIconMenu menu = mLauncher.getWorkspace().getWorkspaceAppIcon(
86                     TEST_APP_NAME).openDeepShortcutMenu();
87 
88             executeOnLauncher(
89                     launcher -> assertTrue("Launcher internal state didn't switch to Showing Menu",
90                             isOptionsPopupVisible(launcher)));
91 
92             final AppIconMenuItem menuItem = menu.getMenuItem(1);
93             assertEquals("Wrong menu item", "Shortcut 2", menuItem.getText());
94             menuItem.launch(getAppPackageName());
95         } finally {
96             allApps.unfreeze();
97         }
98     }
99 }
100