tor-browser

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

browser_inspector_addNode_03.js (3011B)


      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 adding nodes does work as expected: the parent node remains selected and the
      7 // new node is created inside the parent.
      8 
      9 const TEST_URL = URL_ROOT + "doc_inspector_add_node.html";
     10 const PARENT_TREE_LEVEL = 3;
     11 
     12 add_task(async function () {
     13  const { inspector } = await openInspectorForURL(TEST_URL);
     14 
     15  info("Adding a node in an element that has no children and is collapsed");
     16  let parentNode = await getNodeFront("#foo", inspector);
     17  await selectNode(parentNode, inspector);
     18  await testAddNode(parentNode, inspector);
     19 
     20  info(
     21    "Adding a node in an element with children but that has not been expanded yet"
     22  );
     23  parentNode = await getNodeFront("#bar", inspector);
     24  await selectNode(parentNode, inspector);
     25  await testAddNode(parentNode, inspector);
     26 
     27  info(
     28    "Adding a node in an element with children that has been expanded then collapsed"
     29  );
     30  // Select again #bar and collapse it.
     31  parentNode = await getNodeFront("#bar", inspector);
     32  await selectNode(parentNode, inspector);
     33  collapseNode(parentNode, inspector);
     34  await testAddNode(parentNode, inspector);
     35 
     36  info("Adding a node in an element with children that is expanded");
     37  parentNode = await getNodeFront("#bar", inspector);
     38  await selectNode(parentNode, inspector);
     39  await testAddNode(parentNode, inspector);
     40 });
     41 
     42 async function testAddNode(parentNode, inspector) {
     43  const btn = inspector.panelDoc.querySelector("#inspector-element-add-button");
     44  const parentContainer = inspector.markup.getContainer(parentNode);
     45 
     46  is(
     47    parseInt(parentContainer.tagLine.getAttribute("aria-level"), 10),
     48    PARENT_TREE_LEVEL,
     49    "The parent aria-level is up to date."
     50  );
     51 
     52  info(
     53    "Clicking 'add node' and expecting a markup mutation and a new container"
     54  );
     55  const onMutation = inspector.once("markupmutation");
     56  const onNewContainer = inspector.once("container-created");
     57  btn.click();
     58  let mutations = await onMutation;
     59  await onNewContainer;
     60 
     61  // We are only interested in childList mutations here. Filter everything else out as
     62  // there may be unrelated mutations (e.g. "events") grouped in.
     63  mutations = mutations.filter(({ type }) => type === "childList");
     64 
     65  is(mutations.length, 1, "There is one mutation only");
     66  is(mutations[0].added.length, 1, "There is one new node only");
     67 
     68  const newNode = mutations[0].added[0];
     69 
     70  is(
     71    parentNode,
     72    inspector.selection.nodeFront,
     73    "The parent node is still selected"
     74  );
     75  is(
     76    newNode.parentNode(),
     77    parentNode,
     78    "The new node is inside the right parent"
     79  );
     80 
     81  const newNodeContainer = inspector.markup.getContainer(newNode);
     82 
     83  is(
     84    parseInt(newNodeContainer.tagLine.getAttribute("aria-level"), 10),
     85    PARENT_TREE_LEVEL + 1,
     86    "The child aria-level is up to date."
     87  );
     88 }
     89 
     90 function collapseNode(node, inspector) {
     91  const container = inspector.markup.getContainer(node);
     92  container.setExpanded(false);
     93 }