Refactoring: Pull all fullscreen code out of Document and into its own helper class
[WebKit-https.git] / LayoutTests / accessibility / win / selection-and-focus.html
1 <html>
2 <head>
3     <script src="../../resources/js-test.js"></script>
4 </head>
5
6 <body>
7
8 <select id="selectElement" multiple title="selectElement">
9     <option SELECTED>Option 0</option>
10     <option>Option 1</option>
11     <option>Option 2</option>
12     <option DISABLED>Option 3</option>
13 </select>
14
15 <select id="selectElement2" title="selectElement">
16     <option SELECTED>Option 0</option>
17     <option>Option 1</option>
18     <option>Option 2</option>
19     <option DISABLED>Option 3</option>
20 </select>
21
22 <p>This tests that we can adjust focus and selection via accessibility API.</p>
23
24 <p id="notDRT">This test should only be run inside of DumpRenderTree.</p>
25
26 <p id="console"></p>
27
28 <script>
29     function dumpSelection(element)
30     {
31         var options = element.options;
32         for (var i = 0; i < options.length; ++i)
33             debug("Option " + i + " is " + (options[i].selected ? "" : "not ") + "selected.");
34         debug("");
35     }
36
37     if (window.testRunner && window.accessibilityController) {
38         document.getElementById("notDRT").style.visibility = "hidden";
39
40         document.body.focus();
41         shouldBe('accessibilityController.focusedElement.role', '"document"');
42
43         var anonymousBlock = accessibilityController.focusedElement.childAtIndex(0);
44         
45         // Focus the select element.
46         var select = anonymousBlock.childAtIndex(0);
47         select.takeFocus();
48         shouldBe('accessibilityController.focusedElement.role', '"AXList"');
49
50         debug("");
51
52         var selectElement = document.getElementById("selectElement");
53
54         // Option 0 selected
55         accessibilityController.focusedElement.childAtIndex(0).takeSelection();
56         dumpSelection(selectElement);
57
58         // Option 1 selected
59         accessibilityController.focusedElement.childAtIndex(1).takeSelection();
60         dumpSelection(selectElement);
61
62         // Options 1, 2 selected
63         accessibilityController.focusedElement.childAtIndex(2).addSelection();
64         dumpSelection(selectElement);
65
66         // Option 2 selected
67         accessibilityController.focusedElement.childAtIndex(1).removeSelection();
68         dumpSelection(selectElement);
69
70         // Option 2 selected
71         accessibilityController.focusedElement.childAtIndex(0).removeSelection();
72         dumpSelection(selectElement);
73
74         // Options 0, 2 selected
75         accessibilityController.focusedElement.childAtIndex(0).addSelection();
76         dumpSelection(selectElement);
77
78         // Options 0, 2 selected
79         accessibilityController.focusedElement.childAtIndex(0).addSelection();
80         dumpSelection(selectElement);
81
82         // Option 2 selected
83         accessibilityController.focusedElement.childAtIndex(0).removeSelection();
84         dumpSelection(selectElement);
85
86         // No options selected
87         accessibilityController.focusedElement.childAtIndex(2).removeSelection();
88         dumpSelection(selectElement);
89
90         // No options selected (option at index 3 is disabled)
91         accessibilityController.focusedElement.childAtIndex(3).addSelection();
92         dumpSelection(selectElement);
93
94         debug("== single select ==");
95
96         var selectElement2 = document.getElementById("selectElement2");
97         selectElement2.focus();
98
99         var popupMenu = accessibilityController.focusedElement.childAtIndex(0);
100
101         // Option 0 is selected
102         popupMenu.childAtIndex(0).takeSelection();
103         dumpSelection(selectElement2);
104
105         // Option 1 selected
106         popupMenu.childAtIndex(1).takeSelection();
107         dumpSelection(selectElement2);
108
109         // Options 1 selected - addSelection() is not valid for single-select.
110         popupMenu.childAtIndex(2).addSelection();
111         dumpSelection(selectElement2);
112
113         // Options 1 selected - removeSelection() is not valid for single-select.
114         popupMenu.childAtIndex(1).removeSelection();
115         dumpSelection(selectElement2);
116
117         // Options 1 selected - option at index 3 is disabled
118         popupMenu.childAtIndex(3).takeSelection();
119         dumpSelection(selectElement2);
120     }
121 </script>
122 </body>
123 </html>