AX: Provide API for assistive tech to ignore DOM key event handlers
[WebKit-https.git] / LayoutTests / platform / mac / accessibility / prevent-keyboard-event-dispatch.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <script src="../../../resources/js-test-pre.js"></script>
5     <script src="resources/accessibility-helper.js"></script>
6 </head>
7 <body id="body" onkeydown="return keydown();">
8     <script>
9     function preventKeyboardDOMEventDispatch(webArea) {
10         return webArea.boolAttributeValue("AXPreventKeyboardDOMEventDispatch");
11     }
12     function setPreventKeyboardDOMEventDispatch(webArea, value) {
13         webArea.setBoolAttributeValue("AXPreventKeyboardDOMEventDispatch", value);
14     }
15     function keydown(event) {
16         var element = document.getElementById("keydowncount");
17         element.innerHTML = parseInt(element.innerHTML) + 1;
18         return false;
19     }
20     function keycount() {
21         return document.getElementById("keydowncount").innerHTML;
22     }
23     </script>
24     <div>
25         <p>1</p>
26         <p>2</p>
27         <p id="keydowncount">0<p>
28     </div>
29     <div id="console"></div>
30     <script>
31     description("This tests ignoring javascript key handlers that consume key events.");
32     if (window.testRunner) {
33
34         testRunner.dumpAsText();
35
36         if (window.accessibilityController && window.eventSender) {
37
38             var webArea = clearSelectionAndFocusOnWebArea();
39             accessibilityController.enableEnhancedAccessibility(false);
40             shouldBe("accessibilityController.enhancedAccessibilityEnabled", "false");
41             setPreventKeyboardDOMEventDispatch(webArea, false);
42             shouldBe("preventKeyboardDOMEventDispatch(webArea)", "false");
43
44             // Arrowing before enabling AX and ignore dom handlers won't move the caret
45             shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
46             eventSender.keyDown("rightArrow");
47             shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
48             eventSender.keyDown("rightArrow");
49             shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
50
51             // Validate that the handler received 2 keys events
52             shouldBe("keycount()", "'2'");
53
54             // Enable enhanced accessibility (necessary for accessibility specific selection handling).
55             accessibilityController.enableEnhancedAccessibility(true);
56             shouldBe("accessibilityController.enhancedAccessibilityEnabled", "true");
57
58             // Enable IgnoreDOMKeyEventHandlers so that the javascript handler will be skipped
59             setPreventKeyboardDOMEventDispatch(webArea, true);
60             shouldBe("preventKeyboardDOMEventDispatch(webArea)", "true");
61
62             shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
63             eventSender.keyDown("rightArrow");
64             shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
65             eventSender.keyDown("rightArrow");
66             shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 2'");
67
68             // Validate that the handler didn't receive any more key events
69             shouldBe("keycount()", "'2'");
70
71             setPreventKeyboardDOMEventDispatch(webArea, false);
72         }
73     }
74     </script>
75     <script src="../../../resources/js-test-post.js"></script>
76 </body>
77 </html>