summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVadim Tryshev <vadimt@google.com>2018-08-23 13:37:38 -0700
committerVadim Tryshev <vadimt@google.com>2018-11-01 17:45:59 -0700
commitba8957b3c215cf92376cafbdd52d08c2b0852420 (patch)
tree0d530449ffb2ebcdf3479eacddc62a2d3bd7bb57 /tests
parentb3fe661860c6ec909d4726103e9c7d10434a0455 (diff)
downloadandroid_packages_apps_Trebuchet-ba8957b3c215cf92376cafbdd52d08c2b0852420.tar.gz
android_packages_apps_Trebuchet-ba8957b3c215cf92376cafbdd52d08c2b0852420.tar.bz2
android_packages_apps_Trebuchet-ba8957b3c215cf92376cafbdd52d08c2b0852420.zip
Converting ShortcutsLaunchTest gesture-stable
By converting to TAPL. Bug: 110103162 Test; TaplTests Change-Id: I788405f2e52cc0e29ebf69e58feda46b408e9eb9
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java5
-rw-r--r--tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java64
-rw-r--r--tests/tapl/com/android/launcher3/tapl/AppIcon.java12
-rw-r--r--tests/tapl/com/android/launcher3/tapl/AppIconMenu.java46
-rw-r--r--tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java52
-rw-r--r--tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java19
6 files changed, 146 insertions, 52 deletions
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index 532d3e8b0..bc5aaeeb7 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -296,11 +296,6 @@ public abstract class AbstractLauncherUiTest {
Process.myUserHandle()).get(0);
}
- protected LauncherActivityInfo getChromeApp() {
- return LauncherAppsCompat.getInstance(mTargetContext)
- .getActivityList("com.android.chrome", Process.myUserHandle()).get(0);
- }
-
/**
* Broadcast receiver which blocks until the result is received.
*/
diff --git a/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java b/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java
index d7a7f6bbe..e95801a00 100644
--- a/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java
+++ b/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java
@@ -1,22 +1,20 @@
package com.android.launcher3.ui;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.content.pm.LauncherActivityInfo;
-import android.graphics.Point;
+
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
-import android.view.MotionEvent;
-import com.android.launcher3.R;
-import com.android.launcher3.util.Condition;
-import com.android.launcher3.util.Wait;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.popup.ArrowPopup;
+import com.android.launcher3.tapl.AppIconMenu;
+import com.android.launcher3.tapl.AppIconMenuItem;
+import com.android.launcher3.views.OptionsPopupView;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -27,47 +25,33 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ShortcutsLaunchTest extends AbstractLauncherUiTest {
- @Test
- @Ignore
- public void testAppLauncher_portrait() throws Exception {
- lockRotation(true);
- performTest();
+ private boolean isOptionsPopupVisible(Launcher launcher) {
+ final ArrowPopup popup = OptionsPopupView.getOptionsPopup(launcher);
+ return popup != null && popup.isShown();
}
@Test
- @Ignore
- public void testAppLauncher_landscape() throws Exception {
- lockRotation(false);
- performTest();
- }
-
- private void performTest() throws Exception {
+ @PortraitLandscape
+ public void testAppLauncher() throws Exception {
mActivityMonitor.startLauncher();
- LauncherActivityInfo testApp = getSettingsApp();
+ final LauncherActivityInfo testApp = getSettingsApp();
- // Open all apps and wait for load complete
- final UiObject2 appsContainer = TestViewHelpers.openAllApps();
- Wait.atMost(null, Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT);
+ final AppIconMenu menu = mLauncher.
+ pressHome().
+ switchToAllApps().
+ getAppIcon(testApp.getLabel().toString()).
+ openMenu();
- // Find settings app and verify shortcuts appear when long pressed
- UiObject2 icon = scrollAndFind(appsContainer, By.text(testApp.getLabel().toString()));
- // Press icon center until shortcuts appear
- Point iconCenter = icon.getVisibleCenter();
- TestViewHelpers.sendPointer(MotionEvent.ACTION_DOWN, iconCenter);
- UiObject2 deepShortcutsContainer = TestViewHelpers.findViewById(
- R.id.deep_shortcuts_container);
- assertNotNull(deepShortcutsContainer);
- TestViewHelpers.sendPointer(MotionEvent.ACTION_UP, iconCenter);
+ executeOnLauncher(
+ launcher -> assertTrue("Launcher internal state didn't switch to Showing Menu",
+ isOptionsPopupVisible(launcher)));
- // Verify that launching a shortcut opens a page with the same text
- assertTrue(deepShortcutsContainer.getChildCount() > 0);
+ final AppIconMenuItem menuItem = menu.getMenuItem(1);
+ final String itemName = menuItem.getText();
- // Pick second children as it starts showing shortcuts.
- UiObject2 shortcut = deepShortcutsContainer.getChildren().get(1)
- .findObject(TestViewHelpers.getSelectorForId(R.id.bubble_text));
- shortcut.click();
+ menuItem.launch();
assertTrue(mDevice.wait(Until.hasObject(By.pkg(
testApp.getComponentName().getPackageName())
- .text(shortcut.getText())), DEFAULT_UI_TIMEOUT));
+ .text(itemName)), DEFAULT_UI_TIMEOUT));
}
}
diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java
index b7ae9f149..1c0ecb933 100644
--- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java
+++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java
@@ -16,6 +16,7 @@
package com.android.launcher3.tapl;
+import android.graphics.Point;
import android.widget.TextView;
import androidx.test.uiautomator.By;
@@ -56,4 +57,15 @@ public final class AppIcon {
UiObject2 getIcon() {
return mIcon;
}
+
+ /**
+ * Long-clicks the icon to open its menu.
+ */
+ public AppIconMenu openMenu() {
+ final Point iconCenter = mIcon.getVisibleCenter();
+ mLauncher.longTap(iconCenter.x, iconCenter.y);
+ final UiObject2 deepShortcutsContainer = mLauncher.waitForLauncherObject(
+ "deep_shortcuts_container");
+ return new AppIconMenu(mLauncher, deepShortcutsContainer);
+ }
}
diff --git a/tests/tapl/com/android/launcher3/tapl/AppIconMenu.java b/tests/tapl/com/android/launcher3/tapl/AppIconMenu.java
new file mode 100644
index 000000000..2a03f9a08
--- /dev/null
+++ b/tests/tapl/com/android/launcher3/tapl/AppIconMenu.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.tapl;
+
+import static org.junit.Assert.assertTrue;
+
+import androidx.test.uiautomator.UiObject2;
+
+/**
+ * Context menu of an app icon.
+ */
+public class AppIconMenu {
+ private final LauncherInstrumentation mLauncher;
+ private final UiObject2 mDeepShortcutsContainer;
+
+ AppIconMenu(LauncherInstrumentation launcher,
+ UiObject2 deepShortcutsContainer) {
+ mLauncher = launcher;
+ mDeepShortcutsContainer = deepShortcutsContainer;
+ }
+
+ /**
+ * Returns a menu item with a given number. Fails if it doesn't exist.
+ */
+ public AppIconMenuItem getMenuItem(int itemNumber) {
+ assertTrue(mDeepShortcutsContainer.getChildCount() > itemNumber);
+
+ final UiObject2 shortcut = mLauncher.waitForObjectInContainer(
+ mDeepShortcutsContainer.getChildren().get(itemNumber), "bubble_text");
+ return new AppIconMenuItem(mLauncher, shortcut);
+ }
+}
diff --git a/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java b/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java
new file mode 100644
index 000000000..7b2abeb75
--- /dev/null
+++ b/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.tapl;
+
+import static org.junit.Assert.assertTrue;
+
+import androidx.test.uiautomator.UiObject2;
+import androidx.test.uiautomator.Until;
+
+/**
+ * Menu item in an app icon menu.
+ */
+public class AppIconMenuItem {
+ private final LauncherInstrumentation mLauncher;
+ final UiObject2 mShortcut;
+
+ AppIconMenuItem(LauncherInstrumentation launcher,
+ UiObject2 shortcut) {
+ mLauncher = launcher;
+ mShortcut = shortcut;
+ }
+
+ /**
+ * Returns the visible text of the menu item.
+ */
+ public String getText() {
+ return mShortcut.getText();
+ }
+
+ /**
+ * Launches the action for the menu item.
+ */
+ public Background launch() {
+ assertTrue("Clicking a menu item didn't open a new window: " + mShortcut.getText(),
+ mShortcut.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS));
+ return new Background(mLauncher);
+ }
+}
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 31abc53c9..67106f7ea 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -28,6 +28,13 @@ import android.util.Log;
import android.view.Surface;
import android.view.accessibility.AccessibilityEvent;
+import androidx.annotation.NonNull;
+import androidx.test.uiautomator.By;
+import androidx.test.uiautomator.BySelector;
+import androidx.test.uiautomator.UiDevice;
+import androidx.test.uiautomator.UiObject2;
+import androidx.test.uiautomator.Until;
+
import com.android.launcher3.TestProtocol;
import com.android.quickstep.SwipeUpSetting;
@@ -36,13 +43,6 @@ import org.junit.Assert;
import java.lang.ref.WeakReference;
import java.util.concurrent.TimeoutException;
-import androidx.annotation.NonNull;
-import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.BySelector;
-import androidx.test.uiautomator.UiDevice;
-import androidx.test.uiautomator.UiObject2;
-import androidx.test.uiautomator.Until;
-
/**
* The main tapl object. The only object that can be explicitly constructed by the using code. It
* produces all other objects.
@@ -394,6 +394,11 @@ public final class LauncherInstrumentation {
return mDevice;
}
+ void longTap(int x, int y) {
+ mDevice.drag(x, y, x, y, 0);
+ }
+
+
void swipe(int startX, int startY, int endX, int endY) {
executeAndWaitForEvent(
() -> mDevice.swipe(startX, startY, endX, endY, 60),