mobile/android/base/tests/helpers/NavigationHelper.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.tests.helpers;
michael@0 6
michael@0 7 import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertNotNull;
michael@0 8
michael@0 9 import org.mozilla.gecko.tests.UITestContext;
michael@0 10 import org.mozilla.gecko.tests.UITestContext.ComponentType;
michael@0 11 import org.mozilla.gecko.tests.components.AppMenuComponent;
michael@0 12 import org.mozilla.gecko.tests.components.ToolbarComponent;
michael@0 13
michael@0 14 import com.jayway.android.robotium.solo.Solo;
michael@0 15
michael@0 16 /**
michael@0 17 * Provides helper functionality for navigating around the Firefox UI. These functions will often
michael@0 18 * combine actions taken on multiple components to perform larger interactions.
michael@0 19 */
michael@0 20 final public class NavigationHelper {
michael@0 21 private static UITestContext sContext;
michael@0 22 private static Solo sSolo;
michael@0 23
michael@0 24 private static AppMenuComponent sAppMenu;
michael@0 25 private static ToolbarComponent sToolbar;
michael@0 26
michael@0 27 protected static void init(final UITestContext context) {
michael@0 28 sContext = context;
michael@0 29 sSolo = context.getSolo();
michael@0 30
michael@0 31 sAppMenu = (AppMenuComponent) context.getComponent(ComponentType.APPMENU);
michael@0 32 sToolbar = (ToolbarComponent) context.getComponent(ComponentType.TOOLBAR);
michael@0 33 }
michael@0 34
michael@0 35 public static void enterAndLoadUrl(String url) {
michael@0 36 fAssertNotNull("url is not null", url);
michael@0 37
michael@0 38 url = adjustUrl(url);
michael@0 39 sToolbar.enterEditingMode()
michael@0 40 .enterUrl(url)
michael@0 41 .commitEditingMode();
michael@0 42 }
michael@0 43
michael@0 44 /**
michael@0 45 * Returns a new URL with the docshell HTTP server host prefix.
michael@0 46 */
michael@0 47 private static String adjustUrl(final String url) {
michael@0 48 fAssertNotNull("url is not null", url);
michael@0 49
michael@0 50 if (url.startsWith("about:") || url.startsWith("chrome:")) {
michael@0 51 return url;
michael@0 52 }
michael@0 53
michael@0 54 return sContext.getAbsoluteHostnameUrl(url);
michael@0 55 }
michael@0 56
michael@0 57 public static void goBack() {
michael@0 58 if (DeviceHelper.isTablet()) {
michael@0 59 sToolbar.pressBackButton(); // Waits for page load & asserts isNotEditing.
michael@0 60 return;
michael@0 61 }
michael@0 62
michael@0 63 sToolbar.assertIsNotEditing();
michael@0 64 WaitHelper.waitForPageLoad(new Runnable() {
michael@0 65 @Override
michael@0 66 public void run() {
michael@0 67 // TODO: Lower soft keyboard first if applicable. Note that
michael@0 68 // Solo.hideSoftKeyboard() does not clear focus (which might be fine since
michael@0 69 // Gecko would be the element focused).
michael@0 70 sSolo.goBack();
michael@0 71 }
michael@0 72 });
michael@0 73 }
michael@0 74
michael@0 75 public static void goForward() {
michael@0 76 if (DeviceHelper.isTablet()) {
michael@0 77 sToolbar.pressForwardButton(); // Waits for page load & asserts isNotEditing.
michael@0 78 return;
michael@0 79 }
michael@0 80
michael@0 81 sToolbar.assertIsNotEditing();
michael@0 82 WaitHelper.waitForPageLoad(new Runnable() {
michael@0 83 @Override
michael@0 84 public void run() {
michael@0 85 sAppMenu.pressMenuItem(AppMenuComponent.MenuItem.FORWARD);
michael@0 86 }
michael@0 87 });
michael@0 88 }
michael@0 89
michael@0 90 public static void reload() {
michael@0 91 // TODO: On tablets, press reload in TOOLBAR. Note that this is technically
michael@0 92 // an app menu item so tread carefully.
michael@0 93 // On phones, press reload in APPMENU.
michael@0 94 throw new UnsupportedOperationException("Not yet implemented.");
michael@0 95 }
michael@0 96 }

mercurial