Home | History | Annotate | Download | only in ui
      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 dragging a deep shortcut to the home screen.
     19  */
     20 @LargeTest
     21 public class ShortcutsToHomeTest extends LauncherInstrumentationTestCase {
     22 
     23     private LauncherActivityInfo mSettingsApp;
     24 
     25     @Override
     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 
     34     public void testDragIcon_portrait() throws Throwable {
     35         lockRotation(true);
     36         performTest();
     37     }
     38 
     39     public void testDragIcon_landscape() throws Throwable {
     40         lockRotation(false);
     41         performTest();
     42     }
     43 
     44     private void performTest() throws Throwable {
     45         clearHomescreen();
     46         startLauncher();
     47 
     48         // Open all apps and wait for load complete.
     49         final UiObject2 appsContainer = openAllApps();
     50         assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));
     51 
     52         // Find the app and long press it to show shortcuts.
     53         UiObject2 icon = scrollAndFind(appsContainer, By.text(mSettingsApp.getLabel().toString()));
     54         // Press icon center until shortcuts appear
     55         Point iconCenter = icon.getVisibleCenter();
     56         sendPointer(MotionEvent.ACTION_DOWN, iconCenter);
     57         UiObject2 deepShortcutsContainer = findViewById(R.id.deep_shortcuts_container);
     58         assertNotNull(deepShortcutsContainer);
     59         sendPointer(MotionEvent.ACTION_UP, iconCenter);
     60 
     61         // Drag the first shortcut to the home screen.
     62         assertTrue(deepShortcutsContainer.getChildCount() > 0);
     63         UiObject2 shortcut = deepShortcutsContainer.getChildren().get(0)
     64                 .findObject(getSelectorForId(R.id.bubble_text));
     65         String shortcutName = shortcut.getText();
     66         dragToWorkspace(shortcut, false);
     67 
     68         // Verify that the shortcut works on home screen
     69         // (the app opens and has the same text as the shortcut).
     70         mDevice.findObject(By.text(shortcutName)).click();
     71         assertTrue(mDevice.wait(Until.hasObject(By.pkg(
     72                 mSettingsApp.getComponentName().getPackageName())
     73                 .text(shortcutName)), DEFAULT_UI_TIMEOUT));
     74     }
     75 }
     76