Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4645)

Unified Diff: chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/OverviewModeBehaviorWatcher.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/OverviewModeBehaviorWatcher.java
diff --git a/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/OverviewModeBehaviorWatcher.java b/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/OverviewModeBehaviorWatcher.java
new file mode 100644
index 0000000000000000000000000000000000000000..9a8a2816d8f2ad0a2924984e7ebd2cf164ccb7e4
--- /dev/null
+++ b/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/OverviewModeBehaviorWatcher.java
@@ -0,0 +1,82 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.test.util;
+
+import junit.framework.Assert;
+
+import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
+import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+
+/**
+ * Checks and waits for certain overview mode events to happen. Can be used to block test threads
+ * until certain overview mode state criteria are met.
+ */
+public class OverviewModeBehaviorWatcher implements OverviewModeObserver {
+ private final OverviewModeBehavior mOverviewModeBehavior;
+ private boolean mWaitingForShow;
+ private boolean mWaitingForHide;
+
+ private final Criteria mCriteria = new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return !mWaitingForShow && !mWaitingForHide;
+ }
+ };
+
+ /**
+ * Creates an instance of an {@link OverviewModeBehaviorWatcher}. Note that at this point
+ * it will be registered for overview mode events.
+ *
+ * @param behavior The {@link OverviewModeBehavior} to watch.
+ * @param waitForShow Whether or not to wait for overview mode to finish showing.
+ * @param waitForHide Whether or not to wait for overview mode to finish hiding.
+ */
+ public OverviewModeBehaviorWatcher(OverviewModeBehavior behavior, boolean waitForShow,
+ boolean waitForHide) {
+ mOverviewModeBehavior = behavior;
+ mOverviewModeBehavior.addOverviewModeObserver(this);
+
+ mWaitingForShow = waitForShow;
+ mWaitingForHide = waitForHide;
+ }
+
+ @Override
+ public void onOverviewModeStartedShowing(boolean showToolbar) { }
+
+ @Override
+ public void onOverviewModeFinishedShowing() {
+ mWaitingForShow = false;
+ }
+
+ @Override
+ public void onOverviewModeStartedHiding(boolean showToolbar, boolean delayAnimation) { }
+
+ @Override
+ public void onOverviewModeFinishedHiding() {
+ mWaitingForHide = false;
+ }
+
+ /**
+ * Blocks until all of the expected events have occurred. Once the events of this class
+ * are met it will always return immediately from {@link #waitForBehavior()}.
+ * @throws InterruptedException
+ */
+ public void waitForBehavior() throws InterruptedException {
+ try {
+ if (!CriteriaHelper.pollForUIThreadCriteria(mCriteria)) {
+ Assert.assertFalse(
+ "OverviewModeObserver#onOverviewModeFinishedShowing() not called.",
+ mWaitingForShow);
+ Assert.assertFalse(
+ "OverviewModeObserver#onOverviewModeFinishedHiding() not called.",
+ mWaitingForHide);
+ }
+ } finally {
+ mOverviewModeBehavior.removeOverviewModeObserver(this);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698