From 679ec33cc70cd54b72936d8381162d4126701c94 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 4 Nov 2022 14:21:18 -0700 Subject: [PATCH] Waiting for the apps-unfreeze flags instead of enforcing it Bug: 256898879 Test: Will wait for presubmit flakyness to clear Change-Id: Ie2341338bbebfd892998e078d07d31f003ab8d43 --- .../launcher3/ui/TaplTestsLauncher3.java | 1 + .../com/android/launcher3/tapl/AllApps.java | 16 +++++++++++++--- .../tapl/LauncherInstrumentation.java | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 978e84c393..50e099068f 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -335,6 +335,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { @IwTest(focusArea="launcher") @Test @PortraitLandscape + @ScreenRecord // b/256898879 public void testDragAppIcon() throws Throwable { // 1. Open all apps and wait for load complete. // 2. Drag icon to homescreen. diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index 6bbdf48da0..b0cf20f796 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -16,6 +16,9 @@ package com.android.launcher3.tapl; +import static com.android.launcher3.tapl.LauncherInstrumentation.DEFAULT_POLL_INTERVAL; +import static com.android.launcher3.tapl.LauncherInstrumentation.WAIT_TIME_MS; + import android.graphics.Point; import android.graphics.Rect; import android.os.Bundle; @@ -37,6 +40,9 @@ import java.util.stream.Collectors; * Operations on AllApps opened from Home. Also a parent for All Apps opened from Overview. */ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer { + // Defer updates flag used to defer all apps updates by a test's request. + private static final int DEFER_UPDATES_TEST = 1 << 1; + private static final int MAX_SCROLL_ATTEMPTS = 40; private final int mHeight; @@ -292,12 +298,16 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer { */ 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, getFreezeFlags() & DEFER_UPDATES_TEST); + mLauncher.assertTrue(message, mLauncher.waitAndGet(() -> getFreezeFlags() == 0, + WAIT_TIME_MS, DEFAULT_POLL_INTERVAL)); + } + + private int getFreezeFlags() { final Bundle testInfo = mLauncher.getTestInfo(TestProtocol.REQUEST_APP_LIST_FREEZE_FLAGS); - if (testInfo == null) return; - mLauncher.assertEquals(message, 0, testInfo.getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD)); + return testInfo == null ? 0 : testInfo.getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); } } \ No newline at end of file diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 1c5c5fa812..fe060a1609 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -83,6 +83,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.concurrent.TimeoutException; +import java.util.function.BooleanSupplier; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -181,6 +182,7 @@ public final class LauncherInstrumentation { static final String TASKBAR_RES_ID = "taskbar_view"; private static final String SPLIT_PLACEHOLDER_RES_ID = "split_placeholder"; public static final int WAIT_TIME_MS = 30000; + static final long DEFAULT_POLL_INTERVAL = 1000; private static final String SYSTEMUI_PACKAGE = "com.android.systemui"; private static final String ANDROID_PACKAGE = "android"; @@ -1991,4 +1993,21 @@ public final class LauncherInstrumentation { mCallbackAtRunPoint.accept(runPoint); } } + + /** + * Waits until a particular condition is true. Based on WaitMixin. + */ + boolean waitAndGet(BooleanSupplier condition, long timeout, long interval) { + long startTime = SystemClock.uptimeMillis(); + + boolean result = condition.getAsBoolean(); + for (long elapsedTime = 0; !result; elapsedTime = SystemClock.uptimeMillis() - startTime) { + if (elapsedTime >= timeout) { + break; + } + SystemClock.sleep(interval); + result = condition.getAsBoolean(); + } + return result; + } }