Bug 1228170 - Remove legacy menu code from AppMenuComponent. r=sebastian
authorShatur<tushar.saini1285@gmail.com>
Tue, 02 Feb 2016 23:46:58 +0530
changeset 329852 62437a8123876ca69e54c68a40659704139ce2d5
parent 329851 28adba6d7e46f1547ea885be2d016ae205dd8d2f
child 329853 6e1c21facba82b35fd5a31d5375ee471402fb979
child 329899 42818caf0dc483e25ac88c2031ffcf190a561eb6
child 329909 c4065f3543f80754f876f655bd8cb89a134a5c11
child 330830 5f96ac9e695cd23902fc4984952eff3a1b3fe0b9
child 331159 44d37f4ab1569d19f5a1c8004e3702afa06aca2c
child 331160 124756c57ca96db10c790a662d8a407e2357de14
child 331581 67f384853cc7e57f003de21ff3c032e631a390e8
child 331672 439c5be3e04b80df6c7e4430351ebaacf48599e2
child 331690 4c701b026040d1cc4aba2aa52956f161569bcfa1
child 331756 2690c80b6f6e8eee0a8657dca591d3ddb5ec75b6
child 331855 2634c75fbb30796a8083a6f225fcbf9dceff50cf
child 331859 dacc05065713b3ebf1ee37921effcda4c3ae1f58
push id10617
push userdtownsend@mozilla.com
push dateTue, 09 Feb 2016 16:30:19 +0000
reviewerssebastian
bugs1228170
milestone47.0a1
Bug 1228170 - Remove legacy menu code from AppMenuComponent. r=sebastian
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/AppMenuComponent.java
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/AppMenuComponent.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/AppMenuComponent.java
@@ -30,18 +30,16 @@ import com.jayway.android.robotium.solo.
 import com.jayway.android.robotium.solo.Solo;
 
 /**
  * A class representing any interactions that take place on the app menu.
  */
 public class AppMenuComponent extends BaseComponent {
     private static final long MAX_WAITTIME_FOR_MENU_UPDATE_IN_MS = 7500L;
 
-    private Boolean hasLegacyMenu = null;
-
     public enum MenuItem {
         FORWARD(R.string.forward),
         NEW_TAB(R.string.new_tab),
         PAGE(R.string.page),
         RELOAD(R.string.reload);
 
         private final int resourceID;
         private String stringResource;
@@ -83,70 +81,37 @@ public class AppMenuComponent extends Ba
     public AppMenuComponent(final UITestContext testContext) {
         super(testContext);
     }
 
     private void assertMenuIsNotOpen() {
         fAssertFalse("Menu is not open", isMenuOpen());
     }
 
-    /**
-     * Legacy Android devices doesn't have hierarchical menus. Sub-menus, such as "Page", are missing in these devices.
-     * Try to determine if the menu item "Page" is present.
-     *
-     * TODO : This fragile way to determine legacy menus should be replaced with a check for 6-panel menu item.
-     *
-     * @return true if there is a legacy menu.
-     */
-    private boolean hasLegacyMenu() {
-        if (hasLegacyMenu == null) {
-            hasLegacyMenu = findAppMenuItemView(MenuItem.PAGE.getString(mSolo)) == null;
-        }
-
-        return hasLegacyMenu;
-    }
-
     public void assertMenuItemIsDisabledAndVisible(PageMenuItem pageMenuItem) {
         openAppMenu();
 
-        if (!hasLegacyMenu()) {
-            // Non-legacy devices have hierarchical menu, check for parent menu item "page".
-            final View parentMenuItemView = findAppMenuItemView(MenuItem.PAGE.getString(mSolo));
-            if (parentMenuItemView.isEnabled()) {
-                fAssertTrue("The parent 'page' menu item is enabled", parentMenuItemView.isEnabled());
-                fAssertEquals("The parent 'page' menu item is visible", View.VISIBLE,
-                        parentMenuItemView.getVisibility());
-
-                // Parent menu "page" is enabled, open page menu and check for menu item represented by pageMenuItem.
-                pressMenuItem(MenuItem.PAGE.getString(mSolo));
+        // Non-legacy devices have hierarchical menu, check for parent menu item "page".
+        final View parentMenuItemView = findAppMenuItemView(MenuItem.PAGE.getString(mSolo));
+        if (parentMenuItemView.isEnabled()) {
+            fAssertTrue("The parent 'page' menu item is enabled", parentMenuItemView.isEnabled());
+            fAssertEquals("The parent 'page' menu item is visible", View.VISIBLE,
+            parentMenuItemView.getVisibility());
 
-                final View pageMenuItemView = findAppMenuItemView(pageMenuItem.getString(mSolo));
-                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 (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();
+            // Parent menu "page" is enabled, open page menu and check for menu item represented by pageMenuItem.
+            pressMenuItem(MenuItem.PAGE.getString(mSolo));
 
             final View pageMenuItemView = findAppMenuItemView(pageMenuItem.getString(mSolo));
+            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());
-
-            // Close the "More" menu.
-            mSolo.goBack();
+        } else {
+            fAssertFalse("The parent 'page' menu item is not enabled", parentMenuItemView.isEnabled());
+            fAssertEquals("The parent 'page' menu item is visible", View.VISIBLE, parentMenuItemView.getVisibility());
         }
-
         // Close the App Menu.
         mSolo.goBack();
     }
 
     private View getOverflowMenuButtonView() {
         return mSolo.getView(R.id.menu);
     }
 
@@ -202,42 +167,33 @@ public class AppMenuComponent extends Ba
      *
      * @param menuItemTitle, The title of menu item to open.
      */
     private void pressLegacyMenuItem(final String menuItemTitle) {
         mSolo.clickOnMenuItem(menuItemTitle, true);
     }
 
     private void pressMenuItem(final String menuItemTitle) {
-        if (!hasLegacyMenu()) {
             final View menuItemView = findAppMenuItemView(menuItemTitle);
             fAssertTrue("Menu is open", isMenuOpen(menuItemView));
 
             fAssertTrue(String.format("The menu item %s is enabled", menuItemTitle), menuItemView.isEnabled());
             fAssertEquals(String.format("The menu item %s is visible", menuItemTitle), View.VISIBLE,
-                    menuItemView.getVisibility());
+            menuItemView.getVisibility());
 
             mSolo.clickOnView(menuItemView);
-        } else {
-            fAssertTrue("Menu is open", isMenuOpen(menuItemTitle));
-            pressLegacyMenuItem(menuItemTitle);
-        }
     }
 
     private void pressSubMenuItem(final String parentMenuItemTitle, final String childMenuItemTitle) {
         openAppMenu();
 
-        if (!hasLegacyMenu()) {
-            pressMenuItem(parentMenuItemTitle);
+        pressMenuItem(parentMenuItemTitle);
 
-            // Child menu item is not pressed yet, Click on it.
-            pressMenuItem(childMenuItemTitle);
-        } else {
-            pressLegacyMenuItem(childMenuItemTitle);
-        }
+        // Child menu item is not pressed yet, Click on it.
+        pressMenuItem(childMenuItemTitle);        
     }
 
     public void pressMenuItem(MenuItem menuItem) {
         openAppMenu();
         pressMenuItem(menuItem.getString(mSolo));
     }
 
     public void pressMenuItem(final PageMenuItem pageMenuItem) {
@@ -253,35 +209,16 @@ 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);
     }
@@ -292,22 +229,16 @@ public class AppMenuComponent extends Ba
     * @return true if app menu is open.
     */
     private boolean isMenuOpen() {
         // We choose these options because New Tab is near the top of the menu and Page is near the middle/bottom.
         // Intermittently, the menu doesn't scroll to top so we can't just use the first item in the list.
         return isMenuOpen(MenuItem.NEW_TAB.getString(mSolo)) || isMenuOpen(MenuItem.PAGE.getString(mSolo));
     }
 
-    private boolean isLegacyMoreMenuOpen() {
-        // Check if the first menu option is visible.
-        final String shareTitle = mSolo.getString(R.string.share);
-        return RobotiumHelper.searchExactText(shareTitle, 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) {