Merge "Waiting for the apps-unfreeze flags instead of enforcing it" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-11-05 05:23:13 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 3 deletions

View File

@@ -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.

View File

@@ -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);
}
}

View File

@@ -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;
}
}