• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.launcher3.ui;
2 
3 import android.content.pm.LauncherActivityInfo;
4 import android.graphics.Point;
5 import android.os.Process;
6 import android.support.test.uiautomator.By;
7 import android.support.test.uiautomator.UiObject2;
8 import android.support.test.uiautomator.Until;
9 import android.test.suitebuilder.annotation.LargeTest;
10 import android.view.MotionEvent;
11 
12 import com.android.launcher3.R;
13 import com.android.launcher3.compat.LauncherAppsCompat;
14 import com.android.launcher3.util.Condition;
15 import com.android.launcher3.util.Wait;
16 
17 /**
18  * Test for verifying that shortcuts are shown and can be launched after long pressing an app
19  */
20 @LargeTest
21 public class ShortcutsLaunchTest extends LauncherInstrumentationTestCase {
22 
23     private LauncherActivityInfo mSettingsApp;
24 
25     @Override
setUp()26     protected void setUp() throws Exception {
27         super.setUp();
28         setDefaultLauncher();
29 
30         mSettingsApp = LauncherAppsCompat.getInstance(mTargetContext)
31                 .getActivityList("com.android.settings", Process.myUserHandle()).get(0);
32     }
33 
testAppLauncher_portrait()34     public void testAppLauncher_portrait() throws Exception {
35         lockRotation(true);
36         performTest();
37     }
38 
testAppLauncher_landscape()39     public void testAppLauncher_landscape() throws Exception {
40         lockRotation(false);
41         performTest();
42     }
43 
performTest()44     private void performTest() throws Exception {
45         startLauncher();
46 
47         // Open all apps and wait for load complete
48         final UiObject2 appsContainer = openAllApps();
49         assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));
50 
51         // Find settings app and verify shortcuts appear when long pressed
52         UiObject2 icon = scrollAndFind(appsContainer, By.text(mSettingsApp.getLabel().toString()));
53         // Press icon center until shortcuts appear
54         Point iconCenter = icon.getVisibleCenter();
55         sendPointer(MotionEvent.ACTION_DOWN, iconCenter);
56         UiObject2 deepShortcutsContainer = findViewById(R.id.deep_shortcuts_container);
57         assertNotNull(deepShortcutsContainer);
58         sendPointer(MotionEvent.ACTION_UP, iconCenter);
59 
60         // Verify that launching a shortcut opens a page with the same text
61         assertTrue(deepShortcutsContainer.getChildCount() > 0);
62         UiObject2 shortcut = deepShortcutsContainer.getChildren().get(0)
63                 .findObject(getSelectorForId(R.id.bubble_text));
64         shortcut.click();
65         assertTrue(mDevice.wait(Until.hasObject(By.pkg(
66                 mSettingsApp.getComponentName().getPackageName())
67                 .text(shortcut.getText())), DEFAULT_UI_TIMEOUT));
68     }
69 }
70