tor-browser

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

browser_console_many_toggles.js (1889B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that we safely close and reopen the Browser Console.
      5 
      6 "use strict";
      7 
      8 add_task(async function () {
      9  // Enable the multiprocess mode as it is more likely to break on startup
     10  await pushPref("devtools.browsertoolbox.scope", "everything");
     11 
     12  const promises = [];
     13  for (let i = 0; i < 5; i++) {
     14    info("Open the Browser Console");
     15    promises.push(BrowserConsoleManager.toggleBrowserConsole());
     16 
     17    // Use different pause time between opening and closing
     18    await wait(i * 100);
     19 
     20    info("Close the Browser Console");
     21    promises.push(BrowserConsoleManager.closeBrowserConsole());
     22 
     23    // Use different pause time between opening and closing
     24    await wait(i * 100);
     25  }
     26 
     27  info("Wait for all opening/closing promises");
     28  // Ignore any exception here, we expect some as we are racing opening versus destruction
     29  await Promise.allSettled(promises);
     30 
     31  // The browser console may end up being opened or closed because of usage of "toggle"
     32  // Ensure having a console opened to verify it works
     33  let hud = BrowserConsoleManager.getBrowserConsole();
     34  if (!hud) {
     35    info("Reopen the browser console a last time");
     36    hud = await BrowserConsoleManager.toggleBrowserConsole();
     37  }
     38 
     39  info("Log a message and ensure it is visible and the console mostly works");
     40  console.log("message from mochitest");
     41  await checkUniqueMessageExists(hud, "message from mochitest", ".console-api");
     42 
     43  // Clear the messages in order to be able to run this test more than once
     44  // and clear the message we just logged
     45  await clearOutput(hud);
     46 
     47  info("Ensure closing the Browser Console at the end of the test");
     48  await BrowserConsoleManager.closeBrowserConsole();
     49 
     50  ok(
     51    !BrowserConsoleManager.getBrowserConsole(),
     52    "No browser console opened at the end of test"
     53  );
     54 });