Bug 1209967 - Fix AppMenuComponent to work on GB. r=sebastian a=sylvestre
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 25 Nov 2015 15:52:39 -0800
changeset 310463 7990937f9b5cb0af3cb2f5638faffbfa65ed3b2d
parent 310462 05bf2e1a899f02da2f3ad7ad1bc88318a7e4ae46
child 310464 14da949cf6784e28601abc324b4add61b6cdffaf
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, sylvestre
bugs1209967
milestone45.0a2
Bug 1209967 - Fix AppMenuComponent to work on GB. r=sebastian a=sylvestre This required us to use the menu button to open the menu and check if the menu is open by looking at more menu items due to intermittent issues where the menu would not always be scrolled to the top (I think Robotium scrolled the menu before it finished appearing so we couldn't see the first item and failed the isOpen test).
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
@@ -6,23 +6,23 @@ package org.mozilla.gecko.tests.componen
 
 import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertEquals;
 import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertFalse;
 import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertNotNull;
 import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertTrue;
 
 import java.util.List;
 
+import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.menu.MenuItemActionBar;
 import org.mozilla.gecko.menu.MenuItemDefault;
 import org.mozilla.gecko.tests.UITestContext;
 import org.mozilla.gecko.tests.helpers.DeviceHelper;
 import org.mozilla.gecko.tests.helpers.WaitHelper;
-import org.mozilla.gecko.util.HardwareUtils;
 
 import android.text.TextUtils;
 import android.view.View;
 import android.widget.TextView;
 
 import com.jayway.android.robotium.solo.Condition;
 import com.jayway.android.robotium.solo.RobotiumUtils;
 import com.jayway.android.robotium.solo.Solo;
@@ -238,19 +238,19 @@ public class AppMenuComponent extends Ba
 
     public void pressMenuItem(final PageMenuItem pageMenuItem) {
         pressSubMenuItem(PageMenuItem.PARENT_MENU.getString(mSolo), pageMenuItem.getString(mSolo));
     }
 
     private void openAppMenu() {
         assertMenuIsNotOpen();
 
-        // This is a hack needed for tablets where the OverflowMenuButton is always in the GONE state,
+        // This is a hack needed for tablets & GB where the OverflowMenuButton is always in the GONE state,
         // so we press the menu key instead.
-        if (DeviceHelper.isTablet()) {
+        if (DeviceHelper.isTablet() || AppConstants.Versions.preHC) {
             mSolo.sendKey(Solo.MENU);
         } else {
             pressOverflowMenuButton();
         }
 
         waitForMenuOpen();
     }
 
@@ -278,22 +278,24 @@ public class AppMenuComponent extends Ba
 
         fAssertTrue("The overflow menu button is enabled", overflowMenuButton.isEnabled());
         fAssertEquals("The overflow menu button is visible", View.VISIBLE, overflowMenuButton.getVisibility());
 
         mSolo.clickOnView(overflowMenuButton, true);
     }
 
     /**
-    * Determines whether the app menu is open by searching for the text "New tab".
+    * Determines whether the app menu is open by searching for items in the menu.
     *
     * @return true if app menu is open.
     */
     private boolean isMenuOpen() {
-        return isMenuOpen(MenuItem.NEW_TAB.getString(mSolo));
+        // 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.
         return mSolo.searchText(mSolo.getString(R.string.share), true);
     }
 
     /**