tor-browser

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

browser_webconsole_visibility_messages.js (3939B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 // Check messages logged when console not visible are displayed when
      8 // the user show the console again.
      9 
     10 const HTML = `
     11  <!DOCTYPE html>
     12  <html>
     13    <body>
     14      <h1>Test console visibility update</h1>
     15      <script>
     16        function log(str) {
     17          console.log(str);
     18        }
     19      </script>
     20    </body>
     21  </html>
     22 `;
     23 const TEST_URI = "data:text/html;charset=utf-8," + encodeURI(HTML);
     24 const MESSAGES_COUNT = 10;
     25 
     26 add_task(async function () {
     27  const hud = await openNewTabAndConsole(TEST_URI);
     28  const toolbox = hud.toolbox;
     29 
     30  info("Log one message in the console");
     31  SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
     32    content.wrappedJSObject.log("in-console log");
     33  });
     34  await waitFor(() => findConsoleAPIMessage(hud, "in-console log"));
     35 
     36  info("select the inspector");
     37  await toolbox.selectTool("inspector");
     38 
     39  info("Wait for console to be hidden");
     40  const { document } = hud.iframeWindow;
     41  await waitFor(() => document.visibilityState == "hidden");
     42 
     43  const onAllMessagesInStore = new Promise(done => {
     44    const store = hud.ui.wrapper.getStore();
     45    store.subscribe(
     46      () => {
     47        const messages = store.getState().messages.mutableMessagesById.size;
     48        // Also consider the "in-console log" message
     49        if (messages == MESSAGES_COUNT + 1) {
     50          done();
     51        }
     52      },
     53      { ignoreVisibility: true }
     54    );
     55  });
     56 
     57  await SpecialPowers.spawn(
     58    gBrowser.selectedBrowser,
     59    [[MESSAGES_COUNT]],
     60    count => {
     61      for (let i = 1; i <= count; i++) {
     62        content.wrappedJSObject.log("in-inspector log " + i);
     63      }
     64    }
     65  );
     66 
     67  info("Waiting for all messages to be logged into the store");
     68  await onAllMessagesInStore;
     69 
     70  const inInspectorMessages = await findConsoleAPIMessages(hud, "in-inspector");
     71  is(
     72    inInspectorMessages.length,
     73    0,
     74    "No messages from the inspector actually appear in the console"
     75  );
     76 
     77  info("select back the console");
     78  await toolbox.selectTool("webconsole");
     79 
     80  info("And wait for all messages to be visible");
     81  const waitForMessagePromises = [];
     82  for (let j = 1; j <= MESSAGES_COUNT; j++) {
     83    waitForMessagePromises.push(
     84      waitFor(() => findConsoleAPIMessage(hud, "in-inspector log " + j))
     85    );
     86  }
     87 
     88  await Promise.all(waitForMessagePromises);
     89  ok(
     90    true,
     91    "All the messages logged when the console was hidden were displayed."
     92  );
     93 });
     94 
     95 // Similar scenario, but with the split console on the inspector panel.
     96 // Here, the messages should still be logged.
     97 add_task(async function () {
     98  const hud = await openNewTabAndConsole(TEST_URI);
     99  const toolbox = hud.toolbox;
    100 
    101  info("Log one message in the console");
    102  SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
    103    content.wrappedJSObject.log("in-console log");
    104  });
    105  await waitFor(() => findConsoleAPIMessage(hud, "in-console log"));
    106 
    107  info("select the inspector");
    108  await toolbox.selectTool("inspector");
    109 
    110  info("Wait for console to be hidden");
    111  const { document } = hud.iframeWindow;
    112  await waitFor(() => document.visibilityState == "hidden");
    113 
    114  await toolbox.openSplitConsole();
    115 
    116  await SpecialPowers.spawn(
    117    gBrowser.selectedBrowser,
    118    [[MESSAGES_COUNT]],
    119    count => {
    120      for (let i = 1; i <= count; i++) {
    121        content.wrappedJSObject.log("in-inspector log " + i);
    122      }
    123    }
    124  );
    125 
    126  info("Wait for all messages to be visible in the split console");
    127  await waitFor(
    128    async () =>
    129      (
    130        await findMessagesVirtualizedByType({
    131          hud,
    132          text: "in-inspector log ",
    133          typeSelector: ".console-api",
    134        })
    135      ).length === MESSAGES_COUNT
    136  );
    137  ok(true, "All the messages logged when we are using the split console");
    138 
    139  await toolbox.closeSplitConsole();
    140 });