browser_allocations_toolbox.js (1578B)
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 DevTools 7 8 const TEST_URL = 9 "data:text/html;charset=UTF-8,<div>Target allocations test</div>"; 10 11 const { require } = ChromeUtils.importESModule( 12 "resource://devtools/shared/loader/Loader.sys.mjs" 13 ); 14 const { 15 gDevTools, 16 } = require("resource://devtools/client/framework/devtools.js"); 17 18 async function testScript(tab) { 19 const toolbox = await gDevTools.showToolboxForTab(tab, { 20 toolId: "inspector", 21 }); 22 23 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 24 await new Promise(resolve => setTimeout(resolve, 1000)); 25 26 await toolbox.destroy(); 27 28 // Spin the event loop to ensure toolbox destroy is fully completed 29 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 30 await new Promise(resolve => setTimeout(resolve, 0)); 31 } 32 33 add_task(async function () { 34 const tab = await addTab(TEST_URL); 35 36 // Run the test scenario first before recording in order to load all the 37 // modules. Otherwise they get reported as "still allocated" objects, 38 // whereas we do expect them to be kept in memory as they are loaded via 39 // the main DevTools loader, which keeps the module loaded until the 40 // shutdown of Firefox 41 await testScript(tab); 42 43 await startRecordingAllocations(); 44 45 // Now, run the test script. This time, we record this run. 46 for (let i = 0; i < 3; i++) { 47 await testScript(tab); 48 } 49 50 await stopRecordingAllocations("toolbox"); 51 52 gBrowser.removeTab(tab); 53 });