mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 528469 - browser-test.js should ensure windows state between tests (further modified by gavin, r=me), r=gavin
This commit is contained in:
parent
3f3130f146
commit
364bf6fdec
@ -33,14 +33,18 @@ function Tester(aTests, aDumper, aCallback) {
|
|||||||
this.callback = aCallback;
|
this.callback = aCallback;
|
||||||
this._cs = Cc["@mozilla.org/consoleservice;1"].
|
this._cs = Cc["@mozilla.org/consoleservice;1"].
|
||||||
getService(Ci.nsIConsoleService);
|
getService(Ci.nsIConsoleService);
|
||||||
|
this._wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
||||||
|
getService(Ci.nsIWindowMediator);
|
||||||
|
this._fm = Cc["@mozilla.org/focus-manager;1"].
|
||||||
|
getService(Ci.nsIFocusManager);
|
||||||
|
|
||||||
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
this._scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
||||||
getService(Ci.mozIJSSubScriptLoader);
|
getService(Ci.mozIJSSubScriptLoader);
|
||||||
scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", this.EventUtils);
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", this.EventUtils);
|
||||||
// Avoid polluting this scope with packed.js contents.
|
// Avoid polluting this scope with packed.js contents.
|
||||||
var simpleTestScope = {};
|
var simpleTestScope = {};
|
||||||
scriptLoader.loadSubScript("chrome://mochikit/content/MochiKit/packed.js", simpleTestScope);
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/MochiKit/packed.js", simpleTestScope);
|
||||||
scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/SimpleTest.js", simpleTestScope);
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/SimpleTest.js", simpleTestScope);
|
||||||
this.SimpleTest = simpleTestScope.SimpleTest;
|
this.SimpleTest = simpleTestScope.SimpleTest;
|
||||||
}
|
}
|
||||||
Tester.prototype = {
|
Tester.prototype = {
|
||||||
@ -55,20 +59,52 @@ Tester.prototype = {
|
|||||||
get done() {
|
get done() {
|
||||||
return this.currentTestIndex == this.tests.length - 1;
|
return this.currentTestIndex == this.tests.length - 1;
|
||||||
},
|
},
|
||||||
step: function Tester_step() {
|
|
||||||
this.currentTestIndex++;
|
|
||||||
},
|
|
||||||
|
|
||||||
start: function Tester_start() {
|
start: function Tester_start() {
|
||||||
this.dumper.dump("*** Start BrowserChrome Test Results ***\n");
|
this.dumper.dump("*** Start BrowserChrome Test Results ***\n");
|
||||||
this._cs.registerListener(this);
|
this._cs.registerListener(this);
|
||||||
|
|
||||||
if (this.tests.length)
|
if (this.tests.length)
|
||||||
this.execTest();
|
this.nextTest();
|
||||||
else
|
else
|
||||||
this.finish();
|
this.finish();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
waitForWindowsState: function Tester_waitForWindowsState(aCallback) {
|
||||||
|
this.dumper.dump("TEST-INFO | checking window state\n");
|
||||||
|
let windowsEnum = this._wm.getEnumerator("navigator:browser");
|
||||||
|
while (windowsEnum.hasMoreElements()) {
|
||||||
|
let win = windowsEnum.getNext();
|
||||||
|
if (win != window && !win.closed) {
|
||||||
|
let msg = "Found an unexpected browser window";
|
||||||
|
if (this.currentTest) {
|
||||||
|
msg += " at the end of test run";
|
||||||
|
this.currentTest.addResult(new testResult(false, msg, "", false));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.dumper.dump("TEST-UNEXPECTED-FAIL | (browser-test.js) | " + msg + "\n");
|
||||||
|
|
||||||
|
win.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the window is raised before each test.
|
||||||
|
if (this._fm.activeWindow != window) {
|
||||||
|
this.dumper.dump("TEST-INFO | (browser-test.js) | Waiting for window activation...\n");
|
||||||
|
let self = this;
|
||||||
|
window.addEventListener("activate", function () {
|
||||||
|
window.removeEventListener("activate", arguments.callee, false);
|
||||||
|
setTimeout(function () {
|
||||||
|
aCallback.apply(self);
|
||||||
|
}, 0);
|
||||||
|
}, false);
|
||||||
|
window.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
aCallback.apply(this);
|
||||||
|
},
|
||||||
|
|
||||||
finish: function Tester_finish(aSkipSummary) {
|
finish: function Tester_finish(aSkipSummary) {
|
||||||
this._cs.unregisterListener(this);
|
this._cs.unregisterListener(this);
|
||||||
|
|
||||||
@ -100,33 +136,30 @@ Tester.prototype = {
|
|||||||
|
|
||||||
observe: function Tester_observe(aConsoleMessage) {
|
observe: function Tester_observe(aConsoleMessage) {
|
||||||
var msg = "Console message: " + aConsoleMessage.message;
|
var msg = "Console message: " + aConsoleMessage.message;
|
||||||
this.currentTest.addResult(new testMessage(msg));
|
if (this.currentTest)
|
||||||
|
this.currentTest.addResult(new testMessage(msg));
|
||||||
|
else
|
||||||
|
this.dumper.dump("TEST-INFO | (browser-test.js) | " + msg);
|
||||||
},
|
},
|
||||||
|
|
||||||
execTest: function Tester_execTest() {
|
nextTest: function Tester_nextTest() {
|
||||||
|
// Check the window state for the current test before moving to the next one.
|
||||||
|
// This also causes us to check before starting any tests, since nextTest()
|
||||||
|
// is invoked to start the tests.
|
||||||
|
this.waitForWindowsState(this.realNextTest);
|
||||||
|
},
|
||||||
|
|
||||||
|
realNextTest: function Test_realNextTest() {
|
||||||
if (this.done) {
|
if (this.done) {
|
||||||
this.finish();
|
this.finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the window is raised before each test.
|
this.currentTestIndex++;
|
||||||
let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
|
this.execTest();
|
||||||
if (fm.activeWindow != window) {
|
},
|
||||||
this.dumper.dump("Waiting for window activation...\n");
|
|
||||||
let self = this;
|
|
||||||
window.addEventListener("activate", function () {
|
|
||||||
window.removeEventListener("activate", arguments.callee, false);
|
|
||||||
setTimeout(function () {
|
|
||||||
self.execTest();
|
|
||||||
}, 0);
|
|
||||||
}, false);
|
|
||||||
window.focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move to the next test (or first test).
|
|
||||||
this.step();
|
|
||||||
|
|
||||||
|
execTest: function Tester_execTest() {
|
||||||
this.dumper.dump("Running " + this.currentTest.path + "...\n");
|
this.dumper.dump("Running " + this.currentTest.path + "...\n");
|
||||||
|
|
||||||
// Load the tests into a testscope
|
// Load the tests into a testscope
|
||||||
@ -136,10 +169,9 @@ Tester.prototype = {
|
|||||||
this.currentTest.scope.EventUtils = this.EventUtils;
|
this.currentTest.scope.EventUtils = this.EventUtils;
|
||||||
this.currentTest.scope.SimpleTest = this.SimpleTest;
|
this.currentTest.scope.SimpleTest = this.SimpleTest;
|
||||||
|
|
||||||
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
|
||||||
getService(Ci.mozIJSSubScriptLoader);
|
|
||||||
try {
|
try {
|
||||||
scriptLoader.loadSubScript(this.currentTest.path, this.currentTest.scope);
|
this._scriptLoader.loadSubScript(this.currentTest.path,
|
||||||
|
this.currentTest.scope);
|
||||||
|
|
||||||
// Run the test
|
// Run the test
|
||||||
this.currentTest.scope.test();
|
this.currentTest.scope.test();
|
||||||
@ -151,14 +183,14 @@ Tester.prototype = {
|
|||||||
// If the test ran synchronously, move to the next test, otherwise the test
|
// If the test ran synchronously, move to the next test, otherwise the test
|
||||||
// will trigger the next test when it is done.
|
// will trigger the next test when it is done.
|
||||||
if (this.currentTest.scope.__done) {
|
if (this.currentTest.scope.__done) {
|
||||||
this.execTest();
|
this.nextTest();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.currentTest.scope.__waitTimer = setTimeout(function() {
|
this.currentTest.scope.__waitTimer = setTimeout(function() {
|
||||||
self.currentTest.addResult(new testResult(false, "Timed out", "", false));
|
self.currentTest.addResult(new testResult(false, "Timed out", "", false));
|
||||||
self.currentTest.scope.__waitTimer = null;
|
self.currentTest.scope.__waitTimer = null;
|
||||||
self.execTest();
|
self.nextTest();
|
||||||
}, TIMEOUT_SECONDS * 1000);
|
}, TIMEOUT_SECONDS * 1000);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -259,7 +291,7 @@ function testScope(aTester, aTest) {
|
|||||||
if (self.__done && self.__waitTimer) {
|
if (self.__done && self.__waitTimer) {
|
||||||
clearTimeout(self.__waitTimer);
|
clearTimeout(self.__waitTimer);
|
||||||
self.__waitTimer = null;
|
self.__waitTimer = null;
|
||||||
self.__tester.execTest();
|
self.__tester.nextTest();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ _BROWSER_TEST_FILES = browser_pass.js \
|
|||||||
browser_async.js \
|
browser_async.js \
|
||||||
browser_privileges.js \
|
browser_privileges.js \
|
||||||
# Disabled, these are only good for testing the harness' failure reporting
|
# Disabled, these are only good for testing the harness' failure reporting
|
||||||
|
# browser_zz_fail_openwindow.js \
|
||||||
# browser_fail.js \
|
# browser_fail.js \
|
||||||
# browser_fail_async_throw.js \
|
# browser_fail_async_throw.js \
|
||||||
# browser_fail_fp.js \
|
# browser_fail_fp.js \
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
function test() {
|
||||||
|
waitForExplicitFinish();
|
||||||
|
function done() {
|
||||||
|
ok(true, "timeout ran");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
ok(OpenBrowserWindow(), "opened browser window");
|
||||||
|
// and didn't close it!
|
||||||
|
|
||||||
|
setTimeout(done, 10000);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user