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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/util/CallbackHelper.java

Issue 10979009: Move content test utils to content/public/test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased on new branch Created 8 years, 3 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: content/public/android/javatests/src/org/chromium/content/browser/util/CallbackHelper.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/util/CallbackHelper.java b/content/public/android/javatests/src/org/chromium/content/browser/util/CallbackHelper.java
deleted file mode 100644
index c56d49fe3ad35110a331c195eb03960e8fe11ea6..0000000000000000000000000000000000000000
--- a/content/public/android/javatests/src/org/chromium/content/browser/util/CallbackHelper.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (c) 2012 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.content.browser.util;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * A helper class for listening to callbacks.
- */
-public class CallbackHelper {
- protected static int WAIT_TIMEOUT_SECONDS = 5;
-
- private final Object mLock = new Object();
- protected int mCallCount = 0;
-
- /**
- * Gets the number of times the callback has been called.
- *
- * The call count can be used with the waitForCallback() method, indicating a point
- * in time after which the caller wishes to record calls to the callback.
- *
- * In order to wait for a callback caused by X, the call count should be obtained
- * before X occurs.
- *
- * NOTE: any call to the callback that occurs after the call count is obtained
- * will result in the corresponding wait call to resume execution. The call count
- * is intended to 'catch' callbacks that occur after X but before waitForCallback()
- * is called.
- */
- public int getCallCount() {
- synchronized(mLock) {
- return mCallCount;
- }
- }
-
- /**
- * Blocks until the callback is called the specified number of
- * times or throws an exception if we exceeded the specified time frame.
- *
- * This will wait for a callback to be called a specified number of times after
- * the point in time at which the call count was obtained. The method will return
- * immediately if a call occurred the specified number of times after the
- * call count was obtained but before the method was called, otherwise the method will
- * block until the specified call count is reached.
- *
- * @param currentCallCount the value obtained by calling getCallCount().
- * @param numberOfCallsToWaitFor number of calls (counting since
- * currentCallCount was obtained) that we will wait for.
- * @param timeout timeout value. We will wait the specified amount of time for a single
- * callback to occur so the method call may block up to
- * <code>numberOfCallsToWaitFor * timeout</code> units.
- * @param unit timeout unit.
- * @throws InterruptedException
- * @throws TimeoutException Thrown if the method times out before onPageFinished is called.
- */
- public void waitForCallback(int currentCallCount, int numberOfCallsToWaitFor, long timeout,
- TimeUnit unit) throws InterruptedException, TimeoutException {
- assert mCallCount >= currentCallCount;
- assert numberOfCallsToWaitFor > 0;
- synchronized(mLock) {
- int callCountWhenDoneWaiting = currentCallCount + numberOfCallsToWaitFor;
- while (callCountWhenDoneWaiting > mCallCount) {
- int callCountBeforeWait = mCallCount;
- mLock.wait(unit.toMillis(timeout));
- if (callCountBeforeWait == mCallCount) {
- throw new TimeoutException("waitForCallback timed out!");
- }
- }
- }
- }
-
- public void waitForCallback(int currentCallCount, int numberOfCallsToWaitFor)
- throws InterruptedException, TimeoutException {
- waitForCallback(currentCallCount, numberOfCallsToWaitFor,
- WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
- }
-
- public void waitForCallback(int currentCallCount)
- throws InterruptedException, TimeoutException {
- waitForCallback(currentCallCount, 1);
- }
-
- /**
- * Should be called when the callback associated with this helper object is called.
- */
- public void notifyCalled() {
- synchronized(mLock) {
- mCallCount++;
- mLock.notifyAll();
- }
- }
-}
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/android/javatests/src/org/chromium/content/browser/util/Criteria.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698