Bug 1085837 - Fix robocop testAppMenuPathways on Android 2.3. r=mcomella, a=test-only
authorGeoff Brown <gbrown@mozilla.com>
Fri, 19 Dec 2014 09:22:07 -0700
changeset 242541 dc2ab77e2ceb18984d30d69b117eb726ae1a096c
parent 242540 010baae27d0e36ae3781bc2a7a00ee42c8071d76
child 242542 3d7cac2f8f158ea6425a4e5f810d934d91357eb9
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)
reviewersmcomella, test-only
bugs1085837
milestone36.0a2
Bug 1085837 - Fix robocop testAppMenuPathways on Android 2.3. r=mcomella, 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
@@ -15,16 +15,17 @@ 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.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;
 
 /**
  * A class representing any interactions that take place on the app menu.
  */
@@ -169,16 +170,28 @@ public class AppMenuComponent extends Ba
 
         final List<MenuItemDefault> menuItemDefaultList = RobotiumUtils.filterViews(MenuItemDefault.class, views);
         for (MenuItemDefault menuItem : menuItemDefaultList) {
             if (menuItem.getText().equals(text)) {
                 return menuItem;
             }
         }
 
+        // 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 (textView.getText().equals(text)) {
+                View relativeLayout = (View) textView.getParent();
+                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.
      *