summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/allocations/browser_allocations_browser_console.js
blob: 13d0171dfadc2ce0df07f78af5782fdbd35c92fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Record allocations while opening and closing the Browser Console

const TEST_URL =
  "http://example.com/browser/devtools/client/framework/test/allocations/reloaded-page.html";

const { require } = ChromeUtils.importESModule(
  "resource://devtools/shared/loader/Loader.sys.mjs"
);
const {
  BrowserConsoleManager,
} = require("resource://devtools/client/webconsole/browser-console-manager.js");

async function testScript() {
  // Open
  await BrowserConsoleManager.toggleBrowserConsole();

  // Reload the tab to make the test slightly more real
  const hud = BrowserConsoleManager.getBrowserConsole();
  const onTargetProcessed = hud.commands.targetCommand.once(
    "processed-available-target"
  );

  gBrowser.reloadTab(gBrowser.selectedTab);

  info("Wait for target of the new document to be fully processed");
  await onTargetProcessed;

  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
  await new Promise(resolve => setTimeout(resolve, 1000));

  // Close
  await BrowserConsoleManager.toggleBrowserConsole();

  // Browser console still cleanup stuff after the resolution of toggleBrowserConsole.
  // So wait for a little while to ensure it completes all cleanups.
  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
  await new Promise(resolve => setTimeout(resolve, 500));
}

add_task(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [["devtools.browsertoolbox.scope", "everything"]],
  });

  const tab = await addTab(TEST_URL);

  // Run the test scenario first before recording in order to load all the
  // modules. Otherwise they get reported as "still allocated" objects,
  // whereas we do expect them to be kept in memory as they are loaded via
  // the main DevTools loader, which keeps the module loaded until the
  // shutdown of Firefox
  await testScript();

  // Now, run the test script. This time, we record this run.
  await startRecordingAllocations();

  for (let i = 0; i < 3; i++) {
    await testScript();
  }

  await stopRecordingAllocations("browser-console");

  gBrowser.removeTab(tab);
});