mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 944142 - Implement NavigationHelper.goForward for phones. r=mcomella
This commit is contained in:
parent
eff465e5ee
commit
bcdbd307b4
@ -58,6 +58,7 @@ abstract class UITest extends ActivityInstrumentationTestCase2<Activity>
|
||||
private String mBaseIpUrl;
|
||||
|
||||
protected AboutHomeComponent mAboutHome;
|
||||
protected AppMenuComponent mAppMenu;
|
||||
protected ToolbarComponent mToolbar;
|
||||
|
||||
static {
|
||||
@ -120,6 +121,7 @@ abstract class UITest extends ActivityInstrumentationTestCase2<Activity>
|
||||
|
||||
private void initComponents() {
|
||||
mAboutHome = new AboutHomeComponent(this);
|
||||
mAppMenu = new AppMenuComponent(this);
|
||||
mToolbar = new ToolbarComponent(this);
|
||||
}
|
||||
|
||||
@ -163,6 +165,9 @@ abstract class UITest extends ActivityInstrumentationTestCase2<Activity>
|
||||
case ABOUTHOME:
|
||||
return mAboutHome;
|
||||
|
||||
case APPMENU:
|
||||
return mAppMenu;
|
||||
|
||||
case TOOLBAR:
|
||||
return mToolbar;
|
||||
|
||||
|
@ -21,6 +21,7 @@ public interface UITestContext {
|
||||
|
||||
public static enum ComponentType {
|
||||
ABOUTHOME,
|
||||
APPMENU,
|
||||
TOOLBAR
|
||||
}
|
||||
|
||||
|
143
mobile/android/base/tests/components/AppMenuComponent.java
Normal file
143
mobile/android/base/tests/components/AppMenuComponent.java
Normal file
@ -0,0 +1,143 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.tests.components;
|
||||
|
||||
import static org.mozilla.gecko.tests.helpers.AssertionHelper.*;
|
||||
|
||||
import org.mozilla.gecko.menu.MenuItemActionBar;
|
||||
import org.mozilla.gecko.menu.MenuItemDefault;
|
||||
import org.mozilla.gecko.tests.helpers.*;
|
||||
import org.mozilla.gecko.tests.UITestContext;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.R;
|
||||
|
||||
import com.jayway.android.robotium.solo.Condition;
|
||||
import com.jayway.android.robotium.solo.RobotiumUtils;
|
||||
import com.jayway.android.robotium.solo.Solo;
|
||||
|
||||
import android.view.View;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A class representing any interactions that take place on the app menu.
|
||||
*/
|
||||
public class AppMenuComponent extends BaseComponent {
|
||||
public enum MenuItem {
|
||||
FORWARD(R.string.forward),
|
||||
NEW_TAB(R.string.new_tab);
|
||||
|
||||
private final int resourceID;
|
||||
private String stringResource;
|
||||
|
||||
MenuItem(final int resourceID) {
|
||||
this.resourceID = resourceID;
|
||||
}
|
||||
|
||||
public String getString(final Solo solo) {
|
||||
if (stringResource == null) {
|
||||
stringResource = solo.getString(resourceID);
|
||||
}
|
||||
|
||||
return stringResource;
|
||||
}
|
||||
};
|
||||
|
||||
public AppMenuComponent(final UITestContext testContext) {
|
||||
super(testContext);
|
||||
}
|
||||
|
||||
private void assertMenuIsNotOpen() {
|
||||
assertFalse("Menu is not open", isMenuOpen());
|
||||
}
|
||||
|
||||
private View getOverflowMenuButtonView() {
|
||||
return mSolo.getView(R.id.menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to find a MenuItemActionBar/MenuItemDefault with the given text set as contentDescription / text.
|
||||
*
|
||||
* Will return null when the Android legacy menu is in use.
|
||||
*
|
||||
* This method is dependent on not having two views with equivalent contentDescription / text.
|
||||
*/
|
||||
private View findAppMenuItemView(String text) {
|
||||
final List<View> views = mSolo.getViews();
|
||||
|
||||
final List<MenuItemActionBar> menuItemActionBarList = RobotiumUtils.filterViews(MenuItemActionBar.class, views);
|
||||
for (MenuItemActionBar menuItem : menuItemActionBarList) {
|
||||
if (menuItem.getContentDescription().equals(text)) {
|
||||
return menuItem;
|
||||
}
|
||||
}
|
||||
|
||||
final List<MenuItemDefault> menuItemDefaultList = RobotiumUtils.filterViews(MenuItemDefault.class, views);
|
||||
for (MenuItemDefault menuItem : menuItemDefaultList) {
|
||||
if (menuItem.getText().equals(text)) {
|
||||
return menuItem;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void pressMenuItem(MenuItem menuItem) {
|
||||
openAppMenu();
|
||||
|
||||
final String text = menuItem.getString(mSolo);
|
||||
final View menuItemView = findAppMenuItemView(text);
|
||||
|
||||
if (menuItemView != null) {
|
||||
assertTrue("The menu item is enabled", menuItemView.isEnabled());
|
||||
assertEquals("The menu item is visible", View.VISIBLE, menuItemView.getVisibility());
|
||||
|
||||
mSolo.clickOnView(menuItemView);
|
||||
} else {
|
||||
// We could not find a view representing this menu item: Let's let Robotium try to
|
||||
// locate and click it in the legacy Android menu (devices with Android 2.x).
|
||||
//
|
||||
// Even though we already opened the menu to see if we can locate the menu item,
|
||||
// Robotium will also try to open the menu if it doesn't find an open dialog (Does
|
||||
// not happen in this case).
|
||||
mSolo.clickOnMenuItem(text, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void openAppMenu() {
|
||||
assertMenuIsNotOpen();
|
||||
|
||||
if (HardwareUtils.hasMenuButton()) {
|
||||
mSolo.sendKey(Solo.MENU);
|
||||
} else {
|
||||
pressOverflowMenuButton();
|
||||
}
|
||||
|
||||
waitForMenuOpen();
|
||||
}
|
||||
|
||||
private void pressOverflowMenuButton() {
|
||||
final View overflowMenuButton = getOverflowMenuButtonView();
|
||||
|
||||
assertTrue("The overflow menu button is enabled", overflowMenuButton.isEnabled());
|
||||
assertEquals("The overflow menu button is visible", View.VISIBLE, overflowMenuButton.getVisibility());
|
||||
|
||||
mSolo.clickOnView(overflowMenuButton, true);
|
||||
}
|
||||
|
||||
private boolean isMenuOpen() {
|
||||
// The presence of the "New tab" menu item is our best guess about whether
|
||||
// the menu is open or not.
|
||||
return mSolo.searchText(MenuItem.NEW_TAB.getString(mSolo));
|
||||
}
|
||||
|
||||
private void waitForMenuOpen() {
|
||||
WaitHelper.waitFor("menu to open", new Condition() {
|
||||
@Override
|
||||
public boolean isSatisfied() {
|
||||
return isMenuOpen();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ package org.mozilla.gecko.tests.helpers;
|
||||
|
||||
import static org.mozilla.gecko.tests.helpers.AssertionHelper.*;
|
||||
|
||||
import org.mozilla.gecko.tests.components.AppMenuComponent;
|
||||
import org.mozilla.gecko.tests.components.ToolbarComponent;
|
||||
import org.mozilla.gecko.tests.UITestContext;
|
||||
import org.mozilla.gecko.tests.UITestContext.ComponentType;
|
||||
@ -22,12 +23,14 @@ final public class NavigationHelper {
|
||||
private static UITestContext sContext;
|
||||
private static Solo sSolo;
|
||||
|
||||
private static AppMenuComponent sAppMenu;
|
||||
private static ToolbarComponent sToolbar;
|
||||
|
||||
protected static void init(final UITestContext context) {
|
||||
sContext = context;
|
||||
sSolo = context.getSolo();
|
||||
|
||||
sAppMenu = (AppMenuComponent) context.getComponent(ComponentType.APPMENU);
|
||||
sToolbar = (ToolbarComponent) context.getComponent(ComponentType.TOOLBAR);
|
||||
}
|
||||
|
||||
@ -81,8 +84,7 @@ final public class NavigationHelper {
|
||||
WaitHelper.waitForPageLoad(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO: Press forward with APPMENU component
|
||||
throw new UnsupportedOperationException("Not yet implemented.");
|
||||
sAppMenu.pressMenuItem(AppMenuComponent.MenuItem.FORWARD);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ public class testSessionHistory extends UITest {
|
||||
NavigationHelper.goBack();
|
||||
mToolbar.assertTitle(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE);
|
||||
|
||||
// TODO: Implement this functionality and uncomment.
|
||||
/*
|
||||
NavigationHelper.goForward();
|
||||
mToolbar.assertTitle(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE);
|
||||
|
||||
// TODO: Implement this functionality and uncomment.
|
||||
/*
|
||||
NavigationHelper.reload();
|
||||
mToolbar.assertTitle(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE);
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user