tor-browser

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

browser_webconsole_nodes_select.js (2105B)


      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 clicking on open-in-inspector icon does select the node in the inspector.
      8 
      9 const HTML = `
     10  <!DOCTYPE html>
     11  <html>
     12    <body>
     13      <h1>Select node in inspector test</h1>
     14    </body>
     15    <script>
     16      function logNode(selector) {
     17        console.log(document.querySelector(selector));
     18      }
     19    </script>
     20  </html>
     21 `;
     22 const TEST_URI = "data:text/html;charset=utf-8," + encodeURI(HTML);
     23 
     24 add_task(async function () {
     25  const hud = await openNewTabAndConsole(TEST_URI);
     26  const toolbox = hud.toolbox;
     27 
     28  // Loading the inspector panel at first, to make it possible to listen for
     29  // new node selections
     30  await toolbox.loadTool("inspector");
     31  const inspector = toolbox.getPanel("inspector");
     32 
     33  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
     34    content.wrappedJSObject.logNode("h1");
     35  });
     36 
     37  const msg = await waitFor(() => findConsoleAPIMessage(hud, "<h1>"));
     38  const node = msg.querySelector(".objectBox-node");
     39  Assert.notStrictEqual(node, null, "Node was logged as expected");
     40 
     41  const openInInspectorIcon = node.querySelector(".open-inspector");
     42  Assert.notStrictEqual(
     43    openInInspectorIcon,
     44    null,
     45    "The is an open in inspector icon"
     46  );
     47 
     48  info(
     49    "Clicking on the inspector icon and waiting for the " +
     50      "inspector to be selected"
     51  );
     52  const onInspectorSelected = toolbox.once("inspector-selected");
     53  const onInspectorUpdated = inspector.once("inspector-updated");
     54  const onNewNode = toolbox.selection.once("new-node-front");
     55 
     56  openInInspectorIcon.click();
     57 
     58  await onInspectorSelected;
     59  await onInspectorUpdated;
     60  const nodeFront = await onNewNode;
     61 
     62  ok(true, "Inspector selected and new node got selected");
     63  is(nodeFront.displayName, "h1", "The expected node was selected");
     64 
     65  is(
     66    msg.querySelector(".theme-twisty").classList.contains("open"),
     67    false,
     68    "The object inspector wasn't expanded"
     69  );
     70 });