toolkit/components/satchel/test/test_form_submission_cap.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/satchel/test/test_form_submission_cap.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Satchel Test for Form Submisstion Field Cap</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="satchel_common.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<p id="display"></p>
    1.14 +<div id="content" style="display: none">
    1.15 +
    1.16 +  <form id="form1" onsubmit="return checkSubmit(1)">
    1.17 +    <button type="submit">Submit</button>
    1.18 +  </form>
    1.19 +
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<script class="testbody" type="text/javascript">
    1.23 +
    1.24 +/* Test for bug 492701.
    1.25 +   Save only the first MAX_FIELDS_SAVED changed fields in a form.
    1.26 +   Generate numInputFields = MAX_FIELDS_SAVED + 1 fields, change all values,
    1.27 +   and test that only MAX_FIELDS_SAVED are actually saved and that
    1.28 +   field # numInputFields was not saved.
    1.29 +*/
    1.30 +
    1.31 +var numSubmittedForms = 0;
    1.32 +var numInputFields = 101;
    1.33 +
    1.34 +function checkInitialState() {
    1.35 +  countEntries(null, null,
    1.36 +    function (num) {
    1.37 +      ok(!num, "checking for initially empty storage");
    1.38 +      startTest();
    1.39 +    });
    1.40 +}
    1.41 +
    1.42 +function startTest() {
    1.43 +  var form = document.getElementById("form1");
    1.44 +  for (i = 1; i <= numInputFields; i++) {
    1.45 +    var newField = document.createElement("input");
    1.46 +    newField.setAttribute("type", "text");
    1.47 +    newField.setAttribute("name", "test" + i);
    1.48 +    form.appendChild(newField);
    1.49 +  }
    1.50 +
    1.51 +  // Fill in values for the various fields. We could just set the <input>'s
    1.52 +  // value attribute, but we don't save default form values (and we want to
    1.53 +  // ensure unsaved values are because of autocomplete=off or whatever).
    1.54 +  for (i = 1; i <= numInputFields; i++) {
    1.55 +    $_(1, "test" + i).value = i;
    1.56 +  }
    1.57 +
    1.58 +  // submit the first form.
    1.59 +  var button = getFormSubmitButton(1);
    1.60 +  button.click();
    1.61 +}
    1.62 +
    1.63 +
    1.64 +// Called by each form's onsubmit handler.
    1.65 +function checkSubmit(formNum) {
    1.66 +  ok(true, "form " + formNum + " submitted");
    1.67 +  numSubmittedForms++;
    1.68 +
    1.69 +  // check that the first (numInputFields - 1) CHANGED fields are saved
    1.70 +  for (i = 1; i < numInputFields; i++) { // check all but last
    1.71 +    checkForSave("test" + i, i, "checking saved value " + i);
    1.72 +  }
    1.73 +
    1.74 +  // End the test.
    1.75 +  is(numSubmittedForms, 1, "Ensuring all forms were submitted.");
    1.76 +  SimpleTest.finish();
    1.77 +  return false; // return false to cancel current form submission
    1.78 +}
    1.79 +
    1.80 +
    1.81 +window.onload = checkInitialState;
    1.82 +
    1.83 +SimpleTest.waitForExplicitFinish();
    1.84 +
    1.85 +</script>
    1.86 +</pre>
    1.87 +</body>
    1.88 +</html>

mercurial