|
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/. */ |
|
4 |
|
5 package org.mozilla.gecko.tests.helpers; |
|
6 |
|
7 import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertNotNull; |
|
8 |
|
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; |
|
13 |
|
14 import com.jayway.android.robotium.solo.Solo; |
|
15 |
|
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; |
|
23 |
|
24 private static AppMenuComponent sAppMenu; |
|
25 private static ToolbarComponent sToolbar; |
|
26 |
|
27 protected static void init(final UITestContext context) { |
|
28 sContext = context; |
|
29 sSolo = context.getSolo(); |
|
30 |
|
31 sAppMenu = (AppMenuComponent) context.getComponent(ComponentType.APPMENU); |
|
32 sToolbar = (ToolbarComponent) context.getComponent(ComponentType.TOOLBAR); |
|
33 } |
|
34 |
|
35 public static void enterAndLoadUrl(String url) { |
|
36 fAssertNotNull("url is not null", url); |
|
37 |
|
38 url = adjustUrl(url); |
|
39 sToolbar.enterEditingMode() |
|
40 .enterUrl(url) |
|
41 .commitEditingMode(); |
|
42 } |
|
43 |
|
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); |
|
49 |
|
50 if (url.startsWith("about:") || url.startsWith("chrome:")) { |
|
51 return url; |
|
52 } |
|
53 |
|
54 return sContext.getAbsoluteHostnameUrl(url); |
|
55 } |
|
56 |
|
57 public static void goBack() { |
|
58 if (DeviceHelper.isTablet()) { |
|
59 sToolbar.pressBackButton(); // Waits for page load & asserts isNotEditing. |
|
60 return; |
|
61 } |
|
62 |
|
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 } |
|
74 |
|
75 public static void goForward() { |
|
76 if (DeviceHelper.isTablet()) { |
|
77 sToolbar.pressForwardButton(); // Waits for page load & asserts isNotEditing. |
|
78 return; |
|
79 } |
|
80 |
|
81 sToolbar.assertIsNotEditing(); |
|
82 WaitHelper.waitForPageLoad(new Runnable() { |
|
83 @Override |
|
84 public void run() { |
|
85 sAppMenu.pressMenuItem(AppMenuComponent.MenuItem.FORWARD); |
|
86 } |
|
87 }); |
|
88 } |
|
89 |
|
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 } |