toolkit/components/satchel/test/test_form_submission_cap.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial