1 package com.android.launcher3.ui; 2 3 import android.content.pm.LauncherActivityInfo; 4 import android.support.test.filters.LargeTest; 5 import android.support.test.runner.AndroidJUnit4; 6 import android.support.test.uiautomator.By; 7 import android.support.test.uiautomator.UiObject2; 8 import android.support.test.uiautomator.Until; 9 10 import com.android.launcher3.util.Condition; 11 import com.android.launcher3.util.Wait; 12 import com.android.launcher3.util.rule.LauncherActivityRule; 13 import com.android.launcher3.util.rule.ShellCommandRule; 14 15 import org.junit.Rule; 16 import org.junit.Test; 17 import org.junit.runner.RunWith; 18 19 import static org.junit.Assert.assertTrue; 20 21 /** 22 * Test for dragging an icon from all-apps to homescreen. 23 */ 24 @LargeTest 25 @RunWith(AndroidJUnit4.class) 26 public class AllAppsIconToHomeTest extends AbstractLauncherUiTest { 27 28 @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); 29 @Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher(); 30 31 @Test testDragIcon_portrait()32 public void testDragIcon_portrait() throws Throwable { 33 lockRotation(true); 34 performTest(); 35 } 36 37 @Test testDragIcon_landscape()38 public void testDragIcon_landscape() throws Throwable { 39 lockRotation(false); 40 performTest(); 41 } 42 performTest()43 private void performTest() throws Throwable { 44 LauncherActivityInfo settingsApp = getSettingsApp(); 45 46 clearHomescreen(); 47 mActivityMonitor.startLauncher(); 48 49 // Open all apps and wait for load complete. 50 final UiObject2 appsContainer = openAllApps(); 51 assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT)); 52 53 // Drag icon to homescreen. 54 UiObject2 icon = scrollAndFind(appsContainer, By.text(settingsApp.getLabel().toString())); 55 dragToWorkspace(icon, true); 56 57 // Verify that the icon works on homescreen. 58 mDevice.findObject(By.text(settingsApp.getLabel().toString())).click(); 59 assertTrue(mDevice.wait(Until.hasObject(By.pkg( 60 settingsApp.getComponentName().getPackageName()).depth(0)), DEFAULT_UI_TIMEOUT)); 61 } 62 } 63