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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/helpers/GeckoHelper.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.tests.helpers;
     1.9 +
    1.10 +import org.mozilla.gecko.Actions;
    1.11 +import org.mozilla.gecko.Actions.EventExpecter;
    1.12 +import org.mozilla.gecko.GeckoThread;
    1.13 +import org.mozilla.gecko.GeckoThread.LaunchState;
    1.14 +import org.mozilla.gecko.tests.UITestContext;
    1.15 +
    1.16 +import android.app.Activity;
    1.17 +
    1.18 +/**
    1.19 + * Provides helper functions for accessing the underlying Gecko engine.
    1.20 + */
    1.21 +public final class GeckoHelper {
    1.22 +    private static Activity sActivity;
    1.23 +    private static Actions sActions;
    1.24 +
    1.25 +    private GeckoHelper() { /* To disallow instantiation. */ }
    1.26 +
    1.27 +    protected static void init(final UITestContext context) {
    1.28 +        sActivity = context.getActivity();
    1.29 +        sActions = context.getActions();
    1.30 +    }
    1.31 +
    1.32 +    public static void blockForReady() {
    1.33 +        blockForEvent("Gecko:Ready");
    1.34 +    }
    1.35 +
    1.36 +    /**
    1.37 +     * Blocks for the "Gecko:DelayedStartup" event, which occurs after "Gecko:Ready" and the
    1.38 +     * first page load.
    1.39 +     */
    1.40 +    public static void blockForDelayedStartup() {
    1.41 +        blockForEvent("Gecko:DelayedStartup");
    1.42 +    }
    1.43 +
    1.44 +    private static void blockForEvent(final String eventName) {
    1.45 +        final EventExpecter eventExpecter = sActions.expectGeckoEvent(eventName);
    1.46 +
    1.47 +        final boolean isRunning = GeckoThread.checkLaunchState(LaunchState.GeckoRunning);
    1.48 +        if (!isRunning) {
    1.49 +            eventExpecter.blockForEvent();
    1.50 +        }
    1.51 +
    1.52 +        eventExpecter.unregisterListener();
    1.53 +    }
    1.54 +}

mercurial