summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_keybindings_delete_attributes.js
blob: e4dcfe4eacfd37da99791ff57cb6d569b0d3de61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that attributes can be deleted from the markup-view with the delete key
// when they are focused.

const HTML = '<div id="id" class="class" data-id="id"></div>';
const TEST_URL = "data:text/html;charset=utf-8," + encodeURIComponent(HTML);

// List of all the test cases. Each item is an object with the following props:
// - selector: the css selector of the node that should be selected
// - attribute: the name of the attribute that should be focused. Do not
//   specify an attribute that would make it impossible to find the node using
//   selector.
// Note that after each test case, undo is called.
const TEST_DATA = [{
  selector: "#id",
  attribute: "class"
}, {
  selector: "#id",
  attribute: "data-id"
}];

add_task(function* () {
  let {inspector} = yield openInspectorForURL(TEST_URL);
  let {walker} = inspector;

  for (let {selector, attribute} of TEST_DATA) {
    info("Get the container for node " + selector);
    let {editor} = yield getContainerForSelector(selector, inspector);

    info("Focus attribute " + attribute);
    let attr = editor.attrElements.get(attribute).querySelector(".editable");
    attr.focus();

    info("Delete the attribute by pressing delete");
    let mutated = inspector.once("markupmutation");
    EventUtils.sendKey("delete", inspector.panelWin);
    yield mutated;

    info("Check that the node is still here");
    let node = yield walker.querySelector(walker.rootNode, selector);
    ok(node, "The node hasn't been deleted");

    info("Check that the attribute has been deleted");
    node = yield walker.querySelector(walker.rootNode,
                                      selector + "[" + attribute + "]");
    ok(!node, "The attribute does not exist anymore in the DOM");
    ok(!editor.attrElements.get(attribute),
       "The attribute has been removed from the container");

    info("Undo the change");
    yield undoChange(inspector);
    node = yield walker.querySelector(walker.rootNode,
                                      selector + "[" + attribute + "]");
    ok(node, "The attribute is back in the DOM");
    ok(editor.attrElements.get(attribute),
       "The attribute is back on the container");
  }
});