mobile/android/base/tests/helpers/GeckoHelper.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.

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

mercurial