Bug 986738 - End robocop tests with nsIAppStartup.quit(); r=snorp

This commit is contained in:
Geoff Brown 2014-04-04 12:11:21 -06:00
parent c3ab3084ed
commit 23ec106d71
3 changed files with 20 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import org.mozilla.gecko.Element;
import org.mozilla.gecko.FennecNativeActions;
import org.mozilla.gecko.FennecNativeDriver;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.GeckoThread.LaunchState;
import org.mozilla.gecko.R;
@ -137,6 +138,10 @@ abstract class BaseTest extends BaseRobocopTest {
public void tearDown() throws Exception {
try {
mAsserter.endTest();
// request a force quit of the browser and wait for it to take effect
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Robocop:Quit", null));
mSolo.sleep(7000);
// if still running, finish activities as recommended by Robotium
mSolo.finishOpenedActivities();
} catch (Throwable e) {
e.printStackTrace();

View File

@ -11,6 +11,8 @@ import org.mozilla.gecko.Assert;
import org.mozilla.gecko.Driver;
import org.mozilla.gecko.FennecNativeActions;
import org.mozilla.gecko.FennecNativeDriver;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.tests.components.AboutHomeComponent;
import org.mozilla.gecko.tests.components.AppMenuComponent;
import org.mozilla.gecko.tests.components.BaseComponent;
@ -78,6 +80,10 @@ abstract class UITest extends BaseRobocopTest
public void tearDown() throws Exception {
try {
mAsserter.endTest();
// request a force quit of the browser and wait for it to take effect
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Robocop:Quit", null));
mSolo.sleep(7000);
// if still running, finish activities as recommended by Robotium
mSolo.finishOpenedActivities();
} catch (Throwable e) {
e.printStackTrace();

View File

@ -1,6 +1,9 @@
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
function loadIntoWindow(window) {}
function unloadFromWindow(window) {}
@ -41,6 +44,11 @@ function startup(aData, aReason) {
// Load into any new windows
wm.addListener(windowListener);
Services.obs.addObserver(function observe(aSubject, aTopic, aData) {
dump("Robocop:Quit received -- requesting quit");
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
appStartup.quit(Ci.nsIAppStartup.eForceQuit);
}, "Robocop:Quit", false);
}
function shutdown(aData, aReason) {
@ -48,7 +56,6 @@ function shutdown(aData, aReason) {
if (aReason == APP_SHUTDOWN) return;
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
let obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
// Stop watching for new windows
wm.removeListener(windowListener);
@ -56,3 +63,4 @@ function shutdown(aData, aReason) {
function install(aData, aReason) { }
function uninstall(aData, aReason) { }