Bug 1092254 - Use Solo.waitForCondition under the hood in BaseTest.waitForTest. r=liuche, a=test-only
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 03 Nov 2014 03:14:08 -0800
changeset 233621 180de799976d4f8994eb53296a26f6a8e1034570
parent 233620 1a0fd34cd02da21395fee62362c9d9e23ace14c0
child 233622 bd120a8b1abb69b880e3cfe220d276f952d3ac98
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, test-only
bugs1092254
milestone35.0a2
Bug 1092254 - Use Solo.waitForCondition under the hood in BaseTest.waitForTest. r=liuche, a=test-only
mobile/android/base/tests/BaseTest.java
--- a/mobile/android/base/tests/BaseTest.java
+++ b/mobile/android/base/tests/BaseTest.java
@@ -321,35 +321,37 @@ abstract class BaseTest extends BaseRobo
         if (!result) {
             // Log timeout failure for diagnostic purposes only; a failed wait may
             // be normal and does not necessarily warrant a test assertion/failure.
             mAsserter.dumpLog("waitForCondition timeout after " + timeout + " ms.");
         }
         return result;
     }
 
-    // TODO: With Robotium 4.2, we should use Condition and waitForCondition instead.
-    // Future boolean tests should not use this method.
-    protected final boolean waitForTest(BooleanTest t, int timeout) {
-        long end = SystemClock.uptimeMillis() + timeout;
-        while (SystemClock.uptimeMillis() < end) {
-            if (t.test()) {
-                return true;
+    /**
+     * @deprecated use {@link #waitForCondition(Condition, int)} instead
+     */
+    @Deprecated
+    protected final boolean waitForTest(final BooleanTest t, final int timeout) {
+        final boolean isSatisfied = mSolo.waitForCondition(new Condition() {
+            @Override
+            public boolean isSatisfied() {
+                return t.test();
             }
-            mSolo.sleep(100);
+        }, timeout);
+
+        if (!isSatisfied) {
+            // log out wait failure for diagnostic purposes only;
+            // a failed wait may be normal and does not necessarily
+            // warrant a test assertion/failure
+            mAsserter.dumpLog("waitForTest timeout after " + timeout + " ms");
         }
-        // log out wait failure for diagnostic purposes only;
-        // a failed wait may be normal and does not necessarily
-        // warrant a test assertion/failure
-        mAsserter.dumpLog("waitForTest timeout after "+timeout+" ms");
-        return false;
+        return isSatisfied;
     }
 
-    // TODO: With Robotium 4.2, we should use Condition and waitForCondition instead.
-    // Future boolean tests should not implement this interface.
     protected interface BooleanTest {
         public boolean test();
     }
 
     public void SqliteCompare(String dbName, String sqlCommand, ContentValues[] cvs) {
         File profile = new File(mProfile);
         String dbPath = new File(profile, dbName).getPath();