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
|
<html>
<head>
<title>Test removal of focused accessible</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../states.js"></script>
<script type="application/javascript"
src="../promisified-events.js"></script>
<script type="application/javascript">
function focusableStateChange(id, enabled) {
return [EVENT_STATE_CHANGE, e => {
e.QueryInterface(nsIAccessibleStateChangeEvent);
return getAccessible(id) == e.accessible &&
e.state == STATE_FOCUSABLE && (enabled == undefined || e.isEnabled == enabled);
}];
}
function editableStateChange(id, enabled) {
return [EVENT_STATE_CHANGE, e => {
e.QueryInterface(nsIAccessibleStateChangeEvent);
return getAccessible(id) == e.accessible &&
e.state == EXT_STATE_EDITABLE && e.isExtraState &&
(enabled == undefined || e.isEnabled == enabled);
}];
}
async function doTests() {
info("disable buttons.");
// Expect focusable change with 'disabled',
// and don't expect it with 'aria-disabled'.
let p = waitForEvents({
expected: [focusableStateChange("button2", false)],
unexpected: [focusableStateChange("button1")]
});
getNode("button1").setAttribute("aria-disabled", "true");
getNode("button2").disabled = true;
await p;
info("re-enable button");
// Expect focusable change with 'disabled',
// and don't expect it with 'aria-disabled'.
p = waitForEvents({
expected: [focusableStateChange("button2", true)],
unexpected: [focusableStateChange("button1")]
});
getNode("button1").setAttribute("aria-disabled", "false");
getNode("button2").disabled = false;
await p;
info("add tabindex");
// Expect focusable change on non-input,
// and don't expect event on an already focusable input.
p = waitForEvents({
expected: [focusableStateChange("div", true)],
unexpected: [focusableStateChange("button2")]
});
getNode("button2").tabIndex = "0";
getNode("div").tabIndex = "0";
await p;
info("remove tabindex");
// Expect focusable change when removing tabindex.
p = waitForEvent(...focusableStateChange("div", false));
getNode("div").removeAttribute("tabindex");
await p;
info("add contenteditable");
// Expect editable change on non-input,
// and don't expect event on a native input.
p = waitForEvents({
expected: [focusableStateChange("div", true), editableStateChange("div", true)],
unexpected: [focusableStateChange("input"), editableStateChange("input")]
});
getNode("input").contentEditable = true;
getNode("div").contentEditable = true;
await p;
info("remove contenteditable");
// Expect editable change on non-input,
// and don't expect event on a native input.
p = waitForEvents({
expected: [focusableStateChange("div", false), editableStateChange("div", false)],
unexpected: [focusableStateChange("input"), editableStateChange("input")]
});
getNode("input").contentEditable = false;
getNode("div").contentEditable = false;
await p;
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTests);
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<button id="button1"></button>
<button id="button2"></button>
<div id="div">Hello</div>
<input id="input" value="Hello">
</body>
</html>
|