tor-browser

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

browser_markup_keybindings_delete_attributes.js (2339B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests that attributes can be deleted from the markup-view with the delete key
      7 // when they are focused.
      8 
      9 const HTML = '<div id="id" class="class" data-id="id"></div>';
     10 const TEST_URL = "data:text/html;charset=utf-8," + encodeURIComponent(HTML);
     11 
     12 // List of all the test cases. Each item is an object with the following props:
     13 // - selector: the css selector of the node that should be selected
     14 // - attribute: the name of the attribute that should be focused. Do not
     15 //   specify an attribute that would make it impossible to find the node using
     16 //   selector.
     17 // Note that after each test case, undo is called.
     18 const TEST_DATA = [
     19  {
     20    selector: "#id",
     21    attribute: "class",
     22  },
     23  {
     24    selector: "#id",
     25    attribute: "data-id",
     26  },
     27 ];
     28 
     29 add_task(async function () {
     30  const { inspector } = await openInspectorForURL(TEST_URL);
     31  const { walker } = inspector;
     32 
     33  for (const { selector, attribute } of TEST_DATA) {
     34    info("Get the container for node " + selector);
     35    const { editor } = await getContainerForSelector(selector, inspector);
     36 
     37    info("Focus attribute " + attribute);
     38    const attr = editor.attrElements.get(attribute).querySelector(".editable");
     39    attr.focus();
     40 
     41    info("Delete the attribute by pressing delete");
     42    const mutated = inspector.once("markupmutation");
     43    EventUtils.sendKey("delete", inspector.panelWin);
     44    await mutated;
     45 
     46    info("Check that the node is still here");
     47    let node = await walker.querySelector(walker.rootNode, selector);
     48    ok(node, "The node hasn't been deleted");
     49 
     50    info("Check that the attribute has been deleted");
     51    node = await walker.querySelector(
     52      walker.rootNode,
     53      selector + "[" + attribute + "]"
     54    );
     55    ok(!node, "The attribute does not exist anymore in the DOM");
     56    ok(
     57      !editor.attrElements.get(attribute),
     58      "The attribute has been removed from the container"
     59    );
     60 
     61    info("Undo the change");
     62    await undoChange(inspector);
     63    node = await walker.querySelector(
     64      walker.rootNode,
     65      selector + "[" + attribute + "]"
     66    );
     67    ok(node, "The attribute is back in the DOM");
     68    ok(
     69      editor.attrElements.get(attribute),
     70      "The attribute is back on the container"
     71    );
     72  }
     73 });