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
|
<!DOCTYPE html>
<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#specially-focusable">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="default-samples">
<a></a>
<a href=""></a>
<button></button>
<input type="hidden">
<input type="button">
<select><option>abc</option></select>
<textarea></textarea>
<summary id="summary-out"></summary>
<details open><summary id="summary-first"></summary><summary id="summary-second"></summary></details>
<div contenteditable="true"></div>
<iframe></iframe>
<svg><a id="svg-a"></a></svg>
<svg><text id="svg-text"></text></svg>
<img>
</div>
<script>
setup({ explicit_done: true });
window.addEventListener("load", runTests);
function runTests() {
const defaultList = [
['a', false],
['a[href]', true],
['button', true],
['input[type="hidden"]', false],
['input[type="button"]', true],
['select', true],
['textarea', true],
['#summary-out', false],
['#summary-first', true],
['#summary-second', false],
['[contenteditable]', true],
['iframe', true],
['#svg-a', false],
['#svg-text', false],
['img', false],
];
for (entry of defaultList) {
test(() => {
var element = document.querySelector('#default-samples ' + entry[0]);
element.focus();
if (entry[1])
assert_equals(document.activeElement, element);
else
assert_not_equals(document.activeElement, element);
}, entry[0] + ' should ' + (entry[1] ? '' : 'not ') + 'be focusable by default.');
}
runTests_tabindex0();
}
</script>
<div id="tabindex-0">
<a tabindex="0"></a>
<svg><a tabindex="0"></a></svg>
<svg><text tabindex="0"></text></svg>
<summary tabindex="0" id="summary-out-tabindex0"></summary>
<details open><summary id="summary-first"></summary><summary tabindex="0" id="summary-second-tabindex0"></summary></details>
<img tabindex="0">
</div>
<script>
function runTests_tabindex0() {
for (element of document.querySelectorAll('#tabindex-0 [tabindex]')) {
var elementDesc = element.tagName;
if (element.id)
elementDesc += '#' + element.id;
test(() => {
element.focus();
assert_equals(document.activeElement, element);
}, elementDesc + ' with tabindex=0 should be focusable.');
}
runTests_tabindex_negative();
}
</script>
<div id="tabindex-negative">
<a tabindex="-1"></a>
<svg><a tabindex="-1"></a></svg>
<svg><text tabindex="-1"></text></svg>
<summary tabindex="-1" id="summary-out-tabindex-negative"></summary>
<details open><summary id="summary-first"></summary><summary tabindex="0" id="summary-second-tabindex-negative"></summary></details>
<img tabindex="-1">
</div>
<script>
function runTests_tabindex_negative() {
for (element of document.querySelectorAll('#tabindex-negative [tabindex]')) {
var elementDesc = element.tagName;
if (element.id)
elementDesc += '#' + element.id;
test(() => {
element.focus();
assert_equals(document.activeElement, element);
}, elementDesc + ' with tabindex=-1 should be focusable.');
}
runTests_tabindex_invalid();
}
</script>
<div id="tabindex-invalid">
<a tabindex="invalid"></a>
<a href="#" tabindex="invalid" id="with-href" data-focusable=true></a>
<svg><a tabindex="invalid"></a></svg>
<svg><a href="#" tabindex="invalid" id="with-href" data-focusable=true></a></svg>
<svg><text tabindex="invalid"></text></svg>
<div tabindex="invalid"></div>
<summary tabindex="invalid" id="summary-out-tabindex-invalid"></summary>
<img tabindex="invalid">
</div>
<script>
function runTests_tabindex_invalid() {
for (element of document.querySelectorAll('#tabindex-invalid [tabindex]')) {
var focusable = element.dataset && element.dataset.focusable;
var elementDesc = element.tagName;
if (element.id)
elementDesc += '#' + element.id;
test(() => {
element.focus();
focusable ? assert_equals(document.activeElement, element)
: assert_not_equals(document.activeElement, element);
}, `${elementDesc} with tabindex=invalid should ${focusable ? "be" : "not be"} focusable.`);
}
done();
}
</script>
</body>
|