10078c8fe60ade1312e04be4bac39286c53b76b1
[WebKit-https.git] / LayoutTests / accessibility / mac / accessibility-make-first-responder.html
1 <!DOCTYPE html>
2
3 <html>
4 <head>
5 <script src="../../resources/js-test-pre.js"></script>
6 <script>
7     description("Test that assistiveTechnologyMakeFirstResponder works correctly.");
8     window.jsTestIsAsync = true;
9         
10     function makeWindowFirstResponderUIScript() {
11         return `(function() {
12             uiController.makeWindowContentViewFirstResponder();
13         })();`;
14     }
15
16     function isWindowFirstResponderScript() {
17         return `(function() {
18             return uiController.isWindowContentViewFirstResponder;
19         })();`;
20     }
21     
22     function setfirstResponderSuppressionUIScript(x) {
23         return `(function() {
24             return uiController.firstResponderSuppressionForWebView(${x});
25         })();`;
26     }
27
28     function doTest() {
29         // 1. Make window first responder and suppress the first responder change for web content
30         if (window.testRunner) {
31             testRunner.runUIScript(makeWindowFirstResponderUIScript(), function() {
32                 testRunner.runUIScript(setfirstResponderSuppressionUIScript(true), function() {
33                     testSuppressFirstResponderChange();
34                 });
35             });
36         }
37     }
38     
39     function testSuppressFirstResponderChange() {
40         var input = document.getElementById("input");
41         debug("DOM focus");
42         input.focus();
43         testRunner.runUIScript(isWindowFirstResponderScript(), function(result) {
44             debug("Window is still the first responder: " + result);
45             input.blur();
46             // 2. Now make sure accessibility focus will make web content the first responder.
47             testAccessibilityMakeFirstResonder();
48         });
49     }
50     
51     function testAccessibilityMakeFirstResonder() {
52         if (window.accessibilityController) {
53             var inputObj = accessibilityController.accessibleElementById("input");
54             debug("Accessibility focus")
55             inputObj.takeFocus();
56             testRunner.runUIScript(isWindowFirstResponderScript(), function(result) {
57                 debug("Window is still the first responder: " + result);
58                 finishTest();
59             });
60         }
61     }
62     
63     function finishTest() {
64         // Reset _setShouldSuppressFirstResponderChanges
65         testRunner.runUIScript(setfirstResponderSuppressionUIScript(false), function() {
66             finishJSTest();
67         });
68     }
69         
70     window.addEventListener('load', doTest, false);
71     </script>
72 </head>
73 <body>
74     <input id="input" type="text">
75     <script src="../../resources/js-test-post.js"></script>
76 </body>
77 </html>