|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Satchel Test for Form Submisstion</title> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="text/javascript" src="satchel_common.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
8 </head> |
|
9 <body> |
|
10 <p id="display"></p> |
|
11 <iframe id="iframe" src="https://example.com/tests/toolkit/components/satchel/test/subtst_form_submission_1.html"></iframe> |
|
12 <div id="content" style="display: none"> |
|
13 |
|
14 <!-- ===== Things that should not be saved. ===== --> |
|
15 |
|
16 <!-- autocomplete=off for input --> |
|
17 <form id="form1" onsubmit="return checkSubmit(1)"> |
|
18 <input type="text" name="test1" autocomplete="off"> |
|
19 <button type="submit">Submit</button> |
|
20 </form> |
|
21 |
|
22 <!-- autocomplete=off for form --> |
|
23 <form id="form2" onsubmit="return checkSubmit(2)" autocomplete="off"> |
|
24 <input type="text" name="test1"> |
|
25 <button type="submit">Submit</button> |
|
26 </form> |
|
27 |
|
28 <!-- don't save type=hidden --> |
|
29 <form id="form3" onsubmit="return checkSubmit(3)"> |
|
30 <input type="hidden" name="test1"> |
|
31 <button type="submit">Submit</button> |
|
32 </form> |
|
33 |
|
34 <!-- don't save type=checkbox --> |
|
35 <form id="form4" onsubmit="return checkSubmit(4)"> |
|
36 <input type="checkbox" name="test1"> |
|
37 <button type="submit">Submit</button> |
|
38 </form> |
|
39 |
|
40 <!-- Don't save empty values. --> |
|
41 <form id="form5" onsubmit="return checkSubmit(5)"> |
|
42 <input type="text" name="test1" value="originalValue"> |
|
43 <button type="submit">Submit</button> |
|
44 </form> |
|
45 |
|
46 <!-- Don't save unchanged values. --> |
|
47 <form id="form6" onsubmit="return checkSubmit(6)"> |
|
48 <input type="text" name="test1" value="dontSaveThis"> |
|
49 <button type="submit">Submit</button> |
|
50 </form> |
|
51 |
|
52 <!-- Don't save unchanged values. (.value not touched) --> |
|
53 <form id="form7" onsubmit="return checkSubmit(7)"> |
|
54 <input type="text" name="test1" value="dontSaveThis"> |
|
55 <button type="submit">Submit</button> |
|
56 </form> |
|
57 |
|
58 <!-- No field name or ID. --> |
|
59 <form id="form8" onsubmit="return checkSubmit(8)"> |
|
60 <input type="text"> |
|
61 <button type="submit">Submit</button> |
|
62 </form> |
|
63 |
|
64 <!-- Nothing to save! --> |
|
65 <form id="form9" onsubmit="return checkSubmit(9)"> |
|
66 <button type="submit">Submit</button> |
|
67 </form> |
|
68 |
|
69 <!-- input with name too long (300 chars.) --> |
|
70 <form id="form10" onsubmit="return checkSubmit(10)"> |
|
71 <input type="text" name="12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"> |
|
72 <button type="submit">Submit</button> |
|
73 </form> |
|
74 |
|
75 <!-- input with value too long (300 chars.) --> |
|
76 <form id="form11" onsubmit="return checkSubmit(11)"> |
|
77 <input type="text" name="test1"> |
|
78 <button type="submit">Submit</button> |
|
79 </form> |
|
80 |
|
81 <!-- input with value of one space (which should be trimmed) --> |
|
82 <form id="form12" onsubmit="return checkSubmit(12)"> |
|
83 <input type="text" name="test1"> |
|
84 <button type="submit">Submit</button> |
|
85 </form> |
|
86 |
|
87 <!-- password field --> |
|
88 <form id="form13" onsubmit="return checkSubmit(13)"> |
|
89 <input type="password" name="test1"> |
|
90 <button type="submit">Submit</button> |
|
91 </form> |
|
92 |
|
93 <!-- password field (type changed after pageload) --> |
|
94 <form id="form14" onsubmit="return checkSubmit(14)"> |
|
95 <input type="text" name="test1"> |
|
96 <button type="submit">Submit</button> |
|
97 </form> |
|
98 |
|
99 <!-- input with sensitive data (16 digit credit card number) --> |
|
100 <form id="form15" onsubmit="return checkSubmit(15)"> |
|
101 <script type="text/javascript"> |
|
102 var form = document.getElementById('form15'); |
|
103 for (var i = 0; i != 10; i++) |
|
104 { |
|
105 var input = document.createElement('input'); |
|
106 input.type = 'text'; |
|
107 input.name = 'test' + (i + 1); |
|
108 form.appendChild(input); |
|
109 } |
|
110 </script> |
|
111 <button type="submit">Submit</button> |
|
112 </form> |
|
113 |
|
114 <!-- input with sensitive data (15 digit credit card number) --> |
|
115 <form id="form16" onsubmit="return checkSubmit(16)"> |
|
116 <script type="text/javascript"> |
|
117 var form = document.getElementById('form16'); |
|
118 for (var i = 0; i != 10; i++) |
|
119 { |
|
120 var input = document.createElement('input'); |
|
121 input.type = 'text'; |
|
122 input.name = 'test' + (i + 1); |
|
123 form.appendChild(input); |
|
124 } |
|
125 </script> |
|
126 <button type="submit">Submit</button> |
|
127 </form> |
|
128 |
|
129 <!-- input with sensitive data (9 digit credit card number) --> |
|
130 <form id="form17" onsubmit="return checkSubmit(17)"> |
|
131 <input type="text" name="test1"> |
|
132 <button type="submit">Submit</button> |
|
133 </form> |
|
134 |
|
135 <!-- input with sensitive data (16 digit hyphenated credit card number) --> |
|
136 <form id="form18" onsubmit="return checkSubmit(18)"> |
|
137 <input type="text" name="test1"> |
|
138 <button type="submit">Submit</button> |
|
139 </form> |
|
140 |
|
141 <!-- input with sensitive data (15 digit whitespace-separated credit card number) --> |
|
142 <form id="form19" onsubmit="return checkSubmit(19)"> |
|
143 <input type="text" name="test1"> |
|
144 <button type="submit">Submit</button> |
|
145 </form> |
|
146 |
|
147 <!-- form data submitted through HTTPS, when browser.formfill.saveHttpsForms is false --> |
|
148 <form id="form20" action="https://www.example.com/" onsubmit="return checkSubmit(20)"> |
|
149 <input type="text" name="test1"> |
|
150 <button type="submit">Submit</button> |
|
151 </form> |
|
152 |
|
153 <!-- Form 21 is submitted into an iframe, not declared here. --> |
|
154 |
|
155 <!-- Don't save values if the form is invalid. --> |
|
156 <form id="form22" onsubmit="return checkSubmit(22);"> |
|
157 <input type='email' name='test1' oninvalid="return checkSubmit(22);"> |
|
158 <button type='submit'>Submit</button> |
|
159 </form> |
|
160 |
|
161 <!-- Don't save values if the form is invalid. --> |
|
162 <form id="form23" onsubmit="return checkSubmit(23);"> |
|
163 <input type='email' value='foo' oninvalid="return checkSubmit(23);"> |
|
164 <input type='text' name='test1'> |
|
165 <button type='submit'>Submit</button> |
|
166 </form> |
|
167 |
|
168 <!-- Don't save values if the input name is 'searchbar-history' --> |
|
169 <form id="form24" onsubmit="return checkSubmit(24);"> |
|
170 <input type='text' name='searchbar-history'> |
|
171 <button type='submit'>Submit</button> |
|
172 </form> |
|
173 |
|
174 <!-- ===== Things that should be saved ===== --> |
|
175 |
|
176 <!-- Form 100 is submitted into an iframe, not declared here. --> |
|
177 |
|
178 <!-- input with no default value --> |
|
179 <form id="form101" onsubmit="return checkSubmit(101)"> |
|
180 <input type="text" name="test1"> |
|
181 <button type="submit">Submit</button> |
|
182 </form> |
|
183 |
|
184 <!-- input with a default value --> |
|
185 <form id="form102" onsubmit="return checkSubmit(102)"> |
|
186 <input type="text" name="test2" value="originalValue"> |
|
187 <button type="submit">Submit</button> |
|
188 </form> |
|
189 |
|
190 <!-- input uses id but not name --> |
|
191 <form id="form103" onsubmit="return checkSubmit(103)"> |
|
192 <input type="text" id="test3"> |
|
193 <button type="submit">Submit</button> |
|
194 </form> |
|
195 |
|
196 <!-- input with leading and trailing space --> |
|
197 <form id="form104" onsubmit="return checkSubmit(104)"> |
|
198 <input type="text" name="test4"> |
|
199 <button type="submit">Submit</button> |
|
200 </form> |
|
201 |
|
202 <!-- input with leading and trailing whitespace --> |
|
203 <form id="form105" onsubmit="return checkSubmit(105)"> |
|
204 <input type="text" name="test5"> |
|
205 <button type="submit">Submit</button> |
|
206 </form> |
|
207 |
|
208 <!-- input that looks like sensitive data but doesn't |
|
209 satisfy the requirements (incorrect length) --> |
|
210 <form id="form106" onsubmit="return checkSubmit(106)"> |
|
211 <input type="text" name="test6"> |
|
212 <button type="submit">Submit</button> |
|
213 </form> |
|
214 |
|
215 <!-- input that looks like sensitive data but doesn't |
|
216 satisfy the requirements (Luhn check fails for 16 chars) --> |
|
217 <form id="form107" onsubmit="return checkSubmit(107)"> |
|
218 <script type="text/javascript"> |
|
219 var form = document.getElementById('form107'); |
|
220 for (var i = 0; i != 10; i++) |
|
221 { |
|
222 var input = document.createElement('input'); |
|
223 input.type = 'text'; |
|
224 input.name = 'test7_' + (i + 1); |
|
225 form.appendChild(input); |
|
226 } |
|
227 </script> |
|
228 <button type="submit">Submit</button> |
|
229 </form> |
|
230 |
|
231 <!-- input that looks like sensitive data but doesn't |
|
232 satisfy the requirements (Luhn check fails for 15 chars) --> |
|
233 <form id="form108" onsubmit="return checkSubmit(108)"> |
|
234 <script type="text/javascript"> |
|
235 var form = document.getElementById('form108'); |
|
236 for (var i = 0; i != 10; i++) |
|
237 { |
|
238 var input = document.createElement('input'); |
|
239 input.type = 'text'; |
|
240 input.name = 'test8_' + (i + 1); |
|
241 form.appendChild(input); |
|
242 } |
|
243 </script> |
|
244 <button type="submit">Submit</button> |
|
245 </form> |
|
246 |
|
247 <!-- form data submitted through HTTPS, when browser.formfill.saveHttpsForms is true --> |
|
248 <form id="form109" action="https://www.example.com/" onsubmit="return checkSubmit(109)"> |
|
249 <input type="text" name="test9"> |
|
250 <button type="submit">Submit</button> |
|
251 </form> |
|
252 |
|
253 <!-- regular form data, when browser.formfill.saveHttpsForms is false --> |
|
254 <form id="form110" onsubmit="return checkSubmit(110)"> |
|
255 <input type="text" name="test10"> |
|
256 <button type="submit">Submit</button> |
|
257 </form> |
|
258 |
|
259 </div> |
|
260 <pre id="test"> |
|
261 <script class="testbody" type="text/javascript"> |
|
262 |
|
263 var numSubmittedForms = 0; |
|
264 |
|
265 var ccNumbers = { |
|
266 valid15: [ |
|
267 "930771457288760", "474915027480942", |
|
268 "924894781317325", "714816113937185", |
|
269 "790466087343106", "474320195408363", |
|
270 "219211148122351", "633038472250799", |
|
271 "354236732906484", "095347810189325", |
|
272 ], |
|
273 valid16: [ |
|
274 "3091269135815020", "5471839082338112", |
|
275 "0580828863575793", "5015290610002932", |
|
276 "9465714503078607", "4302068493801686", |
|
277 "2721398408985465", "6160334316984331", |
|
278 "8643619970075142", "0218246069710785" |
|
279 ], |
|
280 invalid15: [ |
|
281 "526931005800649", "724952425140686", |
|
282 "379761391174135", "030551436468583", |
|
283 "947377014076746", "254848023655752", |
|
284 "226871580283345", "708025346034339", |
|
285 "917585839076788", "918632588027666" |
|
286 ], |
|
287 invalid16: [ |
|
288 "9946177098017064", "4081194386488872", |
|
289 "3095975979578034", "3662215692222536", |
|
290 "6723210018630429", "4411962856225025", |
|
291 "8276996369036686", "4449796938248871", |
|
292 "3350852696538147", "5011802870046957" |
|
293 ], |
|
294 }; |
|
295 |
|
296 function checkInitialState() { |
|
297 countEntries(null, null, |
|
298 function (num) { |
|
299 ok(!num, "checking for initially empty storage"); |
|
300 startTest(); |
|
301 }); |
|
302 } |
|
303 |
|
304 function startTest() { |
|
305 // Fill in values for the various fields. We could just set the <input>'s |
|
306 // value attribute, but we don't save default form values (and we want to |
|
307 // ensure unsaved values are because of autocomplete=off or whatever). |
|
308 $_(1, "test1").value = "dontSaveThis"; |
|
309 $_(2, "test1").value = "dontSaveThis"; |
|
310 $_(3, "test1").value = "dontSaveThis"; |
|
311 $_(4, "test1").value = "dontSaveThis"; |
|
312 $_(5, "test1").value = ""; |
|
313 $_(6, "test1").value = "dontSaveThis"; |
|
314 // Form 7 deliberately left untouched. |
|
315 // Form 8 has an input with no name or input attribute. |
|
316 var input = document.getElementById("form8").elements[0]; |
|
317 is(input.type, "text", "checking we got unidentified input"); |
|
318 input.value = "dontSaveThis"; |
|
319 // Form 9 has nothing to modify. |
|
320 $_(10, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890").value = "dontSaveThis"; |
|
321 $_(11, "test1").value = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; |
|
322 $_(12, "test1").value = " "; |
|
323 $_(13, "test1").value = "dontSaveThis"; |
|
324 $_(14, "test1").type = "password"; |
|
325 $_(14, "test1").value = "dontSaveThis"; |
|
326 |
|
327 var testData = ccNumbers.valid16; |
|
328 for (var i = 0; i != testData.length; i++) { |
|
329 $_(15, "test" + (i + 1)).value = testData[i]; |
|
330 } |
|
331 |
|
332 testData = ccNumbers.valid15; |
|
333 for (var i = 0; i != testData.length; i++) { |
|
334 $_(16, "test" + (i + 1)).value = testData[i]; |
|
335 } |
|
336 $_(17, "test1").value = "001064088"; |
|
337 $_(18, "test1").value = "0000-0000-0080-4609"; |
|
338 $_(19, "test1").value = "0000 0000 0222 331"; |
|
339 $_(20, "test1").value = "dontSaveThis"; |
|
340 $_(22, "test1").value = "dontSaveThis"; |
|
341 $_(23, "test1").value = "dontSaveThis"; |
|
342 $_(24, "searchbar-history").value = "dontSaveThis"; |
|
343 |
|
344 $_(101, "test1").value = "savedValue"; |
|
345 $_(102, "test2").value = "savedValue"; |
|
346 $_(103, "test3").value = "savedValue"; |
|
347 $_(104, "test4").value = " trimTrailingAndLeadingSpace "; |
|
348 $_(105, "test5").value = "\t trimTrailingAndLeadingWhitespace\t "; |
|
349 $_(106, "test6").value = "00000000109181"; |
|
350 |
|
351 var testData = ccNumbers.invalid16; |
|
352 for (var i = 0; i != testData.length; i++) { |
|
353 $_(107, "test7_" + (i + 1)).value = testData[i]; |
|
354 } |
|
355 |
|
356 var testData = ccNumbers.invalid15; |
|
357 for (var i = 0; i != testData.length; i++) { |
|
358 $_(108, "test8_" + (i + 1)).value = testData[i]; |
|
359 } |
|
360 |
|
361 $_(109, "test9").value = "savedValue"; |
|
362 $_(110, "test10").value = "savedValue"; |
|
363 |
|
364 // submit the first form. |
|
365 var button = getFormSubmitButton(1); |
|
366 button.click(); |
|
367 } |
|
368 |
|
369 |
|
370 // Called by each form's onsubmit handler. |
|
371 function checkSubmit(formNum) { |
|
372 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
|
373 |
|
374 ok(true, "form " + formNum + " submitted"); |
|
375 numSubmittedForms++; |
|
376 |
|
377 // Check for expected storage state. |
|
378 switch (formNum) { |
|
379 // Test 1-24 should not save anything. |
|
380 case 1: |
|
381 case 2: |
|
382 case 3: |
|
383 case 4: |
|
384 case 5: |
|
385 case 6: |
|
386 case 7: |
|
387 case 8: |
|
388 case 9: |
|
389 case 10: |
|
390 case 11: |
|
391 case 12: |
|
392 case 13: |
|
393 case 14: |
|
394 case 15: |
|
395 case 16: |
|
396 case 17: |
|
397 case 18: |
|
398 case 19: |
|
399 case 20: |
|
400 case 21: |
|
401 case 22: |
|
402 case 23: |
|
403 case 24: |
|
404 countEntries(null, null, |
|
405 function (num) { |
|
406 ok(!num, "checking for empty storage"); |
|
407 submitForm(formNum); |
|
408 }); |
|
409 return false; |
|
410 break; |
|
411 case 100: |
|
412 checkForSave("subtest2", "subtestValue", "checking saved subtest value"); |
|
413 break; |
|
414 case 101: |
|
415 checkForSave("test1", "savedValue", "checking saved value"); |
|
416 break; |
|
417 case 102: |
|
418 checkForSave("test2", "savedValue", "checking saved value"); |
|
419 break; |
|
420 case 103: |
|
421 checkForSave("test3", "savedValue", "checking saved value"); |
|
422 break; |
|
423 case 104: |
|
424 checkForSave("test4", "trimTrailingAndLeadingSpace", "checking saved value is trimmed on both sides"); |
|
425 break; |
|
426 case 105: |
|
427 checkForSave("test5", "trimTrailingAndLeadingWhitespace", "checking saved value is trimmed on both sides"); |
|
428 break; |
|
429 case 106: |
|
430 checkForSave("test6", "00000000109181", "checking saved value"); |
|
431 break; |
|
432 case 107: |
|
433 for (var i = 0; i != ccNumbers.invalid16.length; i++) { |
|
434 checkForSave("test7_" + (i + 1), ccNumbers.invalid16[i], "checking saved value"); |
|
435 } |
|
436 break; |
|
437 case 108: |
|
438 for (var i = 0; i != ccNumbers.invalid15.length; i++) { |
|
439 checkForSave("test8_" + (i + 1), ccNumbers.invalid15[i], "checking saved value"); |
|
440 } |
|
441 break; |
|
442 case 109: |
|
443 checkForSave("test9", "savedValue", "checking saved value"); |
|
444 break; |
|
445 case 110: |
|
446 checkForSave("test10", "savedValue", "checking saved value"); |
|
447 break; |
|
448 default: |
|
449 ok(false, "Unexpected form submission"); |
|
450 break; |
|
451 } |
|
452 |
|
453 return submitForm(formNum); |
|
454 } |
|
455 |
|
456 function submitForm(formNum) |
|
457 { |
|
458 // Forms 13 and 14 would trigger a save-password notification. Temporarily |
|
459 // disable pwmgr, then reenable it. |
|
460 if (formNum == 12) |
|
461 SpecialPowers.setBoolPref("signon.rememberSignons", false); |
|
462 if (formNum == 14) |
|
463 SpecialPowers.clearUserPref("signon.rememberSignons"); |
|
464 |
|
465 // Forms 20 and 21 requires browser.formfill.saveHttpsForms to be false |
|
466 if (formNum == 19) |
|
467 SpecialPowers.setBoolPref("browser.formfill.saveHttpsForms", false); |
|
468 // Reset preference now that 20 and 21 are over |
|
469 if (formNum == 21) |
|
470 SpecialPowers.clearUserPref("browser.formfill.saveHttpsForms"); |
|
471 |
|
472 // End the test now on SeaMonkey. |
|
473 if (formNum == 21 && navigator.userAgent.match(/ SeaMonkey\//)) { |
|
474 Services.obs.removeObserver(checkObserver, "satchel-storage-changed"); |
|
475 is(numSubmittedForms, 21, "Ensuring all forms were submitted."); |
|
476 |
|
477 todo(false, "Skipping remaining checks on SeaMonkey ftb. (Bug 589471)"); |
|
478 // finish(), yet let the test actually end first, to be safe. |
|
479 SimpleTest.executeSoon(SimpleTest.finish); |
|
480 |
|
481 return false; // return false to cancel current form submission |
|
482 } |
|
483 |
|
484 // Form 109 requires browser.formfill.save_https_forms to be true; |
|
485 // Form 110 requires it to be false. |
|
486 if (formNum == 108) |
|
487 SpecialPowers.setBoolPref("browser.formfill.saveHttpsForms", true); |
|
488 if (formNum == 109) |
|
489 SpecialPowers.setBoolPref("browser.formfill.saveHttpsForms", false); |
|
490 if (formNum == 110) |
|
491 SpecialPowers.clearUserPref("browser.formfill.saveHttpsForms"); |
|
492 |
|
493 // End the test at the last form. |
|
494 if (formNum == 110) { |
|
495 is(numSubmittedForms, 35, "Ensuring all forms were submitted."); |
|
496 Services.obs.removeObserver(checkObserver, "satchel-storage-changed"); |
|
497 SimpleTest.finish(); |
|
498 return false; // return false to cancel current form submission |
|
499 } |
|
500 |
|
501 // This timeout is here so that button.click() is never called before this |
|
502 // function returns. If button.click() is called before returning, a long |
|
503 // chain of submits will happen recursively since the submit is dispatched |
|
504 // immediately. |
|
505 // |
|
506 // This in itself is fine, but if there are errors in the code, mochitests |
|
507 // will in some cases give you "server too busy", which is hard to debug! |
|
508 // |
|
509 setTimeout(function() { |
|
510 checkObserver.waitForChecks(function() { |
|
511 var nextFormNum = formNum == 24 ? 100 : (formNum + 1); |
|
512 |
|
513 // Submit the next form. Special cases are Forms 21 and 100, which happen |
|
514 // from an HTTPS domain in an iframe. |
|
515 if (nextFormNum == 21 || nextFormNum == 100) { |
|
516 ok(true, "submitting iframe test " + nextFormNum); |
|
517 document.getElementById("iframe").contentWindow.clickButton(nextFormNum); |
|
518 } |
|
519 else { |
|
520 var button = getFormSubmitButton(nextFormNum); |
|
521 button.click(); |
|
522 } |
|
523 }); |
|
524 }, 0); |
|
525 |
|
526 return false; // cancel current form submission |
|
527 } |
|
528 |
|
529 Services.obs.addObserver(checkObserver, "satchel-storage-changed", false); |
|
530 |
|
531 window.onload = checkInitialState; |
|
532 |
|
533 SimpleTest.waitForExplicitFinish(); |
|
534 |
|
535 </script> |
|
536 </pre> |
|
537 </body> |
|
538 </html> |