Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for Form History Autocomplete</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 7 | <script type="text/javascript" src="satchel_common.js"></script> |
michael@0 | 8 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 9 | </head> |
michael@0 | 10 | <body> |
michael@0 | 11 | Form History test: form field autocomplete |
michael@0 | 12 | <p id="display"></p> |
michael@0 | 13 | |
michael@0 | 14 | <!-- We presumably can't hide the content for this test. The large top padding is to allow |
michael@0 | 15 | listening for scrolls to occur. --> |
michael@0 | 16 | <div id="content" style="padding-top: 20000px;"> |
michael@0 | 17 | |
michael@0 | 18 | <!-- normal, basic form --> |
michael@0 | 19 | <form id="form1" onsubmit="return false;"> |
michael@0 | 20 | <input type="text" name="field1"> |
michael@0 | 21 | <button type="submit">Submit</button> |
michael@0 | 22 | </form> |
michael@0 | 23 | |
michael@0 | 24 | <!-- normal, basic form (new fieldname) --> |
michael@0 | 25 | <form id="form2" onsubmit="return false;"> |
michael@0 | 26 | <input type="text" name="field2"> |
michael@0 | 27 | <button type="submit">Submit</button> |
michael@0 | 28 | </form> |
michael@0 | 29 | |
michael@0 | 30 | <!-- form with autocomplete=off on input --> |
michael@0 | 31 | <form id="form3" onsubmit="return false;"> |
michael@0 | 32 | <input type="text" name="field2" autocomplete="off"> |
michael@0 | 33 | <button type="submit">Submit</button> |
michael@0 | 34 | </form> |
michael@0 | 35 | |
michael@0 | 36 | <!-- form with autocomplete=off on form --> |
michael@0 | 37 | <form id="form4" autocomplete="off" onsubmit="return false;"> |
michael@0 | 38 | <input type="text" name="field2"> |
michael@0 | 39 | <button type="submit">Submit</button> |
michael@0 | 40 | </form> |
michael@0 | 41 | |
michael@0 | 42 | <!-- normal form for testing filtering --> |
michael@0 | 43 | <form id="form5" onsubmit="return false;"> |
michael@0 | 44 | <input type="text" name="field3"> |
michael@0 | 45 | <button type="submit">Submit</button> |
michael@0 | 46 | </form> |
michael@0 | 47 | |
michael@0 | 48 | <!-- normal form for testing word boundary filtering --> |
michael@0 | 49 | <form id="form6" onsubmit="return false;"> |
michael@0 | 50 | <input type="text" name="field4"> |
michael@0 | 51 | <button type="submit">Submit</button> |
michael@0 | 52 | </form> |
michael@0 | 53 | |
michael@0 | 54 | <!-- form with maxlength attribute on input --> |
michael@0 | 55 | <form id="form7" onsubmit="return false;"> |
michael@0 | 56 | <input type="text" name="field5" maxlength="10"> |
michael@0 | 57 | <button type="submit">Submit</button> |
michael@0 | 58 | </form> |
michael@0 | 59 | |
michael@0 | 60 | <!-- form with input type='email' --> |
michael@0 | 61 | <form id="form8" onsubmit="return false;"> |
michael@0 | 62 | <input type="email" name="field6"> |
michael@0 | 63 | <button type="submit">Submit</button> |
michael@0 | 64 | </form> |
michael@0 | 65 | |
michael@0 | 66 | <!-- form with input type='tel' --> |
michael@0 | 67 | <form id="form9" onsubmit="return false;"> |
michael@0 | 68 | <input type="tel" name="field7"> |
michael@0 | 69 | <button type="submit">Submit</button> |
michael@0 | 70 | </form> |
michael@0 | 71 | |
michael@0 | 72 | <!-- form with input type='url' --> |
michael@0 | 73 | <form id="form10" onsubmit="return false;"> |
michael@0 | 74 | <input type="url" name="field8"> |
michael@0 | 75 | <button type="submit">Submit</button> |
michael@0 | 76 | </form> |
michael@0 | 77 | |
michael@0 | 78 | <!-- form with input type='search' --> |
michael@0 | 79 | <form id="form11" onsubmit="return false;"> |
michael@0 | 80 | <input type="search" name="field9"> |
michael@0 | 81 | <button type="submit">Submit</button> |
michael@0 | 82 | </form> |
michael@0 | 83 | |
michael@0 | 84 | <!-- form with input type='number' --> |
michael@0 | 85 | <form id="form12" onsubmit="return false;"> |
michael@0 | 86 | <input type="number" name="field10"> |
michael@0 | 87 | <button type="submit">Submit</button> |
michael@0 | 88 | </form> |
michael@0 | 89 | |
michael@0 | 90 | <!-- normal, basic form (with fieldname='searchbar-history') --> |
michael@0 | 91 | <form id="form13" onsubmit="return false;"> |
michael@0 | 92 | <input type="text" name="searchbar-history"> |
michael@0 | 93 | <button type="submit">Submit</button> |
michael@0 | 94 | </form> |
michael@0 | 95 | |
michael@0 | 96 | <!-- form with input type='date' --> |
michael@0 | 97 | <form id="form14" onsubmit="return false;"> |
michael@0 | 98 | <input type="date" name="field11"> |
michael@0 | 99 | <button type="submit">Submit</button> |
michael@0 | 100 | </form> |
michael@0 | 101 | |
michael@0 | 102 | <!-- form with input type='time' --> |
michael@0 | 103 | <form id="form15" onsubmit="return false;"> |
michael@0 | 104 | <input type="time" name="field12"> |
michael@0 | 105 | <button type="submit">Submit</button> |
michael@0 | 106 | </form> |
michael@0 | 107 | |
michael@0 | 108 | <!-- form with input type='range' --> |
michael@0 | 109 | <form id="form16" onsubmit="return false;"> |
michael@0 | 110 | <input type="range" name="field13" max="64"> |
michael@0 | 111 | <button type="submit">Submit</button> |
michael@0 | 112 | </form> |
michael@0 | 113 | |
michael@0 | 114 | <!-- form with input type='color' --> |
michael@0 | 115 | <form id="form17" onsubmit="return false;"> |
michael@0 | 116 | <input type="color" name="field14"> |
michael@0 | 117 | <button type="submit">Submit</button> |
michael@0 | 118 | </form> |
michael@0 | 119 | |
michael@0 | 120 | </div> |
michael@0 | 121 | |
michael@0 | 122 | <pre id="test"> |
michael@0 | 123 | <script class="testbody" type="text/javascript"> |
michael@0 | 124 | |
michael@0 | 125 | /** Test for Form History autocomplete **/ |
michael@0 | 126 | |
michael@0 | 127 | var input = $_(1, "field1"); |
michael@0 | 128 | const shiftModifier = Event.SHIFT_MASK; |
michael@0 | 129 | |
michael@0 | 130 | function setupFormHistory(aCallback) { |
michael@0 | 131 | updateFormHistory([ |
michael@0 | 132 | { op : "remove" }, |
michael@0 | 133 | { op : "add", fieldname : "field1", value : "value1" }, |
michael@0 | 134 | { op : "add", fieldname : "field1", value : "value2" }, |
michael@0 | 135 | { op : "add", fieldname : "field1", value : "value3" }, |
michael@0 | 136 | { op : "add", fieldname : "field1", value : "value4" }, |
michael@0 | 137 | { op : "add", fieldname : "field2", value : "value1" }, |
michael@0 | 138 | { op : "add", fieldname : "field3", value : "a" }, |
michael@0 | 139 | { op : "add", fieldname : "field3", value : "aa" }, |
michael@0 | 140 | { op : "add", fieldname : "field3", value : "aaz" }, |
michael@0 | 141 | { op : "add", fieldname : "field3", value : "aa\xe6" }, // 0xae == latin ae pair (0xc6 == AE) |
michael@0 | 142 | { op : "add", fieldname : "field3", value : "az" }, |
michael@0 | 143 | { op : "add", fieldname : "field3", value : "z" }, |
michael@0 | 144 | { op : "add", fieldname : "field4", value : "a\xe6" }, |
michael@0 | 145 | { op : "add", fieldname : "field4", value : "aa a\xe6" }, |
michael@0 | 146 | { op : "add", fieldname : "field4", value : "aba\xe6" }, |
michael@0 | 147 | { op : "add", fieldname : "field4", value : "bc d\xe6" }, |
michael@0 | 148 | { op : "add", fieldname : "field5", value : "1" }, |
michael@0 | 149 | { op : "add", fieldname : "field5", value : "12" }, |
michael@0 | 150 | { op : "add", fieldname : "field5", value : "123" }, |
michael@0 | 151 | { op : "add", fieldname : "field5", value : "1234" }, |
michael@0 | 152 | { op : "add", fieldname : "field6", value : "value" }, |
michael@0 | 153 | { op : "add", fieldname : "field7", value : "value" }, |
michael@0 | 154 | { op : "add", fieldname : "field8", value : "value" }, |
michael@0 | 155 | { op : "add", fieldname : "field9", value : "value" }, |
michael@0 | 156 | { op : "add", fieldname : "field10", value : "42" }, |
michael@0 | 157 | { op : "add", fieldname : "field11", value : "2010-10-10" }, |
michael@0 | 158 | { op : "add", fieldname : "field12", value : "21:21" }, |
michael@0 | 159 | { op : "add", fieldname : "field13", value : "32" }, // not used, since type=range doesn't have a drop down menu |
michael@0 | 160 | { op : "add", fieldname : "field14", value : "#ffffff" }, // not used, since type=color doesn't have autocomplete currently |
michael@0 | 161 | { op : "add", fieldname : "searchbar-history", value : "blacklist test" }, |
michael@0 | 162 | ], aCallback); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | // All these non-implemeted types might need autocomplete tests in the future. |
michael@0 | 166 | var todoTypes = [ "datetime", "month", "week", "datetime-local" ]; |
michael@0 | 167 | var todoInput = document.createElement("input"); |
michael@0 | 168 | for (var type of todoTypes) { |
michael@0 | 169 | todoInput.type = type; |
michael@0 | 170 | todo_is(todoInput.type, type, type + " type shouldn't be implemented"); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | |
michael@0 | 174 | function setForm(value) { |
michael@0 | 175 | input.value = value; |
michael@0 | 176 | input.focus(); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | var autocompleteMenu = getAutocompletePopup(); |
michael@0 | 180 | |
michael@0 | 181 | // Restore the form to the default state. |
michael@0 | 182 | function restoreForm() { |
michael@0 | 183 | setForm(""); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | // Check for expected form data. |
michael@0 | 187 | function checkForm(expectedValue) { |
michael@0 | 188 | var formID = input.parentNode.id; |
michael@0 | 189 | is(input.value, expectedValue, "Checking " + formID + " input"); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | var testNum = 0; |
michael@0 | 193 | var expectingPopup = false; |
michael@0 | 194 | |
michael@0 | 195 | function expectPopup() |
michael@0 | 196 | { |
michael@0 | 197 | info("expecting popup for test " + testNum); |
michael@0 | 198 | expectingPopup = true; |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | function popupShownListener() |
michael@0 | 202 | { |
michael@0 | 203 | info("popup shown for test " + testNum); |
michael@0 | 204 | if (expectingPopup) { |
michael@0 | 205 | expectingPopup = false; |
michael@0 | 206 | SimpleTest.executeSoon(runTest); |
michael@0 | 207 | } |
michael@0 | 208 | else { |
michael@0 | 209 | ok(false, "Autocomplete popup not expected during test " + testNum); |
michael@0 | 210 | } |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | SpecialPowers.addAutoCompletePopupEventListener(window, "popupshown", popupShownListener); |
michael@0 | 214 | |
michael@0 | 215 | /* |
michael@0 | 216 | * Main section of test... |
michael@0 | 217 | * |
michael@0 | 218 | * This is a bit hacky, as many operations happen asynchronously. |
michael@0 | 219 | * Various mechanisms call runTests as a result of operations: |
michael@0 | 220 | * - set expectingPopup to true, and the next test will occur when the autocomplete popup is shown |
michael@0 | 221 | * - call waitForMenuChange(x) to run the next test when the autocomplete popup to have x items in it |
michael@0 | 222 | * - addEntry calls runs the test when an entry has been added |
michael@0 | 223 | * - some tests scroll the window. This is because the form fill controller happens to scroll |
michael@0 | 224 | * the field into view near the end of the search, and there isn't any other good notification |
michael@0 | 225 | * to listen to for when the search is complete. |
michael@0 | 226 | * - some items still use setTimeout |
michael@0 | 227 | */ |
michael@0 | 228 | function runTest() { |
michael@0 | 229 | testNum++; |
michael@0 | 230 | |
michael@0 | 231 | ok(true, "Starting test #" + testNum); |
michael@0 | 232 | |
michael@0 | 233 | switch(testNum) { |
michael@0 | 234 | case 1: |
michael@0 | 235 | // Make sure initial form is empty. |
michael@0 | 236 | checkForm(""); |
michael@0 | 237 | // Trigger autocomplete popup |
michael@0 | 238 | expectPopup(); |
michael@0 | 239 | restoreForm(); |
michael@0 | 240 | doKey("down"); |
michael@0 | 241 | break; |
michael@0 | 242 | |
michael@0 | 243 | case 2: |
michael@0 | 244 | checkMenuEntries(["value1", "value2", "value3", "value4"], testNum); |
michael@0 | 245 | // Check first entry |
michael@0 | 246 | doKey("down"); |
michael@0 | 247 | checkForm(""); // value shouldn't update |
michael@0 | 248 | doKey("return"); // not "enter"! |
michael@0 | 249 | checkForm("value1"); |
michael@0 | 250 | |
michael@0 | 251 | // Trigger autocomplete popup |
michael@0 | 252 | expectPopup(); |
michael@0 | 253 | restoreForm(); |
michael@0 | 254 | doKey("down"); |
michael@0 | 255 | break; |
michael@0 | 256 | |
michael@0 | 257 | case 3: |
michael@0 | 258 | // Check second entry |
michael@0 | 259 | doKey("down"); |
michael@0 | 260 | doKey("down"); |
michael@0 | 261 | doKey("return"); // not "enter"! |
michael@0 | 262 | checkForm("value2"); |
michael@0 | 263 | |
michael@0 | 264 | // Trigger autocomplete popup |
michael@0 | 265 | expectPopup(); |
michael@0 | 266 | restoreForm(); |
michael@0 | 267 | doKey("down"); |
michael@0 | 268 | break; |
michael@0 | 269 | |
michael@0 | 270 | case 4: |
michael@0 | 271 | // Check third entry |
michael@0 | 272 | doKey("down"); |
michael@0 | 273 | doKey("down"); |
michael@0 | 274 | doKey("down"); |
michael@0 | 275 | doKey("return"); |
michael@0 | 276 | checkForm("value3"); |
michael@0 | 277 | |
michael@0 | 278 | // Trigger autocomplete popup |
michael@0 | 279 | expectPopup(); |
michael@0 | 280 | restoreForm(); |
michael@0 | 281 | doKey("down"); |
michael@0 | 282 | break; |
michael@0 | 283 | |
michael@0 | 284 | case 5: |
michael@0 | 285 | // Check fourth entry |
michael@0 | 286 | doKey("down"); |
michael@0 | 287 | doKey("down"); |
michael@0 | 288 | doKey("down"); |
michael@0 | 289 | doKey("down"); |
michael@0 | 290 | doKey("return"); |
michael@0 | 291 | checkForm("value4"); |
michael@0 | 292 | |
michael@0 | 293 | // Trigger autocomplete popup |
michael@0 | 294 | expectPopup(); |
michael@0 | 295 | restoreForm(); |
michael@0 | 296 | doKey("down"); |
michael@0 | 297 | break; |
michael@0 | 298 | |
michael@0 | 299 | case 6: |
michael@0 | 300 | // Check first entry (wraparound) |
michael@0 | 301 | doKey("down"); |
michael@0 | 302 | doKey("down"); |
michael@0 | 303 | doKey("down"); |
michael@0 | 304 | doKey("down"); |
michael@0 | 305 | doKey("down"); // deselects |
michael@0 | 306 | doKey("down"); |
michael@0 | 307 | doKey("return"); |
michael@0 | 308 | checkForm("value1"); |
michael@0 | 309 | |
michael@0 | 310 | // Trigger autocomplete popup |
michael@0 | 311 | expectPopup(); |
michael@0 | 312 | restoreForm(); |
michael@0 | 313 | doKey("down"); |
michael@0 | 314 | break; |
michael@0 | 315 | |
michael@0 | 316 | case 7: |
michael@0 | 317 | // Check the last entry via arrow-up |
michael@0 | 318 | doKey("up"); |
michael@0 | 319 | doKey("return"); |
michael@0 | 320 | checkForm("value4"); |
michael@0 | 321 | |
michael@0 | 322 | // Trigger autocomplete popup |
michael@0 | 323 | expectPopup(); |
michael@0 | 324 | restoreForm(); |
michael@0 | 325 | doKey("down"); |
michael@0 | 326 | break; |
michael@0 | 327 | |
michael@0 | 328 | case 8: |
michael@0 | 329 | // Check the last entry via arrow-up |
michael@0 | 330 | doKey("down"); // select first entry |
michael@0 | 331 | doKey("up"); // selects nothing! |
michael@0 | 332 | doKey("up"); // select last entry |
michael@0 | 333 | doKey("return"); |
michael@0 | 334 | checkForm("value4"); |
michael@0 | 335 | |
michael@0 | 336 | // Trigger autocomplete popup |
michael@0 | 337 | expectPopup(); |
michael@0 | 338 | restoreForm(); |
michael@0 | 339 | doKey("down"); |
michael@0 | 340 | break; |
michael@0 | 341 | |
michael@0 | 342 | case 9: |
michael@0 | 343 | // Check the last entry via arrow-up (wraparound) |
michael@0 | 344 | doKey("down"); |
michael@0 | 345 | doKey("up"); // deselects |
michael@0 | 346 | doKey("up"); // last entry |
michael@0 | 347 | doKey("up"); |
michael@0 | 348 | doKey("up"); |
michael@0 | 349 | doKey("up"); // first entry |
michael@0 | 350 | doKey("up"); // deselects |
michael@0 | 351 | doKey("up"); // last entry |
michael@0 | 352 | doKey("return"); |
michael@0 | 353 | checkForm("value4"); |
michael@0 | 354 | |
michael@0 | 355 | // Trigger autocomplete popup |
michael@0 | 356 | expectPopup(); |
michael@0 | 357 | restoreForm(); |
michael@0 | 358 | doKey("down"); |
michael@0 | 359 | break; |
michael@0 | 360 | |
michael@0 | 361 | case 10: |
michael@0 | 362 | // Set first entry w/o triggering autocomplete |
michael@0 | 363 | doKey("down"); |
michael@0 | 364 | doKey("right"); |
michael@0 | 365 | checkForm("value1"); |
michael@0 | 366 | |
michael@0 | 367 | // Trigger autocomplete popup |
michael@0 | 368 | expectPopup(); |
michael@0 | 369 | restoreForm(); |
michael@0 | 370 | doKey("down"); |
michael@0 | 371 | break; |
michael@0 | 372 | |
michael@0 | 373 | case 11: |
michael@0 | 374 | // Set first entry w/o triggering autocomplete |
michael@0 | 375 | doKey("down"); |
michael@0 | 376 | doKey("left"); |
michael@0 | 377 | checkForm("value1"); |
michael@0 | 378 | |
michael@0 | 379 | // Trigger autocomplete popup |
michael@0 | 380 | expectPopup(); |
michael@0 | 381 | restoreForm(); |
michael@0 | 382 | doKey("down"); |
michael@0 | 383 | break; |
michael@0 | 384 | |
michael@0 | 385 | case 12: |
michael@0 | 386 | // Check first entry (page up) |
michael@0 | 387 | doKey("down"); |
michael@0 | 388 | doKey("down"); |
michael@0 | 389 | doKey("page_up"); |
michael@0 | 390 | doKey("return"); |
michael@0 | 391 | checkForm("value1"); |
michael@0 | 392 | |
michael@0 | 393 | // Trigger autocomplete popup |
michael@0 | 394 | expectPopup(); |
michael@0 | 395 | restoreForm(); |
michael@0 | 396 | doKey("down"); |
michael@0 | 397 | break; |
michael@0 | 398 | |
michael@0 | 399 | case 13: |
michael@0 | 400 | // Check last entry (page down) |
michael@0 | 401 | doKey("down"); |
michael@0 | 402 | doKey("page_down"); |
michael@0 | 403 | doKey("return"); |
michael@0 | 404 | checkForm("value4"); |
michael@0 | 405 | |
michael@0 | 406 | // Trigger autocomplete popup |
michael@0 | 407 | testNum = 49; |
michael@0 | 408 | expectPopup(); |
michael@0 | 409 | restoreForm(); |
michael@0 | 410 | doKey("down"); |
michael@0 | 411 | break; |
michael@0 | 412 | |
michael@0 | 413 | /* Test removing entries from the dropdown */ |
michael@0 | 414 | |
michael@0 | 415 | case 50: |
michael@0 | 416 | checkMenuEntries(["value1", "value2", "value3", "value4"], testNum); |
michael@0 | 417 | // Delete the first entry (of 4) |
michael@0 | 418 | setForm("value"); |
michael@0 | 419 | doKey("down"); |
michael@0 | 420 | |
michael@0 | 421 | // On OS X, shift-backspace and shift-delete work, just delete does not. |
michael@0 | 422 | // On Win/Linux, shift-backspace does not work, delete and shift-delete do. |
michael@0 | 423 | if (SpecialPowers.OS == "Darwin") |
michael@0 | 424 | doKey("back_space", shiftModifier); |
michael@0 | 425 | else |
michael@0 | 426 | doKey("delete", shiftModifier); |
michael@0 | 427 | |
michael@0 | 428 | // This tests that on OS X shift-backspace didn't delete the last character |
michael@0 | 429 | // in the input (bug 480262). |
michael@0 | 430 | waitForMenuChange(3); |
michael@0 | 431 | break; |
michael@0 | 432 | |
michael@0 | 433 | case 51: |
michael@0 | 434 | checkForm("value"); |
michael@0 | 435 | countEntries("field1", "value1", |
michael@0 | 436 | function (num) { |
michael@0 | 437 | ok(!num, testNum + " checking that f1/v1 was deleted"); |
michael@0 | 438 | runTest(); |
michael@0 | 439 | }); |
michael@0 | 440 | break; |
michael@0 | 441 | |
michael@0 | 442 | case 52: |
michael@0 | 443 | doKey("return"); |
michael@0 | 444 | checkForm("value2"); |
michael@0 | 445 | |
michael@0 | 446 | // Trigger autocomplete popup |
michael@0 | 447 | expectPopup(); |
michael@0 | 448 | restoreForm(); |
michael@0 | 449 | doKey("down"); |
michael@0 | 450 | break; |
michael@0 | 451 | |
michael@0 | 452 | case 53: |
michael@0 | 453 | checkMenuEntries(["value2", "value3", "value4"], testNum); |
michael@0 | 454 | // Check the new first entry (of 3) |
michael@0 | 455 | doKey("down"); |
michael@0 | 456 | doKey("return"); |
michael@0 | 457 | checkForm("value2"); |
michael@0 | 458 | |
michael@0 | 459 | // Trigger autocomplete popup |
michael@0 | 460 | expectPopup(); |
michael@0 | 461 | restoreForm(); |
michael@0 | 462 | doKey("down"); |
michael@0 | 463 | break; |
michael@0 | 464 | |
michael@0 | 465 | case 54: |
michael@0 | 466 | // Delete the second entry (of 3) |
michael@0 | 467 | doKey("down"); |
michael@0 | 468 | doKey("down"); |
michael@0 | 469 | doKey("delete", shiftModifier); |
michael@0 | 470 | waitForMenuChange(2); |
michael@0 | 471 | break; |
michael@0 | 472 | |
michael@0 | 473 | case 55: |
michael@0 | 474 | checkForm(""); |
michael@0 | 475 | countEntries("field1", "value3", |
michael@0 | 476 | function (num) { |
michael@0 | 477 | ok(!num, testNum + " checking that f1/v3 was deleted"); |
michael@0 | 478 | runTest(); |
michael@0 | 479 | }); |
michael@0 | 480 | break; |
michael@0 | 481 | |
michael@0 | 482 | case 56: |
michael@0 | 483 | doKey("return"); |
michael@0 | 484 | checkForm("value4") |
michael@0 | 485 | |
michael@0 | 486 | // Trigger autocomplete popup |
michael@0 | 487 | expectPopup(); |
michael@0 | 488 | restoreForm(); |
michael@0 | 489 | doKey("down"); |
michael@0 | 490 | break; |
michael@0 | 491 | |
michael@0 | 492 | case 57: |
michael@0 | 493 | checkMenuEntries(["value2", "value4"], testNum); |
michael@0 | 494 | // Check the new first entry (of 2) |
michael@0 | 495 | doKey("down"); |
michael@0 | 496 | doKey("return"); |
michael@0 | 497 | checkForm("value2"); |
michael@0 | 498 | |
michael@0 | 499 | // Trigger autocomplete popup |
michael@0 | 500 | expectPopup(); |
michael@0 | 501 | restoreForm(); |
michael@0 | 502 | doKey("down"); |
michael@0 | 503 | break; |
michael@0 | 504 | |
michael@0 | 505 | case 58: |
michael@0 | 506 | // Delete the last entry (of 2) |
michael@0 | 507 | doKey("down"); |
michael@0 | 508 | doKey("down"); |
michael@0 | 509 | doKey("delete", shiftModifier); |
michael@0 | 510 | checkForm(""); |
michael@0 | 511 | waitForMenuChange(1); |
michael@0 | 512 | break; |
michael@0 | 513 | |
michael@0 | 514 | case 59: |
michael@0 | 515 | countEntries("field1", "value4", |
michael@0 | 516 | function (num) { |
michael@0 | 517 | ok(!num, testNum + " checking that f1/v4 was deleted"); |
michael@0 | 518 | runTest(); |
michael@0 | 519 | }); |
michael@0 | 520 | break; |
michael@0 | 521 | |
michael@0 | 522 | case 60: |
michael@0 | 523 | doKey("return"); |
michael@0 | 524 | checkForm("value2"); |
michael@0 | 525 | |
michael@0 | 526 | // Trigger autocomplete popup |
michael@0 | 527 | expectPopup(); |
michael@0 | 528 | restoreForm(); |
michael@0 | 529 | doKey("down"); |
michael@0 | 530 | break; |
michael@0 | 531 | |
michael@0 | 532 | case 61: |
michael@0 | 533 | checkMenuEntries(["value2"], testNum); |
michael@0 | 534 | // Check the new first entry (of 1) |
michael@0 | 535 | doKey("down"); |
michael@0 | 536 | doKey("return"); |
michael@0 | 537 | checkForm("value2"); |
michael@0 | 538 | |
michael@0 | 539 | // Trigger autocomplete popup |
michael@0 | 540 | expectPopup(); |
michael@0 | 541 | restoreForm(); |
michael@0 | 542 | doKey("down"); |
michael@0 | 543 | break; |
michael@0 | 544 | |
michael@0 | 545 | case 62: |
michael@0 | 546 | // Delete the only remaining entry |
michael@0 | 547 | doKey("down"); |
michael@0 | 548 | doKey("delete", shiftModifier); |
michael@0 | 549 | waitForMenuChange(0); |
michael@0 | 550 | break; |
michael@0 | 551 | |
michael@0 | 552 | case 63: |
michael@0 | 553 | checkForm(""); |
michael@0 | 554 | countEntries("field1", "value2", |
michael@0 | 555 | function (num) { |
michael@0 | 556 | ok(!num, testNum + " checking that f1/v2 was deleted"); |
michael@0 | 557 | runTest(); |
michael@0 | 558 | }); |
michael@0 | 559 | break; |
michael@0 | 560 | |
michael@0 | 561 | case 64: |
michael@0 | 562 | // Look at form 2, trigger autocomplete popup |
michael@0 | 563 | input = $_(2, "field2"); |
michael@0 | 564 | testNum = 99; |
michael@0 | 565 | expectPopup(); |
michael@0 | 566 | restoreForm(); |
michael@0 | 567 | doKey("down"); |
michael@0 | 568 | break; |
michael@0 | 569 | |
michael@0 | 570 | /* Test entries with autocomplete=off */ |
michael@0 | 571 | |
michael@0 | 572 | case 100: |
michael@0 | 573 | // Select first entry |
michael@0 | 574 | doKey("down"); |
michael@0 | 575 | doKey("return"); |
michael@0 | 576 | checkForm("value1"); |
michael@0 | 577 | |
michael@0 | 578 | // Look at form 3, try to trigger autocomplete popup |
michael@0 | 579 | input = $_(3, "field2"); |
michael@0 | 580 | restoreForm(); |
michael@0 | 581 | // Sometimes, this will fail if scrollTo(0, 0) is called, so that doesn't |
michael@0 | 582 | // happen here. Fortunately, a different input is used from the last test, |
michael@0 | 583 | // so a scroll should still occur. |
michael@0 | 584 | doKey("down"); |
michael@0 | 585 | waitForScroll(); |
michael@0 | 586 | break; |
michael@0 | 587 | |
michael@0 | 588 | case 101: |
michael@0 | 589 | // Ensure there's no autocomplete dropdown (autocomplete=off is present) |
michael@0 | 590 | doKey("down"); |
michael@0 | 591 | doKey("return"); |
michael@0 | 592 | checkForm(""); |
michael@0 | 593 | |
michael@0 | 594 | // Look at form 4, try to trigger autocomplete popup |
michael@0 | 595 | input = $_(4, "field2"); |
michael@0 | 596 | restoreForm(); |
michael@0 | 597 | doKey("down"); |
michael@0 | 598 | waitForMenuChange(0); |
michael@0 | 599 | break; |
michael@0 | 600 | |
michael@0 | 601 | case 102: |
michael@0 | 602 | // Ensure there's no autocomplete dropdown (autocomplete=off is present) |
michael@0 | 603 | doKey("down"); |
michael@0 | 604 | doKey("return"); |
michael@0 | 605 | checkForm(""); |
michael@0 | 606 | |
michael@0 | 607 | // Look at form 5, try to trigger autocomplete popup |
michael@0 | 608 | input = $_(5, "field3"); |
michael@0 | 609 | restoreForm(); |
michael@0 | 610 | testNum = 199; |
michael@0 | 611 | expectPopup(); |
michael@0 | 612 | input.focus(); |
michael@0 | 613 | sendChar("a"); |
michael@0 | 614 | break; |
michael@0 | 615 | |
michael@0 | 616 | /* Test filtering as characters are typed. */ |
michael@0 | 617 | |
michael@0 | 618 | case 200: |
michael@0 | 619 | checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"], testNum); |
michael@0 | 620 | input.focus(); |
michael@0 | 621 | sendChar("a"); |
michael@0 | 622 | waitForMenuChange(3); |
michael@0 | 623 | break; |
michael@0 | 624 | |
michael@0 | 625 | case 201: |
michael@0 | 626 | checkMenuEntries(["aa", "aaz", "aa\xe6"], testNum); |
michael@0 | 627 | input.focus(); |
michael@0 | 628 | sendChar("\xc6"); |
michael@0 | 629 | waitForMenuChange(1); |
michael@0 | 630 | break; |
michael@0 | 631 | |
michael@0 | 632 | case 202: |
michael@0 | 633 | checkMenuEntries(["aa\xe6"], testNum); |
michael@0 | 634 | doKey("back_space"); |
michael@0 | 635 | waitForMenuChange(3); |
michael@0 | 636 | break; |
michael@0 | 637 | |
michael@0 | 638 | case 203: |
michael@0 | 639 | checkMenuEntries(["aa", "aaz", "aa\xe6"], testNum); |
michael@0 | 640 | doKey("back_space"); |
michael@0 | 641 | waitForMenuChange(5); |
michael@0 | 642 | break; |
michael@0 | 643 | |
michael@0 | 644 | case 204: |
michael@0 | 645 | checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"], testNum); |
michael@0 | 646 | input.focus(); |
michael@0 | 647 | sendChar("z"); |
michael@0 | 648 | waitForMenuChange(2); |
michael@0 | 649 | break; |
michael@0 | 650 | |
michael@0 | 651 | case 205: |
michael@0 | 652 | checkMenuEntries(["az", "aaz"], testNum); |
michael@0 | 653 | input.focus(); |
michael@0 | 654 | doKey("left"); |
michael@0 | 655 | expectPopup(); |
michael@0 | 656 | sendChar("a"); |
michael@0 | 657 | break; |
michael@0 | 658 | |
michael@0 | 659 | case 206: |
michael@0 | 660 | checkMenuEntries(["aaz"], testNum); |
michael@0 | 661 | addEntry("field3", "aazq"); |
michael@0 | 662 | break; |
michael@0 | 663 | |
michael@0 | 664 | case 207: |
michael@0 | 665 | input.focus(); |
michael@0 | 666 | doKey("right"); |
michael@0 | 667 | sendChar("q"); |
michael@0 | 668 | waitForMenuChange(0); |
michael@0 | 669 | break; |
michael@0 | 670 | |
michael@0 | 671 | case 208: |
michael@0 | 672 | // check that results were cached |
michael@0 | 673 | checkMenuEntries([], testNum); |
michael@0 | 674 | addEntry("field3", "aazqq"); |
michael@0 | 675 | break; |
michael@0 | 676 | |
michael@0 | 677 | case 209: |
michael@0 | 678 | input.focus(); |
michael@0 | 679 | window.scrollTo(0, 0); |
michael@0 | 680 | sendChar("q"); |
michael@0 | 681 | waitForScroll(); |
michael@0 | 682 | break; |
michael@0 | 683 | |
michael@0 | 684 | case 210: |
michael@0 | 685 | // check that empty results were cached - bug 496466 |
michael@0 | 686 | checkMenuEntries([], testNum); |
michael@0 | 687 | doKey("escape"); |
michael@0 | 688 | |
michael@0 | 689 | // Look at form 6, try to trigger autocomplete popup |
michael@0 | 690 | input = $_(6, "field4"); |
michael@0 | 691 | restoreForm(); |
michael@0 | 692 | testNum = 249; |
michael@0 | 693 | expectPopup(); |
michael@0 | 694 | input.focus(); |
michael@0 | 695 | sendChar("a"); |
michael@0 | 696 | break; |
michael@0 | 697 | |
michael@0 | 698 | /* Test substring matches and word boundary bonuses */ |
michael@0 | 699 | |
michael@0 | 700 | case 250: |
michael@0 | 701 | // alphabetical results for first character |
michael@0 | 702 | checkMenuEntries(["aa a\xe6", "aba\xe6", "a\xe6"], testNum); |
michael@0 | 703 | input.focus(); |
michael@0 | 704 | |
michael@0 | 705 | // for this test, hide the popup first as it contains the same number of menu |
michael@0 | 706 | |
michael@0 | 707 | sendChar("\xc6"); |
michael@0 | 708 | waitForMenuChange(3, "a\xe6"); |
michael@0 | 709 | break; |
michael@0 | 710 | |
michael@0 | 711 | case 251: |
michael@0 | 712 | // prefix match comes first, then word boundary match |
michael@0 | 713 | // followed by substring match |
michael@0 | 714 | checkMenuEntries(["a\xe6", "aa a\xe6", "aba\xe6"], testNum); |
michael@0 | 715 | |
michael@0 | 716 | restoreForm(); |
michael@0 | 717 | input.focus(); |
michael@0 | 718 | sendChar("b"); |
michael@0 | 719 | waitForMenuChange(1, "bc d\xe6"); |
michael@0 | 720 | break; |
michael@0 | 721 | |
michael@0 | 722 | case 252: |
michael@0 | 723 | checkMenuEntries(["bc d\xe6"], testNum); |
michael@0 | 724 | input.focus(); |
michael@0 | 725 | sendChar(" "); |
michael@0 | 726 | setTimeout(runTest, 300); |
michael@0 | 727 | break; |
michael@0 | 728 | |
michael@0 | 729 | case 253: |
michael@0 | 730 | // check that trailing space has no effect after single char. |
michael@0 | 731 | checkMenuEntries(["bc d\xe6"], testNum); |
michael@0 | 732 | input.focus(); |
michael@0 | 733 | sendChar("\xc6"); |
michael@0 | 734 | waitForMenuChange(2); |
michael@0 | 735 | break; |
michael@0 | 736 | |
michael@0 | 737 | case 254: |
michael@0 | 738 | // check multi-word substring matches |
michael@0 | 739 | checkMenuEntries(["bc d\xe6", "aba\xe6"]); |
michael@0 | 740 | input.focus(); |
michael@0 | 741 | expectPopup(); |
michael@0 | 742 | doKey("left"); |
michael@0 | 743 | sendChar("d"); |
michael@0 | 744 | break; |
michael@0 | 745 | |
michael@0 | 746 | case 255: |
michael@0 | 747 | // check inserting in multi-word searches |
michael@0 | 748 | checkMenuEntries(["bc d\xe6"], testNum); |
michael@0 | 749 | input.focus(); |
michael@0 | 750 | sendChar("z"); |
michael@0 | 751 | waitForMenuChange(0); |
michael@0 | 752 | break; |
michael@0 | 753 | |
michael@0 | 754 | case 256: |
michael@0 | 755 | checkMenuEntries([], testNum); |
michael@0 | 756 | |
michael@0 | 757 | // Look at form 7, try to trigger autocomplete popup |
michael@0 | 758 | input = $_(7, "field5"); |
michael@0 | 759 | testNum = 299; |
michael@0 | 760 | expectPopup(); |
michael@0 | 761 | restoreForm(); |
michael@0 | 762 | doKey("down"); |
michael@0 | 763 | break; |
michael@0 | 764 | |
michael@0 | 765 | case 300: |
michael@0 | 766 | checkMenuEntries(["1", "12", "123", "1234"], testNum); |
michael@0 | 767 | input.maxLength = 4; |
michael@0 | 768 | expectPopup(); |
michael@0 | 769 | doKey("escape"); |
michael@0 | 770 | doKey("down"); |
michael@0 | 771 | break; |
michael@0 | 772 | |
michael@0 | 773 | case 301: |
michael@0 | 774 | checkMenuEntries(["1", "12", "123", "1234"], testNum); |
michael@0 | 775 | input.maxLength = 3; |
michael@0 | 776 | expectPopup(); |
michael@0 | 777 | doKey("escape"); |
michael@0 | 778 | doKey("down"); |
michael@0 | 779 | break; |
michael@0 | 780 | |
michael@0 | 781 | case 302: |
michael@0 | 782 | checkMenuEntries(["1", "12", "123"], testNum); |
michael@0 | 783 | input.maxLength = 2; |
michael@0 | 784 | expectPopup(); |
michael@0 | 785 | doKey("escape"); |
michael@0 | 786 | doKey("down"); |
michael@0 | 787 | break; |
michael@0 | 788 | |
michael@0 | 789 | case 303: |
michael@0 | 790 | checkMenuEntries(["1", "12"], testNum); |
michael@0 | 791 | input.maxLength = 1; |
michael@0 | 792 | expectPopup(); |
michael@0 | 793 | doKey("escape"); |
michael@0 | 794 | doKey("down"); |
michael@0 | 795 | break; |
michael@0 | 796 | |
michael@0 | 797 | case 304: |
michael@0 | 798 | checkMenuEntries(["1"], testNum); |
michael@0 | 799 | input.maxLength = 0; |
michael@0 | 800 | doKey("escape"); |
michael@0 | 801 | doKey("down"); |
michael@0 | 802 | waitForMenuChange(0); |
michael@0 | 803 | break; |
michael@0 | 804 | |
michael@0 | 805 | case 305: |
michael@0 | 806 | checkMenuEntries([], testNum); |
michael@0 | 807 | input.maxLength = 4; |
michael@0 | 808 | |
michael@0 | 809 | // now again with a character typed |
michael@0 | 810 | input.focus(); |
michael@0 | 811 | sendChar("1"); |
michael@0 | 812 | expectPopup(); |
michael@0 | 813 | doKey("escape"); |
michael@0 | 814 | doKey("down"); |
michael@0 | 815 | break; |
michael@0 | 816 | |
michael@0 | 817 | case 306: |
michael@0 | 818 | checkMenuEntries(["1", "12", "123", "1234"], testNum); |
michael@0 | 819 | input.maxLength = 3; |
michael@0 | 820 | expectPopup(); |
michael@0 | 821 | doKey("escape"); |
michael@0 | 822 | doKey("down"); |
michael@0 | 823 | break; |
michael@0 | 824 | |
michael@0 | 825 | case 307: |
michael@0 | 826 | checkMenuEntries(["1", "12", "123"], testNum); |
michael@0 | 827 | input.maxLength = 2; |
michael@0 | 828 | expectPopup(); |
michael@0 | 829 | doKey("escape"); |
michael@0 | 830 | doKey("down"); |
michael@0 | 831 | break; |
michael@0 | 832 | |
michael@0 | 833 | case 308: |
michael@0 | 834 | checkMenuEntries(["1", "12"], testNum); |
michael@0 | 835 | input.maxLength = 1; |
michael@0 | 836 | expectPopup(); |
michael@0 | 837 | doKey("escape"); |
michael@0 | 838 | doKey("down"); |
michael@0 | 839 | break; |
michael@0 | 840 | |
michael@0 | 841 | case 309: |
michael@0 | 842 | checkMenuEntries(["1"], testNum); |
michael@0 | 843 | input.maxLength = 0; |
michael@0 | 844 | doKey("escape"); |
michael@0 | 845 | doKey("down"); |
michael@0 | 846 | waitForMenuChange(0); |
michael@0 | 847 | break; |
michael@0 | 848 | |
michael@0 | 849 | case 310: |
michael@0 | 850 | checkMenuEntries([], testNum); |
michael@0 | 851 | |
michael@0 | 852 | input = $_(8, "field6"); |
michael@0 | 853 | testNum = 399; |
michael@0 | 854 | expectPopup(); |
michael@0 | 855 | restoreForm(); |
michael@0 | 856 | doKey("down"); |
michael@0 | 857 | break; |
michael@0 | 858 | |
michael@0 | 859 | case 400: |
michael@0 | 860 | case 401: |
michael@0 | 861 | case 402: |
michael@0 | 862 | case 403: |
michael@0 | 863 | checkMenuEntries(["value"], testNum); |
michael@0 | 864 | doKey("down"); |
michael@0 | 865 | doKey("return"); |
michael@0 | 866 | checkForm("value"); |
michael@0 | 867 | |
michael@0 | 868 | if (testNum == 400) { |
michael@0 | 869 | input = $_(9, "field7"); |
michael@0 | 870 | } else if (testNum == 401) { |
michael@0 | 871 | input = $_(10, "field8"); |
michael@0 | 872 | } else if (testNum == 402) { |
michael@0 | 873 | input = $_(11, "field9"); |
michael@0 | 874 | } else if (testNum == 403) { |
michael@0 | 875 | input = $_(12, "field10"); |
michael@0 | 876 | } |
michael@0 | 877 | |
michael@0 | 878 | expectPopup(); |
michael@0 | 879 | restoreForm(); |
michael@0 | 880 | doKey("down"); |
michael@0 | 881 | break; |
michael@0 | 882 | |
michael@0 | 883 | case 404: |
michael@0 | 884 | checkMenuEntries(["42"], testNum); |
michael@0 | 885 | doKey("down"); |
michael@0 | 886 | doKey("return"); |
michael@0 | 887 | checkForm("42"); |
michael@0 | 888 | |
michael@0 | 889 | input = $_(14, "field11"); |
michael@0 | 890 | restoreForm(); |
michael@0 | 891 | expectPopup(); |
michael@0 | 892 | doKey("down"); |
michael@0 | 893 | break; |
michael@0 | 894 | |
michael@0 | 895 | case 405: |
michael@0 | 896 | checkMenuEntries(["2010-10-10"]); |
michael@0 | 897 | doKey("down"); |
michael@0 | 898 | doKey("return"); |
michael@0 | 899 | checkForm("2010-10-10"); |
michael@0 | 900 | |
michael@0 | 901 | input = $_(15, "field12"); |
michael@0 | 902 | restoreForm(); |
michael@0 | 903 | expectPopup(); |
michael@0 | 904 | doKey("down"); |
michael@0 | 905 | break; |
michael@0 | 906 | |
michael@0 | 907 | case 406: |
michael@0 | 908 | checkMenuEntries(["21:21"]); |
michael@0 | 909 | doKey("down"); |
michael@0 | 910 | doKey("return"); |
michael@0 | 911 | checkForm("21:21"); |
michael@0 | 912 | |
michael@0 | 913 | input = $_(16, "field13"); |
michael@0 | 914 | restoreForm(); |
michael@0 | 915 | doKey("down"); |
michael@0 | 916 | waitForMenuChange(0); |
michael@0 | 917 | break; |
michael@0 | 918 | |
michael@0 | 919 | case 407: |
michael@0 | 920 | checkMenuEntries([]); // type=range does not have a drop down menu |
michael@0 | 921 | doKey("down"); |
michael@0 | 922 | doKey("return"); |
michael@0 | 923 | checkForm("30"); // default (midway between minimum (0) and maximum (64)) - step |
michael@0 | 924 | |
michael@0 | 925 | input = $_(17, "field14"); |
michael@0 | 926 | restoreForm(); |
michael@0 | 927 | waitForMenuChange(0); |
michael@0 | 928 | break; |
michael@0 | 929 | |
michael@0 | 930 | case 408: |
michael@0 | 931 | checkMenuEntries([]); // type=color does not have a drop down menu |
michael@0 | 932 | checkForm("#000000"); // default color value |
michael@0 | 933 | |
michael@0 | 934 | addEntry("field1", "value1"); |
michael@0 | 935 | break; |
michael@0 | 936 | |
michael@0 | 937 | case 409: |
michael@0 | 938 | input = $_(1, "field1"); |
michael@0 | 939 | // Go to test 500. |
michael@0 | 940 | testNum = 499; |
michael@0 | 941 | |
michael@0 | 942 | expectPopup(); |
michael@0 | 943 | restoreForm(); |
michael@0 | 944 | doKey("down"); |
michael@0 | 945 | break; |
michael@0 | 946 | |
michael@0 | 947 | // Check that the input event is fired. |
michael@0 | 948 | case 500: |
michael@0 | 949 | input.addEventListener("input", function(event) { |
michael@0 | 950 | input.removeEventListener("input", arguments.callee, false); |
michael@0 | 951 | ok(true, testNum + " oninput should have been received"); |
michael@0 | 952 | ok(event.bubbles, testNum + " input event should bubble"); |
michael@0 | 953 | ok(event.cancelable, testNum + " input event should be cancelable"); |
michael@0 | 954 | }, false); |
michael@0 | 955 | |
michael@0 | 956 | doKey("down"); |
michael@0 | 957 | checkForm(""); |
michael@0 | 958 | doKey("return"); |
michael@0 | 959 | checkForm("value1"); |
michael@0 | 960 | testNum = 599; |
michael@0 | 961 | setTimeout(runTest, 100); |
michael@0 | 962 | break; |
michael@0 | 963 | |
michael@0 | 964 | case 600: |
michael@0 | 965 | // check we don't show autocomplete for searchbar-history |
michael@0 | 966 | input = $_(13, "searchbar-history"); |
michael@0 | 967 | |
michael@0 | 968 | // Trigger autocomplete popup |
michael@0 | 969 | checkForm(""); |
michael@0 | 970 | restoreForm(); |
michael@0 | 971 | doKey("down"); |
michael@0 | 972 | waitForMenuChange(0); |
michael@0 | 973 | break; |
michael@0 | 974 | |
michael@0 | 975 | case 601: |
michael@0 | 976 | checkMenuEntries([], testNum); |
michael@0 | 977 | SpecialPowers.removeAutoCompletePopupEventListener(window, "popupshown", popupShownListener); |
michael@0 | 978 | SimpleTest.finish(); |
michael@0 | 979 | return; |
michael@0 | 980 | |
michael@0 | 981 | default: |
michael@0 | 982 | ok(false, "Unexpected invocation of test #" + testNum); |
michael@0 | 983 | SpecialPowers.removeAutoCompletePopupEventListener(window, "popupshown", popupShownListener); |
michael@0 | 984 | SimpleTest.finish(); |
michael@0 | 985 | return; |
michael@0 | 986 | } |
michael@0 | 987 | } |
michael@0 | 988 | |
michael@0 | 989 | function addEntry(name, value) |
michael@0 | 990 | { |
michael@0 | 991 | updateFormHistory({ op : "add", fieldname : name, value: value }, runTest); |
michael@0 | 992 | } |
michael@0 | 993 | |
michael@0 | 994 | // Runs the next test when scroll event occurs |
michael@0 | 995 | function waitForScroll() |
michael@0 | 996 | { |
michael@0 | 997 | addEventListener("scroll", function() { |
michael@0 | 998 | if (!window.pageYOffset) |
michael@0 | 999 | return; |
michael@0 | 1000 | |
michael@0 | 1001 | removeEventListener("scroll", arguments.callee, false); |
michael@0 | 1002 | setTimeout(runTest, 50); |
michael@0 | 1003 | }, false); |
michael@0 | 1004 | } |
michael@0 | 1005 | |
michael@0 | 1006 | function waitForMenuChange(expectedCount, expectedFirstValue) |
michael@0 | 1007 | { |
michael@0 | 1008 | if (autocompleteMenu.tree.view.rowCount != expectedCount) { |
michael@0 | 1009 | SimpleTest.executeSoon(function () waitForMenuChange(expectedCount, expectedFirstValue)); |
michael@0 | 1010 | } |
michael@0 | 1011 | else if (expectedFirstValue && autocompleteMenu.tree.view.rowCount > 1 && |
michael@0 | 1012 | autocompleteMenu.tree.view.getValueAt(0, autocompleteMenu.tree.columns[0]) != expectedFirstValue) { |
michael@0 | 1013 | SimpleTest.executeSoon(function () waitForMenuChange(expectedCount, expectedFirstValue)); |
michael@0 | 1014 | } |
michael@0 | 1015 | else { |
michael@0 | 1016 | runTest(); |
michael@0 | 1017 | } |
michael@0 | 1018 | } |
michael@0 | 1019 | |
michael@0 | 1020 | function checkMenuEntries(expectedValues, testNum) { |
michael@0 | 1021 | var actualValues = getMenuEntries(); |
michael@0 | 1022 | is(actualValues.length, expectedValues.length, testNum + " Checking length of expected menu"); |
michael@0 | 1023 | for (var i = 0; i < expectedValues.length; i++) |
michael@0 | 1024 | is(actualValues[i], expectedValues[i], testNum + " Checking menu entry #"+i); |
michael@0 | 1025 | } |
michael@0 | 1026 | |
michael@0 | 1027 | function getMenuEntries() { |
michael@0 | 1028 | var entries = []; |
michael@0 | 1029 | |
michael@0 | 1030 | // Could perhaps pull values directly from the controller, but it seems |
michael@0 | 1031 | // more reliable to test the values that are actually in the tree? |
michael@0 | 1032 | var column = autocompleteMenu.tree.columns[0]; |
michael@0 | 1033 | var numRows = autocompleteMenu.tree.view.rowCount; |
michael@0 | 1034 | for (var i = 0; i < numRows; i++) { |
michael@0 | 1035 | entries.push(autocompleteMenu.tree.view.getValueAt(i, column)); |
michael@0 | 1036 | } |
michael@0 | 1037 | return entries; |
michael@0 | 1038 | } |
michael@0 | 1039 | |
michael@0 | 1040 | function startTest() { |
michael@0 | 1041 | setupFormHistory(function() { |
michael@0 | 1042 | runTest(); |
michael@0 | 1043 | }); |
michael@0 | 1044 | } |
michael@0 | 1045 | |
michael@0 | 1046 | window.onload = startTest; |
michael@0 | 1047 | |
michael@0 | 1048 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 1049 | </script> |
michael@0 | 1050 | </pre> |
michael@0 | 1051 | </body> |
michael@0 | 1052 | </html> |
michael@0 | 1053 |