michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.tests.helpers; michael@0: michael@0: import org.mozilla.gecko.Actions; michael@0: import org.mozilla.gecko.Actions.EventExpecter; michael@0: import org.mozilla.gecko.GeckoThread; michael@0: import org.mozilla.gecko.GeckoThread.LaunchState; michael@0: import org.mozilla.gecko.tests.UITestContext; michael@0: michael@0: import android.app.Activity; michael@0: michael@0: /** michael@0: * Provides helper functions for accessing the underlying Gecko engine. michael@0: */ michael@0: public final class GeckoHelper { michael@0: private static Activity sActivity; michael@0: private static Actions sActions; michael@0: michael@0: private GeckoHelper() { /* To disallow instantiation. */ } michael@0: michael@0: protected static void init(final UITestContext context) { michael@0: sActivity = context.getActivity(); michael@0: sActions = context.getActions(); michael@0: } michael@0: michael@0: public static void blockForReady() { michael@0: blockForEvent("Gecko:Ready"); michael@0: } michael@0: michael@0: /** michael@0: * Blocks for the "Gecko:DelayedStartup" event, which occurs after "Gecko:Ready" and the michael@0: * first page load. michael@0: */ michael@0: public static void blockForDelayedStartup() { michael@0: blockForEvent("Gecko:DelayedStartup"); michael@0: } michael@0: michael@0: private static void blockForEvent(final String eventName) { michael@0: final EventExpecter eventExpecter = sActions.expectGeckoEvent(eventName); michael@0: michael@0: final boolean isRunning = GeckoThread.checkLaunchState(LaunchState.GeckoRunning); michael@0: if (!isRunning) { michael@0: eventExpecter.blockForEvent(); michael@0: } michael@0: michael@0: eventExpecter.unregisterListener(); michael@0: } michael@0: }