|
1 | 1 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
2 | 2 | <html>
|
3 | 3 | <head>
|
4 |
| -<script src="../resources/js-test-pre.js"></script> |
| 4 | +<script src="../resources/js-test.js"></script> |
| 5 | +<script src="../resources/accessibility-helper.js"></script> |
5 | 6 | </head>
|
6 |
| -<body id="body"> |
| 7 | +<body> |
7 | 8 |
|
8 | 9 | <ul id="tablist_1" role="tablist">
|
9 |
| -<li id="tab_1" role="tab" tabindex="-1" class="">Crust</li> |
10 |
| -<li id="tab_2" role="tab" tabindex="-1" aria-controls="panel_2" class="">Veges</li> |
| 10 | + <li id="tab_1" role="tab" tabindex="-1" class="">Crust</li> |
| 11 | + <li id="tab_2" role="tab" tabindex="-1" aria-controls="panel_2" class="">Veges</li> |
11 | 12 | </ul>
|
12 | 13 |
|
13 | 14 | <h3 tabindex=0 id="elementOutsideTabs">Test</h3>
|
14 | 15 |
|
15 | 16 | <div id="panel_1" role="tabpanel" >
|
16 |
| -<h3 tabindex=0>Select Crust</h3> |
| 17 | + <h3 tabindex=0>Select Crust</h3> |
17 | 18 | </div>
|
18 | 19 |
|
19 | 20 | <div id="panel_2" role="tabpanel" >
|
20 |
| -<h2 id="itemInPanel2" tabindex=0>Select Crust</h2> |
| 21 | + <h2 id="itemInPanel2" tabindex=0>Select Crust</h2> |
21 | 22 | </div>
|
22 | 23 |
|
23 |
| - |
24 |
| -<p id="description"></p> |
25 |
| -<div id="console"></div> |
26 |
| - |
27 | 24 | <script>
|
28 |
| - |
29 |
| - description("This tests that the aria tab item becomes selected if either aria-selected is used, or if aria-controls points to an item that contains KB focus."); |
30 |
| - |
31 |
| - if (window.accessibilityController) { |
32 |
| - |
33 |
| - var tabList = accessibilityController.accessibleElementById('tablist_1'); |
34 |
| - var tab1 = tabList.childAtIndex(0); |
35 |
| - var tab2 = tabList.childAtIndex(1); |
36 |
| - |
37 |
| - // we set KB focus to something in panel_2, which means that tab2 should become selected |
38 |
| - // because it aria-controls panel_2 |
39 |
| - var panel2Item = document.getElementById("itemInPanel2"); |
40 |
| - panel2Item.focus(); |
41 |
| - |
42 |
| - shouldBe("tab2.isSelected", "true"); |
43 |
| - |
44 |
| - // reset KB focus and verify that neither tab is selected |
45 |
| - document.getElementById("elementOutsideTabs").focus(); |
46 |
| - shouldBe("tab1.isSelected", "false"); |
47 |
| - shouldBe("tab2.isSelected", "false"); |
48 |
| - |
49 |
| - // Now we set aria-selected to be true on tab1 so that it should become selected |
50 |
| - document.getElementById("tab_1").setAttribute("aria-selected", "true"); |
51 |
| - shouldBe("tab1.isSelected", "true"); |
52 |
| - } |
53 |
| - |
| 25 | +var output = "This tests that the aria tab item becomes selected if either aria-selected is used, or if aria-controls points to an item that contains KB focus.\n\n"; |
| 26 | + |
| 27 | +if (window.accessibilityController) { |
| 28 | + window.jsTestIsAsync = true; |
| 29 | + |
| 30 | + var tabList = accessibilityController.accessibleElementById('tablist_1'); |
| 31 | + var tab1 = tabList.childAtIndex(0); |
| 32 | + var tab2 = tabList.childAtIndex(1); |
| 33 | + |
| 34 | + var panel2Item = document.getElementById("itemInPanel2"); |
| 35 | + panel2Item.focus(); |
| 36 | + setTimeout(async () => { |
| 37 | + // Set KB focus to something in #panel_2, which means that #tab2 should become selected because it aria-controls #panel_2. |
| 38 | + output += await expectAsync("tab2.isSelected", "true"); |
| 39 | + |
| 40 | + output += "\nRemoving aria-controls from #tab_2\n"; |
| 41 | + document.getElementById("tab_2").removeAttribute("aria-controls"); |
| 42 | + // #tab_2 no longer aria-controls something with KB focus, so it should become unselected. |
| 43 | + output += await expectAsync("tab2.isSelected", "false"); |
| 44 | + |
| 45 | + output += "\nResetting #tab_2 aria-controls to be '#panel_2'\n"; |
| 46 | + document.getElementById("tab_2").setAttribute("aria-controls", "panel_2"); |
| 47 | + output += await expectAsync("tab2.isSelected", "true"); |
| 48 | + |
| 49 | + // Reset KB focus and verify that neither tab is selected. |
| 50 | + document.getElementById("elementOutsideTabs").focus(); |
| 51 | + output += expect("tab1.isSelected", "false"); |
| 52 | + output += expect("tab2.isSelected", "false"); |
| 53 | + |
| 54 | + // Now we set aria-selected to be true on tab1 so that it should become selected |
| 55 | + document.getElementById("tab_1").setAttribute("aria-selected", "true"); |
| 56 | + output += expect("tab1.isSelected", "true"); |
| 57 | + |
| 58 | + debug(output); |
| 59 | + finishJSTest(); |
| 60 | + }, 0); |
| 61 | +} |
54 | 62 | </script>
|
55 |
| - |
56 |
| -<script src="../resources/js-test-post.js"></script> |
57 | 63 | </body>
|
58 | 64 | </html>
|
| 65 | + |
0 commit comments