2013-11-21 22:03:19 +04:00
|
|
|
/* -*- js-indent-level: 2; tab-width: 2; indent-tabs-mode: nil -*- */
|
2018-04-30 13:03:44 +03:00
|
|
|
|
2012-08-03 14:36:59 +04:00
|
|
|
/* eslint-env mozilla/browser-window */
|
2010-09-10 21:20:38 +04:00
|
|
|
/* import-globals-from chrome-harness.js */
|
2018-03-14 05:11:10 +03:00
|
|
|
/* import-globals-from mochitest-e10s-utils.js */
|
2018-04-30 13:03:44 +03:00
|
|
|
|
2009-02-26 01:27:32 +03:00
|
|
|
// Test timeout (seconds)
|
2014-03-24 03:55:34 +04:00
|
|
|
var gTimeoutSeconds = 45;
|
2011-06-08 20:04:14 +04:00
|
|
|
var gConfig;
|
2009-02-26 01:27:32 +03:00
|
|
|
|
Bug 1792341 - Migrate more toolkit/modules consumers to use direct ES module import. r=Gijs,webdriver-reviewers,perftest-reviewers,necko-reviewers,geckoview-reviewers,preferences-reviewers,application-update-reviewers,pip-reviewers,credential-management-reviewers,sgalich,owlish,bytesized,AlexandruIonescu,whimboo,mconley,mixedpuppy
Mainly automated changes. Some manual ESLint fixes and whitespace cleanup.
Differential Revision: https://phabricator.services.mozilla.com/D158452
2022-10-18 14:21:26 +03:00
|
|
|
var { AppConstants } = ChromeUtils.importESModule(
|
|
|
|
"resource://gre/modules/AppConstants.sys.mjs"
|
2019-01-17 21:18:31 +03:00
|
|
|
);
|
2019-07-05 12:01:24 +03:00
|
|
|
|
2023-06-04 16:44:45 +03:00
|
|
|
ChromeUtils.defineESModuleGetters(this, {
|
|
|
|
AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
|
|
|
|
});
|
2019-07-05 12:01:24 +03:00
|
|
|
|
2014-04-11 19:57:59 +04:00
|
|
|
const SIMPLETEST_OVERRIDES = [
|
2018-11-01 16:50:27 +03:00
|
|
|
"ok",
|
|
|
|
"record",
|
|
|
|
"is",
|
|
|
|
"isnot",
|
|
|
|
"todo",
|
|
|
|
"todo_is",
|
|
|
|
"todo_isnot",
|
|
|
|
"info",
|
|
|
|
"expectAssertions",
|
|
|
|
"requestCompleteLog",
|
|
|
|
];
|
2014-04-11 19:57:59 +04:00
|
|
|
|
2018-09-26 17:28:20 +03:00
|
|
|
setTimeout(testInit, 0);
|
2008-09-15 16:38:09 +04:00
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var TabDestroyObserver = {
|
2015-02-27 08:35:26 +03:00
|
|
|
outstanding: new Set(),
|
|
|
|
promiseResolver: null,
|
|
|
|
|
|
|
|
init() {
|
2017-04-15 00:39:22 +03:00
|
|
|
Services.obs.addObserver(this, "message-manager-close");
|
|
|
|
Services.obs.addObserver(this, "message-manager-disconnect");
|
2015-02-27 08:35:26 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
Services.obs.removeObserver(this, "message-manager-close");
|
|
|
|
Services.obs.removeObserver(this, "message-manager-disconnect");
|
|
|
|
},
|
|
|
|
|
|
|
|
observe(subject, topic, data) {
|
|
|
|
if (topic == "message-manager-close") {
|
|
|
|
this.outstanding.add(subject);
|
|
|
|
} else if (topic == "message-manager-disconnect") {
|
|
|
|
this.outstanding.delete(subject);
|
|
|
|
if (!this.outstanding.size && this.promiseResolver) {
|
|
|
|
this.promiseResolver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
wait() {
|
|
|
|
if (!this.outstanding.size) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this.promiseResolver = resolve;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-07-28 04:32:40 +04:00
|
|
|
function testInit() {
|
2011-05-17 21:10:37 +04:00
|
|
|
gConfig = readConfig();
|
2016-03-08 00:32:26 +03:00
|
|
|
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
|
2012-08-03 14:36:59 +04:00
|
|
|
var prefs = Services.prefs;
|
2011-10-06 18:51:03 +04:00
|
|
|
if (prefs.prefHasUserValue("testing.browserTestHarness.running")) {
|
|
|
|
return;
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2011-10-06 18:51:03 +04:00
|
|
|
|
|
|
|
prefs.setBoolPref("testing.browserTestHarness.running", true);
|
|
|
|
|
2013-02-19 22:27:28 +04:00
|
|
|
if (prefs.prefHasUserValue("testing.browserTestHarness.timeout")) {
|
|
|
|
gTimeoutSeconds = prefs.getIntPref("testing.browserTestHarness.timeout");
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2013-02-19 22:27:28 +04:00
|
|
|
|
2011-05-17 21:10:37 +04:00
|
|
|
var sstring = Cc["@mozilla.org/supports-string;1"].createInstance(
|
|
|
|
Ci.nsISupportsString
|
|
|
|
);
|
|
|
|
sstring.data = location.search;
|
|
|
|
|
2012-08-03 14:36:59 +04:00
|
|
|
Services.ww.openWindow(
|
|
|
|
window,
|
2019-12-02 22:16:22 +03:00
|
|
|
"chrome://mochikit/content/browser-harness.xhtml",
|
2012-08-03 14:36:59 +04:00
|
|
|
"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.
|
2023-05-20 15:26:49 +03:00
|
|
|
let messageHandler = function (m) {
|
2013-07-19 17:51:34 +04:00
|
|
|
// eslint-disable-next-line no-undef
|
2011-10-06 18:51:03 +04:00
|
|
|
messageManager.removeMessageListener("chromeEvent", messageHandler);
|
|
|
|
var url = m.json.data;
|
|
|
|
|
2014-07-17 11:02:00 +04:00
|
|
|
// Window is the [ChromeWindow] for messageManager, so we need content.window
|
2011-10-06 18:51:03 +04:00
|
|
|
// Currently chrome tests are run in a content window instead of a ChromeWindow
|
2013-07-19 17:51:34 +04:00
|
|
|
// eslint-disable-next-line no-undef
|
2018-08-01 20:07:11 +03:00
|
|
|
var webNav = content.window.docShell.QueryInterface(Ci.nsIWebNavigation);
|
2019-01-11 14:44:20 +03:00
|
|
|
let loadURIOptions = {
|
2023-05-20 15:26:53 +03:00
|
|
|
triggeringPrincipal:
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal(),
|
2019-01-11 14:44:20 +03:00
|
|
|
};
|
2023-02-14 02:50:41 +03:00
|
|
|
webNav.fixupAndLoadURIString(url, loadURIOptions);
|
2013-07-19 17:51:34 +04:00
|
|
|
};
|
2011-10-06 18:51:03 +04:00
|
|
|
|
2014-03-21 08:00:00 +04:00
|
|
|
var listener =
|
|
|
|
'data:,function doLoad(e) { var data=e.detail&&e.detail.data;removeEventListener("contentEvent", function (e) { doLoad(e); }, false, true);sendAsyncMessage("chromeEvent", {"data":data}); };addEventListener("contentEvent", function (e) { doLoad(e); }, false, true);';
|
2013-07-19 17:51:34 +04:00
|
|
|
// eslint-disable-next-line no-undef
|
2011-10-06 18:51:03 +04:00
|
|
|
messageManager.addMessageListener("chromeEvent", messageHandler);
|
2013-07-19 17:51:34 +04:00
|
|
|
// eslint-disable-next-line no-undef
|
2017-05-19 21:06:12 +03:00
|
|
|
messageManager.loadFrameScript(listener, true);
|
2011-05-17 21:10:37 +04:00
|
|
|
}
|
2014-03-03 02:33:30 +04:00
|
|
|
if (gConfig.e10s) {
|
|
|
|
e10s_init();
|
2016-11-02 13:13:43 +03:00
|
|
|
|
|
|
|
let processCount = prefs.getIntPref("dom.ipc.processCount", 1);
|
|
|
|
if (processCount > 1) {
|
|
|
|
// Currently starting a content process is slow, to aviod timeouts, let's
|
|
|
|
// keep alive content processes.
|
2017-01-13 00:48:23 +03:00
|
|
|
prefs.setIntPref("dom.ipc.keepProcessesAlive.web", processCount);
|
2016-11-02 13:13:43 +03:00
|
|
|
}
|
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
Services.mm.loadFrameScript(
|
|
|
|
"chrome://mochikit/content/shutdown-leaks-collector.js",
|
|
|
|
true
|
|
|
|
);
|
2015-02-25 00:00:54 +03:00
|
|
|
} else {
|
|
|
|
// In non-e10s, only run the ShutdownLeaksCollector in the parent process.
|
2022-11-17 15:00:28 +03:00
|
|
|
ChromeUtils.importESModule(
|
|
|
|
"chrome://mochikit/content/ShutdownLeaksCollector.sys.mjs"
|
|
|
|
);
|
2014-03-03 02:33:30 +04:00
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
|
2018-04-18 21:47:45 +03:00
|
|
|
function isGenerator(value) {
|
|
|
|
return value && typeof value === "object" && typeof value.next === "function";
|
|
|
|
}
|
|
|
|
|
2016-01-25 17:55:57 +03:00
|
|
|
function Tester(aTests, structuredLogger, aCallback) {
|
|
|
|
this.structuredLogger = structuredLogger;
|
2007-07-09 20:24:15 +04:00
|
|
|
this.tests = aTests;
|
|
|
|
this.callback = aCallback;
|
2012-08-03 14:36:59 +04:00
|
|
|
|
|
|
|
this._scriptLoader = Services.scriptloader;
|
2015-03-18 15:38:25 +03:00
|
|
|
this.EventUtils = {};
|
2010-01-21 15:05:27 +03:00
|
|
|
this._scriptLoader.loadSubScript(
|
|
|
|
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js",
|
|
|
|
this.EventUtils
|
|
|
|
);
|
2018-03-14 05:11:10 +03:00
|
|
|
|
2021-01-15 21:20:37 +03:00
|
|
|
this._scriptLoader.loadSubScript(
|
|
|
|
"chrome://mochikit/content/tests/SimpleTest/AccessibilityUtils.js",
|
|
|
|
// AccessibilityUtils are integrated with EventUtils to perform additional
|
|
|
|
// accessibility checks for certain user interactions (clicks, etc). Load
|
|
|
|
// them into the EventUtils scope here.
|
|
|
|
this.EventUtils
|
|
|
|
);
|
|
|
|
this.AccessibilityUtils = this.EventUtils.AccessibilityUtils;
|
|
|
|
|
2019-08-15 02:14:02 +03:00
|
|
|
// Make sure our SpecialPowers actor is instantiated, in case it was
|
|
|
|
// registered after our DOMWindowCreated event was fired (which it
|
|
|
|
// most likely was).
|
2020-01-22 00:32:28 +03:00
|
|
|
void window.windowGlobalChild.getActor("SpecialPowers");
|
2019-08-15 02:14:02 +03:00
|
|
|
|
2009-09-22 13:16:03 +04:00
|
|
|
var simpleTestScope = {};
|
2010-01-21 15:05:27 +03:00
|
|
|
this._scriptLoader.loadSubScript(
|
|
|
|
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js",
|
|
|
|
simpleTestScope
|
|
|
|
);
|
2013-11-21 00:08:07 +04:00
|
|
|
this._scriptLoader.loadSubScript(
|
|
|
|
"chrome://mochikit/content/tests/SimpleTest/MemoryStats.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;
|
2014-05-22 23:09:21 +04:00
|
|
|
|
2019-08-16 00:21:37 +03:00
|
|
|
window.SpecialPowers.SimpleTest = this.SimpleTest;
|
|
|
|
window.SpecialPowers.setAsDefaultAssertHandler();
|
|
|
|
|
2016-03-03 07:58:28 +03:00
|
|
|
var extensionUtilsScope = {
|
|
|
|
registerCleanupFunction: fn => {
|
|
|
|
this.currentTest.scope.registerCleanupFunction(fn);
|
|
|
|
},
|
|
|
|
};
|
2015-08-28 02:29:08 +03:00
|
|
|
extensionUtilsScope.SimpleTest = this.SimpleTest;
|
|
|
|
this._scriptLoader.loadSubScript(
|
|
|
|
"chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js",
|
|
|
|
extensionUtilsScope
|
|
|
|
);
|
|
|
|
this.ExtensionTestUtils = extensionUtilsScope.ExtensionTestUtils;
|
|
|
|
|
2014-05-22 23:09:21 +04:00
|
|
|
this.SimpleTest.harnessParameters = gConfig;
|
|
|
|
|
2013-11-21 00:08:07 +04:00
|
|
|
this.MemoryStats = simpleTestScope.MemoryStats;
|
2022-11-17 15:00:28 +03:00
|
|
|
this.ContentTask = ChromeUtils.importESModule(
|
|
|
|
"resource://testing-common/ContentTask.sys.mjs"
|
2018-01-30 08:17:48 +03:00
|
|
|
).ContentTask;
|
2022-11-17 15:00:28 +03:00
|
|
|
this.BrowserTestUtils = ChromeUtils.importESModule(
|
|
|
|
"resource://testing-common/BrowserTestUtils.sys.mjs"
|
2018-01-30 08:17:48 +03:00
|
|
|
).BrowserTestUtils;
|
2022-11-17 15:00:28 +03:00
|
|
|
this.TestUtils = ChromeUtils.importESModule(
|
|
|
|
"resource://testing-common/TestUtils.sys.mjs"
|
2018-01-30 08:17:48 +03:00
|
|
|
).TestUtils;
|
2022-11-01 16:26:38 +03:00
|
|
|
this.PromiseTestUtils = ChromeUtils.importESModule(
|
|
|
|
"resource://testing-common/PromiseTestUtils.sys.mjs"
|
2018-01-30 08:17:48 +03:00
|
|
|
).PromiseTestUtils;
|
2022-11-17 15:00:28 +03:00
|
|
|
this.Assert = ChromeUtils.importESModule(
|
|
|
|
"resource://testing-common/Assert.sys.mjs"
|
2018-01-30 08:17:48 +03:00
|
|
|
).Assert;
|
2023-03-06 22:13:58 +03:00
|
|
|
this.PerTestCoverageUtils = ChromeUtils.importESModule(
|
|
|
|
"resource://testing-common/PerTestCoverageUtils.sys.mjs"
|
2018-06-27 19:56:09 +03:00
|
|
|
).PerTestCoverageUtils;
|
2014-04-11 19:57:59 +04:00
|
|
|
|
2017-06-18 10:05:06 +03:00
|
|
|
this.PromiseTestUtils.init();
|
|
|
|
|
2014-04-11 19:57:59 +04:00
|
|
|
this.SimpleTestOriginal = {};
|
|
|
|
SIMPLETEST_OVERRIDES.forEach(m => {
|
|
|
|
this.SimpleTestOriginal[m] = this.SimpleTest[m];
|
|
|
|
});
|
2014-04-18 00:23:23 +04:00
|
|
|
|
2015-12-24 01:04:49 +03:00
|
|
|
this._coverageCollector = null;
|
2017-07-23 01:18:00 +03:00
|
|
|
|
2022-07-12 07:21:34 +03:00
|
|
|
const { XPCOMUtils } = ChromeUtils.importESModule(
|
|
|
|
"resource://gre/modules/XPCOMUtils.sys.mjs"
|
2019-01-17 21:18:31 +03:00
|
|
|
);
|
2017-08-28 19:51:08 +03:00
|
|
|
|
2017-07-23 01:18:00 +03:00
|
|
|
// Avoid failing tests when XPCOMUtils.defineLazyScriptGetter is used.
|
2021-05-10 11:56:05 +03:00
|
|
|
XPCOMUtils.overrideScriptLoaderForTests({
|
|
|
|
loadSubScript: (url, obj) => {
|
|
|
|
let before = Object.keys(window);
|
|
|
|
try {
|
|
|
|
return this._scriptLoader.loadSubScript(url, obj);
|
|
|
|
} finally {
|
|
|
|
for (let property of Object.keys(window)) {
|
|
|
|
if (
|
|
|
|
!before.includes(property) &&
|
|
|
|
!this._globalProperties.includes(property)
|
|
|
|
) {
|
|
|
|
this._globalProperties.push(property);
|
|
|
|
this.SimpleTest.info(
|
|
|
|
`Global property added while loading ${url}: ${property}`
|
|
|
|
);
|
2017-07-23 01:18:00 +03:00
|
|
|
}
|
2021-05-10 11:56:05 +03:00
|
|
|
}
|
|
|
|
}
|
2017-07-23 01:18:00 +03:00
|
|
|
},
|
2021-05-10 11:56:05 +03:00
|
|
|
loadSubScriptWithOptions: this._scriptLoader.loadSubScriptWithOptions.bind(
|
|
|
|
this._scriptLoader
|
|
|
|
),
|
2017-08-28 19:51:08 +03:00
|
|
|
});
|
2022-07-28 00:20:20 +03:00
|
|
|
|
|
|
|
// ensure the mouse is reset before each test run
|
2022-11-25 22:09:10 +03:00
|
|
|
if (Services.env.exists("MOZ_AUTOMATION")) {
|
2022-07-28 00:20:20 +03:00
|
|
|
this.EventUtils.synthesizeNativeMouseEvent({
|
|
|
|
type: "mousemove",
|
|
|
|
screenX: 1000,
|
|
|
|
screenY: 10,
|
|
|
|
});
|
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
Tester.prototype = {
|
2009-09-22 13:16:03 +04:00
|
|
|
EventUtils: {},
|
2021-01-15 21:20:37 +03:00
|
|
|
AccessibilityUtils: {},
|
2009-09-22 13:16:03 +04:00
|
|
|
SimpleTest: {},
|
2015-02-12 01:28:44 +03:00
|
|
|
ContentTask: null,
|
2015-08-28 02:29:08 +03:00
|
|
|
ExtensionTestUtils: null,
|
2013-11-21 14:26:33 +04:00
|
|
|
Assert: null,
|
2009-09-22 13:16:03 +04:00
|
|
|
|
2011-08-30 00:14:33 +04:00
|
|
|
repeat: 0,
|
2021-01-15 21:20:37 +03:00
|
|
|
a11y_checks: false,
|
2013-05-24 23:03:50 +04:00
|
|
|
runUntilFailure: false,
|
2007-07-09 20:24:15 +04:00
|
|
|
checker: null,
|
|
|
|
currentTestIndex: -1,
|
2010-08-10 00:54:23 +04:00
|
|
|
lastStartTime: null,
|
2020-05-05 20:25:53 +03:00
|
|
|
lastStartTimestamp: null,
|
2013-09-09 14:21:24 +04:00
|
|
|
lastAssertionCount: 0,
|
2015-12-30 16:50:51 +03:00
|
|
|
failuresFromInitialWindowState: 0,
|
2012-08-03 14:36:59 +04:00
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
get currentTest() {
|
|
|
|
return this.tests[this.currentTestIndex];
|
|
|
|
},
|
|
|
|
get done() {
|
2017-09-15 16:29:44 +03:00
|
|
|
return this.currentTestIndex == this.tests.length - 1 && this.repeat <= 0;
|
2007-07-09 20:24:15 +04:00
|
|
|
},
|
2008-07-16 09:43:15 +04:00
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
start: function Tester_start() {
|
2015-02-27 08:35:26 +03:00
|
|
|
TabDestroyObserver.init();
|
|
|
|
|
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();
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2013-05-24 23:03:50 +04:00
|
|
|
|
|
|
|
if (gConfig.runUntilFailure) {
|
|
|
|
this.runUntilFailure = true;
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2013-05-24 23:03:50 +04:00
|
|
|
|
2021-01-15 21:20:37 +03:00
|
|
|
if (gConfig.a11y_checks != undefined) {
|
|
|
|
this.a11y_checks = gConfig.a11y_checks;
|
|
|
|
}
|
|
|
|
|
2013-05-24 23:03:50 +04:00
|
|
|
if (gConfig.repeat) {
|
|
|
|
this.repeat = gConfig.repeat;
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2013-05-24 23:03:50 +04:00
|
|
|
|
2015-12-24 01:04:49 +03:00
|
|
|
if (gConfig.jscovDirPrefix) {
|
|
|
|
let coveragePath = gConfig.jscovDirPrefix;
|
2022-11-17 15:00:28 +03:00
|
|
|
let { CoverageCollector } = ChromeUtils.importESModule(
|
|
|
|
"resource://testing-common/CoverageUtils.sys.mjs"
|
2019-01-17 21:18:31 +03:00
|
|
|
);
|
2015-12-24 01:04:49 +03:00
|
|
|
this._coverageCollector = new CoverageCollector(coveragePath);
|
|
|
|
}
|
|
|
|
|
2016-01-25 17:55:57 +03:00
|
|
|
this.structuredLogger.info("*** Start BrowserChrome Test Results ***");
|
2012-08-03 14:36:59 +04:00
|
|
|
Services.console.registerListener(this);
|
2012-02-03 13:10:52 +04:00
|
|
|
this._globalProperties = Object.keys(window);
|
2012-11-02 06:46:56 +04:00
|
|
|
this._globalPropertyWhitelist = [
|
|
|
|
"navigator",
|
|
|
|
"constructor",
|
|
|
|
"top",
|
|
|
|
"Application",
|
|
|
|
"__SS_tabsToRestore",
|
|
|
|
"__SSi",
|
|
|
|
"webConsoleCommandController",
|
2018-12-14 00:43:22 +03:00
|
|
|
// Thunderbird
|
|
|
|
"MailMigrator",
|
|
|
|
"SearchIntegration",
|
2023-04-13 19:20:50 +03:00
|
|
|
// lit
|
|
|
|
"reactiveElementVersions",
|
|
|
|
"litHtmlVersions",
|
|
|
|
"litElementVersions",
|
2012-02-03 20:20:08 +04:00
|
|
|
];
|
2009-06-11 21:47:37 +04:00
|
|
|
|
2023-04-20 12:43:41 +03:00
|
|
|
this._repeatingTimers = this._getRepeatingTimers();
|
|
|
|
|
2018-08-03 11:34:00 +03:00
|
|
|
this.PerTestCoverageUtils.beforeTestSync();
|
|
|
|
|
2018-06-06 00:21:53 +03:00
|
|
|
if (this.tests.length) {
|
|
|
|
this.waitForWindowsReady().then(() => {
|
|
|
|
this.nextTest();
|
|
|
|
});
|
|
|
|
} else {
|
2009-01-16 22:19:25 +03:00
|
|
|
this.finish();
|
2018-06-06 00:21:53 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-04-20 12:43:41 +03:00
|
|
|
_getRepeatingTimers() {
|
|
|
|
const kNonRepeatingTimerTypes = [
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT,
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT_LOW_PRIORITY,
|
|
|
|
];
|
|
|
|
return Cc["@mozilla.org/timer-manager;1"]
|
|
|
|
.getService(Ci.nsITimerManager)
|
|
|
|
.getTimers()
|
|
|
|
.filter(t => !kNonRepeatingTimerTypes.includes(t.type));
|
|
|
|
},
|
|
|
|
|
2018-06-06 00:21:53 +03:00
|
|
|
async waitForWindowsReady() {
|
2019-04-02 01:37:12 +03:00
|
|
|
await this.setupDefaultTheme();
|
2018-06-06 00:21:53 +03:00
|
|
|
await new Promise(resolve =>
|
|
|
|
this.waitForGraphicsTestWindowToBeGone(resolve)
|
|
|
|
);
|
|
|
|
await this.promiseMainWindowReady();
|
|
|
|
},
|
|
|
|
|
|
|
|
async promiseMainWindowReady() {
|
2019-05-24 14:58:43 +03:00
|
|
|
if (window.gBrowserInit) {
|
|
|
|
await window.gBrowserInit.idleTasksFinishedPromise;
|
2018-06-06 00:21:53 +03:00
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
},
|
|
|
|
|
2019-04-02 01:37:12 +03:00
|
|
|
async setupDefaultTheme() {
|
|
|
|
// Developer Edition enables the wrong theme by default. Make sure
|
|
|
|
// the ordinary default theme is enabled.
|
|
|
|
let theme = await AddonManager.getAddonByID("default-theme@mozilla.org");
|
|
|
|
await theme.enable();
|
|
|
|
},
|
|
|
|
|
2015-12-30 16:50:51 +03:00
|
|
|
waitForGraphicsTestWindowToBeGone(aCallback) {
|
2018-08-19 04:13:14 +03:00
|
|
|
for (let win of Services.wm.getEnumerator(null)) {
|
2015-12-30 16:50:51 +03:00
|
|
|
if (
|
|
|
|
win != window &&
|
|
|
|
!win.closed &&
|
|
|
|
win.document.documentURI ==
|
|
|
|
"chrome://gfxsanity/content/sanityparent.html"
|
|
|
|
) {
|
|
|
|
this.BrowserTestUtils.domWindowClosed(win).then(aCallback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// graphics test window is already gone, just call callback immediately
|
|
|
|
aCallback();
|
|
|
|
},
|
|
|
|
|
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;
|
2015-12-30 16:50:51 +03:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
2010-07-16 00:38:03 +04:00
|
|
|
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}";
|
|
|
|
|
2014-05-07 17:08:05 +04:00
|
|
|
// Remove stale tabs
|
2020-08-11 18:43:56 +03:00
|
|
|
if (
|
|
|
|
this.currentTest &&
|
|
|
|
window.gBrowser &&
|
|
|
|
AppConstants.MOZ_APP_NAME != "thunderbird" &&
|
|
|
|
gBrowser.tabs.length > 1
|
|
|
|
) {
|
2022-09-14 18:47:15 +03:00
|
|
|
let lastURI = "";
|
|
|
|
let lastURIcount = 0;
|
2010-06-22 22:28:32 +04:00
|
|
|
while (gBrowser.tabs.length > 1) {
|
2019-06-12 00:49:46 +03:00
|
|
|
let lastTab = gBrowser.tabs[gBrowser.tabs.length - 1];
|
2018-03-19 05:12:13 +03:00
|
|
|
if (!lastTab.closing) {
|
|
|
|
// Report the stale tab as an error only when they're not closing.
|
|
|
|
// Tests can finish without waiting for the closing tabs.
|
2022-09-14 18:47:15 +03:00
|
|
|
if (lastURI != lastTab.linkedBrowser.currentURI.spec) {
|
|
|
|
lastURI = lastTab.linkedBrowser.currentURI.spec;
|
|
|
|
} else {
|
|
|
|
lastURIcount++;
|
|
|
|
if (lastURIcount >= 3) {
|
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
2023-05-20 15:26:53 +03:00
|
|
|
name: "terminating browser early - unable to close tabs; skipping remaining tests in folder",
|
2022-09-14 18:47:15 +03:00
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
this.finish();
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 05:12:13 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
baseMsg.replace("{elt}", "tab") +
|
|
|
|
": " +
|
|
|
|
lastTab.linkedBrowser.currentURI.spec,
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2010-06-22 22:28:32 +04:00
|
|
|
gBrowser.removeTab(lastTab);
|
|
|
|
}
|
2010-06-14 19:53:43 +04:00
|
|
|
}
|
|
|
|
|
2014-05-07 17:08:05 +04:00
|
|
|
// Replace the last tab with a fresh one
|
2020-08-11 18:43:56 +03:00
|
|
|
if (window.gBrowser && AppConstants.MOZ_APP_NAME != "thunderbird") {
|
2018-07-06 23:16:29 +03:00
|
|
|
gBrowser.addTab("about:blank", {
|
|
|
|
skipAnimation: true,
|
2023-05-20 15:26:53 +03:00
|
|
|
triggeringPrincipal:
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal(),
|
2018-07-06 23:16:29 +03:00
|
|
|
});
|
2015-09-24 23:32:09 +03:00
|
|
|
gBrowser.removeTab(gBrowser.selectedTab, { skipPermitUnload: true });
|
2014-05-07 17:08:05 +04:00
|
|
|
gBrowser.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove stale windows
|
2016-01-25 17:55:57 +03:00
|
|
|
this.structuredLogger.info("checking window state");
|
2018-08-19 04:13:14 +03:00
|
|
|
for (let win of Services.wm.getEnumerator(null)) {
|
2019-01-29 00:31:18 +03:00
|
|
|
let type = win.document.documentElement.getAttribute("windowtype");
|
2011-03-29 00:29:09 +04:00
|
|
|
if (
|
|
|
|
win != window &&
|
|
|
|
!win.closed &&
|
2019-01-29 00:31:18 +03:00
|
|
|
win.document.documentElement.getAttribute("id") !=
|
|
|
|
"browserTestHarness" &&
|
|
|
|
type != "devtools:webconsole"
|
|
|
|
) {
|
2011-03-29 00:29:09 +04:00
|
|
|
switch (type) {
|
|
|
|
case "navigator:browser":
|
|
|
|
type = "browser window";
|
|
|
|
break;
|
2018-12-14 00:43:22 +03:00
|
|
|
case "mail:3pane":
|
|
|
|
type = "mail window";
|
|
|
|
break;
|
2011-03-29 00:29:09 +04:00
|
|
|
case null:
|
2015-12-29 18:24:26 +03:00
|
|
|
type =
|
|
|
|
"unknown window with document URI: " +
|
|
|
|
win.document.documentURI +
|
|
|
|
" and title: " +
|
|
|
|
win.document.title;
|
2011-03-29 00:29:09 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
let msg = baseMsg.replace("{elt}", type);
|
2015-12-30 16:50:51 +03:00
|
|
|
if (this.currentTest) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name: msg,
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
2015-12-30 16:50:51 +03:00
|
|
|
} else {
|
|
|
|
this.failuresFromInitialWindowState++;
|
2017-06-21 15:40:19 +03:00
|
|
|
this.structuredLogger.error("browser-test.js | " + msg);
|
2015-12-30 16:50:51 +03:00
|
|
|
}
|
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) {
|
2015-09-23 12:42:19 +03:00
|
|
|
var passCount = this.tests.reduce((a, f) => a + f.passCount, 0);
|
|
|
|
var failCount = this.tests.reduce((a, f) => a + f.failCount, 0);
|
|
|
|
var todoCount = this.tests.reduce((a, f) => a + f.todoCount, 0);
|
2013-05-24 23:03:50 +04:00
|
|
|
|
2015-12-30 16:50:51 +03:00
|
|
|
// Include failures from window state checking prior to running the first test
|
|
|
|
failCount += this.failuresFromInitialWindowState;
|
|
|
|
|
2017-09-15 16:29:44 +03:00
|
|
|
TabDestroyObserver.destroy();
|
|
|
|
Services.console.unregisterListener(this);
|
2017-06-18 10:05:06 +03:00
|
|
|
|
2017-09-15 16:29:44 +03:00
|
|
|
// It's important to terminate the module to avoid crashes on shutdown.
|
|
|
|
this.PromiseTestUtils.uninit();
|
2015-03-05 01:00:24 +03:00
|
|
|
|
2017-09-15 16:29:44 +03:00
|
|
|
// In the main process, we print the ShutdownLeaksCollector message here.
|
|
|
|
let pid = Services.appinfo.processID;
|
|
|
|
dump("Completed ShutdownLeaks collections in process " + pid + "\n");
|
2015-03-05 01:00:24 +03:00
|
|
|
|
2017-09-15 16:29:44 +03:00
|
|
|
this.structuredLogger.info("TEST-START | Shutdown");
|
2014-04-18 00:23:23 +04:00
|
|
|
|
2017-09-15 16:29:44 +03:00
|
|
|
if (this.tests.length) {
|
2018-12-14 00:43:22 +03:00
|
|
|
let e10sMode = window.gMultiProcessBrowser ? "e10s" : "non-e10s";
|
2017-09-15 16:29:44 +03:00
|
|
|
this.structuredLogger.info("Browser Chrome Test Summary");
|
|
|
|
this.structuredLogger.info("Passed: " + passCount);
|
|
|
|
this.structuredLogger.info("Failed: " + failCount);
|
|
|
|
this.structuredLogger.info("Todo: " + todoCount);
|
|
|
|
this.structuredLogger.info("Mode: " + e10sMode);
|
|
|
|
} else {
|
|
|
|
this.structuredLogger.error(
|
|
|
|
"browser-test.js | No tests to run. Did you pass invalid test_paths?"
|
|
|
|
);
|
2012-08-03 14:36:59 +04:00
|
|
|
}
|
2017-09-15 16:29:44 +03:00
|
|
|
this.structuredLogger.info("*** End BrowserChrome Test Results ***");
|
|
|
|
|
|
|
|
// Tests complete, notify the callback and return
|
|
|
|
this.callback(this.tests);
|
2021-01-15 21:20:37 +03:00
|
|
|
this.accService = null;
|
2017-09-15 16:29:44 +03:00
|
|
|
this.callback = null;
|
|
|
|
this.tests = null;
|
2012-08-03 14:36:59 +04:00
|
|
|
},
|
|
|
|
|
2013-11-05 19:48:36 +04:00
|
|
|
haltTests: function Tester_haltTests() {
|
|
|
|
// Do not run any further tests
|
|
|
|
this.currentTestIndex = this.tests.length - 1;
|
|
|
|
this.repeat = 0;
|
|
|
|
},
|
|
|
|
|
2016-09-30 07:19:55 +03:00
|
|
|
observe: function Tester_observe(aSubject, aTopic, aData) {
|
|
|
|
if (!aTopic) {
|
|
|
|
this.onConsoleMessage(aSubject);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onConsoleMessage: function Tester_onConsoleMessage(aConsoleMessage) {
|
2012-02-15 00:37:45 +04:00
|
|
|
// Ignore empty messages.
|
|
|
|
if (!aConsoleMessage.message) {
|
|
|
|
return;
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2012-02-15 00:37:45 +04:00
|
|
|
|
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 {
|
2016-01-25 17:55:57 +03:00
|
|
|
this.structuredLogger.info(
|
|
|
|
"TEST-INFO | (browser-test.js) | " + msg.replace(/\n$/, "") + "\n"
|
|
|
|
);
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
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
|
|
|
},
|
|
|
|
|
2022-08-01 19:04:14 +03:00
|
|
|
async ensureVsyncDisabled() {
|
2022-08-01 19:04:15 +03:00
|
|
|
// The WebExtension process keeps vsync enabled forever in headless mode.
|
|
|
|
// See bug 1782541.
|
2022-11-25 22:09:10 +03:00
|
|
|
if (Services.env.get("MOZ_HEADLESS")) {
|
2022-08-01 19:04:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-01 19:04:14 +03:00
|
|
|
try {
|
|
|
|
await this.TestUtils.waitForCondition(
|
|
|
|
() => !ChromeUtils.vsyncEnabled(),
|
|
|
|
"waiting for vsync to be disabled"
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
this.Assert.ok(false, e);
|
|
|
|
this.Assert.ok(
|
|
|
|
false,
|
|
|
|
"vsync remained enabled at the end of the test. " +
|
|
|
|
"Is there an animation still running? " +
|
|
|
|
"Consider talking to the performance team for tips to solve this."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-04-20 12:43:41 +03:00
|
|
|
getNewRepeatingTimers() {
|
|
|
|
let repeatingTimers = this._getRepeatingTimers();
|
|
|
|
let results = [];
|
|
|
|
for (let timer of repeatingTimers) {
|
|
|
|
let { name, delay } = timer;
|
|
|
|
// For now ignore long repeating timers (typically from nsExpirationTracker).
|
|
|
|
if (delay >= 10000) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also ignore the nsAvailableMemoryWatcher timer that is started when the
|
|
|
|
// user-interaction-active notification is fired, and stopped when the
|
|
|
|
// user-interaction-inactive notification occurs.
|
|
|
|
// On Linux it's a 5s timer, on other platforms it's 10s, which is already
|
|
|
|
// ignored by the previous case.
|
|
|
|
if (
|
|
|
|
AppConstants.platform == "linux" &&
|
|
|
|
name == "nsAvailableMemoryWatcher"
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-04-27 01:43:59 +03:00
|
|
|
// Ignore nsHttpConnectionMgr timers which show up on browser mochitests
|
|
|
|
// running with http3. See Bug 1829841.
|
|
|
|
if (name == "nsHttpConnectionMgr") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-04-20 12:43:41 +03:00
|
|
|
if (
|
|
|
|
!this._repeatingTimers.find(t => t.delay == delay && t.name == name)
|
|
|
|
) {
|
|
|
|
results.push(timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (results.length) {
|
|
|
|
ChromeUtils.addProfilerMarker(
|
|
|
|
"NewRepeatingTimers",
|
|
|
|
{ category: "Test" },
|
|
|
|
results.map(t => `${t.name}: ${t.delay}ms`).join(", ")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
},
|
|
|
|
|
|
|
|
async ensureNoNewRepeatingTimers() {
|
|
|
|
let newTimers;
|
|
|
|
try {
|
|
|
|
await this.TestUtils.waitForCondition(
|
2023-05-20 15:26:49 +03:00
|
|
|
async function () {
|
2023-04-20 12:43:41 +03:00
|
|
|
// The array returned by nsITimerManager.getTimers doesn't include
|
|
|
|
// timers that are queued in the event loop of their target thread.
|
|
|
|
// By waiting for a tick, we ensure the timers that might fire about
|
|
|
|
// at the same time as our waitForCondition timer will be included.
|
|
|
|
await this.TestUtils.waitForTick();
|
|
|
|
|
|
|
|
newTimers = this.getNewRepeatingTimers();
|
|
|
|
return !newTimers.length;
|
|
|
|
}.bind(this),
|
|
|
|
"waiting for new repeating timers to be cancelled"
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
this.Assert.ok(false, e);
|
|
|
|
for (let { name, delay } of newTimers) {
|
|
|
|
this.Assert.ok(
|
|
|
|
false,
|
|
|
|
`test left unexpected repeating timer ${name} (duration: ${delay}ms)`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Once the new repeating timers have been reported, add them to
|
|
|
|
// this._repeatingTimers to avoid reporting them again for the next
|
|
|
|
// tests of the manifest.
|
|
|
|
this._repeatingTimers.push(...newTimers);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-18 21:47:45 +03:00
|
|
|
async nextTest() {
|
2009-11-24 00:32:27 +03:00
|
|
|
if (this.currentTest) {
|
2015-12-24 01:04:49 +03:00
|
|
|
if (this._coverageCollector) {
|
|
|
|
this._coverageCollector.recordTestCoverage(this.currentTest.path);
|
|
|
|
}
|
2014-10-04 16:11:00 +04:00
|
|
|
|
2018-06-27 19:56:09 +03:00
|
|
|
this.PerTestCoverageUtils.afterTestSync();
|
|
|
|
|
2009-11-24 00:32:27 +03:00
|
|
|
// Run cleanup functions for the current test before moving on to the
|
|
|
|
// next one.
|
|
|
|
let testScope = this.currentTest.scope;
|
2022-08-26 16:39:38 +03:00
|
|
|
while (testScope.__cleanupFunctions.length) {
|
2009-11-24 00:32:27 +03:00
|
|
|
let func = testScope.__cleanupFunctions.shift();
|
2010-10-30 22:59:18 +04:00
|
|
|
try {
|
2018-04-18 21:47:45 +03:00
|
|
|
let result = await func.apply(testScope);
|
|
|
|
if (isGenerator(result)) {
|
|
|
|
this.SimpleTest.ok(false, "Cleanup function returned a generator");
|
|
|
|
}
|
2010-10-30 22:59:18 +04:00
|
|
|
} catch (ex) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name: "Cleanup function threw an exception",
|
|
|
|
ex,
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
2010-10-30 22:59:18 +04:00
|
|
|
}
|
2014-11-05 19:00:52 +03:00
|
|
|
}
|
|
|
|
|
2020-04-30 21:43:37 +03:00
|
|
|
// Spare tests cleanup work.
|
|
|
|
// Reset gReduceMotionOverride in case the test set it.
|
|
|
|
if (typeof gReduceMotionOverride == "boolean") {
|
|
|
|
gReduceMotionOverride = null;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:25:02 +03:00
|
|
|
Services.obs.notifyObservers(null, "test-complete");
|
|
|
|
|
2014-11-05 19:00:52 +03:00
|
|
|
if (
|
|
|
|
this.currentTest.passCount === 0 &&
|
|
|
|
this.currentTest.failCount === 0 &&
|
|
|
|
this.currentTest.todoCount === 0
|
|
|
|
) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"This test contains no passes, no fails and no todos. Maybe" +
|
|
|
|
" it threw a silent exception? Make sure you use" +
|
|
|
|
" waitForExplicitFinish() if you need it.",
|
|
|
|
})
|
|
|
|
);
|
2014-10-17 18:01:15 +04:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:47:43 +03:00
|
|
|
let winUtils = window.windowUtils;
|
2013-03-16 01:40:37 +04:00
|
|
|
if (winUtils.isTestControllingRefreshes) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name: "test left refresh driver under test control",
|
|
|
|
})
|
|
|
|
);
|
2013-03-16 01:40:37 +04:00
|
|
|
winUtils.restoreNormalRefresh();
|
|
|
|
}
|
|
|
|
|
2011-12-02 16:25:03 +04:00
|
|
|
if (this.SimpleTest.isExpectingUncaughtException()) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"expectUncaughtException was called but no uncaught" +
|
|
|
|
" exception was detected!",
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
2011-12-02 16:25:03 +04:00
|
|
|
}
|
|
|
|
|
2021-04-20 00:56:04 +03:00
|
|
|
this.resolveFinishTestPromise();
|
|
|
|
this.resolveFinishTestPromise = null;
|
|
|
|
this.TestUtils.promiseTestFinished = null;
|
|
|
|
|
2017-06-18 10:05:06 +03:00
|
|
|
this.PromiseTestUtils.ensureDOMPromiseRejectionsProcessed();
|
|
|
|
this.PromiseTestUtils.assertNoUncaughtRejections();
|
|
|
|
this.PromiseTestUtils.assertNoMoreExpectedRejections();
|
2022-08-01 19:04:14 +03:00
|
|
|
await this.ensureVsyncDisabled();
|
2017-06-18 10:05:06 +03:00
|
|
|
|
2023-05-20 15:26:49 +03:00
|
|
|
Object.keys(window).forEach(function (prop) {
|
2013-01-17 21:30:36 +04:00
|
|
|
if (parseInt(prop) == prop) {
|
|
|
|
// This is a string which when parsed as an integer and then
|
|
|
|
// stringified gives the original string. As in, this is in fact a
|
|
|
|
// string representation of an integer, so an index into
|
|
|
|
// window.frames. Skip those.
|
|
|
|
return;
|
|
|
|
}
|
2012-02-03 13:10:52 +04:00
|
|
|
if (!this._globalProperties.includes(prop)) {
|
|
|
|
this._globalProperties.push(prop);
|
2017-05-27 11:12:02 +03:00
|
|
|
if (!this._globalPropertyWhitelist.includes(prop)) {
|
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name: "test left unexpected property on window: " + prop,
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2012-02-03 13:10:52 +04:00
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
2023-04-20 12:43:41 +03:00
|
|
|
await this.ensureNoNewRepeatingTimers();
|
|
|
|
|
2013-07-19 17:51:34 +04:00
|
|
|
// eslint-disable-next-line no-undef
|
2018-04-18 21:47:45 +03:00
|
|
|
await new Promise(resolve => SpecialPowers.flushPrefEnv(resolve));
|
2015-09-17 18:20:32 +03:00
|
|
|
|
2017-04-08 00:46:07 +03:00
|
|
|
if (gConfig.cleanupCrashes) {
|
|
|
|
let gdir = Services.dirsvc.get("UAppData", Ci.nsIFile);
|
|
|
|
gdir.append("Crash Reports");
|
|
|
|
gdir.append("pending");
|
|
|
|
if (gdir.exists()) {
|
|
|
|
let entries = gdir.directoryEntries;
|
|
|
|
while (entries.hasMoreElements()) {
|
2018-05-20 06:17:45 +03:00
|
|
|
let entry = entries.nextFile;
|
2017-04-08 00:46:07 +03:00
|
|
|
if (entry.isFile()) {
|
2017-11-06 18:16:13 +03:00
|
|
|
let msg = "this test left a pending crash report; ";
|
|
|
|
try {
|
|
|
|
entry.remove(false);
|
|
|
|
msg += "deleted " + entry.path;
|
|
|
|
} catch (e) {
|
|
|
|
msg += "could not delete " + entry.path;
|
|
|
|
}
|
2017-04-08 00:46:07 +03:00
|
|
|
this.structuredLogger.info(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-19 17:51:34 +04:00
|
|
|
// Notify a long running test problem if it didn't end up in a timeout.
|
|
|
|
if (this.currentTest.unexpectedTimeouts && !this.currentTest.timedOut) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"This test exceeded the timeout threshold. It should be" +
|
|
|
|
" rewritten or split up. If that's not possible, use" +
|
|
|
|
" requestLongerTimeout(N), but only as a last resort.",
|
|
|
|
})
|
|
|
|
);
|
2013-07-19 17:51:34 +04:00
|
|
|
}
|
|
|
|
|
2013-09-09 14:21:24 +04:00
|
|
|
// If we're in a debug build, check assertion counts. This code
|
|
|
|
// is similar to the code in TestRunner.testUnloaded in
|
|
|
|
// TestRunner.js used for all other types of mochitests.
|
|
|
|
let debugsvc = Cc["@mozilla.org/xpcom/debug;1"].getService(Ci.nsIDebug2);
|
|
|
|
if (debugsvc.isDebugBuild) {
|
|
|
|
let newAssertionCount = debugsvc.assertionCount;
|
|
|
|
let numAsserts = newAssertionCount - this.lastAssertionCount;
|
|
|
|
this.lastAssertionCount = newAssertionCount;
|
|
|
|
|
|
|
|
let max = testScope.__expectedMaxAsserts;
|
|
|
|
let min = testScope.__expectedMinAsserts;
|
|
|
|
if (numAsserts > max) {
|
2017-05-27 11:12:02 +03:00
|
|
|
// TEST-UNEXPECTED-FAIL
|
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"Assertion count " +
|
|
|
|
numAsserts +
|
|
|
|
" is greater than expected range " +
|
|
|
|
min +
|
|
|
|
"-" +
|
|
|
|
max +
|
|
|
|
" assertions.",
|
|
|
|
pass: true, // TEMPORARILY TEST-KNOWN-FAIL
|
|
|
|
todo: true,
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
2013-09-09 14:21:24 +04:00
|
|
|
} else if (numAsserts < min) {
|
|
|
|
// TEST-UNEXPECTED-PASS
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"Assertion count " +
|
|
|
|
numAsserts +
|
|
|
|
" is less than expected range " +
|
|
|
|
min +
|
|
|
|
"-" +
|
|
|
|
max +
|
|
|
|
" assertions.",
|
|
|
|
todo: true,
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
2013-09-09 14:21:24 +04:00
|
|
|
} else if (numAsserts > 0) {
|
|
|
|
// TEST-KNOWN-FAIL
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"Assertion count " +
|
|
|
|
numAsserts +
|
|
|
|
" is within expected range " +
|
|
|
|
min +
|
|
|
|
"-" +
|
|
|
|
max +
|
|
|
|
" assertions.",
|
|
|
|
pass: true,
|
|
|
|
todo: true,
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.currentTest.allowFailure) {
|
|
|
|
if (this.currentTest.expectedAllowedFailureCount) {
|
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"Expected " +
|
|
|
|
this.currentTest.expectedAllowedFailureCount +
|
|
|
|
" failures in this file, got " +
|
|
|
|
this.currentTest.allowedFailureCount +
|
|
|
|
".",
|
|
|
|
pass:
|
|
|
|
this.currentTest.expectedAllowedFailureCount ==
|
|
|
|
this.currentTest.allowedFailureCount,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else if (this.currentTest.allowedFailureCount == 0) {
|
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"We expect at least one assertion to fail because this" +
|
|
|
|
" test file is marked as fail-if in the manifest.",
|
|
|
|
todo: true,
|
2021-02-22 22:38:12 +03:00
|
|
|
knownFailure: this.currentTest.allowFailure,
|
2017-05-27 11:12:02 +03:00
|
|
|
})
|
|
|
|
);
|
2013-09-09 14:21:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 00:08:07 +04:00
|
|
|
// Dump memory stats for main thread.
|
|
|
|
if (
|
|
|
|
Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT
|
|
|
|
) {
|
2015-04-03 18:19:00 +03:00
|
|
|
this.MemoryStats.dump(
|
|
|
|
this.currentTestIndex,
|
2013-11-21 22:03:19 +04:00
|
|
|
this.currentTest.path,
|
|
|
|
gConfig.dumpOutputDirectory,
|
|
|
|
gConfig.dumpAboutMemoryAfterTest,
|
|
|
|
gConfig.dumpDMDAfterTest
|
|
|
|
);
|
2013-11-21 00:08:07 +04:00
|
|
|
}
|
|
|
|
|
2010-08-24 02:44:07 +04:00
|
|
|
// Note the test run time
|
2020-05-05 20:25:53 +03:00
|
|
|
let name = this.currentTest.path;
|
|
|
|
name = name.slice(name.lastIndexOf("/") + 1);
|
|
|
|
ChromeUtils.addProfilerMarker(
|
|
|
|
"browser-test",
|
2021-01-21 00:04:00 +03:00
|
|
|
{ category: "Test", startTime: this.lastStartTimestamp },
|
2020-05-05 20:25:53 +03:00
|
|
|
name
|
|
|
|
);
|
2021-12-09 21:42:48 +03:00
|
|
|
|
|
|
|
// See if we should upload a profile of a failing test.
|
|
|
|
if (this.currentTest.failCount) {
|
|
|
|
// If MOZ_PROFILER_SHUTDOWN is set, the profiler got started from --profiler
|
|
|
|
// and a profile will be shown even if there's no test failure.
|
|
|
|
if (
|
2022-11-25 22:09:10 +03:00
|
|
|
Services.env.exists("MOZ_UPLOAD_DIR") &&
|
|
|
|
!Services.env.exists("MOZ_PROFILER_SHUTDOWN") &&
|
2021-12-09 21:42:48 +03:00
|
|
|
Services.profiler.IsActive()
|
|
|
|
) {
|
|
|
|
let filename = `profile_${name}.json`;
|
2022-11-25 22:09:10 +03:00
|
|
|
let path = Services.env.get("MOZ_UPLOAD_DIR");
|
2021-12-09 21:42:48 +03:00
|
|
|
let profilePath = PathUtils.join(path, filename);
|
|
|
|
try {
|
2023-05-20 15:26:53 +03:00
|
|
|
const { profile } =
|
|
|
|
await Services.profiler.getProfileDataAsGzippedArrayBuffer();
|
2023-03-15 21:19:31 +03:00
|
|
|
await IOUtils.write(profilePath, new Uint8Array(profile));
|
2021-12-09 21:42:48 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"Found unexpected failures during the test; profile uploaded in " +
|
|
|
|
filename,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
// If the profile is large, we may encounter out of memory errors.
|
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name:
|
|
|
|
"Found unexpected failures during the test; failed to upload profile: " +
|
|
|
|
e,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-24 02:44:07 +04:00
|
|
|
let time = Date.now() - this.lastStartTime;
|
2021-07-26 19:47:45 +03:00
|
|
|
|
2016-01-25 17:55:57 +03:00
|
|
|
this.structuredLogger.testEnd(
|
|
|
|
this.currentTest.path,
|
2014-07-17 11:02:00 +04:00
|
|
|
"OK",
|
|
|
|
undefined,
|
|
|
|
"finished in " + time + "ms"
|
|
|
|
);
|
2010-10-19 23:20:49 +04:00
|
|
|
this.currentTest.setDuration(time);
|
2011-06-10 11:00:45 +04:00
|
|
|
|
2013-11-05 19:48:36 +04:00
|
|
|
if (this.runUntilFailure && this.currentTest.failCount > 0) {
|
|
|
|
this.haltTests();
|
|
|
|
}
|
|
|
|
|
2014-04-11 19:57:59 +04:00
|
|
|
// Restore original SimpleTest methods to avoid leaks.
|
|
|
|
SIMPLETEST_OVERRIDES.forEach(m => {
|
|
|
|
this.SimpleTest[m] = this.SimpleTestOriginal[m];
|
|
|
|
});
|
|
|
|
|
2015-10-29 02:50:12 +03:00
|
|
|
this.ContentTask.setTestScope(null);
|
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(() => {
|
|
|
|
if (this.done) {
|
2015-12-24 01:04:49 +03:00
|
|
|
if (this._coverageCollector) {
|
|
|
|
this._coverageCollector.finalize();
|
2020-05-07 20:34:30 +03:00
|
|
|
} else if (
|
|
|
|
!AppConstants.RELEASE_OR_BETA &&
|
|
|
|
!AppConstants.DEBUG &&
|
|
|
|
!AppConstants.MOZ_CODE_COVERAGE &&
|
|
|
|
!AppConstants.ASAN &&
|
|
|
|
!AppConstants.TSAN
|
|
|
|
) {
|
|
|
|
this.finish();
|
|
|
|
return;
|
2015-12-24 01:04:49 +03:00
|
|
|
}
|
2014-08-21 13:18:54 +04:00
|
|
|
|
2013-11-21 00:53:08 +04:00
|
|
|
// Uninitialize a few things explicitly so that they can clean up
|
|
|
|
// frames and browser intentionally kept alive until shutdown to
|
|
|
|
// eliminate false positives.
|
|
|
|
if (gConfig.testRoot == "browser") {
|
2015-04-07 11:09:49 +03:00
|
|
|
// Skip if SeaMonkey
|
|
|
|
if (AppConstants.MOZ_APP_NAME != "seamonkey") {
|
|
|
|
// Replace the document currently loaded in the browser's sidebar.
|
|
|
|
// This will prevent false positives for tests that were the last
|
|
|
|
// to touch the sidebar. They will thus not be blamed for leaking
|
|
|
|
// a document.
|
|
|
|
let sidebar = document.getElementById("sidebar");
|
2018-12-14 00:43:22 +03:00
|
|
|
if (sidebar) {
|
|
|
|
sidebar.setAttribute("src", "data:text/html;charset=utf-8,");
|
2019-06-12 12:07:33 +03:00
|
|
|
sidebar.docShell.createAboutBlankContentViewer(null, null);
|
2018-12-14 00:43:22 +03:00
|
|
|
sidebar.setAttribute("src", "about:blank");
|
|
|
|
}
|
2015-04-07 11:09:49 +03:00
|
|
|
}
|
2013-11-21 00:53:08 +04:00
|
|
|
|
|
|
|
// Destroy BackgroundPageThumbs resources.
|
2023-05-10 23:00:58 +03:00
|
|
|
let { BackgroundPageThumbs } = ChromeUtils.importESModule(
|
|
|
|
"resource://gre/modules/BackgroundPageThumbs.sys.mjs"
|
2019-01-17 21:18:31 +03:00
|
|
|
);
|
2013-11-21 00:53:08 +04:00
|
|
|
BackgroundPageThumbs._destroy();
|
|
|
|
|
2018-12-14 00:43:22 +03:00
|
|
|
if (window.gBrowser) {
|
2019-03-19 20:29:14 +03:00
|
|
|
NewTabPagePreloading.removePreloadedBrowser(window);
|
2018-12-14 00:43:22 +03:00
|
|
|
}
|
2013-11-21 00:53:08 +04:00
|
|
|
}
|
|
|
|
|
2011-07-25 14:11:31 +04:00
|
|
|
// Schedule GC and CC runs before finishing in order to detect
|
2014-02-11 14:07:24 +04:00
|
|
|
// DOM windows leaked by our tests or the tested code. Note that we
|
|
|
|
// use a shrinking GC so that the JS engine will discard JIT code and
|
|
|
|
// JIT caches more aggressively.
|
2012-08-03 14:36:59 +04:00
|
|
|
|
2016-09-27 23:06:37 +03:00
|
|
|
let shutdownCleanup = aCallback => {
|
2014-02-11 14:07:24 +04:00
|
|
|
Cu.schedulePreciseShrinkingGC(() => {
|
2016-09-27 23:06:37 +03:00
|
|
|
// Run the GC and CC a few times to make sure that as much
|
|
|
|
// as possible is freed.
|
|
|
|
let numCycles = 3;
|
2016-10-10 21:18:51 +03:00
|
|
|
for (let i = 0; i < numCycles; i++) {
|
2016-09-27 23:06:37 +03:00
|
|
|
Cu.forceGC();
|
|
|
|
Cu.forceCC();
|
|
|
|
}
|
|
|
|
aCallback();
|
2013-04-24 22:05:17 +04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-12-23 15:37:06 +03:00
|
|
|
let { AsyncShutdown } = ChromeUtils.importESModule(
|
|
|
|
"resource://gre/modules/AsyncShutdown.sys.mjs"
|
2019-01-17 21:18:31 +03:00
|
|
|
);
|
2014-08-31 14:13:08 +04:00
|
|
|
|
|
|
|
let barrier = new AsyncShutdown.Barrier(
|
|
|
|
"ShutdownLeaks: Wait for cleanup to be finished before checking for leaks"
|
|
|
|
);
|
|
|
|
Services.obs.notifyObservers(
|
|
|
|
{ wrappedJSObject: barrier },
|
2017-04-15 00:39:17 +03:00
|
|
|
"shutdown-leaks-before-check"
|
|
|
|
);
|
2019-07-05 12:01:24 +03:00
|
|
|
|
2015-02-27 08:35:26 +03:00
|
|
|
barrier.client.addBlocker(
|
|
|
|
"ShutdownLeaks: Wait for tabs to finish closing",
|
|
|
|
TabDestroyObserver.wait()
|
|
|
|
);
|
|
|
|
|
2014-08-31 14:13:08 +04:00
|
|
|
barrier.wait().then(() => {
|
|
|
|
// Simulate memory pressure so that we're forced to free more resources
|
|
|
|
// and thus get rid of more false leaks like already terminated workers.
|
|
|
|
Services.obs.notifyObservers(
|
|
|
|
null,
|
|
|
|
"memory-pressure",
|
|
|
|
"heap-minimize"
|
|
|
|
);
|
|
|
|
|
2016-09-20 03:18:07 +03:00
|
|
|
Services.ppmm.broadcastAsyncMessage("browser-test:collect-request");
|
2015-02-25 00:00:54 +03:00
|
|
|
|
2016-09-27 23:06:37 +03:00
|
|
|
shutdownCleanup(() => {
|
2014-08-21 13:18:54 +04:00
|
|
|
setTimeout(() => {
|
2016-09-27 23:06:37 +03:00
|
|
|
shutdownCleanup(() => {
|
2014-08-21 13:18:54 +04:00
|
|
|
this.finish();
|
|
|
|
});
|
|
|
|
}, 1000);
|
|
|
|
});
|
2013-04-24 22:05:17 +04:00
|
|
|
});
|
|
|
|
|
2011-06-10 11:00:45 +04:00
|
|
|
return;
|
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2017-09-15 16:29:44 +03:00
|
|
|
if (this.repeat > 0) {
|
|
|
|
--this.repeat;
|
|
|
|
if (this.currentTestIndex < 0) {
|
|
|
|
this.currentTestIndex = 0;
|
|
|
|
}
|
|
|
|
this.execTest();
|
|
|
|
} else {
|
|
|
|
this.currentTestIndex++;
|
|
|
|
if (gConfig.repeat) {
|
|
|
|
this.repeat = gConfig.repeat;
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2017-09-15 16:29:44 +03:00
|
|
|
this.execTest();
|
|
|
|
}
|
2011-06-10 11:00:45 +04:00
|
|
|
});
|
2018-04-18 21:47:45 +03:00
|
|
|
},
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2022-02-04 19:35:58 +03:00
|
|
|
async handleTask(task, currentTest, PromiseTestUtils, isSetup = false) {
|
|
|
|
let currentScope = currentTest.scope;
|
|
|
|
let desc = isSetup ? "setup" : "test";
|
|
|
|
currentScope.SimpleTest.info(`Entering ${desc} ${task.name}`);
|
|
|
|
let startTimestamp = performance.now();
|
|
|
|
try {
|
|
|
|
let result = await task();
|
|
|
|
if (isGenerator(result)) {
|
|
|
|
currentScope.SimpleTest.ok(false, "Task returned a generator");
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
if (currentTest.timedOut) {
|
|
|
|
currentTest.addResult(
|
|
|
|
new testResult({
|
2023-02-08 17:44:37 +03:00
|
|
|
name: `Uncaught exception received from previously timed out ${desc} ${task.name}`,
|
2022-02-04 19:35:58 +03:00
|
|
|
pass: false,
|
|
|
|
ex,
|
|
|
|
stack: typeof ex == "object" && "stack" in ex ? ex.stack : null,
|
|
|
|
allowFailure: currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
// We timed out, so we've already cleaned up for this test, just get outta here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentTest.addResult(
|
|
|
|
new testResult({
|
2023-02-08 17:44:37 +03:00
|
|
|
name: `Uncaught exception in ${desc} ${task.name}`,
|
2022-02-04 19:35:58 +03:00
|
|
|
pass: currentScope.SimpleTest.isExpectingUncaughtException(),
|
|
|
|
ex,
|
|
|
|
stack: typeof ex == "object" && "stack" in ex ? ex.stack : null,
|
|
|
|
allowFailure: currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
PromiseTestUtils.assertNoUncaughtRejections();
|
|
|
|
ChromeUtils.addProfilerMarker(
|
|
|
|
isSetup ? "setup-task" : "task",
|
|
|
|
{ category: "Test", startTime: startTimestamp },
|
|
|
|
task.name.replace(/^bound /, "") || undefined
|
|
|
|
);
|
|
|
|
currentScope.SimpleTest.info(`Leaving ${desc} ${task.name}`);
|
|
|
|
},
|
|
|
|
|
|
|
|
async _runTaskBasedTest(currentTest) {
|
|
|
|
let currentScope = currentTest.scope;
|
|
|
|
|
|
|
|
// First run all the setups:
|
|
|
|
let setupFn;
|
|
|
|
while ((setupFn = currentScope.__setups.shift())) {
|
|
|
|
await this.handleTask(
|
|
|
|
setupFn,
|
|
|
|
currentTest,
|
|
|
|
this.PromiseTestUtils,
|
|
|
|
true /* is setup task */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow for a task to be skipped; we need only use the structured logger
|
|
|
|
// for this, whilst deactivating log buffering to ensure that messages
|
|
|
|
// are always printed to stdout.
|
|
|
|
let skipTask = task => {
|
|
|
|
let logger = this.structuredLogger;
|
|
|
|
logger.deactivateBuffering();
|
|
|
|
logger.testStatus(this.currentTest.path, task.name, "SKIP");
|
|
|
|
logger.warning("Skipping test " + task.name);
|
|
|
|
logger.activateBuffering();
|
|
|
|
};
|
|
|
|
|
|
|
|
let task;
|
|
|
|
while ((task = currentScope.__tasks.shift())) {
|
|
|
|
if (
|
|
|
|
task.__skipMe ||
|
|
|
|
(currentScope.__runOnlyThisTask &&
|
|
|
|
task != currentScope.__runOnlyThisTask)
|
|
|
|
) {
|
|
|
|
skipTask(task);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
await this.handleTask(task, currentTest, this.PromiseTestUtils);
|
|
|
|
}
|
|
|
|
currentScope.finish();
|
|
|
|
},
|
|
|
|
|
2010-01-21 15:05:27 +03:00
|
|
|
execTest: function Tester_execTest() {
|
2016-01-25 17:55:57 +03:00
|
|
|
this.structuredLogger.testStart(this.currentTest.path);
|
2009-06-11 21:47:37 +04:00
|
|
|
|
2011-12-02 16:25:03 +04:00
|
|
|
this.SimpleTest.reset();
|
2021-01-15 21:20:37 +03:00
|
|
|
// Reset accessibility environment.
|
|
|
|
this.AccessibilityUtils.reset(this.a11y_checks);
|
2011-12-02 16:25:03 +04:00
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
// Load the tests into a testscope
|
2014-10-17 18:01:15 +04:00
|
|
|
let currentScope = (this.currentTest.scope = new testScope(
|
|
|
|
this,
|
|
|
|
this.currentTest,
|
|
|
|
this.currentTest.expected
|
|
|
|
));
|
2013-11-21 14:26:33 +04:00
|
|
|
let currentTest = this.currentTest;
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2021-07-26 19:47:45 +03:00
|
|
|
// HTTPS-First (Bug 1704453) TODO: in case a test is annoated
|
|
|
|
// with https_first_disabled then we explicitly flip the pref
|
|
|
|
// dom.security.https_first to false for the duration of the test.
|
|
|
|
if (currentTest.https_first_disabled) {
|
|
|
|
window.SpecialPowers.pushPrefEnv({
|
|
|
|
set: [["dom.security.https_first", false]],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-09 22:01:01 +03:00
|
|
|
if (currentTest.allow_xul_xbl) {
|
|
|
|
window.SpecialPowers.pushPermissions([
|
|
|
|
{ type: "allowXULXBL", allow: true, context: "http://mochi.test:8888" },
|
|
|
|
{ type: "allowXULXBL", allow: true, context: "http://example.org" },
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2009-09-22 13:16:03 +04:00
|
|
|
// Import utils in the test scope.
|
2018-03-14 05:11:10 +03:00
|
|
|
let { scope } = this.currentTest;
|
2020-04-13 21:05:00 +03:00
|
|
|
scope.EventUtils = this.EventUtils;
|
2021-01-15 21:20:37 +03:00
|
|
|
scope.AccessibilityUtils = this.AccessibilityUtils;
|
2018-03-14 05:11:10 +03:00
|
|
|
scope.SimpleTest = this.SimpleTest;
|
|
|
|
scope.gTestPath = this.currentTest.path;
|
|
|
|
scope.ContentTask = this.ContentTask;
|
|
|
|
scope.BrowserTestUtils = this.BrowserTestUtils;
|
|
|
|
scope.TestUtils = this.TestUtils;
|
|
|
|
scope.ExtensionTestUtils = this.ExtensionTestUtils;
|
2013-11-21 14:26:33 +04:00
|
|
|
// Pass a custom report function for mochitest style reporting.
|
2023-05-20 15:26:49 +03:00
|
|
|
scope.Assert = new this.Assert(function (err, message, stack) {
|
2017-05-27 11:12:02 +03:00
|
|
|
currentTest.addResult(
|
|
|
|
new testResult(
|
|
|
|
err
|
|
|
|
? {
|
|
|
|
name: err.message,
|
|
|
|
ex: err.stack,
|
|
|
|
stack: err.stack,
|
|
|
|
allowFailure: currentTest.allowFailure,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
name: message,
|
|
|
|
pass: true,
|
|
|
|
stack,
|
|
|
|
allowFailure: currentTest.allowFailure,
|
|
|
|
}
|
2019-07-05 12:01:24 +03:00
|
|
|
)
|
2017-05-27 11:12:02 +03:00
|
|
|
);
|
2017-10-27 16:38:30 +03:00
|
|
|
}, true);
|
2013-11-21 14:26:33 +04:00
|
|
|
|
2015-10-29 02:50:12 +03:00
|
|
|
this.ContentTask.setTestScope(currentScope);
|
|
|
|
|
2022-11-17 15:00:28 +03:00
|
|
|
// Allow Assert.sys.mjs methods to be tacked to the current scope.
|
2023-05-20 15:26:49 +03:00
|
|
|
scope.export_assertions = function () {
|
2013-11-21 14:26:33 +04:00
|
|
|
for (let func in this.Assert) {
|
|
|
|
this[func] = this.Assert[func].bind(this.Assert);
|
|
|
|
}
|
|
|
|
};
|
2010-09-10 21:20:38 +04:00
|
|
|
|
2010-03-18 23:11:20 +03:00
|
|
|
// Override SimpleTest methods with ours.
|
2023-05-20 15:26:49 +03:00
|
|
|
SIMPLETEST_OVERRIDES.forEach(function (m) {
|
2010-03-18 23:11:20 +03:00
|
|
|
this.SimpleTest[m] = this[m];
|
2018-03-14 05:11:10 +03:00
|
|
|
}, 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 {
|
2018-03-14 05:11:10 +03:00
|
|
|
this._scriptLoader.loadSubScript(
|
|
|
|
"chrome://mochikit/content/chrome-harness.js",
|
|
|
|
scope
|
|
|
|
);
|
2010-09-10 21:20:38 +04:00
|
|
|
} catch (ex) {
|
|
|
|
/* no chrome-harness tools */
|
|
|
|
}
|
|
|
|
|
2023-01-16 17:55:22 +03:00
|
|
|
// Ensure we are not idle at the beginning of the test. If we don't do this,
|
|
|
|
// the browser may behave differently if the previous tests ran long.
|
|
|
|
// eg. the session store behavior changes 3 minutes after the last user event.
|
|
|
|
Cc["@mozilla.org/widget/useridleservice;1"]
|
|
|
|
.getService(Ci.nsIUserIdleServiceInternal)
|
|
|
|
.resetIdleTimeOut(0);
|
|
|
|
|
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 {
|
2018-03-14 05:11:10 +03:00
|
|
|
this._scriptLoader.loadSubScript(headPath, scope);
|
2012-06-15 06:08:17 +04:00
|
|
|
} catch (ex) {
|
2018-10-31 06:11:28 +03:00
|
|
|
// Bug 755558 - Ignore loadSubScript errors due to a missing head.js.
|
|
|
|
const isImportError = /^Error opening input stream/.test(ex.toString());
|
|
|
|
|
|
|
|
// Bug 1503169 - head.js may call loadSubScript, and generate similar errors.
|
|
|
|
// Only swallow errors that are strictly related to loading head.js.
|
|
|
|
const containsHeadPath = ex.toString().includes(headPath);
|
|
|
|
|
|
|
|
if (!isImportError || !containsHeadPath) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name: "head.js import threw an exception",
|
|
|
|
ex,
|
|
|
|
})
|
|
|
|
);
|
2012-06-15 06:08:17 +04:00
|
|
|
}
|
|
|
|
}
|
2009-11-24 00:32:27 +03:00
|
|
|
|
|
|
|
// Import the test script.
|
2007-07-09 20:24:15 +04:00
|
|
|
try {
|
2020-05-05 20:25:53 +03:00
|
|
|
this.lastStartTimestamp = performance.now();
|
2021-04-20 00:56:04 +03:00
|
|
|
this.TestUtils.promiseTestFinished = new Promise(resolve => {
|
|
|
|
this.resolveFinishTestPromise = resolve;
|
|
|
|
});
|
2018-03-14 05:11:10 +03:00
|
|
|
this._scriptLoader.loadSubScript(this.currentTest.path, scope);
|
2007-07-16 04:21:11 +04:00
|
|
|
// Run the test
|
2010-08-10 00:54:23 +04:00
|
|
|
this.lastStartTime = Date.now();
|
2013-06-04 17:35:43 +04:00
|
|
|
if (this.currentTest.scope.__tasks) {
|
|
|
|
// This test consists of tasks, added via the `add_task()` API.
|
|
|
|
if ("test" in this.currentTest.scope) {
|
2019-04-02 16:44:16 +03:00
|
|
|
throw new Error(
|
|
|
|
"Cannot run both a add_task test and a normal test at the same time."
|
|
|
|
);
|
2013-06-04 17:35:43 +04:00
|
|
|
}
|
2022-02-04 19:35:58 +03:00
|
|
|
// Spin off the async work without waiting for it to complete.
|
|
|
|
// It'll call finish() when it's done.
|
|
|
|
this._runTaskBasedTest(this.currentTest);
|
2018-03-14 05:11:10 +03:00
|
|
|
} else if (typeof scope.test == "function") {
|
|
|
|
scope.test();
|
2015-06-11 11:15:00 +03:00
|
|
|
} else {
|
2019-04-02 16:44:16 +03:00
|
|
|
throw new Error(
|
|
|
|
"This test didn't call add_task, nor did it define a generatorTest() function, nor did it define a test() function, so we don't know how to run it."
|
|
|
|
);
|
2011-03-30 03:41:29 +04:00
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
} catch (ex) {
|
2011-12-02 16:25:03 +04:00
|
|
|
if (!this.SimpleTest.isIgnoringAllUncaughtExceptions()) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.currentTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name: "Exception thrown",
|
|
|
|
pass: this.SimpleTest.isExpectingUncaughtException(),
|
|
|
|
ex,
|
|
|
|
allowFailure: this.currentTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
2011-12-02 16:25:03 +04:00
|
|
|
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;
|
2014-09-30 00:05:23 +04:00
|
|
|
var timeoutExpires = Date.now() + gTimeoutSeconds * 1000;
|
|
|
|
var waitUntilAtLeast = timeoutExpires - 1000;
|
2023-05-20 15:26:53 +03:00
|
|
|
this.currentTest.scope.__waitTimer =
|
|
|
|
this.SimpleTest._originalSetTimeout.apply(window, [
|
2015-01-06 23:03:35 +03:00
|
|
|
function timeoutFn() {
|
2014-09-30 00:05:23 +04:00
|
|
|
// We sometimes get woken up long before the gTimeoutSeconds
|
|
|
|
// have elapsed (when running in chaos mode for example). This
|
|
|
|
// code ensures that we don't wrongly time out in that case.
|
|
|
|
if (Date.now() < waitUntilAtLeast) {
|
|
|
|
self.currentTest.scope.__waitTimer = setTimeout(
|
|
|
|
timeoutFn,
|
|
|
|
timeoutExpires - Date.now()
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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(
|
2013-07-19 17:51:34 +04:00
|
|
|
timeoutFn,
|
|
|
|
gTimeoutSeconds * 1000
|
|
|
|
);
|
2009-12-04 17:13:22 +03:00
|
|
|
return;
|
|
|
|
}
|
2013-07-19 17:51:34 +04:00
|
|
|
|
|
|
|
// If the test is taking longer than expected, but it's not hanging,
|
|
|
|
// mark the fact, but let the test continue. At the end of the test,
|
|
|
|
// if it didn't timeout, we will notify the problem through an error.
|
|
|
|
// To figure whether it's an actual hang, compare the time of the last
|
|
|
|
// result or message to half of the timeout time.
|
|
|
|
// Though, to protect against infinite loops, limit the number of times
|
|
|
|
// we allow the test to proceed.
|
|
|
|
const MAX_UNEXPECTED_TIMEOUTS = 10;
|
|
|
|
if (
|
|
|
|
Date.now() - self.currentTest.lastOutputTime <
|
|
|
|
(gTimeoutSeconds / 2) * 1000 &&
|
|
|
|
++self.currentTest.unexpectedTimeouts <= MAX_UNEXPECTED_TIMEOUTS
|
|
|
|
) {
|
|
|
|
self.currentTest.scope.__waitTimer = setTimeout(
|
|
|
|
timeoutFn,
|
|
|
|
gTimeoutSeconds * 1000
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-22 22:38:12 +03:00
|
|
|
let knownFailure = false;
|
|
|
|
if (gConfig.timeoutAsPass) {
|
|
|
|
knownFailure = true;
|
|
|
|
}
|
2017-05-27 11:12:02 +03:00
|
|
|
self.currentTest.addResult(
|
2021-02-22 22:38:12 +03:00
|
|
|
new testResult({
|
|
|
|
name: "Test timed out",
|
|
|
|
allowFailure: knownFailure,
|
|
|
|
})
|
2017-05-27 11:12:02 +03:00
|
|
|
);
|
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();
|
2015-01-06 23:03:35 +03:00
|
|
|
},
|
|
|
|
gTimeoutSeconds * 1000,
|
2023-05-20 15:26:53 +03:00
|
|
|
]);
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
2009-07-03 11:22:31 +04:00
|
|
|
},
|
|
|
|
|
2018-05-09 04:36:22 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"]),
|
2007-07-09 20:24:15 +04:00
|
|
|
};
|
|
|
|
|
2023-03-03 17:53:55 +03:00
|
|
|
// Note: duplicated in SimpleTest.js . See also bug 1820150.
|
2023-04-12 15:40:07 +03:00
|
|
|
function isErrorOrException(err) {
|
2023-02-28 20:04:58 +03:00
|
|
|
// It'd be nice if we had either `Error.isError(err)` or `Error.isInstance(err)`
|
|
|
|
// but we don't, so do it ourselves:
|
|
|
|
if (!err) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-04-12 15:40:07 +03:00
|
|
|
if (err instanceof Ci.nsIException) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-03-03 17:53:55 +03:00
|
|
|
try {
|
|
|
|
let glob = Cu.getGlobalForObject(err);
|
|
|
|
return err instanceof glob.Error;
|
|
|
|
} catch {
|
|
|
|
// getGlobalForObject can be upset if it doesn't get passed an object.
|
|
|
|
// Just do a standard instanceof check using this global and cross fingers:
|
|
|
|
}
|
|
|
|
return err instanceof Error;
|
2023-02-28 20:04:58 +03:00
|
|
|
}
|
|
|
|
|
2017-05-27 11:12:02 +03:00
|
|
|
/**
|
|
|
|
* Represents the result of one test assertion. This is described with a string
|
|
|
|
* in traditional logging, and has a "status" and "expected" property used in
|
|
|
|
* structured logging. Normally, results are mapped as follows:
|
|
|
|
*
|
|
|
|
* pass: todo: Added to: Described as: Status: Expected:
|
|
|
|
* true false passCount TEST-PASS PASS PASS
|
|
|
|
* true true todoCount TEST-KNOWN-FAIL FAIL FAIL
|
|
|
|
* false false failCount TEST-UNEXPECTED-FAIL FAIL PASS
|
|
|
|
* false true failCount TEST-UNEXPECTED-PASS PASS FAIL
|
|
|
|
*
|
|
|
|
* The "allowFailure" argument indicates that this is one of the assertions that
|
|
|
|
* should be allowed to fail, for example because "fail-if" is true for the
|
|
|
|
* current test file in the manifest. In this case, results are mapped this way:
|
|
|
|
*
|
|
|
|
* pass: todo: Added to: Described as: Status: Expected:
|
|
|
|
* true false passCount TEST-PASS PASS PASS
|
|
|
|
* true true todoCount TEST-KNOWN-FAIL FAIL FAIL
|
|
|
|
* false false todoCount TEST-KNOWN-FAIL FAIL FAIL
|
|
|
|
* false true todoCount TEST-KNOWN-FAIL FAIL FAIL
|
|
|
|
*/
|
|
|
|
function testResult({ name, pass, todo, ex, stack, allowFailure }) {
|
|
|
|
this.info = false;
|
|
|
|
this.name = name;
|
2014-08-15 22:42:00 +04:00
|
|
|
this.msg = "";
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2017-05-27 11:12:02 +03:00
|
|
|
if (allowFailure && !pass) {
|
|
|
|
this.allowedFailure = true;
|
|
|
|
this.pass = true;
|
2021-04-01 01:09:29 +03:00
|
|
|
this.todo = false;
|
|
|
|
} else if (allowFailure && pass) {
|
|
|
|
this.pass = true;
|
|
|
|
this.todo = false;
|
2017-05-27 11:12:02 +03:00
|
|
|
} else {
|
|
|
|
this.pass = !!pass;
|
|
|
|
this.todo = todo;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.expected = this.todo ? "FAIL" : "PASS";
|
2009-07-03 11:22:31 +04:00
|
|
|
|
2007-07-12 18:29:33 +04:00
|
|
|
if (this.pass) {
|
2017-05-27 11:12:02 +03:00
|
|
|
this.status = this.expected;
|
|
|
|
return;
|
|
|
|
}
|
2017-05-27 11:12:02 +03:00
|
|
|
|
2017-05-27 11:12:02 +03:00
|
|
|
this.status = this.todo ? "PASS" : "FAIL";
|
|
|
|
|
|
|
|
if (ex) {
|
|
|
|
if (typeof ex == "object" && "fileName" in ex) {
|
|
|
|
// we have an exception - print filename and linenumber information
|
|
|
|
this.msg += "at " + ex.fileName + ":" + ex.lineNumber + " - ";
|
2017-05-28 12:32:16 +03:00
|
|
|
}
|
2023-02-08 17:44:37 +03:00
|
|
|
|
2023-04-12 15:40:07 +03:00
|
|
|
if (
|
|
|
|
typeof ex == "string" ||
|
|
|
|
(typeof ex == "object" && isErrorOrException(ex))
|
|
|
|
) {
|
2023-02-08 17:44:37 +03:00
|
|
|
this.msg += String(ex);
|
|
|
|
} else {
|
2023-02-09 23:12:43 +03:00
|
|
|
try {
|
|
|
|
this.msg += JSON.stringify(ex);
|
|
|
|
} catch {
|
|
|
|
this.msg += String(ex);
|
|
|
|
}
|
2023-02-08 17:44:37 +03:00
|
|
|
}
|
2017-05-27 11:12:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stack) {
|
|
|
|
this.msg += "\nStack trace:\n";
|
|
|
|
let normalized;
|
|
|
|
if (stack instanceof Ci.nsIStackFrame) {
|
|
|
|
let frames = [];
|
2018-05-08 17:10:01 +03:00
|
|
|
for (
|
|
|
|
let frame = stack;
|
|
|
|
frame;
|
|
|
|
frame = frame.asyncCaller || frame.caller
|
|
|
|
) {
|
|
|
|
let msg = `${frame.filename}:${frame.name}:${frame.lineNumber}`;
|
|
|
|
frames.push(frame.asyncCause ? `${frame.asyncCause}*${msg}` : msg);
|
2010-09-22 12:58:42 +04:00
|
|
|
}
|
2017-05-27 11:12:02 +03:00
|
|
|
normalized = frames.join("\n");
|
2014-07-17 11:02:00 +04:00
|
|
|
} else {
|
2017-05-27 11:12:02 +03:00
|
|
|
normalized = "" + stack;
|
2014-07-17 11:02:00 +04:00
|
|
|
}
|
2018-04-20 00:52:47 +03:00
|
|
|
this.msg += normalized;
|
2017-05-27 11:12:02 +03:00
|
|
|
}
|
2013-11-01 23:23:34 +04:00
|
|
|
|
2017-05-27 11:12:02 +03:00
|
|
|
if (gConfig.debugOnFailure) {
|
|
|
|
// You've hit this line because you requested to break into the
|
|
|
|
// debugger upon a testcase failure on your test run.
|
2013-07-19 17:51:34 +04:00
|
|
|
// eslint-disable-next-line no-debugger
|
2017-05-27 11:12:02 +03:00
|
|
|
debugger;
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-27 11:12:02 +03:00
|
|
|
function testMessage(msg) {
|
|
|
|
this.msg = msg || "";
|
2009-07-03 11:22:31 +04:00
|
|
|
this.info = true;
|
|
|
|
}
|
|
|
|
|
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.
|
2014-10-17 18:01:15 +04:00
|
|
|
function testScope(aTester, aTest, expected) {
|
2009-06-11 21:47:37 +04:00
|
|
|
this.__tester = aTester;
|
2014-10-17 18:01:15 +04:00
|
|
|
|
2017-05-27 11:12:02 +03:00
|
|
|
aTest.allowFailure = expected == "fail";
|
2017-05-28 12:32:16 +03:00
|
|
|
|
2017-05-27 11:12:02 +03:00
|
|
|
var self = this;
|
2018-11-01 16:50:27 +03:00
|
|
|
this.ok = function test_ok(condition, name) {
|
|
|
|
if (arguments.length > 2) {
|
|
|
|
const ex = "Too many arguments passed to ok(condition, name)`.";
|
|
|
|
self.record(false, name, ex);
|
|
|
|
} else {
|
|
|
|
self.record(condition, name);
|
|
|
|
}
|
|
|
|
};
|
2019-12-07 21:44:32 +03:00
|
|
|
this.record = function test_record(condition, name, ex, stack, expected) {
|
|
|
|
if (expected == "fail") {
|
|
|
|
aTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name,
|
|
|
|
pass: !condition,
|
|
|
|
todo: true,
|
|
|
|
ex,
|
|
|
|
stack: stack || Components.stack.caller,
|
|
|
|
allowFailure: aTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
aTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name,
|
|
|
|
pass: condition,
|
|
|
|
ex,
|
|
|
|
stack: stack || Components.stack.caller,
|
|
|
|
allowFailure: aTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2008-01-26 00:29:11 +03:00
|
|
|
this.is = function test_is(a, b, name) {
|
2018-11-01 16:50:27 +03:00
|
|
|
self.record(
|
2020-07-30 21:50:26 +03:00
|
|
|
Object.is(a, b),
|
2018-11-01 16:50:27 +03:00
|
|
|
name,
|
2020-07-30 21:50:26 +03:00
|
|
|
`Got ${self.repr(a)}, expected ${self.repr(b)}`,
|
2018-11-01 16:50:27 +03:00
|
|
|
false,
|
2010-09-22 12:58:42 +04:00
|
|
|
Components.stack.caller
|
|
|
|
);
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2021-02-24 04:27:11 +03:00
|
|
|
this.isfuzzy = function test_isfuzzy(a, b, epsilon, name) {
|
|
|
|
self.record(
|
|
|
|
a >= b - epsilon && a <= b + epsilon,
|
|
|
|
name,
|
|
|
|
`Got ${self.repr(a)}, expected ${self.repr(b)} epsilon: +/- ${self.repr(
|
|
|
|
epsilon
|
|
|
|
)}`,
|
|
|
|
false,
|
|
|
|
Components.stack.caller
|
|
|
|
);
|
|
|
|
};
|
2008-01-26 00:29:11 +03:00
|
|
|
this.isnot = function test_isnot(a, b, name) {
|
2018-11-01 16:50:27 +03:00
|
|
|
self.record(
|
2020-07-30 21:50:26 +03:00
|
|
|
!Object.is(a, b),
|
2018-11-01 16:50:27 +03:00
|
|
|
name,
|
2020-07-30 21:50:26 +03:00
|
|
|
`Didn't expect ${self.repr(a)}, but got it`,
|
2018-11-01 16:50:27 +03:00
|
|
|
false,
|
2010-09-22 12:58:42 +04:00
|
|
|
Components.stack.caller
|
|
|
|
);
|
2008-07-16 09:43:15 +04:00
|
|
|
};
|
2017-05-27 11:12:02 +03:00
|
|
|
this.todo = function test_todo(condition, name, ex, stack) {
|
|
|
|
aTest.addResult(
|
|
|
|
new testResult({
|
|
|
|
name,
|
|
|
|
pass: !condition,
|
|
|
|
todo: true,
|
|
|
|
ex,
|
|
|
|
stack: stack || Components.stack.caller,
|
|
|
|
allowFailure: aTest.allowFailure,
|
|
|
|
})
|
|
|
|
);
|
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(
|
2020-07-30 21:50:26 +03:00
|
|
|
Object.is(a, b),
|
2010-09-22 12:58:42 +04:00
|
|
|
name,
|
2020-07-30 21:50:26 +03:00
|
|
|
`Got ${self.repr(a)}, expected ${self.repr(b)}`,
|
2010-09-22 12:58:42 +04:00
|
|
|
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(
|
2020-07-30 21:50:26 +03:00
|
|
|
!Object.is(a, b),
|
2010-09-22 12:58:42 +04:00
|
|
|
name,
|
2020-07-30 21:50:26 +03:00
|
|
|
`Didn't expect ${self.repr(a)}, but got it`,
|
2010-09-22 12:58:42 +04:00
|
|
|
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
|
|
|
};
|
2020-07-30 21:50:26 +03:00
|
|
|
this.repr = function repr(o) {
|
|
|
|
if (typeof o == "undefined") {
|
|
|
|
return "undefined";
|
|
|
|
} else if (o === null) {
|
|
|
|
return "null";
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (typeof o.__repr__ == "function") {
|
|
|
|
return o.__repr__();
|
|
|
|
} else if (typeof o.repr == "function" && o.repr != repr) {
|
|
|
|
return o.repr();
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
try {
|
|
|
|
if (
|
|
|
|
typeof o.NAME == "string" &&
|
|
|
|
(o.toString == Function.prototype.toString ||
|
|
|
|
o.toString == Object.prototype.toString)
|
|
|
|
) {
|
|
|
|
return o.NAME;
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
var ostring;
|
|
|
|
try {
|
|
|
|
if (Object.is(o, +0)) {
|
|
|
|
ostring = "+0";
|
|
|
|
} else if (Object.is(o, -0)) {
|
|
|
|
ostring = "-0";
|
|
|
|
} else if (typeof o === "string") {
|
|
|
|
ostring = JSON.stringify(o);
|
|
|
|
} else if (Array.isArray(o)) {
|
|
|
|
ostring = "[" + o.map(val => repr(val)).join(", ") + "]";
|
|
|
|
} else {
|
|
|
|
ostring = String(o);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
return `[${Object.prototype.toString.call(o)}]`;
|
|
|
|
}
|
|
|
|
if (typeof o == "function") {
|
|
|
|
ostring = ostring.replace(/\) \{[^]*/, ") { ... }");
|
|
|
|
}
|
|
|
|
return ostring;
|
|
|
|
};
|
2008-01-26 02:33:17 +03:00
|
|
|
|
2008-10-30 20:22:17 +03:00
|
|
|
this.executeSoon = function test_executeSoon(func) {
|
2017-04-15 00:39:23 +03:00
|
|
|
Services.tm.dispatchToMainThread({
|
2008-10-30 20:22:17 +03:00
|
|
|
run() {
|
|
|
|
func();
|
|
|
|
},
|
2017-04-15 00:39:23 +03:00
|
|
|
});
|
2008-10-30 20:22:17 +03:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-09-09 14:21:24 +04:00
|
|
|
this.expectAssertions = function test_expectAssertions(aMin, aMax) {
|
|
|
|
let min = aMin;
|
|
|
|
let max = aMax;
|
|
|
|
if (typeof max == "undefined") {
|
|
|
|
max = min;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
typeof min != "number" ||
|
|
|
|
typeof max != "number" ||
|
|
|
|
min < 0 ||
|
|
|
|
max < min
|
|
|
|
) {
|
2019-04-02 16:44:16 +03:00
|
|
|
throw new Error("bad parameter to expectAssertions");
|
2013-09-09 14:21:24 +04:00
|
|
|
}
|
|
|
|
self.__expectedMinAsserts = min;
|
|
|
|
self.__expectedMaxAsserts = max;
|
|
|
|
};
|
|
|
|
|
2023-05-20 15:26:53 +03:00
|
|
|
this.setExpectedFailuresForSelfTest =
|
|
|
|
function test_setExpectedFailuresForSelfTest(expectedAllowedFailureCount) {
|
|
|
|
aTest.allowFailure = true;
|
|
|
|
aTest.expectedAllowedFailureCount = expectedAllowedFailureCount;
|
|
|
|
};
|
2014-10-17 18:01:15 +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) {
|
2023-05-20 15:26:49 +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
|
|
|
};
|
2014-09-03 19:25:18 +04:00
|
|
|
|
|
|
|
this.requestCompleteLog = function test_requestCompleteLog() {
|
2016-01-25 17:55:57 +03:00
|
|
|
self.__tester.structuredLogger.deactivateBuffering();
|
2023-05-20 15:26:49 +03:00
|
|
|
self.registerCleanupFunction(function () {
|
2016-01-25 17:55:57 +03:00
|
|
|
self.__tester.structuredLogger.activateBuffering();
|
2014-09-03 19:25:18 +04:00
|
|
|
});
|
|
|
|
};
|
2018-03-14 05:11:10 +03:00
|
|
|
|
2009-07-03 11:22:31 +04:00
|
|
|
return this;
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
2017-07-18 15:42:16 +03:00
|
|
|
|
|
|
|
function decorateTaskFn(fn) {
|
|
|
|
fn = fn.bind(this);
|
2020-11-21 00:40:14 +03:00
|
|
|
fn.skip = (val = true) => (fn.__skipMe = val);
|
2017-07-18 15:42:16 +03:00
|
|
|
fn.only = () => (this.__runOnlyThisTask = fn);
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
testScope.prototype = {
|
2009-06-11 21:47:37 +04:00
|
|
|
__done: true,
|
2013-06-04 17:35:43 +04:00
|
|
|
__tasks: null,
|
2022-02-04 19:35:58 +03:00
|
|
|
__setups: [],
|
2017-07-18 15:42:16 +03:00
|
|
|
__runOnlyThisTask: 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,
|
2013-09-09 14:21:24 +04:00
|
|
|
__expectedMinAsserts: 0,
|
|
|
|
__expectedMaxAsserts: 0,
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2009-09-22 13:16:03 +04:00
|
|
|
EventUtils: {},
|
2021-01-15 21:20:37 +03:00
|
|
|
AccessibilityUtils: {},
|
2011-06-10 11:00:45 +04:00
|
|
|
SimpleTest: {},
|
2015-02-12 01:28:44 +03:00
|
|
|
ContentTask: null,
|
2015-02-23 07:11:22 +03:00
|
|
|
BrowserTestUtils: null,
|
|
|
|
TestUtils: null,
|
2015-08-28 02:29:08 +03:00
|
|
|
ExtensionTestUtils: null,
|
2013-11-21 14:26:33 +04:00
|
|
|
Assert: null,
|
2013-06-04 17:35:43 +04:00
|
|
|
|
|
|
|
/**
|
2018-04-18 21:47:45 +03:00
|
|
|
* Add a function which returns a promise (usually an async function)
|
|
|
|
* as a test task.
|
2013-06-04 17:35:43 +04:00
|
|
|
*
|
2018-04-18 21:47:45 +03:00
|
|
|
* The task ends when the promise returned by the function resolves or
|
|
|
|
* rejects. If the test function throws, or the promise it returns
|
|
|
|
* rejects, the test is reported as a failure. Execution continues
|
|
|
|
* with the next test function.
|
2013-06-04 17:35:43 +04:00
|
|
|
*
|
|
|
|
* Example usage:
|
|
|
|
*
|
2018-04-18 21:47:45 +03:00
|
|
|
* add_task(async function test() {
|
2020-11-03 22:17:27 +03:00
|
|
|
* let result = await Promise.resolve(true);
|
2013-06-04 17:35:43 +04:00
|
|
|
*
|
|
|
|
* ok(result);
|
|
|
|
*
|
2018-04-18 21:47:45 +03:00
|
|
|
* let secondary = await someFunctionThatReturnsAPromise(result);
|
2013-06-04 17:35:43 +04:00
|
|
|
* is(secondary, "expected value");
|
|
|
|
* });
|
|
|
|
*
|
2018-04-18 21:47:45 +03:00
|
|
|
* add_task(async function test_early_return() {
|
|
|
|
* let result = await somethingThatReturnsAPromise();
|
2013-06-04 17:35:43 +04:00
|
|
|
*
|
|
|
|
* if (!result) {
|
|
|
|
* // Test is ended immediately, with success.
|
|
|
|
* return;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* is(result, "foo");
|
|
|
|
* });
|
|
|
|
*/
|
|
|
|
add_task(aFunction) {
|
|
|
|
if (!this.__tasks) {
|
|
|
|
this.waitForExplicitFinish();
|
|
|
|
this.__tasks = [];
|
|
|
|
}
|
2017-07-18 15:42:16 +03:00
|
|
|
let bound = decorateTaskFn.call(this, aFunction);
|
|
|
|
this.__tasks.push(bound);
|
|
|
|
return bound;
|
2013-06-04 17:35:43 +04:00
|
|
|
},
|
2011-06-10 11:00:45 +04:00
|
|
|
|
2022-02-04 19:35:58 +03:00
|
|
|
add_setup(aFunction) {
|
|
|
|
if (!this.__setups.length) {
|
|
|
|
this.waitForExplicitFinish();
|
|
|
|
}
|
|
|
|
let bound = aFunction.bind(this);
|
|
|
|
this.__setups.push(bound);
|
|
|
|
return bound;
|
|
|
|
},
|
|
|
|
|
2011-06-10 11:00:45 +04:00
|
|
|
destroy: function test_destroy() {
|
|
|
|
for (let prop in this) {
|
|
|
|
delete this[prop];
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2011-06-10 11:00:45 +04:00
|
|
|
},
|
2007-07-09 20:24:15 +04:00
|
|
|
};
|