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