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
--- 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");