| Index: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/CriteriaHelper.java
|
| diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/CriteriaHelper.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/CriteriaHelper.java
|
| index 32df58b62e1186895f8d68b09deff8d8770ee851..2783142471b817aa9cee3e6f747bf1dd3103fffd 100644
|
| --- a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/CriteriaHelper.java
|
| +++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/CriteriaHelper.java
|
| @@ -27,7 +27,7 @@ import java.util.concurrent.Callable;
|
| * Sample Usage:
|
| * <code>
|
| * public void waitForTabFullyLoaded(final Tab tab) {
|
| - * CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
|
| + * CriteriaHelper.pollUiThread(new Criteria() {
|
| * {@literal @}Override
|
| * public boolean isSatisified() {
|
| * if (tab.getWebContents() == null) {
|
| @@ -52,13 +52,18 @@ public class CriteriaHelper {
|
| /**
|
| * Checks whether the given Criteria is satisfied at a given interval, until either
|
| * the criteria is satisfied, or the specified maxTimeoutMs number of ms has elapsed.
|
| + *
|
| + * <p>
|
| + * This evaluates the Criteria on the Instrumentation thread, which more often than not is not
|
| + * correct in an InstrumentationTest. Use
|
| + * {@link #pollUiThread(Criteria, long, long)} instead.
|
| + *
|
| * @param criteria The Criteria that will be checked.
|
| * @param maxTimeoutMs The maximum number of ms that this check will be performed for
|
| - * before timeout.
|
| + * before timeout.
|
| * @param checkIntervalMs The number of ms between checks.
|
| - * @throws InterruptedException
|
| */
|
| - public static void pollForCriteria(Criteria criteria, long maxTimeoutMs,
|
| + public static void pollInstrumentationThread(Criteria criteria, long maxTimeoutMs,
|
| long checkIntervalMs) throws InterruptedException {
|
| boolean isSatisfied = criteria.isSatisfied();
|
| long startTime = SystemClock.uptimeMillis();
|
| @@ -69,15 +74,30 @@ public class CriteriaHelper {
|
| Assert.assertTrue(criteria.getFailureReason(), isSatisfied);
|
| }
|
|
|
| + // TODO(tedchoc): Remove once downstream tests point to pollInstrumentationThread.
|
| + public static void pollForCriteria(Criteria criteria, long maxTimeoutMs,
|
| + long checkIntervalMs) throws InterruptedException {
|
| + pollInstrumentationThread(criteria, maxTimeoutMs, checkIntervalMs);
|
| + }
|
| +
|
| /**
|
| * Checks whether the given Criteria is satisfied polling at a default interval.
|
| *
|
| + * <p>
|
| + * This evaluates the Criteria on the test thread, which more often than not is not correct
|
| + * in an InstrumentationTest. Use {@link #pollUiThread(Criteria)} instead.
|
| + *
|
| * @param criteria The Criteria that will be checked.
|
| - * @throws InterruptedException
|
| - * @see #pollForCriteria(Criteria, long, long)
|
| + *
|
| + * @see #pollInstrumentationThread(Criteria, long, long)
|
| */
|
| + public static void pollInstrumentationThread(Criteria criteria) throws InterruptedException {
|
| + pollInstrumentationThread(criteria, DEFAULT_MAX_TIME_TO_POLL, DEFAULT_POLLING_INTERVAL);
|
| + }
|
| +
|
| + // TODO(tedchoc): Remove once downstream tests point to pollInstrumentationThread.
|
| public static void pollForCriteria(Criteria criteria) throws InterruptedException {
|
| - pollForCriteria(criteria, DEFAULT_MAX_TIME_TO_POLL, DEFAULT_POLLING_INTERVAL);
|
| + pollInstrumentationThread(criteria);
|
| }
|
|
|
| /**
|
| @@ -86,12 +106,12 @@ public class CriteriaHelper {
|
| *
|
| * @param criteria The Criteria that will be checked.
|
| * @param maxTimeoutMs The maximum number of ms that this check will be performed for
|
| - * before timeout.
|
| + * before timeout.
|
| * @param checkIntervalMs The number of ms between checks.
|
| - * @throws InterruptedException
|
| - * @see #pollForCriteria(Criteria)
|
| + *
|
| + * @see #pollInstrumentationThread(Criteria)
|
| */
|
| - public static void pollForUIThreadCriteria(final Criteria criteria, long maxTimeoutMs,
|
| + public static void pollUiThread(final Criteria criteria, long maxTimeoutMs,
|
| long checkIntervalMs) throws InterruptedException {
|
| final Callable<Boolean> callable = new Callable<Boolean>() {
|
| @Override
|
| @@ -100,7 +120,7 @@ public class CriteriaHelper {
|
| }
|
| };
|
|
|
| - pollForCriteria(new Criteria() {
|
| + pollInstrumentationThread(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| return ThreadUtils.runOnUiThreadBlockingNoException(callable);
|
| @@ -113,15 +133,26 @@ public class CriteriaHelper {
|
| }, maxTimeoutMs, checkIntervalMs);
|
| }
|
|
|
| + // TODO(tedchoc): Remove once downstream tests point to pollUiThread.
|
| + public static void pollForUIThreadCriteria(final Criteria criteria, long maxTimeoutMs,
|
| + long checkIntervalMs) throws InterruptedException {
|
| + pollUiThread(criteria, maxTimeoutMs, checkIntervalMs);
|
| + }
|
| +
|
| /**
|
| * Checks whether the given Criteria is satisfied polling at a default interval on the UI
|
| * thread.
|
| * @param criteria The Criteria that will be checked.
|
| - * @throws InterruptedException
|
| - * @see #pollForCriteria(Criteria)
|
| + *
|
| + * @see #pollInstrumentationThread(Criteria)
|
| */
|
| + public static void pollUiThread(final Criteria criteria) throws InterruptedException {
|
| + pollUiThread(criteria, DEFAULT_MAX_TIME_TO_POLL, DEFAULT_POLLING_INTERVAL);
|
| + }
|
| +
|
| + // TODO(tedchoc): Remove once downstream tests point to pollUiThread.
|
| public static void pollForUIThreadCriteria(final Criteria criteria)
|
| throws InterruptedException {
|
| - pollForUIThreadCriteria(criteria, DEFAULT_MAX_TIME_TO_POLL, DEFAULT_POLLING_INTERVAL);
|
| + pollUiThread(criteria);
|
| }
|
| }
|
|
|