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 225924 cdd31f8931ae
parent 225919 72938afdf993
child 225925 2ad92b68de0b
push id4070
push userryanvm@gmail.com
push date2014-11-04 15:37 +0000
treeherdermozilla-beta@2ad92b68de0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, test-only
bugs1092254
milestone34.0
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
@@ -305,35 +305,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 asssertion/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();