Bug 1085837 - Open legacy "More" menu before asserting menu item is disabled; r=liuche
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 31 Oct 2014 17:08:30 -0700
changeset 220547 73b2de63fc8d9122bf8f108102459885ef596d04
parent 220546 79f04caf9dc96a2fedbe7849331f3593a8575821
child 220548 aa47abc628177532902370efe0e7782e9141afe8
push id53133
push usergbrown@mozilla.com
push dateFri, 19 Dec 2014 16:22:24 +0000
treeherdermozilla-inbound@73dbbfed2b30 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1085837
milestone37.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 1085837 - Open legacy "More" menu before asserting menu item is disabled; r=liuche
mobile/android/base/tests/components/AppMenuComponent.java
--- a/mobile/android/base/tests/components/AppMenuComponent.java
+++ b/mobile/android/base/tests/components/AppMenuComponent.java
@@ -118,34 +118,45 @@ public class AppMenuComponent extends Ba
                 fAssertNotNull("The page menu item is not null", pageMenuItemView);
                 fAssertFalse("The page menu item is not enabled", pageMenuItemView.isEnabled());
                 fAssertEquals("The page menu item is visible", View.VISIBLE, pageMenuItemView.getVisibility());
             } else {
                 fAssertFalse("The parent 'page' menu item is not enabled", parentMenuItemView.isEnabled());
                 fAssertEquals("The parent 'page' menu item is visible", View.VISIBLE, parentMenuItemView.getVisibility());
             }
         } else {
-            // Legacy devices don't have parent menu item "page", check for menu item represented by pageMenuItem.
+            // Legacy devices (Android 2.3 and earlier) don't have the parent menu, "Page", so check directly for the menu
+            // item represented by pageMenuItem.
+            //
+            // We need to make sure the appropriate menu view is constructed
+            // so open the "More" menu to additionally construct those views.
+            openLegacyMoreMenu();
+
             final View pageMenuItemView = findAppMenuItemView(pageMenuItem.getString(mSolo));
             fAssertFalse("The page menu item is not enabled", pageMenuItemView.isEnabled());
             fAssertEquals("The page menu item is visible", View.VISIBLE, pageMenuItemView.getVisibility());
+
+            // Close the "More" menu.
+            mSolo.goBack();
         }
 
         // Close the App Menu.
         mSolo.goBack();
     }
 
     private View getOverflowMenuButtonView() {
         return mSolo.getView(R.id.menu);
     }
 
     /**
      * Try to find a MenuItemActionBar/MenuItemDefault with the given text set as contentDescription / text.
      *
-     * Will return null when the Android legacy menu is in use.
+     * When using legacy menus, make sure the menu has been opened to the appropriate level
+     * (i.e. base menu or "More" menu) to ensure the appropriate menu views are in memory.
+     * TODO: ^ Maybe we just need to have opened the "More" menu and the current one doesn't matter.
      *
      * This method is dependent on not having two views with equivalent contentDescription / text.
      */
     private View findAppMenuItemView(String text) {
         mSolo.waitForText(text, 1, MAX_WAITTIME_FOR_MENU_UPDATE_IN_MS);
 
         final List<View> views = mSolo.getViews();
 
@@ -224,16 +235,35 @@ public class AppMenuComponent extends Ba
             mSolo.sendKey(Solo.MENU);
         } else {
             pressOverflowMenuButton();
         }
 
         waitForMenuOpen();
     }
 
+    /**
+     * Opens the "More" options menu on legacy Android devices. Assumes the base menu
+     * (i.e. {@link #openAppMenu()}) has already been called and thus the menu is open.
+     */
+    private void openLegacyMoreMenu() {
+        fAssertTrue("The base menu is already open", isMenuOpen());
+
+        // Since there may be more views with "More" on the screen,
+        // this is not robust. However, there may not be a better way.
+        mSolo.clickOnText("^More$");
+
+        WaitHelper.waitFor("legacy \"More\" menu to open", new Condition() {
+            @Override
+            public boolean isSatisfied() {
+                return isLegacyMoreMenuOpen();
+            }
+        });
+    }
+
     private void pressOverflowMenuButton() {
         final View overflowMenuButton = getOverflowMenuButtonView();
 
         fAssertTrue("The overflow menu button is enabled", overflowMenuButton.isEnabled());
         fAssertEquals("The overflow menu button is visible", View.VISIBLE, overflowMenuButton.getVisibility());
 
         mSolo.clickOnView(overflowMenuButton, true);
     }
@@ -242,25 +272,30 @@ public class AppMenuComponent extends Ba
     * Determines whether the app menu is open by searching for the text "New tab".
     *
     * @return true if app menu is open.
     */
     private boolean isMenuOpen() {
         return isMenuOpen(MenuItem.NEW_TAB.getString(mSolo));
     }
 
+    private boolean isLegacyMoreMenuOpen() {
+        // Check if the first menu option is visible.
+        return mSolo.searchText(mSolo.getString(R.string.share), true);
+    }
+
     /**
      * Determines whether the app menu is open by searching for the text in menuItemTitle.
      *
      * @param menuItemTitle, The contentDescription of menu item to search.
      *
      * @return true if app menu is open.
      */
     private boolean isMenuOpen(String menuItemTitle) {
-        return mSolo.searchText(menuItemTitle);
+        return mSolo.searchText(menuItemTitle, true);
     }
 
     private void waitForMenuOpen() {
         WaitHelper.waitFor("menu to open", new Condition() {
             @Override
             public boolean isSatisfied() {
                 return isMenuOpen();
             }