tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_allocations_target.js (1655B)


      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 spawning Commands and the first top level target
      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  CommandsFactory,
     16 } = require("resource://devtools/shared/commands/commands-factory.js");
     17 
     18 async function testScript(tab) {
     19  const commands = await CommandsFactory.forTab(tab);
     20  await commands.targetCommand.startListening();
     21 
     22  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     23  await new Promise(resolve => setTimeout(resolve, 1000));
     24 
     25  // destroy the commands to also destroy the dedicated client.
     26  await commands.destroy();
     27 
     28  // Spin the event loop to ensure commands destruction 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  await testScript(tab);
     47 
     48  await stopRecordingAllocations("target");
     49 
     50  gBrowser.removeTab(tab);
     51 });