Bug 912519 - (2) Minor refactor of testSettingsMenuItems; r=liuche
authorGeoff Brown <gbrown@mozilla.com>
Tue, 10 Sep 2013 18:18:07 -0600
changeset 159388 c856007f844e5793077dc1e4cf62d8e875ea0682
parent 159387 380a028c1a60edc10bab98fb8fef1bc857014d95
child 159389 0f03efa6263d7c1d76c9725e4e0d94f6e51e90f9
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs912519
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 912519 - (2) Minor refactor of testSettingsMenuItems; r=liuche
mobile/android/base/tests/testSettingsMenuItems.java.in
--- a/mobile/android/base/tests/testSettingsMenuItems.java.in
+++ b/mobile/android/base/tests/testSettingsMenuItems.java.in
@@ -207,49 +207,34 @@ public class testSettingsMenuItems exten
             for (String[] item : sectionItems) {
                 int itemLen = item.length;
 
                 // Each item must at least have a title.
                 mAsserter.ok(item.length > 0, "Section-item", "Each item must at least have a title");
 
                 // Check item title.
                 String itemTitle = "^" + item[0] + "$";
-                boolean foundText = waitForText(itemTitle);
-                if (!foundText) {
-                    // If we don't see the item, scroll down once in case it's off-screen.
-                    scrollDown();
-                    foundText = mSolo.waitForText(itemTitle);
-                }
+                boolean foundText = waitExtraForText(itemTitle);
                 mAsserter.ok(foundText, "Waiting for settings item " + itemTitle + " in section " + section,
                              "The " + itemTitle + " option is present in section " + section);
                 // Check item default, if it exists.
                 if (itemLen > 1) {
                     String itemDefault = "^" + item[1] + "$";
-                    foundText = waitForText(itemDefault);
-                    if (!foundText) {
-                        // If we don't see the item, scroll down once in case it's off-screen.
-                        scrollDown();
-                        foundText = mSolo.waitForText(itemDefault);
-                    }
+                    foundText = waitExtraForText(itemDefault);
                     mAsserter.ok(foundText, "Waiting for settings item default " + itemDefault
                                  + " in section " + section,
                                  "The " + itemDefault + " default is present in section " + section);
                 }
                 // Check item choices, if they exist.
                 if (itemLen > 2) {
                     waitForEnabledText(itemTitle);
                     mSolo.clickOnText(itemTitle);
                     for (int i = 2; i < itemLen; i++) {
                         String itemChoice = "^" + item[i] + "$";
-                        foundText = waitForText(itemChoice);
-                        if (!foundText) {
-                            // If we don't see the item, scroll down once in case it's off-screen.
-                            scrollDown();
-                            foundText = mSolo.waitForText(itemChoice);
-                        }
+                        foundText = waitExtraForText(itemChoice);
                         mAsserter.ok(foundText, "Waiting for settings item choice " + itemChoice
                                      + " in section " + section,
                                      "The " + itemChoice + " choice is present in section " + section);
                     }
                     // Leave submenu after checking.
                     if (waitForText("^Cancel$")) {
                         mSolo.clickOnText("^Cancel$");
                     } else {
@@ -261,18 +246,24 @@ public class testSettingsMenuItems exten
             // Navigate back a screen if on a phone.
             if (mDevice.type.equals("phone")) {
                 // Click back to return to previous menu. Tablets shouldn't do this because they use headers and fragments.
                 mActions.sendSpecialKey(Actions.SpecialKey.BACK);
             }
         }
     }
 
-    /**
-     * Hacky way to scroll down.
-     *
-     * solo.scroll* does not work in dialogs.
-     */
-    private void scrollDown() {
-        MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
-        meh.dragSync(mMidWidth, mMidHeight+100, mMidWidth, mMidHeight-100);
+    // Solo.waitForText usually scrolls down in a view when text is not visible.
+    // In this test, Solo.waitForText scrolling does not work, so we use this
+    // hack to do the same thing.
+    private boolean waitExtraForText(String txt) {
+        boolean foundText = waitForText(txt);
+        if (!foundText) {
+            // If we don't see the item, scroll down once in case it's off-screen.
+            // Hacky way to scroll down.  solo.scroll* does not work in dialogs.
+            MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
+            meh.dragSync(mMidWidth, mMidHeight+100, mMidWidth, mMidHeight-100);
+
+            foundText = mSolo.waitForText(txt);
+        }
+        return foundText;
     }
 }