tor-browser

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

browser_inspector_addNode_02.js (2381B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that the add node button and context menu items have the right state
      7 // depending on the current selection.
      8 
      9 const TEST_URL = URL_ROOT + "doc_inspector_add_node.html";
     10 
     11 add_task(async function () {
     12  const { inspector } = await openInspectorForURL(TEST_URL);
     13 
     14  info("Select the DOCTYPE element");
     15  let { nodes } = await inspector.walker.children(inspector.walker.rootNode);
     16  await selectNode(nodes[0], inspector);
     17  assertState(false, inspector, "The button and item are disabled on DOCTYPE");
     18 
     19  info("Select the ::before pseudo-element");
     20  const body = await getNodeFront("body", inspector);
     21  ({ nodes } = await inspector.walker.children(body));
     22  await selectNode(nodes[0], inspector);
     23  assertState(
     24    false,
     25    inspector,
     26    "The button and item are disabled on a pseudo-element"
     27  );
     28 
     29  info("Select the svg element");
     30  await selectNode("svg", inspector);
     31  assertState(
     32    false,
     33    inspector,
     34    "The button and item are disabled on a SVG element"
     35  );
     36 
     37  info("Select the div#foo element");
     38  await selectNode("#foo", inspector);
     39  assertState(
     40    true,
     41    inspector,
     42    "The button and item are enabled on a DIV element"
     43  );
     44 
     45  info("Select the documentElement element (html)");
     46  await selectNode("html", inspector);
     47  assertState(
     48    false,
     49    inspector,
     50    "The button and item are disabled on the documentElement"
     51  );
     52 
     53  info("Select the iframe element");
     54  await selectNode("iframe", inspector);
     55  assertState(
     56    false,
     57    inspector,
     58    "The button and item are disabled on an IFRAME element"
     59  );
     60 });
     61 
     62 function assertState(isEnabled, inspector, desc) {
     63  const doc = inspector.panelDoc;
     64  const btn = doc.querySelector("#inspector-element-add-button");
     65 
     66  // Force an update of the context menu to make sure menu items are updated
     67  // according to the current selection. This normally happens when the menu is
     68  // opened, but for the sake of this test's simplicity, we directly call the
     69  // private update function instead.
     70  const allMenuItems = openContextMenuAndGetAllItems(inspector);
     71  const menuItem = allMenuItems.find(item => item.id === "node-menu-add");
     72  ok(menuItem, "The item is in the menu");
     73  is(!menuItem.disabled, isEnabled, desc);
     74 
     75  is(!btn.hasAttribute("disabled"), isEnabled, desc);
     76 }