Bug 897970 - Fix robocop testBookmark for x86/JB; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Thu, 25 Jul 2013 17:38:10 -0700
changeset 152358 277c1e376c3cacb878d29301c992aaf290f3ae6f
parent 152357 6089b164088dbb4de39966cf58040f57d3544f00
child 152359 639f164cc46ed3e84f1ecf10f0d83f3804a2019c
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs897970
milestone25.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 897970 - Fix robocop testBookmark for x86/JB; r=jmaher
mobile/android/base/tests/BaseTest.java.in
mobile/android/base/tests/testBookmark.java.in
mobile/android/base/tests/testHistoryTab.java.in
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -725,16 +725,50 @@ abstract class BaseTest extends Activity
         }
         return parsedEventData;
     }
 
     public final void runOnUiThreadSync(Runnable runnable) {
         RobocopUtils.runOnUiThreadSync(mActivity, runnable);
     }
 
+    /* Tap the "star" (bookmark) button to bookmark or un-bookmark the current page */
+    public void toggleBookmark() {
+        mActions.sendSpecialKey(Actions.SpecialKey.MENU);
+        waitForText("Settings");
+
+        // On ICS+ phones, there is no button labeled "Bookmarks"
+        // instead we have to just dig through every button on the screen
+        ArrayList<View> images = mSolo.getCurrentViews();
+        for (int i = 0; i < images.size(); i++) {
+            final View view = images.get(i);
+            boolean found = false;
+            found = "Bookmark".equals(view.getContentDescription());
+
+            // on older android versions, try looking at the button's text
+            if (!found) {
+                if (view instanceof TextView) {
+                    found = "Bookmark".equals(((TextView)view).getText());
+                }
+            }
+
+            if (found) {
+                int[] xy = new int[2];
+                view.getLocationOnScreen(xy);
+
+                final int viewWidth = view.getWidth();
+                final int viewHeight = view.getHeight();
+                final float x = xy[0] + (viewWidth / 2.0f);
+                float y = xy[1] + (viewHeight / 2.0f);
+
+                mSolo.clickOnScreen(x, y);
+            }
+        }
+    }
+
     /**
     * This method will edit the bookmark with index = bookmarkIndex from the list of bookmarks
     * For the field index:
     *     fieldIndex = 1 - the Bookmark name
     *     fieldIndex = 2 - the Bookmark url
     *     fieldIndex = 3 - the Bookmark keyword
     */
     public void editBookmark(int bookmarkIndex, int fieldIndex, String addedText, ListView list) {
@@ -877,16 +911,18 @@ abstract class BaseTest extends Activity
                     Element reloadBtn = mDriver.findElement(getActivity(), "reload");
                     reloadBtn.click();
                 } else {
                     mSolo.clickOnText("^Reload$");
                 }
             }
         }
 
+        // DEPRECATED!
+        // Use BaseTest.toggleBookmark() in new code.
         public void bookmark() {
             if (devType.equals("tablet")) {
                 if (!osVersion.equals("4.x")){
                     Element bookmarkBtn = mDriver.findElement(getActivity(), "bookmark");
                     bookmarkBtn.click();
                 }
                 else {
                     mActions.sendSpecialKey(Actions.SpecialKey.MENU);
--- a/mobile/android/base/tests/testBookmark.java.in
+++ b/mobile/android/base/tests/testBookmark.java.in
@@ -141,24 +141,16 @@ public class testBookmark extends PixelT
             mRemoveBookmark.invoke(null, getActivity().getContentResolver(), BOOKMARK_URL);
         } catch(java.lang.IllegalAccessException ex) {
             mAsserter.is(true, false, "Can not call removeBookmark");
         } catch(java.lang.reflect.InvocationTargetException ex) {
             mAsserter.is(true, false, "Error calling removeBookmark");
         }
     }
 
-    // This method opens the menu and selects the "Bookmark" menu item
-    private void toggleBookmark() {
-        getInstrumentation().waitForIdleSync();
-        mActions.sendSpecialKey(Actions.SpecialKey.MENU);
-        waitForText("Bookmark");
-        mSolo.clickOnText("Bookmark");
-    }
-
     private void setUpBookmark() {
         // Bookmark a page for the test
         loadAndPaint(BOOKMARK_URL);
         toggleBookmark();
         mAsserter.is(mSolo.waitForText("Bookmark added"), true, "bookmark added successfully");
 
         // Navigate back to about:home for the test
         loadAndPaint(ABOUT_HOME_URL);
--- a/mobile/android/base/tests/testHistoryTab.java.in
+++ b/mobile/android/base/tests/testHistoryTab.java.in
@@ -46,47 +46,17 @@ public class testHistoryTab extends Pixe
         // load two pages so there is something in our history
         // bookmark one of them
         String url = getAbsoluteUrl("/robocop/robocop_big_link.html");
         loadAndPaint(url);
 
         url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
         loadAndPaint(url);
 
-        mActions.sendSpecialKey(Actions.SpecialKey.MENU);
-        waitForText("Settings");
-
-        // On ICS+ phones, there is no button labeled "Bookmarks"
-        // instead we have to just dig through every button on the screen
-        ArrayList<View> images = mSolo.getCurrentViews();
-        for (int i = 0; i < images.size(); i++) {
-          final View view = images.get(i);
-          boolean found = false;
-          found = "Bookmark".equals(view.getContentDescription());
-
-          // on older android versions, try looking at the button's text
-          if (!found) {
-              if (view instanceof TextView) {
-                 found = "Bookmark".equals(((TextView)view).getText());
-              }
-          }
-
-          if (found) {
-            int[] xy = new int[2];
-            view.getLocationOnScreen(xy);
-
-            final int viewWidth = view.getWidth();
-            final int viewHeight = view.getHeight();
-            final float x = xy[0] + (viewWidth / 2.0f);
-            float y = xy[1] + (viewHeight / 2.0f);
-
-            mSolo.clickOnScreen(x, y);
-          }
-        }
-        
+        toggleBookmark();
         mAsserter.is(mSolo.waitForText("Bookmark added"), true, "bookmark added successfully");
 
         testList(url);
         testContextMenu(url);
         testClick(getAbsoluteUrl("/robocop/robocop_big_link.html"));
     }
 
     private void testList(String url) {