Wed, 31 Dec 2014 06:09:35 +0100
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 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;
13 import android.app.Activity;
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;
22 private GeckoHelper() { /* To disallow instantiation. */ }
24 protected static void init(final UITestContext context) {
25 sActivity = context.getActivity();
26 sActions = context.getActions();
27 }
29 public static void blockForReady() {
30 blockForEvent("Gecko:Ready");
31 }
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 }
41 private static void blockForEvent(final String eventName) {
42 final EventExpecter eventExpecter = sActions.expectGeckoEvent(eventName);
44 final boolean isRunning = GeckoThread.checkLaunchState(LaunchState.GeckoRunning);
45 if (!isRunning) {
46 eventExpecter.blockForEvent();
47 }
49 eventExpecter.unregisterListener();
50 }
51 }