tor-browser

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

browser_dom_nodes_highlight.js (2013B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_PAGE_URL = URL_ROOT + "page_dom_nodes.html";
      7 
      8 /**
      9 * Checks that hovering nodes highlights them in the content page
     10 */
     11 add_task(async function () {
     12  info("Test DOM panel node highlight started");
     13 
     14  const { panel, tab } = await addTestTab(TEST_PAGE_URL);
     15  const toolbox = gDevTools.getToolboxForTab(tab);
     16  const highlighter = toolbox.getHighlighter();
     17 
     18  const tests = [
     19    {
     20      expected: "h1",
     21      getNode: async () => {
     22        return getRowByIndex(panel, 0).querySelector(".objectBox-node");
     23      },
     24    },
     25    {
     26      expected: "h2",
     27      getNode: async () => {
     28        info("Expand specified row and wait till children are displayed");
     29        await expandRow(panel, "B");
     30        return getRowByIndex(panel, 1).querySelector(".objectBox-node");
     31      },
     32    },
     33  ];
     34 
     35  for (const test of tests) {
     36    info(`Get the NodeFront for ${test.expected}`);
     37    const node = await test.getNode();
     38 
     39    info("Highlight the node by moving the cursor on it");
     40    const onHighlighterShown = highlighter.waitForHighlighterShown();
     41    EventUtils.synthesizeMouseAtCenter(
     42      node,
     43      {
     44        type: "mouseover",
     45      },
     46      node.ownerDocument.defaultView
     47    );
     48    const { nodeFront } = await onHighlighterShown;
     49    is(
     50      nodeFront.displayName,
     51      test.expected,
     52      "The correct node was highlighted"
     53    );
     54 
     55    info("Unhighlight the node by moving the cursor away from it");
     56    const onHighlighterHidden = highlighter.waitForHighlighterHidden();
     57    const btn = toolbox.doc.querySelector("#toolbox-meatball-menu-button");
     58    EventUtils.synthesizeMouseAtCenter(
     59      btn,
     60      {
     61        type: "mouseover",
     62      },
     63      btn.ownerDocument.defaultView
     64    );
     65 
     66    const { nodeFront: unhighlightedNode } = await onHighlighterHidden;
     67    is(
     68      unhighlightedNode.displayName,
     69      test.expected,
     70      "The node was unhighlighted"
     71    );
     72  }
     73 });