michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.tests.helpers; michael@0: michael@0: import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertNotNull; michael@0: michael@0: import org.mozilla.gecko.tests.UITestContext; michael@0: import org.mozilla.gecko.tests.UITestContext.ComponentType; michael@0: import org.mozilla.gecko.tests.components.AppMenuComponent; michael@0: import org.mozilla.gecko.tests.components.ToolbarComponent; michael@0: michael@0: import com.jayway.android.robotium.solo.Solo; michael@0: michael@0: /** michael@0: * Provides helper functionality for navigating around the Firefox UI. These functions will often michael@0: * combine actions taken on multiple components to perform larger interactions. michael@0: */ michael@0: final public class NavigationHelper { michael@0: private static UITestContext sContext; michael@0: private static Solo sSolo; michael@0: michael@0: private static AppMenuComponent sAppMenu; michael@0: private static ToolbarComponent sToolbar; michael@0: michael@0: protected static void init(final UITestContext context) { michael@0: sContext = context; michael@0: sSolo = context.getSolo(); michael@0: michael@0: sAppMenu = (AppMenuComponent) context.getComponent(ComponentType.APPMENU); michael@0: sToolbar = (ToolbarComponent) context.getComponent(ComponentType.TOOLBAR); michael@0: } michael@0: michael@0: public static void enterAndLoadUrl(String url) { michael@0: fAssertNotNull("url is not null", url); michael@0: michael@0: url = adjustUrl(url); michael@0: sToolbar.enterEditingMode() michael@0: .enterUrl(url) michael@0: .commitEditingMode(); michael@0: } michael@0: michael@0: /** michael@0: * Returns a new URL with the docshell HTTP server host prefix. michael@0: */ michael@0: private static String adjustUrl(final String url) { michael@0: fAssertNotNull("url is not null", url); michael@0: michael@0: if (url.startsWith("about:") || url.startsWith("chrome:")) { michael@0: return url; michael@0: } michael@0: michael@0: return sContext.getAbsoluteHostnameUrl(url); michael@0: } michael@0: michael@0: public static void goBack() { michael@0: if (DeviceHelper.isTablet()) { michael@0: sToolbar.pressBackButton(); // Waits for page load & asserts isNotEditing. michael@0: return; michael@0: } michael@0: michael@0: sToolbar.assertIsNotEditing(); michael@0: WaitHelper.waitForPageLoad(new Runnable() { michael@0: @Override michael@0: public void run() { michael@0: // TODO: Lower soft keyboard first if applicable. Note that michael@0: // Solo.hideSoftKeyboard() does not clear focus (which might be fine since michael@0: // Gecko would be the element focused). michael@0: sSolo.goBack(); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: public static void goForward() { michael@0: if (DeviceHelper.isTablet()) { michael@0: sToolbar.pressForwardButton(); // Waits for page load & asserts isNotEditing. michael@0: return; michael@0: } michael@0: michael@0: sToolbar.assertIsNotEditing(); michael@0: WaitHelper.waitForPageLoad(new Runnable() { michael@0: @Override michael@0: public void run() { michael@0: sAppMenu.pressMenuItem(AppMenuComponent.MenuItem.FORWARD); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: public static void reload() { michael@0: // TODO: On tablets, press reload in TOOLBAR. Note that this is technically michael@0: // an app menu item so tread carefully. michael@0: // On phones, press reload in APPMENU. michael@0: throw new UnsupportedOperationException("Not yet implemented."); michael@0: } michael@0: }