summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_console_many_toggles.js
blob: 21bbde1d1415a093ce28e935ee2d59c69a1afb9d (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that we safely close and reopen the Browser Console.

"use strict";

add_task(async function () {
  // Enable the multiprocess mode as it is more likely to break on startup
  await pushPref("devtools.browsertoolbox.scope", "everything");

  const promises = [];
  for (let i = 0; i < 5; i++) {
    info("Open the Browser Console");
    promises.push(BrowserConsoleManager.toggleBrowserConsole());

    // Use different pause time between opening and closing
    await wait(i * 100);

    info("Close the Browser Console");
    promises.push(BrowserConsoleManager.closeBrowserConsole());

    // Use different pause time between opening and closing
    await wait(i * 100);
  }

  info("Wait for all opening/closing promises");
  // Ignore any exception here, we expect some as we are racing opening versus destruction
  await Promise.allSettled(promises);

  // The browser console may end up being opened or closed because of usage of "toggle"
  // Ensure having a console opened to verify it works
  let hud = BrowserConsoleManager.getBrowserConsole();
  if (!hud) {
    info("Reopen the browser console a last time");
    hud = await BrowserConsoleManager.toggleBrowserConsole();
  }

  info("Log a message and ensure it is visible and the console mostly works");
  console.log("message from mochitest");
  await checkUniqueMessageExists(hud, "message from mochitest", ".console-api");

  // Clear the messages in order to be able to run this test more than once
  // and clear the message we just logged
  await clearOutput(hud);

  info("Ensure closing the Browser Console at the end of the test");
  await BrowserConsoleManager.closeBrowserConsole();

  ok(
    !BrowserConsoleManager.getBrowserConsole(),
    "No browser console opened at the end of test"
  );
});