summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/selectable/test_select.html
blob: 324831a498ef84189ae06d51f039b93d8a028e5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<html>

<head>
  <title>nsIAccessibleSelectable HTML select testing</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  </style>

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../states.js"></script>
  <script type="application/javascript"
          src="../selectable.js"></script>

  <script type="application/javascript">

    function doTest() {
      // ////////////////////////////////////////////////////////////////////////
      // select@size="1" aka combobox

      var id = "combobox";
      var combobox = getAccessible(id);
      var comboboxList = combobox.firstChild;
      ok(isAccessible(comboboxList, [nsIAccessibleSelectable]),
         "No selectable accessible for list of " + id);

      var select = getAccessible(comboboxList, [nsIAccessibleSelectable]);
      testSelectableSelection(select, [ "cb1_item1" ]);

      // select 2nd item
      select.addItemToSelection(1);
      testSelectableSelection(select, [ "cb1_item2" ], "addItemToSelection(1): ");

      // unselect 2nd item, 1st item gets selected automatically
      select.removeItemFromSelection(1);
      testSelectableSelection(select, [ "cb1_item1" ],
                              "removeItemFromSelection(1): ");

      // doesn't change selection
      is(select.selectAll(), false,
         "No way to select all items in combobox '" + id + "'");
      testSelectableSelection(select, [ "cb1_item1" ], "selectAll: ");

      // doesn't change selection
      select.unselectAll();
      testSelectableSelection(select, [ "cb1_item1" ], "unselectAll: ");

      // ////////////////////////////////////////////////////////////////////////
      // select@size="1" with optgroups

      id = "combobox2";
      combobox = getAccessible(id);
      comboboxList = combobox.firstChild;
      ok(isAccessible(comboboxList, [nsIAccessibleSelectable]),
         "No selectable accessible for list of " + id);

      select = getAccessible(comboboxList, [nsIAccessibleSelectable]);
      testSelectableSelection(select, [ "cb2_item1" ]);

      select.addItemToSelection(1);
      testSelectableSelection(select, [ "cb2_item2" ]);

      select.removeItemFromSelection(1);
      testSelectableSelection(select, [ "cb2_item1" ]);

      is(select.selectAll(), false,
         "No way to select all items in combobox " + id + "'");
      testSelectableSelection(select, [ "cb2_item1" ]);

      select.unselectAll();
      testSelectableSelection(select, [ "cb2_item1" ]);

      // ////////////////////////////////////////////////////////////////////////
      // select@size="4" aka single selectable listbox

      id = "listbox";
      ok(isAccessible(id, [nsIAccessibleSelectable]),
         "No selectable accessible for " + id);

      select = getAccessible(id, [nsIAccessibleSelectable]);
      testSelectableSelection(select, [ ]);

      // select 2nd item
      select.addItemToSelection(1);
      testSelectableSelection(select, [ "lb1_item2" ], "addItemToSelection(1): ");

      // unselect 2nd item, 1st item gets selected automatically
      select.removeItemFromSelection(1);
      testSelectableSelection(select, [ ],
                              "removeItemFromSelection(1): ");

      // doesn't change selection
      is(select.selectAll(), false,
         "No way to select all items in single selectable listbox '" + id + "'");
      testSelectableSelection(select, [ ], "selectAll: ");

      // doesn't change selection
      select.unselectAll();
      testSelectableSelection(select, [ ], "unselectAll: ");

      // ////////////////////////////////////////////////////////////////////////
      // select@size="4" with optgroups, single selectable

      id = "listbox2";
      ok(isAccessible(id, [nsIAccessibleSelectable]),
         "No selectable accessible for " + id);

      select = getAccessible(id, [nsIAccessibleSelectable]);
      testSelectableSelection(select, [ ]);

      select.addItemToSelection(1);
      testSelectableSelection(select, [ "lb2_item2" ]);

      select.removeItemFromSelection(1);
      testSelectableSelection(select, [ ]);

      is(select.selectAll(), false,
         "No way to select all items in single selectable listbox " + id + "'");
      testSelectableSelection(select, [ ]);

      select.unselectAll();
      testSelectableSelection(select, [ ]);

      // ////////////////////////////////////////////////////////////////////////
      // select@size="4" multiselect aka listbox

      id = "listbox3";
      ok(isAccessible(id, [nsIAccessibleSelectable]),
         "No selectable accessible for " + id);

      select = getAccessible(id, [nsIAccessibleSelectable]);
      testSelectableSelection(select, [ ]);

      select.addItemToSelection(0);
      testSelectableSelection(select, [ "lb3_item1" ], "addItemToSelection: ");

      select.removeItemFromSelection(0);
      testSelectableSelection(select, [ ], "removeItemFromSelection: ");

      is(select.selectAll(), true,
         "All items in listbox '" + id + "' should be selected");
      testSelectableSelection(select, [ "lb3_item1", "lb3_item2"],
                              "selectAll: ");

      select.unselectAll();
      testSelectableSelection(select, [ ], "unselectAll: ");

      // ////////////////////////////////////////////////////////////////////////
      // select@size="4" multiselect with optgroups

      id = "listbox4";
      ok(isAccessible(id, [nsIAccessibleSelectable]),
         "No selectable accessible for " + id);

      select = getAccessible(id, [nsIAccessibleSelectable]);
      testSelectableSelection(select, [ ]);

      select.addItemToSelection(0);
      testSelectableSelection(select, [ "lb4_item1" ]);

      select.removeItemFromSelection(0);
      testSelectableSelection(select, [ ]);

      is(select.selectAll(), true,
         "All items in listbox '" + id + "' should be selected");
      testSelectableSelection(select, [ "lb4_item1", "lb4_item2"]);

      select.unselectAll();
      testSelectableSelection(select, [ ]);

      SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTest);
  </script>

</head>

<body>

  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=530014"
     title="ARIA single selectable widget should implement nsIAccessibleSelectable">
    Mozilla Bug 530014
  </a><br>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=590176"
     title="add pseudo SelectAccessible interface">
    Mozilla Bug 590176
  </a><br>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>

  <select id="combobox">
    <option id="cb1_item1">option1</option>
    <option id="cb1_item2">option2</option>
  </select>

  <select id="combobox2">
    <option id="cb2_item1">option1</option>
    <optgroup>optgroup
      <option id="cb2_item2">option2</option>
    </optgroup>
  </select>

  <select id="listbox" size="4">
    <option id="lb1_item1">option1</option>
    <option id="lb1_item2">option2</option>
  </select>

  <select id="listbox2" size="4">
    <option id="lb2_item1">option1</option>
    <optgroup>optgroup>
      <option id="lb2_item2">option2</option>
    </optgroup>
  </select>

  <select id="listbox3" size="4" multiple="true">
    <option id="lb3_item1">option1</option>
    <option id="lb3_item2">option2</option>
  </select>

  <select id="listbox4" size="4" multiple="true">
    <option id="lb4_item1">option1</option>
    <optgroup>optgroup>
      <option id="lb4_item2">option2</option>
    </optgroup>
  </select>

</body>
</html>