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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// Checks for the NodeTabbingOrderHighlighter.
add_task(async function () {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: MAIN_DOMAIN + "doc_accessibility_infobar.html",
},
async function (browser) {
await SpecialPowers.spawn(browser, [], async function () {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);
const {
HighlighterEnvironment,
} = require("resource://devtools/server/actors/highlighters.js");
const {
NodeTabbingOrderHighlighter,
} = require("resource://devtools/server/actors/highlighters/node-tabbing-order.js");
// Checks for updated content for an infobar.
async function testShowHide(highlighter, node, index) {
const shown = highlighter.show(node, { index });
const infoBarText = highlighter.getElement("infobar-text");
ok(shown, "Highlighter is shown.");
is(
parseInt(infoBarText.getTextContent(), 10),
index,
"infobar text content is correct"
);
highlighter.hide();
}
// Start testing. First, create highlighter environment and initialize.
const env = new HighlighterEnvironment();
env.initFromWindow(content.window);
// Wait for loading highlighter environment content to complete before
// creating the highlighter.
await new Promise(resolve => {
const doc = env.document;
function onContentLoaded() {
if (
doc.readyState === "interactive" ||
doc.readyState === "complete"
) {
resolve();
} else {
doc.addEventListener("DOMContentLoaded", onContentLoaded, {
once: true,
});
}
}
onContentLoaded();
});
// Now, we can test the Infobar's index content.
const node = content.document.createElement("div");
content.document.body.append(node);
const highlighter = new NodeTabbingOrderHighlighter(env);
await highlighter.isReady;
info("Showing Node tabbing order highlighter with index");
await testShowHide(highlighter, node, 1);
info("Showing Node tabbing order highlighter with new index");
await testShowHide(highlighter, node, 9);
info(
"Showing and highlighting focused node with the Node tabbing order highlighter"
);
highlighter.show(node, { index: 1 });
highlighter.updateFocus(true);
const { classList } = highlighter.getElement("root");
ok(classList.contains("focused"), "Focus styling is applied");
highlighter.updateFocus(false);
ok(!classList.contains("focused"), "Focus styling is removed");
highlighter.hide();
});
}
);
});
|