Clean up asynchronous behavior in some accessibility tests
[WebKit-https.git] / LayoutTests / accessibility / mac / selection-sync.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="textbox" tabindex=0 id="textbox" contenteditable=true>
9 <p>one two three. four five six.</p>
10 </div>
11
12 <p id="description"></p>
13 <div id="console"></div>
14 <div id="notifications"></div>
15
16 <script>
17
18     description("This tests that selection changes originating from accessibility API include AXTextStateSync=true.");
19
20     var AXTextStateChangeTypeSelectionMove = 2;
21     var AXTextStateChangeTypeSelectionExtend = AXTextStateChangeTypeSelectionMove + 1;
22
23     var AXTextSelectionDirectionDiscontiguous = 5;
24
25     var webArea = 0;
26     var count = 0;
27     var results = [];
28     var resultIndex = 0;
29     function notificationCallback(notification, userInfo) {
30         if (notification == "AXSelectedTextChanged") {
31             count++;
32             if (userInfo)
33                 results.push(userInfo);
34             if (count == 5) {
35                 shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
36                 shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionDiscontiguous");
37                 shouldBe("results[resultIndex][\"AXTextStateSync\"]", "true");
38
39                 resultIndex++;
40                 shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
41                 shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionDiscontiguous");
42                 shouldBe("results[resultIndex][\"AXTextStateSync\"]", "true");
43
44                 resultIndex++;
45                 shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
46                 shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionDiscontiguous");
47                 shouldBe("results[resultIndex][\"AXTextStateSync\"]", "true");
48
49                 resultIndex++;
50                 shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
51                 shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionDiscontiguous");
52                 shouldBe("results[resultIndex][\"AXTextStateSync\"]", "true");
53
54                 resultIndex++;
55                 shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
56                 shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionDiscontiguous");
57                 shouldBe("results[resultIndex][\"AXTextStateSync\"]", "true");
58
59                 webArea.removeNotificationListener();
60                 finishJSTest();
61             }
62         }
63     }
64
65     if (window.accessibilityController) {
66         window.jsTestIsAsync = true;
67
68         accessibilityController.enableEnhancedAccessibility(true);
69
70         webArea = accessibilityController.rootElement.childAtIndex(0);
71         var addedNotification = webArea.addNotificationListener(notificationCallback);
72         shouldBe("addedNotification", "true");
73
74         textbox = document.getElementById("textbox");
75         var axTextbox = accessibilityController.accessibleElementById("textbox");
76         axTextbox.takeFocus();
77         axTextbox.setSelectedTextRange(4,0);
78         axTextbox.setSelectedTextRange(0,3);
79
80         var markerThree = axTextbox.textMarkerForIndex(3);
81         var markerFour = axTextbox.textMarkerForIndex(4);
82         var moveRange = axTextbox.textMarkerRangeForMarkers(markerThree, markerThree);
83         var extendRange = axTextbox.textMarkerRangeForMarkers(markerThree, markerFour);
84         webArea.setSelectedVisibleTextRange(moveRange);
85         webArea.setSelectedVisibleTextRange(extendRange);
86     } else
87         debug("window.accessibilityController is not present");
88
89 </script>
90 <script src="../../resources/js-test-post.js"></script>
91 </body>
92 </html>