browser_startup_content.js (5972B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /* This test records which services, frame scripts, process scripts, and 5 * JS modules are loaded when creating a new content process. 6 * 7 * If you made changes that cause this test to fail, it's likely because you 8 * are loading more JS code during content process startup. Please try to 9 * avoid this. 10 * 11 * If your code isn't strictly required to show a page, consider loading it 12 * lazily. If you can't, consider delaying its load until after we have started 13 * handling user events. 14 */ 15 16 "use strict"; 17 18 /* Set this to true only for debugging purpose; it makes the output noisy. */ 19 const kDumpAllStacks = false; 20 21 const known_scripts = { 22 modules: new Set([ 23 "chrome://mochikit/content/ShutdownLeaksCollector.sys.mjs", 24 25 // General utilities 26 "resource://gre/modules/AppConstants.sys.mjs", 27 "resource://gre/modules/Timer.sys.mjs", 28 "resource://gre/modules/XPCOMUtils.sys.mjs", 29 30 // Logging related 31 // eslint-disable-next-line mozilla/use-console-createInstance 32 "resource://gre/modules/Log.sys.mjs", 33 34 // Browser front-end 35 "resource:///actors/AboutReaderChild.sys.mjs", 36 "resource:///actors/InteractionsChild.sys.mjs", 37 "resource:///actors/LinkHandlerChild.sys.mjs", 38 "resource:///actors/SearchSERPTelemetryChild.sys.mjs", 39 "resource://gre/actors/ContentMetaChild.sys.mjs", 40 "resource://gre/modules/Readerable.sys.mjs", 41 42 // Telemetry 43 "resource://gre/modules/TelemetryControllerBase.sys.mjs", // bug 1470339 44 "resource://gre/modules/TelemetryControllerContent.sys.mjs", // bug 1470339 45 46 // Extensions 47 "resource://gre/modules/ExtensionProcessScript.sys.mjs", 48 "resource://gre/modules/ExtensionUtils.sys.mjs", 49 ]), 50 frameScripts: new Set([ 51 // Test related 52 "chrome://mochikit/content/shutdown-leaks-collector.js", 53 ]), 54 processScripts: new Set([ 55 "chrome://global/content/process-content.js", 56 "resource://gre/modules/extensionProcessScriptLoader.js", 57 ]), 58 }; 59 60 // Items on this list *might* load when creating the process, as opposed to 61 // items in the main list, which we expect will always load. 62 const intermittently_loaded_scripts = { 63 modules: new Set([ 64 "resource://gre/modules/nsAsyncShutdown.sys.mjs", 65 66 // Translations code which may be preffed on. 67 "resource://gre/actors/TranslationsChild.sys.mjs", 68 "resource://gre/modules/translations/LanguageDetector.sys.mjs", 69 "resource://gre/modules/ConsoleAPIStorage.sys.mjs", // Logging related. 70 71 // Session store. 72 "resource://gre/modules/sessionstore/SessionHistory.sys.mjs", 73 74 // Cookie banner handling. 75 "resource://gre/actors/CookieBannerChild.sys.mjs", 76 "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", 77 78 // Canonical URL detection behind pref `browser.tabs.notes.enabled` 79 "resource:///actors/CanonicalURLChild.sys.mjs", 80 "moz-src:///browser/components/tabnotes/CanonicalURL.sys.mjs", 81 82 // Test related 83 "chrome://remote/content/marionette/actors/MarionetteEventsChild.sys.mjs", 84 "chrome://remote/content/shared/Log.sys.mjs", 85 "resource://testing-common/BrowserTestUtilsChild.sys.mjs", 86 "resource://testing-common/ContentEventListenerChild.sys.mjs", 87 "resource://specialpowers/AppTestDelegateChild.sys.mjs", 88 "resource://testing-common/SpecialPowersChild.sys.mjs", 89 "resource://testing-common/WrapPrivileged.sys.mjs", 90 ]), 91 frameScripts: new Set([]), 92 processScripts: new Set([]), 93 }; 94 95 const forbiddenScripts = { 96 services: new Set([ 97 "@mozilla.org/base/telemetry-startup;1", 98 "@mozilla.org/embedcomp/default-tooltiptextprovider;1", 99 "@mozilla.org/push/Service;1", 100 ]), 101 }; 102 103 add_task(async function () { 104 SimpleTest.requestCompleteLog(); 105 106 let tab = await BrowserTestUtils.openNewForegroundTab({ 107 gBrowser, 108 url: 109 getRootDirectory(gTestPath).replace( 110 "chrome://mochitests/content", 111 "https://example.com" 112 ) + "file_empty.html", 113 forceNewProcess: true, 114 }); 115 116 let mm = gBrowser.selectedBrowser.messageManager; 117 let promise = BrowserTestUtils.waitForMessage(mm, "Test:LoadedScripts"); 118 119 // Load a custom frame script to avoid using SpecialPowers.spawn which may 120 // load other modules. 121 mm.loadFrameScript( 122 "data:text/javascript,(" + 123 function () { 124 /* eslint-env mozilla/frame-script */ 125 const Cm = Components.manager; 126 Cm.QueryInterface(Ci.nsIServiceManager); 127 const { AppConstants } = ChromeUtils.importESModule( 128 "resource://gre/modules/AppConstants.sys.mjs" 129 ); 130 let collectStacks = AppConstants.NIGHTLY_BUILD || AppConstants.DEBUG; 131 let modules = new Map(); 132 for (let module of Cu.loadedESModules) { 133 modules.set( 134 module, 135 collectStacks ? Cu.getModuleImportStack(module) : "" 136 ); 137 } 138 let services = new Map(); 139 for (let contractID of Object.keys(Cc)) { 140 try { 141 if ( 142 Cm.isServiceInstantiatedByContractID(contractID, Ci.nsISupports) 143 ) { 144 services.set(contractID, ""); 145 } 146 } catch (e) {} 147 } 148 sendAsyncMessage("Test:LoadedScripts", { 149 modules, 150 services, 151 }); 152 } + 153 ")()", 154 false 155 ); 156 157 let loadedInfo = await promise; 158 159 // Gather loaded frame scripts. 160 loadedInfo.frameScripts = new Map(); 161 for (let [uri] of Services.mm.getDelayedFrameScripts()) { 162 loadedInfo.frameScripts.set(uri, ""); 163 } 164 165 // Gather loaded process scripts. 166 loadedInfo.processScripts = new Map(); 167 for (let [uri] of Services.ppmm.getDelayedProcessScripts()) { 168 loadedInfo.processScripts.set(uri, ""); 169 } 170 171 await checkLoadedScripts({ 172 loadedInfo, 173 known: known_scripts, 174 intermittent: intermittently_loaded_scripts, 175 forbidden: forbiddenScripts, 176 dumpAllStacks: kDumpAllStacks, 177 }); 178 179 BrowserTestUtils.removeTab(tab); 180 });