2009-02-26 01:27:32 +03:00
|
|
|
// Test timeout (seconds)
|
|
|
|
const TIMEOUT_SECONDS = 30;
|
2011-06-08 20:04:14 +04:00
|
|
|
var gConfig;
|
2009-02-26 01:27:32 +03:00
|
|
|
|
2008-02-29 00:36:30 +03:00
|
|
|
if (Cc === undefined) {
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Ci = Components.interfaces;
|
2011-07-14 02:34:01 +04:00
|
|
|
var Cu = Components.utils;
|
2008-02-29 00:36:30 +03:00
|
|
|
}
|
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);
|
|
|
|
|
2011-05-17 21:10:37 +04:00
|
|
|
gConfig = readConfig();
|
|
|
|
if (gConfig.testRoot == "browser") {
|
2011-10-06 18:51:03 +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);
|
|
|
|
|
2011-05-17 21:10:37 +04:00
|
|
|
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=no,resizable,titlebar,toolbar=no,width=800,height=600", sstring);
|
2011-10-06 18:51:03 +04:00
|
|
|
} else {
|
|
|
|
// This code allows us to redirect without requiring specialpowers for chrome and a11y tests.
|
|
|
|
function messageHandler(m) {
|
|
|
|
messageManager.removeMessageListener("chromeEvent", messageHandler);
|
|
|
|
var url = m.json.data;
|
|
|
|
|
|
|
|
// Window is the [ChromeWindow] for messageManager, so we need content.window
|
|
|
|
// Currently chrome tests are run in a content window instead of a ChromeWindow
|
|
|
|
var webNav = content.window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIWebNavigation);
|
|
|
|
webNav.loadURI(url, null, null, null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
var listener = 'data:,function doLoad(e) { var data=e.getData("data");removeEventListener("contentEvent", function (e) { doLoad(e); }, false, true);sendAsyncMessage("chromeEvent", {"data":data}); };addEventListener("contentEvent", function (e) { doLoad(e); }, false, true);';
|
|
|
|
messageManager.loadFrameScript(listener, true);
|
|
|
|
messageManager.addMessageListener("chromeEvent", messageHandler);
|
2011-05-17 21:10:37 +04:00
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
|
2009-06-11 21:47:37 +04:00
|
|
|
function Tester(aTests, aDumper, aCallback) {
|
|
|
|
this.dumper = aDumper;
|
2007-07-09 20:24:15 +04:00
|
|
|
this.tests = aTests;
|
|
|
|
this.callback = aCallback;
|
2009-07-03 11:22:31 +04:00
|
|
|
this._cs = Cc["@mozilla.org/consoleservice;1"].
|
|
|
|
getService(Ci.nsIConsoleService);
|
2010-01-21 15:05:27 +03:00
|
|
|
this._wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
|
|
|
this._fm = Cc["@mozilla.org/focus-manager;1"].
|
|
|
|
getService(Ci.nsIFocusManager);
|
2009-09-22 13:16:03 +04:00
|
|
|
|
2010-01-21 15:05:27 +03:00
|
|
|
this._scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
|
|
|
getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", this.EventUtils);
|
2009-09-22 13:16:03 +04:00
|
|
|
var simpleTestScope = {};
|
2011-10-06 18:51:03 +04:00
|
|
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js", simpleTestScope);
|
|
|
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js", simpleTestScope);
|
|
|
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromePowers.js", simpleTestScope);
|
2010-01-21 15:05:27 +03:00
|
|
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/SimpleTest.js", simpleTestScope);
|
2010-08-24 21:29:34 +04:00
|
|
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/chrome-harness.js", simpleTestScope);
|
2009-09-22 13:16:03 +04:00
|
|
|
this.SimpleTest = simpleTestScope.SimpleTest;
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
Tester.prototype = {
|
2009-09-22 13:16:03 +04:00
|
|
|
EventUtils: {},
|
|
|
|
SimpleTest: {},
|
|
|
|
|
2011-08-30 00:14:33 +04:00
|
|
|
repeat: 0,
|
2007-07-09 20:24:15 +04:00
|
|
|
checker: null,
|
|
|
|
currentTestIndex: -1,
|
2010-08-10 00:54:23 +04:00
|
|
|
lastStartTime: null,
|
2007-07-09 20:24:15 +04:00
|
|
|
get currentTest() {
|
|
|
|
return this.tests[this.currentTestIndex];
|
|
|
|
},
|
|
|
|
get done() {
|
|
|
|
return this.currentTestIndex == this.tests.length - 1;
|
|
|
|
},
|
2008-07-16 09:43:15 +04:00
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
start: function Tester_start() {
|
2011-07-15 01:39:17 +04:00
|
|
|
//if testOnLoad was not called, then gConfig is not defined
|
2012-02-03 13:10:52 +04:00
|
|
|
if (!gConfig)
|
2011-07-15 01:39:17 +04:00
|
|
|
gConfig = readConfig();
|
2011-08-30 00:14:33 +04:00
|
|
|
this.repeat = gConfig.repeat;
|
2009-06-11 21:47:37 +04:00
|
|
|
this.dumper.dump("*** Start BrowserChrome Test Results ***\n");
|
2009-07-03 11:22:31 +04:00
|
|
|
this._cs.registerListener(this);
|
2012-02-03 13:10:52 +04:00
|
|
|
this._globalProperties = Object.keys(window);
|
|
|
|
this._globalPropertyWhitelist = ["navigator", "constructor", "Application",
|
2012-02-03 20:20:08 +04:00
|
|
|
"__SS_tabsToRestore", "webConsoleCommandController",
|
|
|
|
|
|
|
|
// Temporarily added to whitelist for Fennec tests:
|
|
|
|
"AddonUpdateChecker",
|
|
|
|
"PlacesAggregatedTransaction",
|
|
|
|
"PlacesCreateFolderTransaction",
|
|
|
|
"PlacesCreateBookmarkTransaction",
|
|
|
|
"PlacesCreateSeparatorTransaction",
|
|
|
|
"PlacesCreateLivemarkTransaction",
|
|
|
|
"PlacesMoveItemTransaction",
|
|
|
|
"PlacesRemoveItemTransaction",
|
|
|
|
"PlacesEditItemTitleTransaction",
|
|
|
|
"PlacesEditBookmarkURITransaction",
|
|
|
|
"PlacesSetItemAnnotationTransaction",
|
|
|
|
"PlacesSetPageAnnotationTransaction",
|
|
|
|
"PlacesEditBookmarkKeywordTransaction",
|
|
|
|
"PlacesEditBookmarkPostDataTransaction",
|
|
|
|
"PlacesEditLivemarkSiteURITransaction",
|
|
|
|
"PlacesEditLivemarkFeedURITransaction",
|
|
|
|
"PlacesEditItemDateAddedTransaction",
|
|
|
|
"PlacesEditItemLastModifiedTransaction",
|
|
|
|
"PlacesSortFolderByNameTransaction",
|
|
|
|
"PlacesTagURITransaction",
|
|
|
|
"PlacesUntagURITransaction",
|
|
|
|
"DownloadUtils",
|
|
|
|
"AddonRepository",
|
|
|
|
"LocaleRepository",
|
|
|
|
"Contacts",
|
|
|
|
"VKBstateHasChanged"
|
|
|
|
];
|
2009-06-11 21:47:37 +04:00
|
|
|
|
2009-01-16 22:19:25 +03:00
|
|
|
if (this.tests.length)
|
2010-01-21 15:05:27 +03:00
|
|
|
this.nextTest();
|
2009-01-16 22:19:25 +03:00
|
|
|
else
|
|
|
|
this.finish();
|
2007-07-09 20:24:15 +04:00
|
|
|
},
|
|
|
|
|
2010-01-21 15:05:27 +03:00
|
|
|
waitForWindowsState: function Tester_waitForWindowsState(aCallback) {
|
2010-07-16 00:38:03 +04:00
|
|
|
let timedOut = this.currentTest && this.currentTest.timedOut;
|
|
|
|
let baseMsg = timedOut ? "Found a {elt} after previous test timed out"
|
|
|
|
: this.currentTest ? "Found an unexpected {elt} at the end of test run"
|
|
|
|
: "Found an unexpected {elt}";
|
|
|
|
|
2010-06-16 07:55:46 +04:00
|
|
|
if (this.currentTest && window.gBrowser && gBrowser.tabs.length > 1) {
|
2010-06-22 22:28:32 +04:00
|
|
|
while (gBrowser.tabs.length > 1) {
|
|
|
|
let lastTab = gBrowser.tabContainer.lastChild;
|
2010-07-16 00:38:03 +04:00
|
|
|
let msg = baseMsg.replace("{elt}", "tab") +
|
|
|
|
": " + lastTab.linkedBrowser.currentURI.spec;
|
2010-06-22 22:28:32 +04:00
|
|
|
this.currentTest.addResult(new testResult(false, msg, "", false));
|
|
|
|
gBrowser.removeTab(lastTab);
|
|
|
|
}
|
2010-06-14 19:53:43 +04:00
|
|
|
}
|
|
|
|
|
2010-01-21 15:05:27 +03:00
|
|
|
this.dumper.dump("TEST-INFO | checking window state\n");
|
2011-03-29 00:29:09 +04:00
|
|
|
let windowsEnum = this._wm.getEnumerator(null);
|
2010-01-21 15:05:27 +03:00
|
|
|
while (windowsEnum.hasMoreElements()) {
|
|
|
|
let win = windowsEnum.getNext();
|
2011-03-29 00:29:09 +04:00
|
|
|
if (win != window && !win.closed &&
|
|
|
|
win.document.documentElement.getAttribute("id") != "browserTestHarness") {
|
|
|
|
let type = win.document.documentElement.getAttribute("windowtype");
|
|
|
|
switch (type) {
|
|
|
|
case "navigator:browser":
|
|
|
|
type = "browser window";
|
|
|
|
break;
|
|
|
|
case null:
|
|
|
|
type = "unknown window";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
let msg = baseMsg.replace("{elt}", type);
|
2010-07-16 00:38:03 +04:00
|
|
|
if (this.currentTest)
|
2010-01-21 15:05:27 +03:00
|
|
|
this.currentTest.addResult(new testResult(false, msg, "", false));
|
|
|
|
else
|
2011-11-12 14:52:39 +04:00
|
|
|
this.dumper.dump("TEST-UNEXPECTED-FAIL | (browser-test.js) | " + msg + "\n");
|
2010-01-21 15:05:27 +03:00
|
|
|
|
|
|
|
win.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the window is raised before each test.
|
2011-06-10 11:00:45 +04:00
|
|
|
this.SimpleTest.waitForFocus(aCallback);
|
2010-01-21 15:05:27 +03:00
|
|
|
},
|
|
|
|
|
2009-06-11 21:47:37 +04:00
|
|
|
finish: function Tester_finish(aSkipSummary) {
|
2011-08-30 00:14:33 +04:00
|
|
|
if (this.repeat > 0) {
|
|
|
|
--this.repeat;
|
2011-07-15 01:39:17 +04:00
|
|
|
this.currentTestIndex = -1;
|
|
|
|
this.nextTest();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this._cs.unregisterListener(this);
|
|
|
|
|
|
|
|
this.dumper.dump("\nINFO TEST-START | Shutdown\n");
|
|
|
|
if (this.tests.length) {
|
|
|
|
this.dumper.dump("Browser Chrome Test Summary\n");
|
|
|
|
|
|
|
|
function sum(a,b) a+b;
|
|
|
|
var passCount = this.tests.map(function (f) f.passCount).reduce(sum);
|
|
|
|
var failCount = this.tests.map(function (f) f.failCount).reduce(sum);
|
|
|
|
var todoCount = this.tests.map(function (f) f.todoCount).reduce(sum);
|
|
|
|
|
|
|
|
this.dumper.dump("\tPassed: " + passCount + "\n" +
|
|
|
|
"\tFailed: " + failCount + "\n" +
|
|
|
|
"\tTodo: " + todoCount + "\n");
|
|
|
|
} else {
|
|
|
|
this.dumper.dump("TEST-UNEXPECTED-FAIL | (browser-test.js) | " +
|
2011-11-12 14:46:07 +04:00
|
|
|
"No tests to run. Did you pass an invalid --test-path?\n");
|
2011-07-15 01:39:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
this.dumper.dump("\n*** End BrowserChrome Test Results ***\n");
|
|
|
|
|
|
|
|
this.dumper.done();
|
|
|
|
|
|
|
|
// Tests complete, notify the callback and return
|
|
|
|
this.callback(this.tests);
|
|
|
|
this.callback = null;
|
|
|
|
this.tests = null;
|
2009-06-11 21:47:37 +04:00
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
},
|
|
|
|
|
2009-07-03 11:22:31 +04:00
|
|
|
observe: function Tester_observe(aConsoleMessage) {
|
2010-08-19 13:35:09 +04:00
|
|
|
try {
|
|
|
|
var msg = "Console message: " + aConsoleMessage.message;
|
|
|
|
if (this.currentTest)
|
|
|
|
this.currentTest.addResult(new testMessage(msg));
|
|
|
|
else
|
2011-11-12 14:52:39 +04:00
|
|
|
this.dumper.dump("TEST-INFO | (browser-test.js) | " + msg.replace(/\n$/, "") + "\n");
|
2010-08-19 13:35:09 +04:00
|
|
|
} catch (ex) {
|
|
|
|
// Swallow exception so we don't lead to another error being reported,
|
|
|
|
// throwing us into an infinite loop
|
|
|
|
}
|
2009-07-03 11:22:31 +04:00
|
|
|
},
|
|
|
|
|
2010-01-21 15:05:27 +03:00
|
|
|
nextTest: function Tester_nextTest() {
|
2009-11-24 00:32:27 +03:00
|
|
|
if (this.currentTest) {
|
|
|
|
// Run cleanup functions for the current test before moving on to the
|
|
|
|
// next one.
|
|
|
|
let testScope = this.currentTest.scope;
|
|
|
|
while (testScope.__cleanupFunctions.length > 0) {
|
|
|
|
let func = testScope.__cleanupFunctions.shift();
|
2010-10-30 22:59:18 +04:00
|
|
|
try {
|
|
|
|
func.apply(testScope);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
this.currentTest.addResult(new testResult(false, "Cleanup function threw an exception", ex, false));
|
|
|
|
}
|
2009-11-24 00:32:27 +03:00
|
|
|
};
|
2010-08-24 02:44:07 +04:00
|
|
|
|
2011-12-02 16:25:03 +04:00
|
|
|
if (this.SimpleTest.isExpectingUncaughtException()) {
|
|
|
|
this.currentTest.addResult(new testResult(false, "expectUncaughtException was called but no uncaught exception was detected!", "", false));
|
|
|
|
}
|
|
|
|
|
2012-02-03 13:10:52 +04:00
|
|
|
Object.keys(window).forEach(function (prop) {
|
|
|
|
if (this._globalProperties.indexOf(prop) == -1) {
|
|
|
|
this._globalProperties.push(prop);
|
|
|
|
if (this._globalPropertyWhitelist.indexOf(prop) == -1)
|
|
|
|
this.currentTest.addResult(new testResult(false, "leaked window property: " + prop, "", false));
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
2011-02-02 19:00:47 +03:00
|
|
|
// Clear document.popupNode. The test could have set it to a custom value
|
|
|
|
// for its own purposes, nulling it out it will go back to the default
|
|
|
|
// behavior of returning the last opened popup.
|
|
|
|
document.popupNode = null;
|
|
|
|
|
2010-08-24 02:44:07 +04:00
|
|
|
// Note the test run time
|
|
|
|
let time = Date.now() - this.lastStartTime;
|
2010-10-19 23:20:49 +04:00
|
|
|
this.dumper.dump("INFO TEST-END | " + this.currentTest.path + " | finished in " + time + "ms\n");
|
|
|
|
this.currentTest.setDuration(time);
|
2011-06-10 11:00:45 +04:00
|
|
|
|
|
|
|
testScope.destroy();
|
|
|
|
this.currentTest.scope = null;
|
2009-11-24 00:32:27 +03:00
|
|
|
}
|
|
|
|
|
2010-01-21 15:05:27 +03:00
|
|
|
// 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.
|
2011-06-10 11:00:45 +04:00
|
|
|
this.waitForWindowsState((function () {
|
|
|
|
if (this.done) {
|
2011-07-25 14:11:31 +04:00
|
|
|
// Schedule GC and CC runs before finishing in order to detect
|
|
|
|
// DOM windows leaked by our tests or the tested code.
|
|
|
|
Cu.schedulePreciseGC((function () {
|
|
|
|
let winutils = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
winutils.garbageCollect();
|
|
|
|
winutils.garbageCollect();
|
|
|
|
winutils.garbageCollect();
|
|
|
|
this.finish();
|
|
|
|
}).bind(this));
|
2011-06-10 11:00:45 +04:00
|
|
|
return;
|
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2011-06-10 11:00:45 +04:00
|
|
|
this.currentTestIndex++;
|
|
|
|
this.execTest();
|
|
|
|
}).bind(this));
|
2010-01-21 15:05:27 +03:00
|
|
|
},
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2010-01-21 15:05:27 +03:00
|
|
|
execTest: function Tester_execTest() {
|
2010-06-11 08:28:34 +04:00
|
|
|
this.dumper.dump("TEST-START | " + this.currentTest.path + "\n");
|
2009-06-11 21:47:37 +04:00
|
|
|
|
2011-12-02 16:25:03 +04:00
|
|
|
this.SimpleTest.reset();
|
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
// Load the tests into a testscope
|
2009-06-11 21:47:37 +04:00
|
|
|
this.currentTest.scope = new testScope(this, this.currentTest);
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2009-09-22 13:16:03 +04:00
|
|
|
// Import utils in the test scope.
|
|
|
|
this.currentTest.scope.EventUtils = this.EventUtils;
|
|
|
|
this.currentTest.scope.SimpleTest = this.SimpleTest;
|
2010-09-10 21:20:38 +04:00
|
|
|
this.currentTest.scope.gTestPath = this.currentTest.path;
|
|
|
|
|
2010-03-18 23:11:20 +03:00
|
|
|
// Override SimpleTest methods with ours.
|
2011-12-02 16:25:03 +04:00
|
|
|
["ok", "is", "isnot", "todo", "todo_is", "todo_isnot", "info"].forEach(function(m) {
|
2010-03-18 23:11:20 +03:00
|
|
|
this.SimpleTest[m] = this[m];
|
|
|
|
}, this.currentTest.scope);
|
2009-09-22 13:16:03 +04:00
|
|
|
|
2010-09-10 21:20:38 +04:00
|
|
|
//load the tools to work with chrome .jar and remote
|
|
|
|
try {
|
|
|
|
this._scriptLoader.loadSubScript("chrome://mochikit/content/chrome-harness.js", this.currentTest.scope);
|
|
|
|
} catch (ex) { /* no chrome-harness tools */ }
|
|
|
|
|
2009-11-24 00:32:27 +03:00
|
|
|
// Import head.js script if it exists.
|
|
|
|
var currentTestDirPath =
|
|
|
|
this.currentTest.path.substr(0, this.currentTest.path.lastIndexOf("/"));
|
|
|
|
var headPath = currentTestDirPath + "/head.js";
|
|
|
|
try {
|
|
|
|
this._scriptLoader.loadSubScript(headPath, this.currentTest.scope);
|
|
|
|
} catch (ex) { /* no head */ }
|
|
|
|
|
|
|
|
// Import the test script.
|
2007-07-09 20:24:15 +04:00
|
|
|
try {
|
2010-01-21 15:05:27 +03:00
|
|
|
this._scriptLoader.loadSubScript(this.currentTest.path,
|
|
|
|
this.currentTest.scope);
|
2007-07-16 04:21:11 +04:00
|
|
|
|
|
|
|
// Run the test
|
2010-08-10 00:54:23 +04:00
|
|
|
this.lastStartTime = Date.now();
|
2011-03-30 03:41:29 +04:00
|
|
|
if ("generatorTest" in this.currentTest.scope) {
|
|
|
|
if ("test" in this.currentTest.scope)
|
|
|
|
throw "Cannot run both a generator test and a normal test at the same time.";
|
|
|
|
|
|
|
|
// This test is a generator. It will not finish immediately.
|
|
|
|
this.currentTest.scope.waitForExplicitFinish();
|
|
|
|
var result = this.currentTest.scope.generatorTest();
|
|
|
|
this.currentTest.scope.__generator = result;
|
|
|
|
result.next();
|
|
|
|
} else {
|
|
|
|
this.currentTest.scope.test();
|
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
} catch (ex) {
|
2011-12-02 16:25:03 +04:00
|
|
|
var isExpected = !!this.SimpleTest.isExpectingUncaughtException();
|
|
|
|
if (!this.SimpleTest.isIgnoringAllUncaughtExceptions()) {
|
|
|
|
this.currentTest.addResult(new testResult(isExpected, "Exception thrown", ex, false));
|
|
|
|
this.SimpleTest.expectUncaughtException(false);
|
|
|
|
} else {
|
|
|
|
this.currentTest.addResult(new testMessage("Exception thrown: " + ex));
|
|
|
|
}
|
2011-03-30 03:41:29 +04:00
|
|
|
this.currentTest.scope.finish();
|
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.
|
2009-06-11 21:47:37 +04:00
|
|
|
if (this.currentTest.scope.__done) {
|
2010-01-21 15:05:27 +03:00
|
|
|
this.nextTest();
|
2009-02-26 01:27:32 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-07-09 20:24:15 +04:00
|
|
|
var self = this;
|
2009-06-11 21:47:37 +04:00
|
|
|
this.currentTest.scope.__waitTimer = setTimeout(function() {
|
2009-12-04 17:13:22 +03:00
|
|
|
if (--self.currentTest.scope.__timeoutFactor > 0) {
|
|
|
|
// We were asked to wait a bit longer.
|
|
|
|
self.currentTest.scope.info(
|
|
|
|
"Longer timeout required, waiting longer... Remaining timeouts: " +
|
|
|
|
self.currentTest.scope.__timeoutFactor);
|
|
|
|
self.currentTest.scope.__waitTimer =
|
|
|
|
setTimeout(arguments.callee, TIMEOUT_SECONDS * 1000);
|
|
|
|
return;
|
|
|
|
}
|
2010-08-23 05:29:05 +04:00
|
|
|
self.currentTest.addResult(new testResult(false, "Test timed out", "", false));
|
2010-07-16 00:38:03 +04:00
|
|
|
self.currentTest.timedOut = true;
|
2009-06-11 21:47:37 +04:00
|
|
|
self.currentTest.scope.__waitTimer = null;
|
2010-01-21 15:05:27 +03:00
|
|
|
self.nextTest();
|
2009-05-03 20:28:43 +04:00
|
|
|
}, TIMEOUT_SECONDS * 1000);
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
2009-07-03 11:22:31 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (aIID.equals(Ci.nsIConsoleListener) ||
|
|
|
|
aIID.equals(Ci.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-22 12:58:42 +04:00
|
|
|
function testResult(aCondition, aName, aDiag, aIsTodo, aStack) {
|
2009-07-03 11:22:31 +04:00
|
|
|
this.msg = aName || "";
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2009-07-03 11:22:31 +04:00
|
|
|
this.info = false;
|
2007-07-09 20:24:15 +04:00
|
|
|
this.pass = !!aCondition;
|
2007-07-12 18:29:33 +04:00
|
|
|
this.todo = aIsTodo;
|
2009-07-03 11:22:31 +04:00
|
|
|
|
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 {
|
2009-07-10 23:34:04 +04:00
|
|
|
if (aDiag) {
|
|
|
|
if (typeof aDiag == "object" && "fileName" in aDiag) {
|
|
|
|
// we have an exception - print filename and linenumber information
|
|
|
|
this.msg += " at " + aDiag.fileName + ":" + aDiag.lineNumber;
|
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
this.msg += " - " + aDiag;
|
2009-07-10 23:34:04 +04:00
|
|
|
}
|
2010-09-22 12:58:42 +04:00
|
|
|
if (aStack) {
|
|
|
|
this.msg += "\nStack trace:\n";
|
|
|
|
var frame = aStack;
|
|
|
|
while (frame) {
|
|
|
|
this.msg += " " + frame + "\n";
|
|
|
|
frame = frame.caller;
|
|
|
|
}
|
|
|
|
}
|
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-07-03 11:22:31 +04:00
|
|
|
function testMessage(aName) {
|
|
|
|
this.msg = aName || "";
|
|
|
|
this.info = true;
|
|
|
|
this.result = "TEST-INFO";
|
|
|
|
}
|
|
|
|
|
2009-06-11 21:47:37 +04:00
|
|
|
// Need to be careful adding properties to this object, since its properties
|
|
|
|
// cannot conflict with global variables used in tests.
|
|
|
|
function testScope(aTester, aTest) {
|
|
|
|
this.__tester = aTester;
|
2008-01-26 00:29:11 +03:00
|
|
|
|
|
|
|
var self = this;
|
2010-09-22 12:58:42 +04:00
|
|
|
this.ok = function test_ok(condition, name, diag, stack) {
|
2011-12-02 16:25:03 +04:00
|
|
|
aTest.addResult(new testResult(condition, name, diag, false,
|
|
|
|
stack ? stack : Components.stack.caller));
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 00:29:11 +03:00
|
|
|
this.is = function test_is(a, b, name) {
|
2010-09-22 12:58:42 +04:00
|
|
|
self.ok(a == b, name, "Got " + a + ", expected " + b, false,
|
|
|
|
Components.stack.caller);
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 00:29:11 +03:00
|
|
|
this.isnot = function test_isnot(a, b, name) {
|
2010-09-22 12:58:42 +04:00
|
|
|
self.ok(a != b, name, "Didn't expect " + a + ", but got it", false,
|
|
|
|
Components.stack.caller);
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2010-09-22 12:58:42 +04:00
|
|
|
this.todo = function test_todo(condition, name, diag, stack) {
|
2011-12-02 16:25:03 +04:00
|
|
|
aTest.addResult(new testResult(!condition, name, diag, true,
|
|
|
|
stack ? stack : Components.stack.caller));
|
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) {
|
2010-09-22 12:58:42 +04:00
|
|
|
self.todo(a == b, name, "Got " + a + ", expected " + b,
|
|
|
|
Components.stack.caller);
|
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) {
|
2010-09-22 12:58:42 +04:00
|
|
|
self.todo(a != b, name, "Didn't expect " + a + ", but got it",
|
|
|
|
Components.stack.caller);
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2009-07-03 11:22:31 +04:00
|
|
|
this.info = function test_info(name) {
|
2011-12-02 16:25:03 +04:00
|
|
|
aTest.addResult(new testMessage(name));
|
2009-07-03 11:22:31 +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);
|
|
|
|
};
|
|
|
|
|
2011-03-30 03:41:29 +04:00
|
|
|
this.nextStep = function test_nextStep(arg) {
|
|
|
|
if (self.__done) {
|
|
|
|
aTest.addResult(new testResult(false, "nextStep was called too many times", "", false));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!self.__generator) {
|
|
|
|
aTest.addResult(new testResult(false, "nextStep called with no generator", "", false));
|
|
|
|
self.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
self.__generator.send(arg);
|
|
|
|
} catch (ex if ex instanceof StopIteration) {
|
|
|
|
// StopIteration means test is finished.
|
|
|
|
self.finish();
|
|
|
|
} catch (ex) {
|
2011-12-02 16:25:03 +04:00
|
|
|
var isExpected = !!self.SimpleTest.isExpectingUncaughtException();
|
|
|
|
if (!self.SimpleTest.isIgnoringAllUncaughtExceptions()) {
|
|
|
|
aTest.addResult(new testResult(isExpected, "Exception thrown", ex, false));
|
|
|
|
self.SimpleTest.expectUncaughtException(false);
|
|
|
|
} else {
|
|
|
|
aTest.addResult(new testMessage("Exception thrown: " + ex));
|
|
|
|
}
|
2011-03-30 03:41:29 +04:00
|
|
|
self.finish();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-11-24 00:32:27 +03:00
|
|
|
this.waitForExplicitFinish = function test_waitForExplicitFinish() {
|
2009-06-11 21:47:37 +04:00
|
|
|
self.__done = false;
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2009-06-11 21:47:37 +04:00
|
|
|
|
2010-05-18 17:31:03 +04:00
|
|
|
this.waitForFocus = function test_waitForFocus(callback, targetWindow, expectBlankPage) {
|
|
|
|
self.SimpleTest.waitForFocus(callback, targetWindow, expectBlankPage);
|
2009-09-22 13:16:03 +04:00
|
|
|
};
|
|
|
|
|
2011-04-23 04:04:15 +04:00
|
|
|
this.waitForClipboard = function test_waitForClipboard(expected, setup, success, failure, flavor) {
|
|
|
|
self.SimpleTest.waitForClipboard(expected, setup, success, failure, flavor);
|
2010-06-03 00:38:32 +04:00
|
|
|
};
|
|
|
|
|
2009-11-24 00:32:27 +03:00
|
|
|
this.registerCleanupFunction = function test_registerCleanupFunction(aFunction) {
|
|
|
|
self.__cleanupFunctions.push(aFunction);
|
|
|
|
};
|
|
|
|
|
2009-12-04 17:13:22 +03:00
|
|
|
this.requestLongerTimeout = function test_requestLongerTimeout(aFactor) {
|
|
|
|
self.__timeoutFactor = aFactor;
|
|
|
|
};
|
|
|
|
|
2010-09-10 21:20:38 +04:00
|
|
|
this.copyToProfile = function test_copyToProfile(filename) {
|
|
|
|
self.SimpleTest.copyToProfile(filename);
|
|
|
|
};
|
|
|
|
|
2011-12-02 16:25:03 +04:00
|
|
|
this.expectUncaughtException = function test_expectUncaughtException(aExpecting) {
|
|
|
|
self.SimpleTest.expectUncaughtException(aExpecting);
|
2011-07-15 06:43:09 +04:00
|
|
|
};
|
|
|
|
|
2011-12-02 16:25:03 +04:00
|
|
|
this.ignoreAllUncaughtExceptions = function test_ignoreAllUncaughtExceptions(aIgnoring) {
|
|
|
|
self.SimpleTest.ignoreAllUncaughtExceptions(aIgnoring);
|
2011-11-12 15:06:54 +04:00
|
|
|
};
|
|
|
|
|
2008-01-26 00:29:11 +03:00
|
|
|
this.finish = function test_finish() {
|
2009-06-11 21:47:37 +04:00
|
|
|
self.__done = true;
|
|
|
|
if (self.__waitTimer) {
|
2009-02-26 01:27:32 +03:00
|
|
|
self.executeSoon(function() {
|
2009-06-11 21:47:37 +04:00
|
|
|
if (self.__done && self.__waitTimer) {
|
|
|
|
clearTimeout(self.__waitTimer);
|
|
|
|
self.__waitTimer = null;
|
2010-01-21 15:05:27 +03:00
|
|
|
self.__tester.nextTest();
|
2009-02-26 01:27:32 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
testScope.prototype = {
|
2009-06-11 21:47:37 +04:00
|
|
|
__done: true,
|
2011-03-30 03:41:29 +04:00
|
|
|
__generator: null,
|
2009-06-11 21:47:37 +04:00
|
|
|
__waitTimer: null,
|
2009-11-24 00:32:27 +03:00
|
|
|
__cleanupFunctions: [],
|
2009-12-04 17:13:22 +03:00
|
|
|
__timeoutFactor: 1,
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2009-09-22 13:16:03 +04:00
|
|
|
EventUtils: {},
|
2011-06-10 11:00:45 +04:00
|
|
|
SimpleTest: {},
|
|
|
|
|
|
|
|
destroy: function test_destroy() {
|
|
|
|
for (let prop in this)
|
|
|
|
delete this[prop];
|
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
};
|