browser_allocations_browser_console.js (2199B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Record allocations while opening and closing the Browser Console 7 8 const TEST_URL = 9 "http://example.com/browser/devtools/client/framework/test/allocations/reloaded-page.html"; 10 11 const { require } = ChromeUtils.importESModule( 12 "resource://devtools/shared/loader/Loader.sys.mjs" 13 ); 14 const { 15 BrowserConsoleManager, 16 } = require("resource://devtools/client/webconsole/browser-console-manager.js"); 17 18 async function testScript() { 19 // Open 20 await BrowserConsoleManager.toggleBrowserConsole(); 21 22 // Reload the tab to make the test slightly more real 23 const hud = BrowserConsoleManager.getBrowserConsole(); 24 const onTargetProcessed = hud.commands.targetCommand.once( 25 "processed-available-target" 26 ); 27 28 gBrowser.reloadTab(gBrowser.selectedTab); 29 30 info("Wait for target of the new document to be fully processed"); 31 await onTargetProcessed; 32 33 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 34 await new Promise(resolve => setTimeout(resolve, 1000)); 35 36 // Close 37 await BrowserConsoleManager.toggleBrowserConsole(); 38 39 // Browser console still cleanup stuff after the resolution of toggleBrowserConsole. 40 // So wait for a little while to ensure it completes all cleanups. 41 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 42 await new Promise(resolve => setTimeout(resolve, 500)); 43 } 44 45 add_task(async function () { 46 await SpecialPowers.pushPrefEnv({ 47 set: [["devtools.browsertoolbox.scope", "everything"]], 48 }); 49 50 const tab = await addTab(TEST_URL); 51 52 // Run the test scenario first before recording in order to load all the 53 // modules. Otherwise they get reported as "still allocated" objects, 54 // whereas we do expect them to be kept in memory as they are loaded via 55 // the main DevTools loader, which keeps the module loaded until the 56 // shutdown of Firefox 57 await testScript(); 58 59 // Now, run the test script. This time, we record this run. 60 await startRecordingAllocations(); 61 62 for (let i = 0; i < 3; i++) { 63 await testScript(); 64 } 65 66 await stopRecordingAllocations("browser-console"); 67 68 gBrowser.removeTab(tab); 69 });