AX: defer focusedUIElement notifications
[WebKit-https.git] / LayoutTests / accessibility / mac / aria-menu-item-selected-notification.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test-pre.js"></script>
5 </head>
6 <body id="body">
7
8 <div id="menu" role="menu">
9     <div role="menuitem" id="item1" aria-label="item1" tabindex="0">Menu item 1</div>
10     <div role="menuitemradio" id="item2" aria-label="item2" tabindex="0">Menu item 2</div>
11     <div role="menuitemcheckbox" id="item3" aria-label="item3" tabindex="0">Menu item 3</div>
12 </div>
13
14 <p id="description"></p>
15 <div id="console"></div>
16
17 <script>
18
19     description("This tests that a AXMenuItemSelected notification gets fired when a menuitem is focused.");
20
21     var element = 0;
22     var notification = 0;
23     var notificationCount = 0;
24     function ariaCallback(element, notification) {
25         if (notification == "AXMenuItemSelected") {
26            notificationCount++;
27
28            debug("Received menu item selected notification: " + notification);
29            debug("Menu item selected element: " + element.role);
30            debug("Menu item selected element description: " + element.description + "\n");
31            if (notificationCount == 3) {
32                accessibilityController.removeNotificationListener();
33                finishJSTest();
34            }
35         }
36     }
37
38     if (window.accessibilityController) {
39         window.jsTestIsAsync = true;
40
41         var addedNotification = accessibilityController.addNotificationListener(ariaCallback);
42         accessibilityController.accessibleElementById("menu");
43
44         shouldBe("addedNotification", "true");
45
46         // Trigger notification through focus.
47         document.getElementById("item1").focus();
48
49         setTimeout(function() {
50             // Trigger notification through aria-selected.
51             document.getElementById("item2").setAttribute("aria-selected", "true");
52
53             setTimeout(function() {
54                 // Ensure we don't get a notification when aria-selected is false.
55                 document.getElementById("item2").setAttribute("aria-selected", "false");
56
57                 setTimeout(function() {
58                     // Trigger another notification through focus to ensure we don't
59                     document.getElementById("item3").focus();
60                 }, 1);
61             }, 1);
62         }, 1);
63     }
64
65 </script>
66
67 <script src="../../resources/js-test-post.js"></script>
68 </body>
69 </html>