|
8 | 8 |
|
9 | 9 | <button id="button" aria-expanded="false">
|
10 | 10 |
|
| 11 | +<button id="show-popover-btn" popovertarget="mypopover" popovertargetaction="show">Show popover</button> |
| 12 | +<button id="hide-popover-btn" popovertarget="mypopover" popovertargetaction="hide">Hide popover</button> |
| 13 | +<div id="mypopover" popover>Popover content</div> |
| 14 | + |
11 | 15 | <script>
|
12 |
| - let output = "This tests that aria-expanded changes will send notifications.\n"; |
| 16 | +let output = "This tests that expanded notifications will be sent when the appropriate changes occur.\n"; |
13 | 17 |
|
14 |
| - let notificationCount = 0; |
15 |
| - function notificationCallback(element, notification) { |
16 |
| - if (notification == "AXExpandedChanged") { |
17 |
| - notificationCount++; |
| 18 | +let notificationCount = 0; |
| 19 | +function notificationCallback(element, notification) { |
| 20 | + if (notification == "AXExpandedChanged") { |
| 21 | + notificationCount++; |
18 | 22 |
|
19 |
| - output += `Received notification: ${notification}\n`; |
20 |
| - output += `Expanded status: ${element.isExpanded}\n`; |
21 |
| - } |
| 23 | + output += `Received notification: ${notification}\n`; |
| 24 | + output += `Expanded status: ${element.isExpanded}\n`; |
22 | 25 | }
|
| 26 | +} |
23 | 27 |
|
24 |
| - if (window.accessibilityController) { |
25 |
| - window.jsTestIsAsync = true; |
| 28 | +if (window.accessibilityController) { |
| 29 | + window.jsTestIsAsync = true; |
26 | 30 |
|
27 |
| - accessibilityController.addNotificationListener(notificationCallback); |
28 |
| - let button = accessibilityController.accessibleElementById("button"); |
29 |
| - output += `Initial expanded status: ${button.isExpanded}\n`; |
| 31 | + accessibilityController.addNotificationListener(notificationCallback); |
| 32 | + let button = accessibilityController.accessibleElementById("button"); |
| 33 | + output += `Initial expanded status: ${button.isExpanded}\n`; |
30 | 34 |
|
31 |
| - document.getElementById("button").setAttribute("aria-expanded", "true"); |
32 |
| - setTimeout(async () => { |
33 |
| - await waitFor(() => { |
34 |
| - return button.isExpanded; |
35 |
| - }); |
| 35 | + document.getElementById("button").setAttribute("aria-expanded", "true"); |
| 36 | + setTimeout(async () => { |
| 37 | + await waitFor(() => button.isExpanded); |
36 | 38 |
|
37 |
| - document.getElementById("button").setAttribute("aria-expanded", "false"); |
38 |
| - await waitFor(() => { |
39 |
| - return !button.isExpanded; |
40 |
| - }); |
| 39 | + document.getElementById("button").setAttribute("aria-expanded", "false"); |
| 40 | + await waitFor(() => !button.isExpanded); |
| 41 | + await waitFor(() => notificationCount == 2); |
41 | 42 |
|
42 |
| - await waitFor(() => { |
43 |
| - return notificationCount == 2; |
44 |
| - }); |
| 43 | + // Now test popover. |
| 44 | + output += expect("accessibilityController.accessibleElementById('show-popover-btn').isExpanded", "false"); |
| 45 | + output += expect("accessibilityController.accessibleElementById('hide-popover-btn').isExpanded", "false"); |
45 | 46 |
|
46 |
| - debug(output); |
47 |
| - accessibilityController.removeNotificationListener(); |
48 |
| - finishJSTest(); |
49 |
| - }, 0); |
50 |
| - } |
| 47 | + document.getElementById("show-popover-btn").click(); |
| 48 | + await waitFor(() => notificationCount == 3); |
| 49 | + // We expanded the popover via #show-popover-btn, but #hide-popover-btn (which is also linked to the popover) should be considered expanded now as well. |
| 50 | + output += await expectAsync("accessibilityController.accessibleElementById('hide-popover-btn').isExpanded", "true"); |
| 51 | + |
| 52 | + document.getElementById("hide-popover-btn").click(); |
| 53 | + await waitFor(() => notificationCount == 4); |
| 54 | + output += await expectAsync("accessibilityController.accessibleElementById('show-popover-btn').isExpanded", "false"); |
| 55 | + |
| 56 | + debug(output); |
| 57 | + accessibilityController.removeNotificationListener(); |
| 58 | + finishJSTest(); |
| 59 | + }, 0); |
| 60 | +} |
51 | 61 | </script>
|
52 | 62 | </body>
|
53 | 63 | </html>
|
0 commit comments