summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorvadimt <vadimt@google.com>2019-06-04 13:59:43 -0700
committervadimt <vadimt@google.com>2019-06-06 11:10:56 -0700
commitd4c90e12e9b6b61d3c0374ee5899425c84ffe65b (patch)
tree689ab03575a555087992e67640d0a7a334e4e19e /tests
parent8474ab2b9dfb05daf82f0afe3f05181a2e40b89c (diff)
downloadandroid_packages_apps_Trebuchet-d4c90e12e9b6b61d3c0374ee5899425c84ffe65b.tar.gz
android_packages_apps_Trebuchet-d4c90e12e9b6b61d3c0374ee5899425c84ffe65b.tar.bz2
android_packages_apps_Trebuchet-d4c90e12e9b6b61d3c0374ee5899425c84ffe65b.zip
Freezing all apps updates during certain tests
This CL adds a very low risk because most (but not all) changes affect only Launcher behavior during the test. This should fix a lab-only flake when all apps keeps changing while the test is working with it. Example: test figures out which icon to click, by the moment it clicks there, there is another icon there, or the icon is under the search box, and clicking opens IME. Switching test devices to airplane mode didn't help. The earlier change that prevents popup menu cancellation is not general enough. Now the tests are given an API to explicitly freeze and unfreeze all-apps, which should be a final solution. Bug: 132900132 Bug: 133765434 Change-Id: I8b81cc9be004482beb6cdcdd05406e2d9b4c7629
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java184
-rw-r--r--tests/tapl/com/android/launcher3/tapl/AllApps.java22
-rw-r--r--tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java6
3 files changed, 138 insertions, 74 deletions
diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
index 4f8b87c51..d171004fc 100644
--- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
+++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
@@ -108,47 +108,63 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
@Test
@Ignore
public void testPressHomeOnAllAppsContextMenu() throws Exception {
- mLauncher.getWorkspace().switchToAllApps().getAppIcon("TestActivity7").openMenu();
+ final AllApps allApps = mLauncher.getWorkspace().switchToAllApps();
+ allApps.freeze();
+ try {
+ allApps.getAppIcon("TestActivity7").openMenu();
+ } finally {
+ allApps.unfreeze();
+ }
mLauncher.pressHome();
}
public static void runAllAppsTest(AbstractLauncherUiTest test, AllApps allApps) {
- assertNotNull("allApps parameter is null", allApps);
-
- assertTrue(
- "Launcher internal state is not All Apps", test.isInState(LauncherState.ALL_APPS));
-
- // Test flinging forward and backward.
- test.executeOnLauncher(launcher -> assertEquals(
- "All Apps started in already scrolled state", 0, test.getAllAppsScroll(launcher)));
-
- allApps.flingForward();
- assertTrue("Launcher internal state is not All Apps",
- test.isInState(LauncherState.ALL_APPS));
- final Integer flingForwardY = test.getFromLauncher(
- launcher -> test.getAllAppsScroll(launcher));
- test.executeOnLauncher(
- launcher -> assertTrue("flingForward() didn't scroll App Apps", flingForwardY > 0));
-
- allApps.flingBackward();
- assertTrue(
- "Launcher internal state is not All Apps", test.isInState(LauncherState.ALL_APPS));
- final Integer flingBackwardY = test.getFromLauncher(
- launcher -> test.getAllAppsScroll(launcher));
- test.executeOnLauncher(launcher -> assertTrue("flingBackward() didn't scroll App Apps",
- flingBackwardY < flingForwardY));
-
- // Test scrolling down to YouTube.
- assertNotNull("All apps: can't fine YouTube", allApps.getAppIcon("YouTube"));
- // Test scrolling up to Camera.
- assertNotNull("All apps: can't fine Camera", allApps.getAppIcon("Camera"));
- // Test failing to find a non-existing app.
- final AllApps allAppsFinal = allApps;
- expectFail("All apps: could find a non-existing app",
- () -> allAppsFinal.getAppIcon("NO APP"));
-
- assertTrue(
- "Launcher internal state is not All Apps", test.isInState(LauncherState.ALL_APPS));
+ allApps.freeze();
+ try {
+ assertNotNull("allApps parameter is null", allApps);
+
+ assertTrue(
+ "Launcher internal state is not All Apps",
+ test.isInState(LauncherState.ALL_APPS));
+
+ // Test flinging forward and backward.
+ test.executeOnLauncher(launcher -> assertEquals(
+ "All Apps started in already scrolled state", 0,
+ test.getAllAppsScroll(launcher)));
+
+ allApps.flingForward();
+ assertTrue("Launcher internal state is not All Apps",
+ test.isInState(LauncherState.ALL_APPS));
+ final Integer flingForwardY = test.getFromLauncher(
+ launcher -> test.getAllAppsScroll(launcher));
+ test.executeOnLauncher(
+ launcher -> assertTrue("flingForward() didn't scroll App Apps",
+ flingForwardY > 0));
+
+ allApps.flingBackward();
+ assertTrue(
+ "Launcher internal state is not All Apps",
+ test.isInState(LauncherState.ALL_APPS));
+ final Integer flingBackwardY = test.getFromLauncher(
+ launcher -> test.getAllAppsScroll(launcher));
+ test.executeOnLauncher(launcher -> assertTrue("flingBackward() didn't scroll App Apps",
+ flingBackwardY < flingForwardY));
+
+ // Test scrolling down to YouTube.
+ assertNotNull("All apps: can't fine YouTube", allApps.getAppIcon("YouTube"));
+ // Test scrolling up to Camera.
+ assertNotNull("All apps: can't fine Camera", allApps.getAppIcon("Camera"));
+ // Test failing to find a non-existing app.
+ final AllApps allAppsFinal = allApps;
+ expectFail("All apps: could find a non-existing app",
+ () -> allAppsFinal.getAppIcon("NO APP"));
+
+ assertTrue(
+ "Launcher internal state is not All Apps",
+ test.isInState(LauncherState.ALL_APPS));
+ } finally {
+ allApps.unfreeze();
+ }
}
@Test
@@ -199,12 +215,17 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
}
public static void runIconLaunchFromAllAppsTest(AbstractLauncherUiTest test, AllApps allApps) {
- final AppIcon app = allApps.getAppIcon("TestActivity7");
- assertNotNull("AppIcon.launch returned null", app.launch(getAppPackageName()));
- test.executeOnLauncher(launcher -> assertTrue(
- "Launcher activity is the top activity; expecting another activity to be the top "
- + "one",
- test.isInBackground(launcher)));
+ allApps.freeze();
+ try {
+ final AppIcon app = allApps.getAppIcon("TestActivity7");
+ assertNotNull("AppIcon.launch returned null", app.launch(getAppPackageName()));
+ test.executeOnLauncher(launcher -> assertTrue(
+ "Launcher activity is the top activity; expecting another activity to be the top "
+ + "one",
+ test.isInBackground(launcher)));
+ } finally {
+ allApps.unfreeze();
+ }
}
@Test
@@ -260,20 +281,23 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
public void testLaunchMenuItem() throws Exception {
if (!TestHelpers.isInLauncherProcess()) return;
- final AppIconMenu menu = mLauncher.
+ final AllApps allApps = mLauncher.
getWorkspace().
- switchToAllApps().
- getAppIcon(APP_NAME).
- openMenu();
-
- executeOnLauncher(
- launcher -> assertTrue("Launcher internal state didn't switch to Showing Menu",
- isOptionsPopupVisible(launcher)));
+ switchToAllApps();
+ allApps.freeze();
+ try {
+ final AppIconMenu menu = allApps.
+ getAppIcon(APP_NAME).
+ openMenu();
- final AppIconMenuItem menuItem = menu.getMenuItem(1);
- final String itemName = menuItem.getText();
+ executeOnLauncher(
+ launcher -> assertTrue("Launcher internal state didn't switch to Showing Menu",
+ isOptionsPopupVisible(launcher)));
- menuItem.launch(getAppPackageName());
+ menu.getMenuItem(1).launch(getAppPackageName());
+ } finally {
+ allApps.unfreeze();
+ }
}
@Test
@@ -282,12 +306,18 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
// 1. Open all apps and wait for load complete.
// 2. Drag icon to homescreen.
// 3. Verify that the icon works on homescreen.
- mLauncher.getWorkspace().
- switchToAllApps().
- getAppIcon(APP_NAME).
- dragToWorkspace().
- getWorkspaceAppIcon(APP_NAME).
- launch(getAppPackageName());
+ final AllApps allApps = mLauncher.getWorkspace().
+ switchToAllApps();
+ allApps.freeze();
+ try {
+ allApps.
+ getAppIcon(APP_NAME).
+ dragToWorkspace().
+ getWorkspaceAppIcon(APP_NAME).
+ launch(getAppPackageName());
+ } finally {
+ allApps.unfreeze();
+ }
executeOnLauncher(launcher -> assertTrue(
"Launcher activity is the top activity; expecting another activity to be the top "
+ "one",
@@ -302,21 +332,27 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
// 1. Open all apps and wait for load complete.
// 2. Find the app and long press it to show shortcuts.
// 3. Press icon center until shortcuts appear
- final AppIconMenuItem menuItem = mLauncher.
+ final AllApps allApps = mLauncher.
getWorkspace().
- switchToAllApps().
- getAppIcon(APP_NAME).
- openMenu().
- getMenuItem(0);
- final String shortcutName = menuItem.getText();
-
- // 4. Drag the first shortcut to the home screen.
- // 5. Verify that the shortcut works on home screen
- // (the app opens and has the same text as the shortcut).
- menuItem.
- dragToWorkspace().
- getWorkspaceAppIcon(shortcutName).
- launch(getAppPackageName());
+ switchToAllApps();
+ allApps.freeze();
+ try {
+ final AppIconMenuItem menuItem = allApps.
+ getAppIcon(APP_NAME).
+ openMenu().
+ getMenuItem(0);
+ final String shortcutName = menuItem.getText();
+
+ // 4. Drag the first shortcut to the home screen.
+ // 5. Verify that the shortcut works on home screen
+ // (the app opens and has the same text as the shortcut).
+ menuItem.
+ dragToWorkspace().
+ getWorkspaceAppIcon(shortcutName).
+ launch(getAppPackageName());
+ } finally {
+ allApps.unfreeze();
+ }
}
public static String getAppPackageName() {
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index d03035a87..21d763e30 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -48,6 +48,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
"apps_list_view");
// Wait for the recycler to populate.
mLauncher.waitForObjectInContainer(appListRecycler, By.clazz(TextView.class));
+ verifyNotFrozen("All apps freeze flags upon opening all apps");
}
@Override
@@ -210,4 +211,25 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
verifyActiveContainer();
}
}
+
+ /**
+ * Freezes updating app list upon app install/uninstall/update.
+ */
+ public void freeze() {
+ mLauncher.getTestInfo(TestProtocol.REQUEST_FREEZE_APP_LIST);
+ }
+
+ /**
+ * Resumes updating app list upon app install/uninstall/update.
+ */
+ public void unfreeze() {
+ mLauncher.getTestInfo(TestProtocol.REQUEST_UNFREEZE_APP_LIST);
+ verifyNotFrozen("All apps freeze flags upon unfreezing");
+ }
+
+ private void verifyNotFrozen(String message) {
+ mLauncher.assertEquals(message, 0, mLauncher.getTestInfo(
+ TestProtocol.REQUEST_APP_LIST_FREEZE_FLAGS).
+ getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD));
+ }
}
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index e45fca8c0..8ebe52565 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -292,6 +292,12 @@ public final class LauncherInstrumentation {
}
}
+ void assertEquals(String message, long expected, long actual) {
+ if (expected != actual) {
+ fail(message + " expected: " + expected + " but was: " + actual);
+ }
+ }
+
void assertNotEquals(String message, int unexpected, int actual) {
if (unexpected == actual) {
failEquals(message, actual);