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

Unified Diff: components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java

Issue 1419033005: [Cronet] Remove CriteriaHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework CronetSamepleTest Created 5 years, 2 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: components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java b/components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java
deleted file mode 100644
index 8a9ac7a7ad1df5ae2b0127d90f2cd5ea41b78216..0000000000000000000000000000000000000000
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2014 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.net;
-
-import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
-
-import android.os.SystemClock;
-
-/**
- * Helper methods for creating and managing criteria.
- * <p>
- * If possible, use callbacks or testing delegates instead of criteria as they
- * do not introduce any polling delays. Should only use Criteria if no suitable
- * other approach exists.
- */
-public class CriteriaHelper {
-
- /** The default maximum time to wait for a criteria to become valid. */
- public static final long DEFAULT_MAX_TIME_TO_POLL = scaleTimeout(3000);
-
- /**
- * The default polling interval to wait between checking for a satisfied
- * criteria.
- */
- public static final long DEFAULT_POLLING_INTERVAL = 50;
-
- /**
- * 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.
- *
- * @param criteria The Criteria that will be checked.
- * @param maxTimeoutMs The maximum number of ms that this check will be
- * performed for before timeout.
- * @param checkIntervalMs The number of ms between checks.
- * @return {@code true} if checking has ended with the criteria being
- * satisfied.
- * @throws InterruptedException
- */
- public static boolean pollForCriteria(Criteria criteria, long maxTimeoutMs,
- long checkIntervalMs) throws InterruptedException {
- boolean isSatisfied = criteria.isSatisfied();
- long startTime = SystemClock.uptimeMillis();
- while (!isSatisfied
- && SystemClock.uptimeMillis() - startTime < maxTimeoutMs) {
- Thread.sleep(checkIntervalMs);
- isSatisfied = criteria.isSatisfied();
- }
- return isSatisfied;
- }
-
- /**
- * Checks whether the given Criteria is satisfied polling at a default
- * interval.
- *
- * @param criteria The Criteria that will be checked.
- * @return {@code true} if checking has ended with the criteria being
- * satisfied.
- * @throws InterruptedException
- * @see #pollForCriteria(Criteria, long, long)
- */
- public static boolean pollForCriteria(Criteria criteria)
- throws InterruptedException {
- return pollForCriteria(criteria, DEFAULT_MAX_TIME_TO_POLL,
- DEFAULT_POLLING_INTERVAL);
- }
-
- /**
- * Performs the runnable action, then checks whether the given criteria are
- * satisfied until the specified timeout, using the pollForCriteria method.
- * If not, then the runnable action is performed again, to a maximum of
- * maxAttempts tries.
- */
- public static boolean runUntilCriteria(Runnable runnable, Criteria criteria,
- int maxAttempts, long maxTimeoutMs, long checkIntervalMs)
- throws InterruptedException {
- int count = 0;
- boolean success = false;
- while (count < maxAttempts && !success) {
- count++;
- runnable.run();
- success = pollForCriteria(criteria, maxTimeoutMs, checkIntervalMs);
- }
- return success;
- }
-}

Powered by Google App Engine
This is Rietveld 408576698