Bug 1265011 - Add test for hardware menu key support (Bug 1229967). r=sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 15 Apr 2016 17:46:07 +0200
changeset 352096 81bbc1eb329a2cfd47f476774d7719d4c6ef7cf5
parent 351979 afd82f887093e5e9e4015115ca5795ec82a6f732
child 518577 d0c4a1cc131bcd80def638fe3c14244f4ab2e44e
push id15614
push usermozilla@buttercookie.de
push dateFri, 15 Apr 2016 17:47:11 +0000
reviewerssebastian
bugs1265011, 1229967
milestone48.0a1
Bug 1265011 - Add test for hardware menu key support (Bug 1229967). r=sebastian Make sure that the app menu can be opened and closed via the hardware menu key. MozReview-Commit-ID: 3E459eCRneY
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/AppMenuComponent.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testAppMenuPathways.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
@@ -78,17 +78,21 @@ public class AppMenuComponent extends Ba
             return stringResource;
         }
     };
 
     public AppMenuComponent(final UITestContext testContext) {
         super(testContext);
     }
 
-    private void assertMenuIsNotOpen() {
+    public void assertMenuIsOpen() {
+        fAssertTrue("Menu is open", isMenuOpen());
+    }
+
+    public void assertMenuIsNotOpen() {
         fAssertFalse("Menu is not open", isMenuOpen());
     }
 
     public void assertMenuItemIsDisabledAndVisible(PageMenuItem pageMenuItem) {
         openAppMenu();
 
         // Non-legacy devices have hierarchical menu, check for parent menu item "page".
         final View parentMenuItemView = findAppMenuItemView(MenuItem.PAGE.getString(mSolo));
@@ -266,17 +270,26 @@ public class AppMenuComponent extends Ba
      *                      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() {
+    public void waitForMenuOpen() {
         WaitHelper.waitFor("menu to open", new Condition() {
             @Override
             public boolean isSatisfied() {
                 return isMenuOpen();
             }
         });
     }
+
+    public void waitForMenuClose() {
+        WaitHelper.waitFor("menu to close", new Condition() {
+            @Override
+            public boolean isSatisfied() {
+                return !isMenuOpen();
+            }
+        });
+    }
 }
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testAppMenuPathways.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testAppMenuPathways.java
@@ -5,31 +5,46 @@
 package org.mozilla.gecko.tests;
 
 import org.json.JSONObject;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.tests.components.AppMenuComponent;
 import org.mozilla.gecko.tests.helpers.GeckoHelper;
 import org.mozilla.gecko.tests.helpers.NavigationHelper;
 
+import com.robotium.solo.Solo;
+
 /**
  * Set of tests to test UI App menu and submenus the user interact with.
  */
 public class testAppMenuPathways extends UITest {
 
     /**
      * Robocop supports only a single test function per test class. Therefore, we
      * have a single top-level test function that dispatches to sub-tests.
      */
     public void testAppMenuPathways() {
         GeckoHelper.blockForReady();
 
+        _testHardwareMenuKeyOpenClose();
         _testSaveAsPDFPathway();
     }
 
+    public void _testHardwareMenuKeyOpenClose() {
+        mAppMenu.assertMenuIsNotOpen();
+
+        mSolo.sendKey(Solo.MENU);
+        mAppMenu.waitForMenuOpen();
+        mAppMenu.assertMenuIsOpen();
+
+        mSolo.sendKey(Solo.MENU);
+        mAppMenu.waitForMenuClose();
+        mAppMenu.assertMenuIsNotOpen();
+    }
+
     public void _testSaveAsPDFPathway() {
         // Page menu should be disabled in about:home.
         mAppMenu.assertMenuItemIsDisabledAndVisible(AppMenuComponent.PageMenuItem.SAVE_AS_PDF);
 
         // Generate a mock Content:LocationChange message with video mime-type for the current tab (tabId = 0).
         final JSONObject message = new JSONObject();
         try {
             message.put("contentType", "video/webm");