diff options
author | Tony Wickham <twickham@google.com> | 2016-11-14 15:22:52 -0800 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2016-11-14 15:29:10 -0800 |
commit | f38d8593bd8973f50d0101f2e51181b6b39b6e9a (patch) | |
tree | 3d9c6932b3ace1a9aaf0780da01a170da3b31d33 /tests | |
parent | 05b20b0712015da9436ab638cf7cdb68b54958ff (diff) | |
download | android_packages_apps_Trebuchet-f38d8593bd8973f50d0101f2e51181b6b39b6e9a.tar.gz android_packages_apps_Trebuchet-f38d8593bd8973f50d0101f2e51181b6b39b6e9a.tar.bz2 android_packages_apps_Trebuchet-f38d8593bd8973f50d0101f2e51181b6b39b6e9a.zip |
Add ShortcutsLaunchTest and ShortcutsToHomeTest.
- ShortcutsLaunchTest verifies that launching shortcut
from the deep shortcuts container works.
- ShortcutsToHomeTest verifies that shortcuts can be
dragged from the deep shortcuts container.
Change-Id: I6919b69d4ea1c9e0f13a8f236266745c12ef0715
Diffstat (limited to 'tests')
3 files changed, 143 insertions, 1 deletions
diff --git a/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java b/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java index f592c57c0..fcf712227 100644 --- a/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java +++ b/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java @@ -196,7 +196,7 @@ public class LauncherInstrumentationTestCase extends InstrumentationTestCase { } } - private void sendPointer(int action, Point point) { + protected void sendPointer(int action, Point point) { MotionEvent event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), action, point.x, point.y, 0); getInstrumentation().sendPointerSync(event); diff --git a/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java b/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java new file mode 100644 index 000000000..f892e6349 --- /dev/null +++ b/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java @@ -0,0 +1,68 @@ +package com.android.launcher3.ui; + +import android.graphics.Point; +import android.support.test.uiautomator.By; +import android.support.test.uiautomator.UiObject2; +import android.support.test.uiautomator.Until; +import android.test.suitebuilder.annotation.LargeTest; +import android.view.MotionEvent; + +import com.android.launcher3.R; +import com.android.launcher3.compat.LauncherActivityInfoCompat; +import com.android.launcher3.compat.LauncherAppsCompat; +import com.android.launcher3.compat.UserHandleCompat; +import com.android.launcher3.util.Condition; +import com.android.launcher3.util.Wait; + +/** + * Test for verifying that shortcuts are shown and can be launched after long pressing an app + */ +@LargeTest +public class ShortcutsLaunchTest extends LauncherInstrumentationTestCase { + + private LauncherActivityInfoCompat mSettingsApp; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mSettingsApp = LauncherAppsCompat.getInstance(mTargetContext) + .getActivityList("com.android.settings", UserHandleCompat.myUserHandle()).get(0); + } + + public void testAppLauncher_portrait() throws Exception { + lockRotation(true); + performTest(); + } + + public void testAppLauncher_landscape() throws Exception { + lockRotation(false); + performTest(); + } + + private void performTest() throws Exception { + startLauncher(); + + // Open all apps and wait for load complete + final UiObject2 appsContainer = openAllApps(); + assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT)); + + // Find settings app and verify shortcuts appear when long pressed + UiObject2 icon = scrollAndFind(appsContainer, By.text(mSettingsApp.getLabel().toString())); + // Press icon center until shortcuts appear + Point iconCenter = icon.getVisibleCenter(); + sendPointer(MotionEvent.ACTION_DOWN, iconCenter); + UiObject2 deepShortcutsContainer = findViewById(R.id.deep_shortcuts_container); + assertNotNull(deepShortcutsContainer); + sendPointer(MotionEvent.ACTION_UP, iconCenter); + + // Verify that launching a shortcut opens a page with the same text + assertTrue(deepShortcutsContainer.getChildCount() > 0); + UiObject2 shortcut = deepShortcutsContainer.getChildren().get(0) + .findObject(getSelectorForId(R.id.deep_shortcut)); + shortcut.click(); + assertTrue(mDevice.wait(Until.hasObject(By.pkg( + mSettingsApp.getComponentName().getPackageName()) + .text(shortcut.getText())), DEFAULT_UI_TIMEOUT)); + } +} diff --git a/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java b/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java new file mode 100644 index 000000000..f9a0e6eaa --- /dev/null +++ b/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java @@ -0,0 +1,74 @@ +package com.android.launcher3.ui; + +import android.graphics.Point; +import android.support.test.uiautomator.By; +import android.support.test.uiautomator.UiObject2; +import android.support.test.uiautomator.Until; +import android.test.suitebuilder.annotation.LargeTest; +import android.view.MotionEvent; + +import com.android.launcher3.R; +import com.android.launcher3.compat.LauncherActivityInfoCompat; +import com.android.launcher3.compat.LauncherAppsCompat; +import com.android.launcher3.compat.UserHandleCompat; +import com.android.launcher3.util.Condition; +import com.android.launcher3.util.Wait; + +/** + * Test for dragging a deep shortcut to the home screen. + */ +@LargeTest +public class ShortcutsToHomeTest extends LauncherInstrumentationTestCase { + + private LauncherActivityInfoCompat mSettingsApp; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mSettingsApp = LauncherAppsCompat.getInstance(mTargetContext) + .getActivityList("com.android.settings", UserHandleCompat.myUserHandle()).get(0); + } + + public void testDragIcon_portrait() throws Throwable { + lockRotation(true); + performTest(); + } + + public void testDragIcon_landscape() throws Throwable { + lockRotation(false); + performTest(); + } + + private void performTest() throws Throwable { + clearHomescreen(); + startLauncher(); + + // Open all apps and wait for load complete. + final UiObject2 appsContainer = openAllApps(); + assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT)); + + // Find the app and long press it to show shortcuts. + UiObject2 icon = scrollAndFind(appsContainer, By.text(mSettingsApp.getLabel().toString())); + // Press icon center until shortcuts appear + Point iconCenter = icon.getVisibleCenter(); + sendPointer(MotionEvent.ACTION_DOWN, iconCenter); + UiObject2 deepShortcutsContainer = findViewById(R.id.deep_shortcuts_container); + assertNotNull(deepShortcutsContainer); + sendPointer(MotionEvent.ACTION_UP, iconCenter); + + // Drag the first shortcut to the home screen. + assertTrue(deepShortcutsContainer.getChildCount() > 0); + UiObject2 shortcut = deepShortcutsContainer.getChildren().get(0) + .findObject(getSelectorForId(R.id.deep_shortcut)); + String shortcutName = shortcut.getText(); + dragToWorkspace(shortcut, false); + + // Verify that the shortcut works on home screen + // (the app opens and has the same text as the shortcut). + mDevice.findObject(By.text(shortcutName)).click(); + assertTrue(mDevice.wait(Until.hasObject(By.pkg( + mSettingsApp.getComponentName().getPackageName()) + .text(shortcutName)), DEFAULT_UI_TIMEOUT)); + } +} |