Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

/* Any copyright is dedicated to the Public Domain.
/* This test records which services, frame scripts, process scripts, and
* JS modules are loaded when creating a new content process.
*
* If you made changes that cause this test to fail, it's likely because you
* are loading more JS code during content process startup. Please try to
* avoid this.
*
* If your code isn't strictly required to show a page, consider loading it
* lazily. If you can't, consider delaying its load until after we have started
* handling user events.
*/
"use strict";
/* Set this to true only for debugging purpose; it makes the output noisy. */
const kDumpAllStacks = false;
const known_scripts = {
modules: new Set([
// General utilities
// Logging related
// eslint-disable-next-line mozilla/use-console-createInstance
// Browser front-end
// Telemetry
// Extensions
]),
frameScripts: new Set([
// Test related
]),
processScripts: new Set([
]),
};
// Items on this list *might* load when creating the process, as opposed to
// items in the main list, which we expect will always load.
const intermittently_loaded_scripts = {
modules: new Set([
// Translations code which may be preffed on.
// Session store.
// Cookie banner handling.
// Test related
]),
frameScripts: new Set([]),
processScripts: new Set([]),
};
const forbiddenScripts = {
services: new Set([
"@mozilla.org/base/telemetry-startup;1",
"@mozilla.org/embedcomp/default-tooltiptextprovider;1",
"@mozilla.org/push/Service;1",
]),
};
add_task(async function () {
SimpleTest.requestCompleteLog();
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
url:
getRootDirectory(gTestPath).replace(
) + "file_empty.html",
forceNewProcess: true,
});
let mm = gBrowser.selectedBrowser.messageManager;
let promise = BrowserTestUtils.waitForMessage(mm, "Test:LoadedScripts");
// Load a custom frame script to avoid using SpecialPowers.spawn which may
// load other modules.
mm.loadFrameScript(
"data:text/javascript,(" +
function () {
/* eslint-env mozilla/frame-script */
const Cm = Components.manager;
Cm.QueryInterface(Ci.nsIServiceManager);
const { AppConstants } = ChromeUtils.importESModule(
);
let collectStacks = AppConstants.NIGHTLY_BUILD || AppConstants.DEBUG;
let modules = {};
for (let module of Cu.loadedJSModules) {
modules[module] = collectStacks
? Cu.getModuleImportStack(module)
: "";
}
for (let module of Cu.loadedESModules) {
modules[module] = collectStacks
? Cu.getModuleImportStack(module)
: "";
}
let services = {};
for (let contractID of Object.keys(Cc)) {
try {
if (
Cm.isServiceInstantiatedByContractID(contractID, Ci.nsISupports)
) {
services[contractID] = "";
}
} catch (e) {}
}
sendAsyncMessage("Test:LoadedScripts", {
modules,
services,
});
} +
")()",
false
);
let loadedInfo = await promise;
// Gather loaded frame scripts.
loadedInfo.frameScripts = {};
for (let [uri] of Services.mm.getDelayedFrameScripts()) {
loadedInfo.frameScripts[uri] = "";
}
// Gather loaded process scripts.
loadedInfo.processScripts = {};
for (let [uri] of Services.ppmm.getDelayedProcessScripts()) {
loadedInfo.processScripts[uri] = "";
}
await checkLoadedScripts({
loadedInfo,
known: known_scripts,
intermittent: intermittently_loaded_scripts,
forbidden: forbiddenScripts,
dumpAllStacks: kDumpAllStacks,
});
BrowserTestUtils.removeTab(tab);
});