OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.test.util; |
| 6 |
| 7 import junit.framework.Assert; |
| 8 |
| 9 import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; |
| 10 import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.Overv
iewModeObserver; |
| 11 import org.chromium.content.browser.test.util.Criteria; |
| 12 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 13 |
| 14 /** |
| 15 * Checks and waits for certain overview mode events to happen. Can be used to
block test threads |
| 16 * until certain overview mode state criteria are met. |
| 17 */ |
| 18 public class OverviewModeBehaviorWatcher implements OverviewModeObserver { |
| 19 private final OverviewModeBehavior mOverviewModeBehavior; |
| 20 private boolean mWaitingForShow; |
| 21 private boolean mWaitingForHide; |
| 22 |
| 23 private final Criteria mCriteria = new Criteria() { |
| 24 @Override |
| 25 public boolean isSatisfied() { |
| 26 return !mWaitingForShow && !mWaitingForHide; |
| 27 } |
| 28 }; |
| 29 |
| 30 /** |
| 31 * Creates an instance of an {@link OverviewModeBehaviorWatcher}. Note that
at this point |
| 32 * it will be registered for overview mode events. |
| 33 * |
| 34 * @param behavior The {@link OverviewModeBehavior} to watch. |
| 35 * @param waitForShow Whether or not to wait for overview mode to finish sho
wing. |
| 36 * @param waitForHide Whether or not to wait for overview mode to finish hid
ing. |
| 37 */ |
| 38 public OverviewModeBehaviorWatcher(OverviewModeBehavior behavior, boolean wa
itForShow, |
| 39 boolean waitForHide) { |
| 40 mOverviewModeBehavior = behavior; |
| 41 mOverviewModeBehavior.addOverviewModeObserver(this); |
| 42 |
| 43 mWaitingForShow = waitForShow; |
| 44 mWaitingForHide = waitForHide; |
| 45 } |
| 46 |
| 47 @Override |
| 48 public void onOverviewModeStartedShowing(boolean showToolbar) { } |
| 49 |
| 50 @Override |
| 51 public void onOverviewModeFinishedShowing() { |
| 52 mWaitingForShow = false; |
| 53 } |
| 54 |
| 55 @Override |
| 56 public void onOverviewModeStartedHiding(boolean showToolbar, boolean delayAn
imation) { } |
| 57 |
| 58 @Override |
| 59 public void onOverviewModeFinishedHiding() { |
| 60 mWaitingForHide = false; |
| 61 } |
| 62 |
| 63 /** |
| 64 * Blocks until all of the expected events have occurred. Once the events o
f this class |
| 65 * are met it will always return immediately from {@link #waitForBehavior()}
. |
| 66 * @throws InterruptedException |
| 67 */ |
| 68 public void waitForBehavior() throws InterruptedException { |
| 69 try { |
| 70 if (!CriteriaHelper.pollForUIThreadCriteria(mCriteria)) { |
| 71 Assert.assertFalse( |
| 72 "OverviewModeObserver#onOverviewModeFinishedShowing() no
t called.", |
| 73 mWaitingForShow); |
| 74 Assert.assertFalse( |
| 75 "OverviewModeObserver#onOverviewModeFinishedHiding() not
called.", |
| 76 mWaitingForHide); |
| 77 } |
| 78 } finally { |
| 79 mOverviewModeBehavior.removeOverviewModeObserver(this); |
| 80 } |
| 81 } |
| 82 } |
OLD | NEW |