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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Check that basic keyboard shortcuts work in the web console.
"use strict";
const HTML_FILENAME = `test.html`;
const HTML_CONTENT = `<!DOCTYPE html><p>Test keyboard accessibility</p>
<script>
for (let i = 1; i <= 100; i++) {
console.log("console message " + i);
}
function logTrace() {
const sub = () => console.trace("console trace message");
sub();
}
logTrace();
</script>
`;
const TRACE_FRAME_LINE_REGEX = /test\.html:\d+:?\d*/;
const httpServer = createTestHTTPServer();
httpServer.registerContentType("html", "text/html");
httpServer.registerPathHandler(
"/" + HTML_FILENAME,
function (request, response) {
response.setStatusLine(request.httpVersion, 200, "OK");
response.write(HTML_CONTENT);
}
);
const port = httpServer.identity.primaryPort;
const TEST_URI = `http://localhost:${port}/${HTML_FILENAME}`;
add_task(async function () {
// Force tabfocus for all elements on OSX.
SpecialPowers.pushPrefEnv({ set: [["accessibility.tabfocus", 7]] });
const hud = await openNewTabAndConsole(TEST_URI);
info("Web Console opened");
const outputScroller = hud.ui.outputScroller;
const traceMsgNode = await waitFor(
() => findConsoleAPIMessage(hud, "console trace message"),
"waiting for all the messages to be displayed",
100,
1000
);
// wait for all the stacktrace frames to be rendered.
await waitFor(() =>
traceMsgNode.querySelector(".message-body-wrapper > .stacktrace .frames")
);
let currentPosition = outputScroller.scrollTop;
const bottom = currentPosition;
hud.jsterm.focus();
info("Check Page up keyboard shortcut");
EventUtils.synthesizeKey("KEY_PageUp");
isnot(
outputScroller.scrollTop,
currentPosition,
"scroll position changed after page up"
);
info("Check Page down keyboard shortcut");
currentPosition = outputScroller.scrollTop;
EventUtils.synthesizeKey("KEY_PageDown");
Assert.greater(
outputScroller.scrollTop,
currentPosition,
"scroll position now at bottom"
);
info("Check Home keyboard shortcut");
EventUtils.synthesizeKey("KEY_Home");
is(outputScroller.scrollTop, 0, "scroll position now at top");
info("Check End keyboard shortcut");
EventUtils.synthesizeKey("KEY_End");
const scrollTop = outputScroller.scrollTop;
ok(
scrollTop > 0 && Math.abs(scrollTop - bottom) <= 5,
"scroll position now at bottom"
);
info("Hit Shift-Tab to focus switch to editor mode button");
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
ok(
outputScroller.ownerDocument.activeElement.classList.contains(
"webconsole-input-openEditorButton"
),
"switch to editor mode button is focused"
);
info("Check stacktrace frames can be focused");
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
ok(
outputScroller.ownerDocument.activeElement.closest(".message.trace"),
"The active element is in the trace message"
);
is(
TRACE_FRAME_LINE_REGEX.exec(
outputScroller.ownerDocument.activeElement.innerText
)?.[0],
"test.html:10",
`last frame of the stacktrace is focused ${outputScroller.ownerDocument.activeElement.innerText}`
);
is(
outputScroller.ownerDocument.activeElement.getAttribute("class"),
"frame",
"active element has expected class"
);
info("Hit Tab to navigate to second frame of the stacktrace");
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
ok(
outputScroller.ownerDocument.activeElement.closest(".message.trace"),
"The active element is in the trace message"
);
is(
TRACE_FRAME_LINE_REGEX.exec(
outputScroller.ownerDocument.activeElement.innerText
)?.[0],
"test.html:8",
"second frame of the stacktrace is focused"
);
is(
outputScroller.ownerDocument.activeElement.getAttribute("class"),
"frame",
"active element has expected class"
);
info("Hit Tab to navigate to first frame of the stacktrace");
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
ok(
outputScroller.ownerDocument.activeElement.closest(".message.trace"),
"The active element is in the trace message"
);
is(
TRACE_FRAME_LINE_REGEX.exec(
outputScroller.ownerDocument.activeElement.innerText
)?.[0],
"test.html:7",
"third frame of the stacktrace is focused"
);
is(
outputScroller.ownerDocument.activeElement.getAttribute("class"),
"frame",
"active element has expected class"
);
info("Hit Tab to navigate to the message location");
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
ok(
outputScroller.ownerDocument.activeElement.closest(".message.trace"),
"The active element is in the trace message"
);
is(
outputScroller.ownerDocument.activeElement.getAttribute("class"),
"frame-link-source",
"active element is the console trace message location"
);
is(
TRACE_FRAME_LINE_REGEX.exec(
outputScroller.ownerDocument.activeElement.innerText
)?.[0],
"test.html:7:33",
"active element is expected message location"
);
info("Hit Tab to navigate to the previous message location");
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
ok(
!outputScroller.ownerDocument.activeElement.closest(".message.trace"),
"The active element is not in the trace message"
);
is(
outputScroller.ownerDocument.activeElement.getAttribute("class"),
"frame-link-source",
"active element is the console trace message location"
);
is(
TRACE_FRAME_LINE_REGEX.exec(
outputScroller.ownerDocument.activeElement.innerText
)[0],
"test.html:4:15",
"active element is expected message location"
);
info("Clear output");
hud.jsterm.focus();
info("try ctrl-l to clear output");
let clearShortcut;
if (Services.appinfo.OS === "Darwin") {
clearShortcut = WCUL10n.getStr("webconsole.clear.keyOSX");
} else {
clearShortcut = WCUL10n.getStr("webconsole.clear.key");
}
synthesizeKeyShortcut(clearShortcut);
await waitFor(() => !findAllMessages(hud).length);
ok(isInputFocused(hud), "console was cleared and input is focused");
if (Services.appinfo.OS === "Darwin") {
info("Log a new message from the content page");
const onMessage = waitForMessageByType(
hud,
"another simple text message",
".console-api"
);
SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
content.console.log("another simple text message");
});
await onMessage;
info("Send Cmd-K to clear console");
synthesizeKeyShortcut(WCUL10n.getStr("webconsole.clear.alternativeKeyOSX"));
await waitFor(() => !findAllMessages(hud).length);
ok(
isInputFocused(hud),
"console was cleared as expected with alternative shortcut"
);
}
// Focus filter
info("try ctrl-f to focus filter");
synthesizeKeyShortcut(WCUL10n.getStr("webconsole.find.key"));
ok(!isInputFocused(hud), "input is not focused");
ok(hasFocus(getFilterInput(hud)), "filter input is focused");
info("try ctrl-f when filter is already focused");
synthesizeKeyShortcut(WCUL10n.getStr("webconsole.find.key"));
ok(!isInputFocused(hud), "input is not focused");
is(
getFilterInput(hud),
outputScroller.ownerDocument.activeElement,
"filter input is focused"
);
info("Ctrl-U should open view:source when input is focused");
hud.jsterm.focus();
const onTabOpen = BrowserTestUtils.waitForNewTab(
gBrowser,
url => url.startsWith("view-source:"),
true
);
EventUtils.synthesizeKey("u", { accelKey: true });
await onTabOpen;
ok(
true,
"The view source tab was opened with the expected keyboard shortcut"
);
});
|