tor-browser

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

browser_webconsole_nodes_highlight.js (2759B)


      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 hovering logged nodes highlight them in the content page.
      8 
      9 const HTML = `
     10  <!DOCTYPE html>
     11  <html>
     12    <body>
     13      <h1>Node Highlight  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  const highlighterTestFront = await getHighlighterTestFront(toolbox);
     29  const highlighter = toolbox.getHighlighter();
     30  let onHighlighterShown;
     31  let onHighlighterHidden;
     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  const view = node.ownerDocument.defaultView;
     41  const nonHighlightEl = toolbox.doc.getElementById(
     42    "toolbox-meatball-menu-button"
     43  );
     44 
     45  info("Highlight the node by moving the cursor on it");
     46  onHighlighterShown = highlighter.waitForHighlighterShown();
     47 
     48  EventUtils.synthesizeMouseAtCenter(node, { type: "mousemove" }, view);
     49 
     50  const { nodeFront } = await onHighlighterShown;
     51  is(nodeFront.displayName, "h1", "The correct node was highlighted");
     52  isVisible = await highlighterTestFront.isHighlighting();
     53  ok(isVisible, "Highlighter is displayed");
     54 
     55  info("Unhighlight the node by moving away from the node");
     56  onHighlighterHidden = highlighter.waitForHighlighterHidden();
     57  EventUtils.synthesizeMouseAtCenter(
     58    nonHighlightEl,
     59    { type: "mousemove" },
     60    view
     61  );
     62 
     63  await onHighlighterHidden;
     64  ok(true, "node-unhighlight event was fired when moving away from the node");
     65 
     66  info("Check we don't have zombie highlighters when briefly hovering a node");
     67  onHighlighterShown = highlighter.waitForHighlighterShown();
     68  onHighlighterHidden = highlighter.waitForHighlighterHidden();
     69  // Move hover the node and then right after move out.
     70  EventUtils.synthesizeMouseAtCenter(node, { type: "mousemove" }, view);
     71  EventUtils.synthesizeMouseAtCenter(
     72    nonHighlightEl,
     73    { type: "mousemove" },
     74    view
     75  );
     76  await Promise.all([onHighlighterShown, onHighlighterHidden]);
     77  ok(true, "The highlighter was removed");
     78 
     79  isVisible = await highlighterTestFront.isHighlighting();
     80  is(isVisible, false, "The highlighter is not displayed anymore");
     81 });