Bug 1079693 - When calling waitForText in testAddonManager, only look through visible views. r=bnicholson
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 14 Oct 2014 18:32:44 -0700
changeset 210420 8637c4d76046d72ecd98b2b9bfb83c5aa5b7ea1b
parent 210419 ce98fd405802ba90025a54d76f8c31b80cfba02e
child 210421 2b027c3e17368ece2d620684de17f0c3c9e9e5d5
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbnicholson
bugs1079693
milestone36.0a1
Bug 1079693 - When calling waitForText in testAddonManager, only look through visible views. r=bnicholson
mobile/android/base/tests/BaseTest.java
--- a/mobile/android/base/tests/BaseTest.java
+++ b/mobile/android/base/tests/BaseTest.java
@@ -48,16 +48,17 @@ import android.view.inputmethod.InputMet
 import android.widget.AdapterView;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ListAdapter;
 import android.widget.TextView;
 
 import com.jayway.android.robotium.solo.Condition;
 import com.jayway.android.robotium.solo.Solo;
+import com.jayway.android.robotium.solo.Timeout;
 
 /**
  *  A convenient base class suitable for most Robocop tests.
  */
 @SuppressWarnings("unchecked")
 abstract class BaseTest extends BaseRobocopTest {
     private static final int VERIFY_URL_TIMEOUT = 2000;
     private static final int MAX_WAIT_ENABLED_TEXT_MS = 10000;
@@ -391,18 +392,27 @@ abstract class BaseTest extends BaseRobo
         return true;
     }
 
     public InputStream getAsset(String filename) throws IOException {
         AssetManager assets = getInstrumentation().getContext().getAssets();
         return assets.open(filename);
     }
 
-    public boolean waitForText(String text) {
-        boolean rc = mSolo.waitForText(text);
+    public boolean waitForText(final String text) {
+        // false is the default value for finding only
+        // visible views in `Solo.waitForText(String)`.
+        return waitForText(text, false);
+    }
+
+    public boolean waitForText(final String text, final boolean onlyVisibleViews) {
+        // We use the default robotium values from
+        // `Waiter.waitForText(String)` for unspecified arguments.
+        final boolean rc =
+                mSolo.waitForText(text, 0, Timeout.getLargeTimeout(), true, onlyVisibleViews);
         if (!rc) {
             // log out failed wait for diagnostic purposes only;
             // waitForText failures are sometimes expected/normal
             mAsserter.dumpLog("waitForText timeout on "+text);
         }
         return rc;
     }
 
@@ -454,17 +464,17 @@ abstract class BaseTest extends BaseRobo
             // log out failed wait for diagnostic purposes only;
             // failures are sometimes expected/normal
             mAsserter.dumpLog("waitForEnabledText timeout on "+text);
         }
         return rc;
     }
 
 
-    /** 
+    /**
      * Select <item> from Menu > "Settings" > <section>.
      */
     public void selectSettingsItem(String section, String item) {
         String[] itemPath = { "Settings", section, item };
         selectMenuItemByPath(itemPath);
     }
 
     /**
@@ -484,17 +494,17 @@ abstract class BaseTest extends BaseRobo
             }
         }
     }
 
     public final void selectMenuItem(String menuItemName) {
         // build the item name ready to be used
         String itemName = "^" + menuItemName + "$";
         mActions.sendSpecialKey(Actions.SpecialKey.MENU);
-        if (waitForText(itemName)) {
+        if (waitForText(itemName, true)) {
             mSolo.clickOnText(itemName);
         } else {
             // Older versions of Android have additional settings under "More",
             // including settings that newer versions have under "Tools."
             if (mSolo.searchText("(^More$|^Tools$)")) {
                 mSolo.clickOnText("(^More$|^Tools$)");
             }
             waitForText(itemName);
@@ -943,17 +953,17 @@ abstract class BaseTest extends BaseRobo
     }
 
     /**
      * Set the preference and wait for it to change before proceeding with the test.
      */
     public void setPreferenceAndWaitForChange(final JSONObject jsonPref) {
         mActions.sendGeckoEvent("Preferences:Set", jsonPref.toString());
 
-        // Get the preference name from the json and store it in an array. This array 
+        // Get the preference name from the json and store it in an array. This array
         // will be used later while fetching the preference data.
         String[] prefNames = new String[1];
         try {
             prefNames[0] = jsonPref.getString("name");
         } catch (JSONException e) {
             mAsserter.ok(false, "Exception in setPreferenceAndWaitForChange", getStackTraceString(e));
         }