toolkit/components/satchel/test/test_form_submission_cap.html

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:e242bcb19a84
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Satchel Test for Form Submisstion Field Cap</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 <div id="content" style="display: none">
12
13 <form id="form1" onsubmit="return checkSubmit(1)">
14 <button type="submit">Submit</button>
15 </form>
16
17 </div>
18 <pre id="test">
19 <script class="testbody" type="text/javascript">
20
21 /* Test for bug 492701.
22 Save only the first MAX_FIELDS_SAVED changed fields in a form.
23 Generate numInputFields = MAX_FIELDS_SAVED + 1 fields, change all values,
24 and test that only MAX_FIELDS_SAVED are actually saved and that
25 field # numInputFields was not saved.
26 */
27
28 var numSubmittedForms = 0;
29 var numInputFields = 101;
30
31 function checkInitialState() {
32 countEntries(null, null,
33 function (num) {
34 ok(!num, "checking for initially empty storage");
35 startTest();
36 });
37 }
38
39 function startTest() {
40 var form = document.getElementById("form1");
41 for (i = 1; i <= numInputFields; i++) {
42 var newField = document.createElement("input");
43 newField.setAttribute("type", "text");
44 newField.setAttribute("name", "test" + i);
45 form.appendChild(newField);
46 }
47
48 // Fill in values for the various fields. We could just set the <input>'s
49 // value attribute, but we don't save default form values (and we want to
50 // ensure unsaved values are because of autocomplete=off or whatever).
51 for (i = 1; i <= numInputFields; i++) {
52 $_(1, "test" + i).value = i;
53 }
54
55 // submit the first form.
56 var button = getFormSubmitButton(1);
57 button.click();
58 }
59
60
61 // Called by each form's onsubmit handler.
62 function checkSubmit(formNum) {
63 ok(true, "form " + formNum + " submitted");
64 numSubmittedForms++;
65
66 // check that the first (numInputFields - 1) CHANGED fields are saved
67 for (i = 1; i < numInputFields; i++) { // check all but last
68 checkForSave("test" + i, i, "checking saved value " + i);
69 }
70
71 // End the test.
72 is(numSubmittedForms, 1, "Ensuring all forms were submitted.");
73 SimpleTest.finish();
74 return false; // return false to cancel current form submission
75 }
76
77
78 window.onload = checkInitialState;
79
80 SimpleTest.waitForExplicitFinish();
81
82 </script>
83 </pre>
84 </body>
85 </html>

mercurial