|
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 org.mozilla.gecko.Actions; |
|
8 import org.mozilla.gecko.Actions.EventExpecter; |
|
9 import org.mozilla.gecko.GeckoThread; |
|
10 import org.mozilla.gecko.GeckoThread.LaunchState; |
|
11 import org.mozilla.gecko.tests.UITestContext; |
|
12 |
|
13 import android.app.Activity; |
|
14 |
|
15 /** |
|
16 * Provides helper functions for accessing the underlying Gecko engine. |
|
17 */ |
|
18 public final class GeckoHelper { |
|
19 private static Activity sActivity; |
|
20 private static Actions sActions; |
|
21 |
|
22 private GeckoHelper() { /* To disallow instantiation. */ } |
|
23 |
|
24 protected static void init(final UITestContext context) { |
|
25 sActivity = context.getActivity(); |
|
26 sActions = context.getActions(); |
|
27 } |
|
28 |
|
29 public static void blockForReady() { |
|
30 blockForEvent("Gecko:Ready"); |
|
31 } |
|
32 |
|
33 /** |
|
34 * Blocks for the "Gecko:DelayedStartup" event, which occurs after "Gecko:Ready" and the |
|
35 * first page load. |
|
36 */ |
|
37 public static void blockForDelayedStartup() { |
|
38 blockForEvent("Gecko:DelayedStartup"); |
|
39 } |
|
40 |
|
41 private static void blockForEvent(final String eventName) { |
|
42 final EventExpecter eventExpecter = sActions.expectGeckoEvent(eventName); |
|
43 |
|
44 final boolean isRunning = GeckoThread.checkLaunchState(LaunchState.GeckoRunning); |
|
45 if (!isRunning) { |
|
46 eventExpecter.blockForEvent(); |
|
47 } |
|
48 |
|
49 eventExpecter.unregisterListener(); |
|
50 } |
|
51 } |