toolkit/components/satchel/test/test_form_submission.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.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,538 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Satchel Test for Form Submisstion</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 +<iframe id="iframe" src="https://example.com/tests/toolkit/components/satchel/test/subtst_form_submission_1.html"></iframe>
    1.15 +<div id="content" style="display: none">
    1.16 +  
    1.17 +  <!-- ===== Things that should not be saved. ===== -->
    1.18 +
    1.19 +  <!-- autocomplete=off for input -->
    1.20 +  <form id="form1" onsubmit="return checkSubmit(1)">
    1.21 +    <input type="text" name="test1" autocomplete="off">
    1.22 +    <button type="submit">Submit</button>
    1.23 +  </form>
    1.24 +
    1.25 +  <!-- autocomplete=off for form -->
    1.26 +  <form id="form2" onsubmit="return checkSubmit(2)" autocomplete="off">
    1.27 +    <input type="text" name="test1">
    1.28 +    <button type="submit">Submit</button>
    1.29 +  </form>
    1.30 +
    1.31 +  <!-- don't save type=hidden -->
    1.32 +  <form id="form3" onsubmit="return checkSubmit(3)">
    1.33 +    <input type="hidden" name="test1">
    1.34 +    <button type="submit">Submit</button>
    1.35 +  </form>
    1.36 +
    1.37 +  <!-- don't save type=checkbox -->
    1.38 +  <form id="form4" onsubmit="return checkSubmit(4)">
    1.39 +    <input type="checkbox" name="test1">
    1.40 +    <button type="submit">Submit</button>
    1.41 +  </form>
    1.42 +
    1.43 +  <!-- Don't save empty values. -->
    1.44 +  <form id="form5" onsubmit="return checkSubmit(5)">
    1.45 +    <input type="text" name="test1" value="originalValue">
    1.46 +    <button type="submit">Submit</button>
    1.47 +  </form>
    1.48 +
    1.49 +  <!-- Don't save unchanged values. -->
    1.50 +  <form id="form6" onsubmit="return checkSubmit(6)">
    1.51 +    <input type="text" name="test1" value="dontSaveThis">
    1.52 +    <button type="submit">Submit</button>
    1.53 +  </form>
    1.54 +
    1.55 +  <!-- Don't save unchanged values. (.value not touched) -->
    1.56 +  <form id="form7" onsubmit="return checkSubmit(7)">
    1.57 +    <input type="text" name="test1" value="dontSaveThis">
    1.58 +    <button type="submit">Submit</button>
    1.59 +  </form>
    1.60 +
    1.61 +  <!-- No field name or ID. -->
    1.62 +  <form id="form8" onsubmit="return checkSubmit(8)">
    1.63 +    <input type="text">
    1.64 +    <button type="submit">Submit</button>
    1.65 +  </form>
    1.66 +
    1.67 +  <!-- Nothing to save! -->
    1.68 +  <form id="form9" onsubmit="return checkSubmit(9)">
    1.69 +    <button type="submit">Submit</button>
    1.70 +  </form>
    1.71 +
    1.72 +  <!-- input with name too long (300 chars.) -->
    1.73 +  <form id="form10" onsubmit="return checkSubmit(10)">
    1.74 +    <input type="text" name="12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890">
    1.75 +    <button type="submit">Submit</button>
    1.76 +  </form>
    1.77 +
    1.78 +  <!-- input with value too long (300 chars.) -->
    1.79 +  <form id="form11" onsubmit="return checkSubmit(11)">
    1.80 +    <input type="text" name="test1">
    1.81 +    <button type="submit">Submit</button>
    1.82 +  </form>
    1.83 +
    1.84 +  <!-- input with value of one space (which should be trimmed) -->
    1.85 +  <form id="form12" onsubmit="return checkSubmit(12)">
    1.86 +    <input type="text" name="test1">
    1.87 +    <button type="submit">Submit</button>
    1.88 +  </form>
    1.89 +
    1.90 +  <!-- password field -->
    1.91 +  <form id="form13" onsubmit="return checkSubmit(13)">
    1.92 +    <input type="password" name="test1">
    1.93 +    <button type="submit">Submit</button>
    1.94 +  </form>
    1.95 +
    1.96 +  <!-- password field (type changed after pageload) -->
    1.97 +  <form id="form14" onsubmit="return checkSubmit(14)">
    1.98 +    <input type="text" name="test1">
    1.99 +    <button type="submit">Submit</button>
   1.100 +  </form>
   1.101 +
   1.102 +  <!-- input with sensitive data (16 digit credit card number) -->
   1.103 +  <form id="form15" onsubmit="return checkSubmit(15)">
   1.104 +    <script type="text/javascript">
   1.105 +      var form = document.getElementById('form15');
   1.106 +      for (var i = 0; i != 10; i++)
   1.107 +      {
   1.108 +        var input = document.createElement('input');
   1.109 +        input.type = 'text';
   1.110 +        input.name = 'test' + (i + 1);
   1.111 +        form.appendChild(input);
   1.112 +      }
   1.113 +    </script>
   1.114 +    <button type="submit">Submit</button>
   1.115 +  </form>
   1.116 +
   1.117 +  <!-- input with sensitive data (15 digit credit card number) -->
   1.118 +  <form id="form16" onsubmit="return checkSubmit(16)">
   1.119 +    <script type="text/javascript">
   1.120 +      var form = document.getElementById('form16');
   1.121 +      for (var i = 0; i != 10; i++)
   1.122 +      {
   1.123 +        var input = document.createElement('input');
   1.124 +        input.type = 'text';
   1.125 +        input.name = 'test' + (i + 1);
   1.126 +        form.appendChild(input);
   1.127 +      }
   1.128 +    </script>
   1.129 +    <button type="submit">Submit</button>
   1.130 +  </form>
   1.131 +
   1.132 +  <!-- input with sensitive data (9 digit credit card number) -->
   1.133 +  <form id="form17" onsubmit="return checkSubmit(17)">
   1.134 +    <input type="text" name="test1">
   1.135 +    <button type="submit">Submit</button>
   1.136 +  </form>
   1.137 +
   1.138 +  <!-- input with sensitive data (16 digit hyphenated credit card number) -->
   1.139 +  <form id="form18" onsubmit="return checkSubmit(18)">
   1.140 +    <input type="text" name="test1">
   1.141 +    <button type="submit">Submit</button>
   1.142 +  </form>
   1.143 +
   1.144 +  <!-- input with sensitive data (15 digit whitespace-separated credit card number) -->
   1.145 +  <form id="form19" onsubmit="return checkSubmit(19)">
   1.146 +    <input type="text" name="test1">
   1.147 +    <button type="submit">Submit</button>
   1.148 +  </form>
   1.149 +
   1.150 +  <!-- form data submitted through HTTPS, when browser.formfill.saveHttpsForms is false -->
   1.151 +  <form id="form20" action="https://www.example.com/" onsubmit="return checkSubmit(20)">
   1.152 +    <input type="text" name="test1">
   1.153 +    <button type="submit">Submit</button>
   1.154 +  </form>
   1.155 +
   1.156 +  <!-- Form 21 is submitted into an iframe, not declared here. -->
   1.157 +
   1.158 +  <!-- Don't save values if the form is invalid. -->
   1.159 +  <form id="form22" onsubmit="return checkSubmit(22);">
   1.160 +    <input type='email' name='test1' oninvalid="return checkSubmit(22);">
   1.161 +    <button type='submit'>Submit</button>
   1.162 +  </form>
   1.163 +
   1.164 +  <!-- Don't save values if the form is invalid. -->
   1.165 +  <form id="form23" onsubmit="return checkSubmit(23);">
   1.166 +    <input type='email' value='foo' oninvalid="return checkSubmit(23);">
   1.167 +    <input type='text' name='test1'>
   1.168 +    <button type='submit'>Submit</button>
   1.169 +  </form>
   1.170 +
   1.171 +  <!-- Don't save values if the input name is 'searchbar-history' -->
   1.172 +  <form id="form24" onsubmit="return checkSubmit(24);">
   1.173 +    <input type='text' name='searchbar-history'>
   1.174 +    <button type='submit'>Submit</button>
   1.175 +  </form>
   1.176 +
   1.177 +  <!-- ===== Things that should be saved ===== -->
   1.178 +
   1.179 +  <!-- Form 100 is submitted into an iframe, not declared here. -->
   1.180 +
   1.181 +  <!-- input with no default value -->
   1.182 +  <form id="form101" onsubmit="return checkSubmit(101)">
   1.183 +    <input type="text" name="test1">
   1.184 +    <button type="submit">Submit</button>
   1.185 +  </form>
   1.186 +
   1.187 +  <!-- input with a default value -->
   1.188 +  <form id="form102" onsubmit="return checkSubmit(102)">
   1.189 +    <input type="text" name="test2" value="originalValue">
   1.190 +    <button type="submit">Submit</button>
   1.191 +  </form>
   1.192 +
   1.193 +  <!-- input uses id but not name -->
   1.194 +  <form id="form103" onsubmit="return checkSubmit(103)">
   1.195 +    <input type="text" id="test3">
   1.196 +    <button type="submit">Submit</button>
   1.197 +  </form>
   1.198 +
   1.199 +  <!-- input with leading and trailing space -->
   1.200 +  <form id="form104" onsubmit="return checkSubmit(104)">
   1.201 +    <input type="text" name="test4">
   1.202 +    <button type="submit">Submit</button>
   1.203 +  </form>
   1.204 +
   1.205 +  <!-- input with leading and trailing whitespace -->
   1.206 +  <form id="form105" onsubmit="return checkSubmit(105)">
   1.207 +    <input type="text" name="test5">
   1.208 +    <button type="submit">Submit</button>
   1.209 +  </form>
   1.210 +
   1.211 +  <!-- input that looks like sensitive data but doesn't
   1.212 +       satisfy the requirements (incorrect length) -->
   1.213 +  <form id="form106" onsubmit="return checkSubmit(106)">
   1.214 +    <input type="text" name="test6">
   1.215 +    <button type="submit">Submit</button>
   1.216 +  </form>
   1.217 +
   1.218 +  <!-- input that looks like sensitive data but doesn't
   1.219 +       satisfy the requirements (Luhn check fails for 16 chars) -->
   1.220 +  <form id="form107" onsubmit="return checkSubmit(107)">
   1.221 +    <script type="text/javascript">
   1.222 +      var form = document.getElementById('form107');
   1.223 +      for (var i = 0; i != 10; i++)
   1.224 +      {
   1.225 +        var input = document.createElement('input');
   1.226 +        input.type = 'text';
   1.227 +        input.name = 'test7_' + (i + 1);
   1.228 +        form.appendChild(input);
   1.229 +      }
   1.230 +    </script>
   1.231 +    <button type="submit">Submit</button>
   1.232 +  </form>
   1.233 +
   1.234 +  <!-- input that looks like sensitive data but doesn't
   1.235 +       satisfy the requirements (Luhn check fails for 15 chars) -->
   1.236 +  <form id="form108" onsubmit="return checkSubmit(108)">
   1.237 +    <script type="text/javascript">
   1.238 +      var form = document.getElementById('form108');
   1.239 +      for (var i = 0; i != 10; i++)
   1.240 +      {
   1.241 +        var input = document.createElement('input');
   1.242 +        input.type = 'text';
   1.243 +        input.name = 'test8_' + (i + 1);
   1.244 +        form.appendChild(input);
   1.245 +      }
   1.246 +    </script>
   1.247 +    <button type="submit">Submit</button>
   1.248 +  </form>
   1.249 +
   1.250 +  <!-- form data submitted through HTTPS, when browser.formfill.saveHttpsForms is true -->
   1.251 +  <form id="form109" action="https://www.example.com/" onsubmit="return checkSubmit(109)">
   1.252 +    <input type="text" name="test9">
   1.253 +    <button type="submit">Submit</button>
   1.254 +  </form>
   1.255 +
   1.256 +  <!-- regular form data, when browser.formfill.saveHttpsForms is false -->
   1.257 +  <form id="form110" onsubmit="return checkSubmit(110)">
   1.258 +    <input type="text" name="test10">
   1.259 +    <button type="submit">Submit</button>
   1.260 +  </form>
   1.261 +
   1.262 +</div>
   1.263 +<pre id="test">
   1.264 +<script class="testbody" type="text/javascript">
   1.265 +
   1.266 +var numSubmittedForms = 0;
   1.267 +
   1.268 +var ccNumbers = {
   1.269 +  valid15: [
   1.270 +    "930771457288760", "474915027480942",
   1.271 +    "924894781317325", "714816113937185",
   1.272 +    "790466087343106", "474320195408363",
   1.273 +    "219211148122351", "633038472250799",
   1.274 +    "354236732906484", "095347810189325",
   1.275 +  ],
   1.276 +  valid16: [
   1.277 +    "3091269135815020", "5471839082338112",
   1.278 +    "0580828863575793", "5015290610002932",
   1.279 +    "9465714503078607", "4302068493801686",
   1.280 +    "2721398408985465", "6160334316984331",
   1.281 +    "8643619970075142", "0218246069710785"
   1.282 +  ],
   1.283 +  invalid15: [
   1.284 +    "526931005800649", "724952425140686",
   1.285 +    "379761391174135", "030551436468583",
   1.286 +    "947377014076746", "254848023655752",
   1.287 +    "226871580283345", "708025346034339",
   1.288 +    "917585839076788", "918632588027666"
   1.289 +  ],
   1.290 +  invalid16: [
   1.291 +    "9946177098017064", "4081194386488872",
   1.292 +    "3095975979578034", "3662215692222536",
   1.293 +    "6723210018630429", "4411962856225025",
   1.294 +    "8276996369036686", "4449796938248871",
   1.295 +    "3350852696538147", "5011802870046957"
   1.296 +  ],
   1.297 +};
   1.298 +
   1.299 +function checkInitialState() {
   1.300 +  countEntries(null, null,
   1.301 +    function (num) {
   1.302 +      ok(!num, "checking for initially empty storage");
   1.303 +      startTest();
   1.304 +    });
   1.305 +}
   1.306 +
   1.307 +function startTest() {
   1.308 +  // Fill in values for the various fields. We could just set the <input>'s
   1.309 +  // value attribute, but we don't save default form values (and we want to
   1.310 +  // ensure unsaved values are because of autocomplete=off or whatever).
   1.311 +  $_(1, "test1").value = "dontSaveThis";
   1.312 +  $_(2, "test1").value = "dontSaveThis";
   1.313 +  $_(3, "test1").value = "dontSaveThis";
   1.314 +  $_(4, "test1").value = "dontSaveThis";
   1.315 +  $_(5, "test1").value = "";
   1.316 +  $_(6, "test1").value = "dontSaveThis";
   1.317 +  // Form 7 deliberately left untouched.
   1.318 +  // Form 8 has an input with no name or input attribute.
   1.319 +  var input = document.getElementById("form8").elements[0];
   1.320 +  is(input.type, "text", "checking we got unidentified input");
   1.321 +  input.value = "dontSaveThis";
   1.322 +  // Form 9 has nothing to modify.
   1.323 +  $_(10, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890").value = "dontSaveThis";
   1.324 +  $_(11, "test1").value = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
   1.325 +  $_(12, "test1").value = " ";
   1.326 +  $_(13, "test1").value = "dontSaveThis";
   1.327 +  $_(14, "test1").type  = "password";
   1.328 +  $_(14, "test1").value = "dontSaveThis";
   1.329 +
   1.330 +  var testData = ccNumbers.valid16;
   1.331 +  for (var i = 0; i != testData.length; i++) {
   1.332 +    $_(15, "test" + (i + 1)).value = testData[i];
   1.333 +  }
   1.334 +
   1.335 +  testData = ccNumbers.valid15;
   1.336 +  for (var i = 0; i != testData.length; i++) {
   1.337 +    $_(16, "test" + (i + 1)).value = testData[i];
   1.338 +  }
   1.339 +  $_(17, "test1").value = "001064088";
   1.340 +  $_(18, "test1").value = "0000-0000-0080-4609";
   1.341 +  $_(19, "test1").value = "0000 0000 0222 331";
   1.342 +  $_(20, "test1").value = "dontSaveThis";
   1.343 +  $_(22, "test1").value = "dontSaveThis";
   1.344 +  $_(23, "test1").value = "dontSaveThis";
   1.345 +  $_(24, "searchbar-history").value = "dontSaveThis";
   1.346 +
   1.347 +  $_(101, "test1").value = "savedValue";
   1.348 +  $_(102, "test2").value = "savedValue";
   1.349 +  $_(103, "test3").value = "savedValue";
   1.350 +  $_(104, "test4").value = " trimTrailingAndLeadingSpace ";
   1.351 +  $_(105, "test5").value = "\t trimTrailingAndLeadingWhitespace\t ";
   1.352 +  $_(106, "test6").value = "00000000109181";
   1.353 +
   1.354 +  var testData = ccNumbers.invalid16;
   1.355 +  for (var i = 0; i != testData.length; i++) {
   1.356 +    $_(107, "test7_" + (i + 1)).value = testData[i];
   1.357 +  }
   1.358 +
   1.359 +  var testData = ccNumbers.invalid15;
   1.360 +  for (var i = 0; i != testData.length; i++) {
   1.361 +    $_(108, "test8_" + (i + 1)).value = testData[i];
   1.362 +  }
   1.363 +
   1.364 +  $_(109, "test9").value = "savedValue";
   1.365 +  $_(110, "test10").value = "savedValue";
   1.366 +
   1.367 +  // submit the first form.
   1.368 +  var button = getFormSubmitButton(1);
   1.369 +  button.click();
   1.370 +}
   1.371 +
   1.372 +
   1.373 +// Called by each form's onsubmit handler.
   1.374 +function checkSubmit(formNum) {
   1.375 +  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   1.376 +
   1.377 +  ok(true, "form " + formNum + " submitted");
   1.378 +  numSubmittedForms++;
   1.379 +
   1.380 +  // Check for expected storage state.
   1.381 +  switch (formNum) {
   1.382 +    // Test 1-24 should not save anything.
   1.383 +    case 1:
   1.384 +    case 2:
   1.385 +    case 3:
   1.386 +    case 4:
   1.387 +    case 5:
   1.388 +    case 6:
   1.389 +    case 7:
   1.390 +    case 8:
   1.391 +    case 9:
   1.392 +    case 10:
   1.393 +    case 11:
   1.394 +    case 12:
   1.395 +    case 13:
   1.396 +    case 14:
   1.397 +    case 15:
   1.398 +    case 16:
   1.399 +    case 17:
   1.400 +    case 18:
   1.401 +    case 19:
   1.402 +    case 20:
   1.403 +    case 21:
   1.404 +    case 22:
   1.405 +    case 23:
   1.406 +    case 24:
   1.407 +      countEntries(null, null,
   1.408 +        function (num) {
   1.409 +          ok(!num, "checking for empty storage");
   1.410 +          submitForm(formNum);
   1.411 +        });
   1.412 +        return false;
   1.413 +        break;
   1.414 +    case 100:
   1.415 +        checkForSave("subtest2", "subtestValue", "checking saved subtest value");
   1.416 +        break;
   1.417 +    case 101:
   1.418 +        checkForSave("test1", "savedValue", "checking saved value");
   1.419 +        break;
   1.420 +    case 102:
   1.421 +        checkForSave("test2", "savedValue", "checking saved value");
   1.422 +        break;
   1.423 +    case 103:
   1.424 +        checkForSave("test3", "savedValue", "checking saved value");
   1.425 +        break;
   1.426 +    case 104:
   1.427 +        checkForSave("test4", "trimTrailingAndLeadingSpace", "checking saved value is trimmed on both sides");
   1.428 +        break;
   1.429 +    case 105:
   1.430 +        checkForSave("test5", "trimTrailingAndLeadingWhitespace", "checking saved value is trimmed on both sides");
   1.431 +        break;
   1.432 +    case 106:
   1.433 +        checkForSave("test6", "00000000109181", "checking saved value");
   1.434 +        break;
   1.435 +    case 107:
   1.436 +        for (var i = 0; i != ccNumbers.invalid16.length; i++) {
   1.437 +          checkForSave("test7_" + (i + 1), ccNumbers.invalid16[i], "checking saved value");
   1.438 +        }
   1.439 +        break;
   1.440 +    case 108:
   1.441 +        for (var i = 0; i != ccNumbers.invalid15.length; i++) {
   1.442 +          checkForSave("test8_" + (i + 1), ccNumbers.invalid15[i], "checking saved value");
   1.443 +        }
   1.444 +        break;
   1.445 +    case 109:
   1.446 +        checkForSave("test9", "savedValue", "checking saved value");
   1.447 +        break;
   1.448 +    case 110:
   1.449 +        checkForSave("test10", "savedValue", "checking saved value");
   1.450 +        break;
   1.451 +    default:
   1.452 +        ok(false, "Unexpected form submission");
   1.453 +        break;
   1.454 +  }
   1.455 +
   1.456 +  return submitForm(formNum);
   1.457 +}
   1.458 +
   1.459 +function submitForm(formNum)
   1.460 +{
   1.461 +  // Forms 13 and 14 would trigger a save-password notification. Temporarily
   1.462 +  // disable pwmgr, then reenable it.
   1.463 +  if (formNum == 12)
   1.464 +      SpecialPowers.setBoolPref("signon.rememberSignons", false);
   1.465 +  if (formNum == 14)
   1.466 +      SpecialPowers.clearUserPref("signon.rememberSignons");
   1.467 +
   1.468 +  // Forms 20 and 21 requires browser.formfill.saveHttpsForms to be false
   1.469 +  if (formNum == 19)
   1.470 +    SpecialPowers.setBoolPref("browser.formfill.saveHttpsForms", false);
   1.471 +  // Reset preference now that 20 and 21 are over
   1.472 +  if (formNum == 21)
   1.473 +    SpecialPowers.clearUserPref("browser.formfill.saveHttpsForms");
   1.474 +
   1.475 +  // End the test now on SeaMonkey.
   1.476 +  if (formNum == 21 && navigator.userAgent.match(/ SeaMonkey\//)) {
   1.477 +    Services.obs.removeObserver(checkObserver, "satchel-storage-changed");
   1.478 +    is(numSubmittedForms, 21, "Ensuring all forms were submitted.");
   1.479 +
   1.480 +    todo(false, "Skipping remaining checks on SeaMonkey ftb. (Bug 589471)");
   1.481 +    // finish(), yet let the test actually end first, to be safe.
   1.482 +    SimpleTest.executeSoon(SimpleTest.finish);
   1.483 +
   1.484 +    return false; // return false to cancel current form submission
   1.485 +  }
   1.486 +
   1.487 +  // Form 109 requires browser.formfill.save_https_forms to be true;
   1.488 +  // Form 110 requires it to be false.
   1.489 +  if (formNum == 108)
   1.490 +    SpecialPowers.setBoolPref("browser.formfill.saveHttpsForms", true);
   1.491 +  if (formNum == 109)
   1.492 +    SpecialPowers.setBoolPref("browser.formfill.saveHttpsForms", false);
   1.493 +  if (formNum == 110)
   1.494 +    SpecialPowers.clearUserPref("browser.formfill.saveHttpsForms");
   1.495 +
   1.496 +  // End the test at the last form.
   1.497 +  if (formNum == 110) {
   1.498 +    is(numSubmittedForms, 35, "Ensuring all forms were submitted.");
   1.499 +    Services.obs.removeObserver(checkObserver, "satchel-storage-changed");
   1.500 +    SimpleTest.finish();
   1.501 +    return false; // return false to cancel current form submission
   1.502 +  }
   1.503 +
   1.504 +  // This timeout is here so that button.click() is never called before this
   1.505 +  // function returns. If button.click() is called before returning, a long
   1.506 +  // chain of submits will happen recursively since the submit is dispatched
   1.507 +  // immediately.
   1.508 +  //
   1.509 +  // This in itself is fine, but if there are errors in the code, mochitests
   1.510 +  // will in some cases give you "server too busy", which is hard to debug!
   1.511 +  //
   1.512 +  setTimeout(function() {
   1.513 +    checkObserver.waitForChecks(function() {
   1.514 +      var nextFormNum = formNum == 24 ? 100 : (formNum + 1);
   1.515 +
   1.516 +      // Submit the next form. Special cases are Forms 21 and 100, which happen
   1.517 +      // from an HTTPS domain in an iframe.
   1.518 +      if (nextFormNum == 21 || nextFormNum == 100) {
   1.519 +        ok(true, "submitting iframe test " + nextFormNum);
   1.520 +        document.getElementById("iframe").contentWindow.clickButton(nextFormNum);
   1.521 +      }
   1.522 +      else {
   1.523 +        var button = getFormSubmitButton(nextFormNum);
   1.524 +        button.click();
   1.525 +      }
   1.526 +    });
   1.527 +  }, 0);
   1.528 +
   1.529 +  return false; // cancel current form submission
   1.530 +}
   1.531 +
   1.532 +Services.obs.addObserver(checkObserver, "satchel-storage-changed", false);
   1.533 +
   1.534 +window.onload = checkInitialState;
   1.535 +
   1.536 +SimpleTest.waitForExplicitFinish();
   1.537 +
   1.538 +</script>
   1.539 +</pre>
   1.540 +</body>
   1.541 +</html>

mercurial