summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_navigation.js
blob: 5bfd9719fbee457df49eb4d82fba3855bbfd2dbd (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that the markup-view nodes can be navigated to with the keyboard

const TEST_URL = URL_ROOT + "doc_markup_navigation.html";
const TEST_DATA = [
  ["pageup", "*doctype*"],
  ["down", "html"],
  ["down", "head"],
  ["down", "body"],
  ["down", "node0"],
  ["right", "node0"],
  ["down", "node1"],
  ["down", "node2"],
  ["down", "node3"],
  ["down", "*comment*"],
  ["down", "node4"],
  ["right", "node4"],
  ["down", "*text*"],
  ["down", "node5"],
  ["down", "*text*"],
  ["down", "node6"],
  ["down", "*text*"],
  ["down", "*comment*"],
  ["down", "node7"],
  ["right", "node7"],
  ["down", "*text*"],
  ["down", "node8"],
  ["left", "node7"],
  ["left", "node7"],
  ["right", "node7"],
  ["right", "*text*"],
  ["down", "node8"],
  ["down", "*text*"],
  ["down", "node9"],
  ["down", "*text*"],
  ["down", "node10"],
  ["down", "*text*"],
  ["down", "node11"],
  ["down", "*text*"],
  ["down", "node12"],
  ["right", "node12"],
  ["down", "*text*"],
  ["down", "node13"],
  ["down", "node14"],
  ["down", "node15"],
  ["down", "node15"],
  ["down", "node15"],
  ["up", "node14"],
  ["up", "node13"],
  ["up", "*text*"],
  ["up", "node12"],
  ["left", "node12"],
  ["down", "node14"],
  ["home", "*doctype*"],
  ["pagedown", "*text*"],
  ["down", "node5"],
  ["down", "*text*"],
  ["down", "node6"],
  ["down", "*text*"],
  ["down", "*comment*"],
  ["down", "node7"],
  ["left", "node7"],
  ["down", "*text*"],
  ["down", "node9"],
  ["down", "*text*"],
  ["down", "node10"],
  ["pageup", "*text*"],
  ["pageup", "*doctype*"],
  ["down", "html"],
  ["left", "html"],
  ["down", "head"]
];

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

  info("Making sure the markup-view frame is focused");
  inspector.markup._frame.focus();

  info("Starting to iterate through the test data");
  for (let [key, className] of TEST_DATA) {
    info("Testing step: " + key + " to navigate to " + className);
    pressKey(key);

    info("Making sure markup-view children get updated");
    yield waitForChildrenUpdated(inspector);

    info("Checking the right node is selected");
    checkSelectedNode(key, className, inspector);
  }

  // In theory, we should wait for the inspector-updated event at each iteration
  // of the previous loop where we expect the current node to change (because
  // changing the current node ends up refreshing the rule-view, breadcrumbs,
  // ...), but this would make this test a *lot* slower. Instead, having a final
  // catch-all event works too.
  yield inspector.once("inspector-updated");
});

function pressKey(key) {
  switch (key) {
    case "right":
      EventUtils.synthesizeKey("VK_RIGHT", {});
      break;
    case "down":
      EventUtils.synthesizeKey("VK_DOWN", {});
      break;
    case "left":
      EventUtils.synthesizeKey("VK_LEFT", {});
      break;
    case "up":
      EventUtils.synthesizeKey("VK_UP", {});
      break;
    case "pageup":
      EventUtils.synthesizeKey("VK_PAGE_UP", {});
      break;
    case "pagedown":
      EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
      break;
    case "home":
      EventUtils.synthesizeKey("VK_HOME", {});
      break;
  }
}

function checkSelectedNode(key, className, inspector) {
  let node = inspector.selection.nodeFront;

  if (className == "*comment*") {
    is(node.nodeType, Node.COMMENT_NODE,
       "Found a comment after pressing " + key);
  } else if (className == "*text*") {
    is(node.nodeType, Node.TEXT_NODE,
       "Found text after pressing " + key);
  } else if (className == "*doctype*") {
    is(node.nodeType, Node.DOCUMENT_TYPE_NODE,
       "Found the doctype after pressing " + key);
  } else {
    is(node.className, className,
       "Found node: " + className + " after pressing " + key);
  }
}