Files
tubestation/toolkit/components/extensions/test/mochitest/head.js
Andrew McCreight 272cee1e65 Bug 1432992, part 1 - Remove definitions of Ci, Cr, Cc, and Cu. r=florian
This patch was autogenerated by my decomponents.py

It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.

It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.

It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)

MozReview-Commit-ID: DeSHcClQ7cG
2018-02-06 09:36:57 -08:00

101 lines
2.8 KiB
JavaScript

"use strict";
/* exported AppConstants, Assert */
var {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
// We run tests under two different configurations, from mochitest.ini and
// mochitest-remote.ini. When running from mochitest-remote.ini, the tests are
// copied to the sub-directory "test-oop-extensions", which we detect here, and
// use to select our configuration.
let remote = location.pathname.includes("test-oop-extensions");
SpecialPowers.pushPrefEnv({set: [
["extensions.webextensions.remote", remote],
]});
if (remote) {
// We don't want to reset this at the end of the test, so that we don't have
// to spawn a new extension child process for each test unit.
SpecialPowers.setIntPref("dom.ipc.keepProcessesAlive.extension", 1);
}
{
let chromeScript = SpecialPowers.loadChromeScript(
SimpleTest.getTestFileURL("chrome_cleanup_script.js"));
SimpleTest.registerCleanupFunction(async () => {
await new Promise(resolve => setTimeout(resolve, 0));
chromeScript.sendAsyncMessage("check-cleanup");
let results = await chromeScript.promiseOneMessage("cleanup-results");
chromeScript.destroy();
if (results.extraWindows.length || results.extraTabs.length) {
ok(false, `Test left extra windows or tabs: ${JSON.stringify(results)}\n`);
}
});
}
let Assert = {
rejects(promise, msg) {
return promise.then(() => {
ok(false, msg);
}, () => {
ok(true, msg);
});
},
};
/* exported waitForLoad */
function waitForLoad(win) {
return new Promise(resolve => {
win.addEventListener("load", function() {
resolve();
}, {capture: true, once: true});
});
}
/* exported loadChromeScript */
function loadChromeScript(fn) {
let wrapper = `
const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
(${fn.toString()})();`;
return SpecialPowers.loadChromeScript(new Function(wrapper));
}
/* exported consoleMonitor */
let consoleMonitor = {
start(messages) {
this.chromeScript = SpecialPowers.loadChromeScript(
SimpleTest.getTestFileURL("mochitest_console.js"));
this.chromeScript.sendAsyncMessage("consoleStart", messages);
},
async finished() {
let done = this.chromeScript.promiseOneMessage("consoleDone").then(done => {
this.chromeScript.destroy();
return done;
});
this.chromeScript.sendAsyncMessage("waitForConsole");
let test = await done;
ok(test.ok, test.message);
},
};
/* exported waitForState */
function waitForState(sw, state) {
return new Promise(resolve => {
if (sw.state === state) {
return resolve();
}
sw.addEventListener("statechange", function onStateChange() {
if (sw.state === state) {
sw.removeEventListener("statechange", onStateChange);
resolve();
}
});
});
}