2009-02-26 01:27:32 +03:00
|
|
|
// Test timeout (seconds)
|
|
|
|
const TIMEOUT_SECONDS = 30;
|
|
|
|
|
2008-02-29 00:36:30 +03:00
|
|
|
if (Cc === undefined) {
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
window.addEventListener("load", testOnLoad, false);
|
|
|
|
|
|
|
|
function testOnLoad() {
|
2008-09-15 16:38:09 +04:00
|
|
|
window.removeEventListener("load", testOnLoad, false);
|
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
// Make sure to launch the test harness for the first opened window only
|
|
|
|
var prefs = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
if (prefs.prefHasUserValue("testing.browserTestHarness.running"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
prefs.setBoolPref("testing.browserTestHarness.running", true);
|
|
|
|
|
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
|
|
|
var sstring = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
sstring.data = location.search;
|
|
|
|
ww.openWindow(window, "chrome://mochikit/content/browser-harness.xul", "browserTest",
|
|
|
|
"chrome,centerscreen,dialog,resizable,titlebar,toolbar=no,width=800,height=600", sstring);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Tester(aTests, aCallback) {
|
|
|
|
this.tests = aTests;
|
|
|
|
this.callback = aCallback;
|
|
|
|
}
|
|
|
|
Tester.prototype = {
|
|
|
|
checker: null,
|
|
|
|
currentTestIndex: -1,
|
|
|
|
get currentTest() {
|
|
|
|
return this.tests[this.currentTestIndex];
|
|
|
|
},
|
|
|
|
get done() {
|
|
|
|
return this.currentTestIndex == this.tests.length - 1;
|
|
|
|
},
|
|
|
|
step: function Tester_step() {
|
|
|
|
this.currentTestIndex++;
|
|
|
|
},
|
2008-07-16 09:43:15 +04:00
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
start: function Tester_start() {
|
2009-01-16 22:19:25 +03:00
|
|
|
if (this.tests.length)
|
|
|
|
this.execTest();
|
|
|
|
else
|
|
|
|
this.finish();
|
2007-07-09 20:24:15 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
finish: function Tester_finish() {
|
|
|
|
// Tests complete, notify the callback and return
|
|
|
|
this.callback(this.tests);
|
|
|
|
this.callback = null;
|
|
|
|
this.tests = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
execTest: function Tester_execTest() {
|
|
|
|
if (this.done) {
|
|
|
|
this.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to the next test (or first test).
|
|
|
|
this.step();
|
|
|
|
|
|
|
|
// Load the tests into a testscope
|
2009-02-26 01:27:32 +03:00
|
|
|
this.currentTest.scope = new testScope(this, this.currentTest.tests);
|
2007-07-09 20:24:15 +04:00
|
|
|
|
|
|
|
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
|
|
|
getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
try {
|
2007-07-16 04:21:11 +04:00
|
|
|
scriptLoader.loadSubScript(this.currentTest.path, this.currentTest.scope);
|
|
|
|
|
|
|
|
// Run the test
|
2007-07-09 20:24:15 +04:00
|
|
|
this.currentTest.scope.test();
|
|
|
|
} catch (ex) {
|
2007-07-12 18:29:33 +04:00
|
|
|
this.currentTest.tests.push(new testResult(false, "Exception thrown", ex, false));
|
2007-07-16 04:21:11 +04:00
|
|
|
this.currentTest.scope.done = true;
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
|
2009-02-26 01:27:32 +03:00
|
|
|
// If the test ran synchronously, move to the next test, otherwise the test
|
|
|
|
// will trigger the next test when it is done.
|
2007-07-09 20:24:15 +04:00
|
|
|
if (this.currentTest.scope.done) {
|
|
|
|
this.execTest();
|
2009-02-26 01:27:32 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-07-09 20:24:15 +04:00
|
|
|
var self = this;
|
2009-02-26 01:27:32 +03:00
|
|
|
this.currentTest.scope.waitTimer = setTimeout(function() {
|
|
|
|
self.currentTest.tests.push(new testResult(false, "Timed out", "", false));
|
|
|
|
self.currentTest.scope.waitTimer = null;
|
|
|
|
self.execTest();
|
|
|
|
}, TIMEOUT_SECONDS * 1000);;
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function testResult(aCondition, aName, aDiag, aIsTodo) {
|
|
|
|
aName = aName || "";
|
|
|
|
|
|
|
|
this.pass = !!aCondition;
|
2007-07-12 18:29:33 +04:00
|
|
|
this.todo = aIsTodo;
|
2008-07-16 09:43:15 +04:00
|
|
|
this.msg = aName;
|
2007-07-12 18:29:33 +04:00
|
|
|
if (this.pass) {
|
|
|
|
if (aIsTodo)
|
2008-07-16 09:43:15 +04:00
|
|
|
this.result = "TEST-KNOWN-FAIL";
|
2007-07-12 18:29:33 +04:00
|
|
|
else
|
2008-07-16 09:43:15 +04:00
|
|
|
this.result = "TEST-PASS";
|
2007-07-12 18:29:33 +04:00
|
|
|
} else {
|
2007-07-09 20:24:15 +04:00
|
|
|
if (aDiag)
|
|
|
|
this.msg += " - " + aDiag;
|
2008-07-16 09:43:15 +04:00
|
|
|
if (aIsTodo)
|
|
|
|
this.result = "TEST-UNEXPECTED-PASS";
|
|
|
|
else
|
|
|
|
this.result = "TEST-UNEXPECTED-FAIL";
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-26 01:27:32 +03:00
|
|
|
function testScope(aTester, aTests) {
|
2007-07-09 20:24:15 +04:00
|
|
|
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
|
|
|
getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", this.EventUtils);
|
|
|
|
|
2009-02-26 01:27:32 +03:00
|
|
|
this.tester = aTester;
|
2007-07-09 20:24:15 +04:00
|
|
|
this.tests = aTests;
|
2008-01-26 00:29:11 +03:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
this.ok = function test_ok(condition, name, diag) {
|
|
|
|
self.tests.push(new testResult(condition, name, diag, false));
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 00:29:11 +03:00
|
|
|
this.is = function test_is(a, b, name) {
|
|
|
|
self.ok(a == b, name, "Got " + a + ", expected " + b);
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 00:29:11 +03:00
|
|
|
this.isnot = function test_isnot(a, b, name) {
|
|
|
|
self.ok(a != b, name, "Didn't expect " + a + ", but got it");
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 00:29:11 +03:00
|
|
|
this.todo = function test_todo(condition, name, diag) {
|
|
|
|
self.tests.push(new testResult(!condition, name, diag, true));
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 02:33:17 +03:00
|
|
|
this.todo_is = function test_todo_is(a, b, name) {
|
|
|
|
self.todo(a == b, name, "Got " + a + ", expected " + b);
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 02:33:17 +03:00
|
|
|
this.todo_isnot = function test_todo_isnot(a, b, name) {
|
|
|
|
self.todo(a != b, name, "Didn't expect " + a + ", but got it");
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 02:33:17 +03:00
|
|
|
|
2008-10-30 20:22:17 +03:00
|
|
|
this.executeSoon = function test_executeSoon(func) {
|
|
|
|
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
|
|
|
|
|
|
|
tm.mainThread.dispatch({
|
|
|
|
run: function() {
|
|
|
|
func();
|
|
|
|
}
|
|
|
|
}, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
};
|
|
|
|
|
2008-01-26 00:29:11 +03:00
|
|
|
this.waitForExplicitFinish = function test_WFEF() {
|
|
|
|
self.done = false;
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 00:29:11 +03:00
|
|
|
this.finish = function test_finish() {
|
|
|
|
self.done = true;
|
2009-02-26 01:27:32 +03:00
|
|
|
if (self.waitTimer) {
|
|
|
|
self.executeSoon(function() {
|
|
|
|
if (self.done && self.waitTimer) {
|
|
|
|
clearTimeout(self.waitTimer);
|
|
|
|
self.waitTimer = null;
|
|
|
|
self.tester.execTest();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
testScope.prototype = {
|
|
|
|
done: true,
|
2009-02-26 01:27:32 +03:00
|
|
|
waitTimer: null,
|
2007-07-09 20:24:15 +04:00
|
|
|
|
|
|
|
EventUtils: {}
|
|
|
|
};
|