1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/helpers/NavigationHelper.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.tests.helpers; 1.9 + 1.10 +import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertNotNull; 1.11 + 1.12 +import org.mozilla.gecko.tests.UITestContext; 1.13 +import org.mozilla.gecko.tests.UITestContext.ComponentType; 1.14 +import org.mozilla.gecko.tests.components.AppMenuComponent; 1.15 +import org.mozilla.gecko.tests.components.ToolbarComponent; 1.16 + 1.17 +import com.jayway.android.robotium.solo.Solo; 1.18 + 1.19 +/** 1.20 + * Provides helper functionality for navigating around the Firefox UI. These functions will often 1.21 + * combine actions taken on multiple components to perform larger interactions. 1.22 + */ 1.23 +final public class NavigationHelper { 1.24 + private static UITestContext sContext; 1.25 + private static Solo sSolo; 1.26 + 1.27 + private static AppMenuComponent sAppMenu; 1.28 + private static ToolbarComponent sToolbar; 1.29 + 1.30 + protected static void init(final UITestContext context) { 1.31 + sContext = context; 1.32 + sSolo = context.getSolo(); 1.33 + 1.34 + sAppMenu = (AppMenuComponent) context.getComponent(ComponentType.APPMENU); 1.35 + sToolbar = (ToolbarComponent) context.getComponent(ComponentType.TOOLBAR); 1.36 + } 1.37 + 1.38 + public static void enterAndLoadUrl(String url) { 1.39 + fAssertNotNull("url is not null", url); 1.40 + 1.41 + url = adjustUrl(url); 1.42 + sToolbar.enterEditingMode() 1.43 + .enterUrl(url) 1.44 + .commitEditingMode(); 1.45 + } 1.46 + 1.47 + /** 1.48 + * Returns a new URL with the docshell HTTP server host prefix. 1.49 + */ 1.50 + private static String adjustUrl(final String url) { 1.51 + fAssertNotNull("url is not null", url); 1.52 + 1.53 + if (url.startsWith("about:") || url.startsWith("chrome:")) { 1.54 + return url; 1.55 + } 1.56 + 1.57 + return sContext.getAbsoluteHostnameUrl(url); 1.58 + } 1.59 + 1.60 + public static void goBack() { 1.61 + if (DeviceHelper.isTablet()) { 1.62 + sToolbar.pressBackButton(); // Waits for page load & asserts isNotEditing. 1.63 + return; 1.64 + } 1.65 + 1.66 + sToolbar.assertIsNotEditing(); 1.67 + WaitHelper.waitForPageLoad(new Runnable() { 1.68 + @Override 1.69 + public void run() { 1.70 + // TODO: Lower soft keyboard first if applicable. Note that 1.71 + // Solo.hideSoftKeyboard() does not clear focus (which might be fine since 1.72 + // Gecko would be the element focused). 1.73 + sSolo.goBack(); 1.74 + } 1.75 + }); 1.76 + } 1.77 + 1.78 + public static void goForward() { 1.79 + if (DeviceHelper.isTablet()) { 1.80 + sToolbar.pressForwardButton(); // Waits for page load & asserts isNotEditing. 1.81 + return; 1.82 + } 1.83 + 1.84 + sToolbar.assertIsNotEditing(); 1.85 + WaitHelper.waitForPageLoad(new Runnable() { 1.86 + @Override 1.87 + public void run() { 1.88 + sAppMenu.pressMenuItem(AppMenuComponent.MenuItem.FORWARD); 1.89 + } 1.90 + }); 1.91 + } 1.92 + 1.93 + public static void reload() { 1.94 + // TODO: On tablets, press reload in TOOLBAR. Note that this is technically 1.95 + // an app menu item so tread carefully. 1.96 + // On phones, press reload in APPMENU. 1.97 + throw new UnsupportedOperationException("Not yet implemented."); 1.98 + } 1.99 +}