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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial