Bug 1144879 - Android 4.3 testSessionHistory | Menu is open. r=mcomella
authorMelchiorre Alastra <miticomilko@hotmail.com>
Mon, 07 Dec 2015 15:00:55 +0100
changeset 317395 3b83bc04babe91f4a2c06d0e7fc21673e211628d
parent 317394 a6a1f948a4665f48205e819c3defa7adf1de1b00
child 317396 9c4636421d7175d97c10bed8ca198bd473e7aeb4
push id8691
push userbmo:vivekb.balakrishnan@gmail.com
push dateWed, 23 Dec 2015 21:07:27 +0000
reviewersmcomella
bugs1144879
milestone46.0a1
Bug 1144879 - Android 4.3 testSessionHistory | Menu is open. r=mcomella
mobile/android/tests/browser/robocop/robocop.ini
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/AppMenuComponent.java
--- a/mobile/android/tests/browser/robocop/robocop.ini
+++ b/mobile/android/tests/browser/robocop/robocop.ini
@@ -133,17 +133,15 @@ skip-if = android_version == "18"
 [src/org/mozilla/gecko/tests/testGeckoRequest.java]
 [src/org/mozilla/gecko/tests/testInputConnection.java]
 # disabled on Android 2.3, 4.3; bug 1025968
 skip-if = android_version == "10" || android_version == "18"
 [src/org/mozilla/gecko/tests/testJavascriptBridge.java]
 [src/org/mozilla/gecko/tests/testNativeCrypto.java]
 [src/org/mozilla/gecko/tests/testReaderModeTitle.java]
 [src/org/mozilla/gecko/tests/testSessionHistory.java]
-# disabled on Android 4.3, bug 1144879
-skip-if = android_version == "18"
 [src/org/mozilla/gecko/tests/testStateWhileLoading.java]
 
 [src/org/mozilla/gecko/tests/testAccessibleCarets.java]
 
 # testStumblerSetting disabled on Android 4.3, bug 1145846
 [src/org/mozilla/gecko/tests/testStumblerSetting.java]
 skip-if = android_version == "10" || android_version == "18"
--- 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
@@ -17,16 +17,17 @@ import org.mozilla.gecko.menu.MenuItemAc
 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 android.text.TextUtils;
 import android.view.View;
 import android.widget.TextView;
+import android.widget.RelativeLayout;
 
 import com.jayway.android.robotium.solo.Condition;
 import com.jayway.android.robotium.solo.RobotiumUtils;
 import com.jayway.android.robotium.solo.Solo;
 
 /**
  * A class representing any interactions that take place on the app menu.
  */
@@ -179,46 +180,48 @@ public class AppMenuComponent extends Ba
         // On Android 2.3, menu items may be instances of
         // com.android.internal.view.menu.ListMenuItemView, each with a child
         // android.widget.RelativeLayout which in turn has a child
         // TextView with the appropriate text.
         final List<TextView> textViewList = RobotiumUtils.filterViews(TextView.class, views);
         for (TextView textView : textViewList) {
             if (TextUtils.equals(textView.getText(), text)) {
                 View relativeLayout = (View) textView.getParent();
-                View listMenuItemView = (View)relativeLayout.getParent();
-                return listMenuItemView;
+                if (relativeLayout instanceof RelativeLayout) {
+                    View listMenuItemView = (View)relativeLayout.getParent();
+                    return listMenuItemView;
+                }
             }
         }
         return null;
     }
 
     /**
      * Helper function to let Robotium locate and click menu item from legacy Android menu (devices with Android 2.x).
      *
      * Robotium will also try to open the menu if there are no open dialog.
      *
-     * @param menuItemText, The title of menu item to open.
+     * @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) {
-        fAssertTrue("Menu is open", isMenuOpen(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());
 
             mSolo.clickOnView(menuItemView);
         } else {
+            fAssertTrue("Menu is open", isMenuOpen(menuItemTitle));
             pressLegacyMenuItem(menuItemTitle);
         }
     }
 
     private void pressSubMenuItem(final String parentMenuItemTitle, final String childMenuItemTitle) {
         openAppMenu();
 
         if (!hasLegacyMenu()) {
@@ -301,17 +304,30 @@ public class AppMenuComponent extends Ba
     /**
      * 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, true);
+        final View menuItemView = findAppMenuItemView(menuItemTitle);
+        return isMenuOpen(menuItemView) ? true : mSolo.searchText(menuItemTitle, true);
+    }
+
+    /**
+     * If a ListMenuItemView with menuItemTitle is visible then the app menu is open .
+     *
+     * @param menuItemView, must be a ListMenuItemView with menuItemTitle.
+     *                      You must use findAppMenuItemView(menuItemTitle) to obtain it.
+     *
+     * @return true if app menu is open.
+     */
+    private boolean isMenuOpen(View menuItemView) {
+        return (menuItemView != null) && (menuItemView.getVisibility() == View.VISIBLE);
     }
 
     private void waitForMenuOpen() {
         WaitHelper.waitFor("menu to open", new Condition() {
             @Override
             public boolean isSatisfied() {
                 return isMenuOpen();
             }