1 package com.android.launcher3.ui; 2 3 import android.content.pm.LauncherActivityInfo; 4 import android.graphics.Point; 5 import android.support.test.filters.LargeTest; 6 import android.support.test.runner.AndroidJUnit4; 7 import android.support.test.uiautomator.By; 8 import android.support.test.uiautomator.UiObject2; 9 import android.support.test.uiautomator.Until; 10 import android.view.MotionEvent; 11 12 import com.android.launcher3.R; 13 import com.android.launcher3.util.Condition; 14 import com.android.launcher3.util.Wait; 15 import com.android.launcher3.util.rule.LauncherActivityRule; 16 import com.android.launcher3.util.rule.ShellCommandRule; 17 18 import org.junit.Rule; 19 import org.junit.Test; 20 import org.junit.runner.RunWith; 21 22 import static org.junit.Assert.assertNotNull; 23 import static org.junit.Assert.assertTrue; 24 25 /** 26 * Test for dragging a deep shortcut to the home screen. 27 */ 28 @LargeTest 29 @RunWith(AndroidJUnit4.class) 30 public class ShortcutsToHomeTest extends AbstractLauncherUiTest { 31 32 @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); 33 @Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher(); 34 35 @Test testDragIcon_portrait()36 public void testDragIcon_portrait() throws Throwable { 37 lockRotation(true); 38 performTest(); 39 } 40 41 @Test testDragIcon_landscape()42 public void testDragIcon_landscape() throws Throwable { 43 lockRotation(false); 44 performTest(); 45 } 46 performTest()47 private void performTest() throws Throwable { 48 clearHomescreen(); 49 mActivityMonitor.startLauncher(); 50 51 LauncherActivityInfo settingsApp = getSettingsApp(); 52 53 // Open all apps and wait for load complete. 54 final UiObject2 appsContainer = openAllApps(); 55 assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT)); 56 57 // Find the app and long press it to show shortcuts. 58 UiObject2 icon = scrollAndFind(appsContainer, By.text(settingsApp.getLabel().toString())); 59 // Press icon center until shortcuts appear 60 Point iconCenter = icon.getVisibleCenter(); 61 sendPointer(MotionEvent.ACTION_DOWN, iconCenter); 62 UiObject2 deepShortcutsContainer = findViewById(R.id.deep_shortcuts_container); 63 assertNotNull(deepShortcutsContainer); 64 sendPointer(MotionEvent.ACTION_UP, iconCenter); 65 66 // Drag the first shortcut to the home screen. 67 assertTrue(deepShortcutsContainer.getChildCount() > 0); 68 UiObject2 shortcut = deepShortcutsContainer.getChildren().get(0) 69 .findObject(getSelectorForId(R.id.bubble_text)); 70 String shortcutName = shortcut.getText(); 71 dragToWorkspace(shortcut, false); 72 73 // Verify that the shortcut works on home screen 74 // (the app opens and has the same text as the shortcut). 75 mDevice.findObject(By.text(shortcutName)).click(); 76 assertTrue(mDevice.wait(Until.hasObject(By.pkg( 77 settingsApp.getComponentName().getPackageName()) 78 .text(shortcutName)), DEFAULT_UI_TIMEOUT)); 79 } 80 } 81