Clean up asynchronous behavior in some accessibility tests
[WebKit-https.git] / LayoutTests / accessibility / mac / selected-rows-table.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 role="grid" id="grid" tabindex="0">
9
10 <div role="row" aria-selected="true" id="row0">
11   <span role="gridcell">a</span>
12 </div>
13
14 <Br><Br>
15
16 <div role="row">
17  <span role="gridcell">b</span>
18 </div>
19
20 <br><br>
21
22 <div aria-selected="true" role="row">
23   <span role="gridcell">c</span>
24 </div>
25
26 </div>
27
28 <p id="description"></p>
29 <div id="console"></div>
30 <div id="notifications"></div>
31
32 <script>
33
34     description("This tests that the selected rows of a table are exposed correctly and that when they change, a notification is sent.");
35
36     var axTree = 0;
37     function notifyCallback(notification) {  
38         document.getElementById("notifications").innerHTML += "Notification: " + notification + "<br>";
39         if (notification == "AXSelectedRowsChanged") {
40             axTree.removeNotificationListener();
41             finishJSTest();
42         }
43     }
44
45     if (window.accessibilityController) {
46         window.jsTestIsAsync = true;
47
48         document.getElementById("grid").focus();
49
50         axTree = window.accessibilityController.focusedElement;
51
52         var addedNotification = axTree.addNotificationListener(notifyCallback);
53         shouldBe("addedNotification", "true");
54
55         // First row is selected.
56         shouldBeTrue("axTree.selectedRowAtIndex(0).isEqual(axTree.rowAtIndex(0))");
57
58         // Third row is selected.
59         shouldBeTrue("axTree.selectedRowAtIndex(1).isEqual(axTree.rowAtIndex(2))");
60
61         // Change the selected state to ensure the notification is sent.
62         document.getElementById("row0").setAttribute("aria-selected", "false");
63     } else
64         debug("window.accessibilityController is not present");
65
66 </script>
67
68 <script src="../../resources/js-test-post.js"></script>
69 </body>
70 </html>