browser_test_select.js (9687B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /* import-globals-from ../../mochitest/selectable.js */ 8 /* import-globals-from ../../mochitest/states.js */ 9 10 // //////////////////////////////////////////////////////////////////////// 11 // select@size="1" aka combobox 12 addAccessibleTask( 13 `<select id="combobox"> 14 <option id="item1">option1</option> 15 <option id="item2">option2</option> 16 </select>`, 17 async function (browser, docAcc) { 18 info("select@size='1' aka combobox"); 19 let combobox = findAccessibleChildByID(docAcc, "combobox"); 20 let comboboxList = combobox.firstChild; 21 ok( 22 isAccessible(comboboxList, [nsIAccessibleSelectable]), 23 "No selectable accessible for combobox" 24 ); 25 26 let select = getAccessible(comboboxList, [nsIAccessibleSelectable]); 27 testSelectableSelection(select, ["item1"]); 28 29 // select 2nd item 30 let promise = Promise.all([ 31 waitForStateChange("item2", STATE_SELECTED, true), 32 waitForStateChange("item1", STATE_SELECTED, false), 33 ]); 34 select.addItemToSelection(1); 35 await promise; 36 testSelectableSelection(select, ["item2"], "addItemToSelection(1): "); 37 38 // unselect 2nd item, 1st item gets selected automatically 39 promise = Promise.all([ 40 waitForStateChange("item2", STATE_SELECTED, false), 41 waitForStateChange("item1", STATE_SELECTED, true), 42 ]); 43 select.removeItemFromSelection(1); 44 await promise; 45 testSelectableSelection(select, ["item1"], "removeItemFromSelection(1): "); 46 47 // doesn't change selection 48 is(select.selectAll(), false, "No way to select all items in combobox"); 49 testSelectableSelection(select, ["item1"], "selectAll: "); 50 51 // doesn't change selection 52 select.unselectAll(); 53 testSelectableSelection(select, ["item1"], "unselectAll: "); 54 }, 55 { 56 chrome: true, 57 topLevel: true, 58 iframe: true, 59 remoteIframe: true, 60 } 61 ); 62 63 // //////////////////////////////////////////////////////////////////////// 64 // select@size="1" with optgroups 65 addAccessibleTask( 66 `<select id="combobox"> 67 <option id="item1">option1</option> 68 <optgroup>optgroup 69 <option id="item2">option2</option> 70 </optgroup> 71 </select>`, 72 async function (browser, docAcc) { 73 info("select@size='1' with optgroups"); 74 let combobox = findAccessibleChildByID(docAcc, "combobox"); 75 let comboboxList = combobox.firstChild; 76 ok( 77 isAccessible(comboboxList, [nsIAccessibleSelectable]), 78 "No selectable accessible for combobox" 79 ); 80 81 let select = getAccessible(comboboxList, [nsIAccessibleSelectable]); 82 testSelectableSelection(select, ["item1"]); 83 84 let promise = Promise.all([ 85 waitForStateChange("item2", STATE_SELECTED, true), 86 waitForStateChange("item1", STATE_SELECTED, false), 87 ]); 88 select.addItemToSelection(1); 89 await promise; 90 testSelectableSelection(select, ["item2"], "addItemToSelection(1): "); 91 92 promise = Promise.all([ 93 waitForStateChange("item2", STATE_SELECTED, false), 94 waitForStateChange("item1", STATE_SELECTED, true), 95 ]); 96 select.removeItemFromSelection(1); 97 await promise; 98 testSelectableSelection(select, ["item1"], "removeItemFromSelection(1): "); 99 100 is(select.selectAll(), false, "No way to select all items in combobox"); 101 testSelectableSelection(select, ["item1"]); 102 103 select.unselectAll(); 104 testSelectableSelection(select, ["item1"]); 105 }, 106 { 107 chrome: true, 108 topLevel: true, 109 iframe: true, 110 remoteIframe: true, 111 } 112 ); 113 114 // //////////////////////////////////////////////////////////////////////// 115 // select@size="4" aka single selectable listbox 116 addAccessibleTask( 117 `<select id="listbox" size="4"> 118 <option id="item1">option1</option> 119 <option id="item2">option2</option> 120 </select>`, 121 async function (browser, docAcc) { 122 info("select@size='4' aka single selectable listbox"); 123 let select = findAccessibleChildByID(docAcc, "listbox", [ 124 nsIAccessibleSelectable, 125 ]); 126 testSelectableSelection(select, []); 127 128 // select 2nd item 129 let promise = waitForStateChange("item2", STATE_SELECTED, true); 130 select.addItemToSelection(1); 131 await promise; 132 testSelectableSelection(select, ["item2"], "addItemToSelection(1): "); 133 134 // unselect 2nd item, 1st item gets selected automatically 135 promise = waitForStateChange("item2", STATE_SELECTED, false); 136 select.removeItemFromSelection(1); 137 await promise; 138 testSelectableSelection(select, [], "removeItemFromSelection(1): "); 139 140 // doesn't change selection 141 is( 142 select.selectAll(), 143 false, 144 "No way to select all items in single selectable listbox" 145 ); 146 testSelectableSelection(select, [], "selectAll: "); 147 148 // doesn't change selection 149 select.unselectAll(); 150 testSelectableSelection(select, [], "unselectAll: "); 151 }, 152 { 153 chrome: true, 154 topLevel: true, 155 iframe: true, 156 remoteIframe: true, 157 } 158 ); 159 160 // //////////////////////////////////////////////////////////////////////// 161 // select@size="4" with optgroups, single selectable 162 addAccessibleTask( 163 `<select id="listbox" size="4"> 164 <option id="item1">option1</option> 165 <optgroup>optgroup> 166 <option id="item2">option2</option> 167 </optgroup> 168 </select>`, 169 async function (browser, docAcc) { 170 info("select@size='4' with optgroups, single selectable"); 171 let select = findAccessibleChildByID(docAcc, "listbox", [ 172 nsIAccessibleSelectable, 173 ]); 174 testSelectableSelection(select, []); 175 176 let promise = waitForStateChange("item2", STATE_SELECTED, true); 177 select.addItemToSelection(1); 178 await promise; 179 testSelectableSelection(select, ["item2"]); 180 181 promise = waitForStateChange("item2", STATE_SELECTED, false); 182 select.removeItemFromSelection(1); 183 await promise; 184 testSelectableSelection(select, []); 185 186 is( 187 select.selectAll(), 188 false, 189 "No way to select all items in single selectable listbox" 190 ); 191 testSelectableSelection(select, []); 192 193 select.unselectAll(); 194 testSelectableSelection(select, []); 195 }, 196 { 197 chrome: true, 198 topLevel: true, 199 iframe: true, 200 remoteIframe: true, 201 } 202 ); 203 204 // //////////////////////////////////////////////////////////////////////// 205 // select@size="4" multiselect aka listbox 206 addAccessibleTask( 207 `<select id="listbox" size="4" multiple="true"> 208 <option id="item1">option1</option> 209 <option id="item2">option2</option> 210 </select>`, 211 async function (browser, docAcc) { 212 info("select@size='4' multiselect aka listbox"); 213 let select = findAccessibleChildByID(docAcc, "listbox", [ 214 nsIAccessibleSelectable, 215 ]); 216 await testMultiSelectable( 217 select, 218 ["item1", "item2"], 219 "select@size='4' multiselect aka listbox " 220 ); 221 }, 222 { 223 chrome: true, 224 topLevel: true, 225 iframe: true, 226 remoteIframe: true, 227 } 228 ); 229 230 // //////////////////////////////////////////////////////////////////////// 231 // select@size="4" multiselect with optgroups 232 addAccessibleTask( 233 `<select id="listbox" size="4" multiple="true"> 234 <option id="item1">option1</option> 235 <optgroup>optgroup> 236 <option id="item2">option2</option> 237 </optgroup> 238 </select>`, 239 async function (browser, docAcc) { 240 info("select@size='4' multiselect with optgroups"); 241 let select = findAccessibleChildByID(docAcc, "listbox", [ 242 nsIAccessibleSelectable, 243 ]); 244 await testMultiSelectable( 245 select, 246 ["item1", "item2"], 247 "select@size='4' multiselect aka listbox " 248 ); 249 }, 250 { 251 chrome: true, 252 topLevel: true, 253 iframe: true, 254 remoteIframe: true, 255 } 256 ); 257 258 // //////////////////////////////////////////////////////////////////////// 259 // multiselect with coalesced selection event 260 addAccessibleTask( 261 `<select id="listbox" size="4" multiple="true"> 262 <option id="item1">option1</option> 263 <option id="item2">option2</option> 264 <option id="item3">option3</option> 265 <option id="item4">option4</option> 266 <option id="item5">option5</option> 267 <option id="item6">option6</option> 268 <option id="item7">option7</option> 269 <option id="item8">option8</option> 270 <option id="item9">option9</option> 271 </select>`, 272 async function (browser, docAcc) { 273 info("select@size='4' multiselect with coalesced selection event"); 274 let select = findAccessibleChildByID(docAcc, "listbox", [ 275 nsIAccessibleSelectable, 276 ]); 277 await testMultiSelectable( 278 select, 279 [ 280 "item1", 281 "item2", 282 "item3", 283 "item4", 284 "item5", 285 "item6", 286 "item7", 287 "item8", 288 "item9", 289 ], 290 "select@size='4' multiselect with coalesced selection event " 291 ); 292 }, 293 { 294 chrome: false, 295 topLevel: true, 296 iframe: false, 297 remoteIframe: false, 298 } 299 ); 300 301 /** 302 * Ensure that we don't assert when dealing with defunct items in selection 303 * events dropped due to coalescence (bug 1800755). 304 */ 305 addAccessibleTask( 306 ` 307 <form id="form"> 308 <select id="select"> 309 <option> 310 <optgroup id="optgroup"> 311 <option> 312 </optgroup> 313 </select> 314 </form> 315 `, 316 async function (browser) { 317 let selected = waitForEvent(EVENT_SELECTION_WITHIN, "select"); 318 await invokeContentTask(browser, [], () => { 319 const form = content.document.getElementById("form"); 320 const select = content.document.getElementById("select"); 321 const optgroup = content.document.getElementById("optgroup"); 322 form.reset(); 323 select.selectedIndex = 1; 324 select.add(optgroup); 325 select.item(0).remove(); 326 }); 327 await selected; 328 } 329 );