Merge "Improving navigation mode switch rule and around" into ub-launcher3-master

This commit is contained in:
TreeHugger Robot
2019-12-16 22:36:42 +00:00
committed by Android (Google) Code Review
6 changed files with 28 additions and 22 deletions
@@ -35,6 +35,7 @@ import androidx.test.uiautomator.UiDevice;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.FailureWatcher;
import com.android.systemui.shared.system.QuickStepContract;
@@ -57,6 +58,8 @@ public class NavigationModeSwitchRule implements TestRule {
static final String TAG = "QuickStepOnOffRule";
public static final int WAIT_TIME_MS = 10000;
public enum Mode {
THREE_BUTTON, TWO_BUTTON, ZERO_BUTTON, ALL
}
@@ -118,8 +121,8 @@ public class NavigationModeSwitchRule implements TestRule {
if (mode == THREE_BUTTON || mode == ALL) {
evaluateWithThreeButtons();
}
} catch (Exception e) {
Log.e(TAG, "Exception", e);
} catch (Throwable e) {
Log.e(TAG, "Error", e);
throw e;
} finally {
assertTrue("Couldn't set overlay",
@@ -195,19 +198,14 @@ public class NavigationModeSwitchRule implements TestRule {
currentSysUiNavigationMode() == expectedMode);
}
for (int i = 0; i != 100; ++i) {
if (mLauncher.getNavigationModel() == expectedMode) break;
Thread.sleep(100);
}
assertTrue("Couldn't switch to " + overlayPackage,
mLauncher.getNavigationModel() == expectedMode);
Wait.atMost("Couldn't switch to " + overlayPackage,
() -> mLauncher.getNavigationModel() == expectedMode, WAIT_TIME_MS,
mLauncher);
for (int i = 0; i != 100; ++i) {
if (mLauncher.getNavigationModeMismatchError() == null) break;
Thread.sleep(100);
}
final String error = mLauncher.getNavigationModeMismatchError();
assertTrue("Switching nav mode: " + error, error == null);
Wait.atMost(() -> "Switching nav mode: "
+ mLauncher.getNavigationModeMismatchError(),
() -> mLauncher.getNavigationModeMismatchError() == null, WAIT_TIME_MS,
mLauncher);
return true;
}
@@ -259,7 +259,7 @@ public abstract class AbstractLauncherUiTest {
protected <T> T getOnUiThread(final Callable<T> callback) {
try {
return mMainThreadExecutor.submit(callback).get();
} catch (Exception e) {
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
@@ -38,8 +38,8 @@ class PortraitLandscapeRunner implements TestRule {
evaluateInPortrait();
evaluateInLandscape();
} catch (Exception e) {
Log.e(TAG, "Exception", e);
} catch (Throwable e) {
Log.e(TAG, "Error", e);
throw e;
} finally {
mTest.mDevice.setOrientationNatural();
@@ -103,11 +103,11 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
setResult(acceptConfig);
if (acceptConfig) {
Wait.atMost(null, new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
Wait.atMost("", new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
} else {
// Verify that the widget id is deleted.
Wait.atMost(null, () -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null,
Wait.atMost("", () -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null,
DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
}
}
@@ -170,7 +170,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest {
// Go back to home
mLauncher.pressHome();
Wait.atMost(null, new ItemSearchCondition(itemMatcher), DEFAULT_ACTIVITY_TIMEOUT,
Wait.atMost("", new ItemSearchCondition(itemMatcher), DEFAULT_ACTIVITY_TIMEOUT,
mLauncher);
}
+10 -2
View File
@@ -7,6 +7,8 @@ import com.android.launcher3.tapl.LauncherInstrumentation;
import org.junit.Assert;
import java.util.function.Supplier;
/**
* A utility class for waiting for a condition to be true.
*/
@@ -16,10 +18,16 @@ public class Wait {
public static void atMost(String message, Condition condition, long timeout,
LauncherInstrumentation launcher) {
atMost(() -> message, condition, timeout, DEFAULT_SLEEP_MS, launcher);
}
public static void atMost(Supplier<String> message, Condition condition, long timeout,
LauncherInstrumentation launcher) {
atMost(message, condition, timeout, DEFAULT_SLEEP_MS, launcher);
}
public static void atMost(String message, Condition condition, long timeout, long sleepMillis,
public static void atMost(Supplier<String> message, Condition condition, long timeout,
long sleepMillis,
LauncherInstrumentation launcher) {
final long startTime = SystemClock.uptimeMillis();
long endTime = startTime + timeout;
@@ -45,6 +53,6 @@ public class Wait {
}
Log.d("Wait", "atMost: timed out: " + SystemClock.uptimeMillis());
launcher.checkForAnomaly();
Assert.fail(message);
Assert.fail(message.get());
}
}