Bug 1085837 - Open legacy "More" menu before asserting menu item is disabled. r=liuche, a=test-only
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 31 Oct 2014 17:08:30 -0700
changeset 242540 010baae27d0e36ae3781bc2a7a00ee42c8071d76
parent 242539 888ab5f9e5676d834bb3d3a1c551a19c68c0deb2
child 242541 dc2ab77e2ceb18984d30d69b117eb726ae1a096c
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, test-only
bugs1085837
milestone36.0a2
Bug 1085837 - Open legacy "More" menu before asserting menu item is disabled. r=liuche, a=test-only
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();
             }