tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_novalidate_attribute.html (2824B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=556013
      5 -->
      6 <head>
      7  <title>Test for Bug 556013</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=556013">Mozilla Bug 556013</a>
     14 <p id="display"></p>
     15 <iframe style='width:50px; height: 50px;' name='t'></iframe>
     16 <div id="content">
     17  <form target='t' action='data:text/html,' novalidate>
     18    <input id='av' required>
     19    <input id='a' type='submit'>
     20  </form>
     21  <form target='t' action='data:text/html,' novalidate>
     22    <input id='bv' type='checkbox' required>
     23    <button id='b' type='submit'></button>
     24  </form>
     25  <form target='t' action='data:text/html,' novalidate>
     26    <input id='c' required>
     27  </form>
     28 </div>
     29 <pre id="test">
     30 <script type="application/javascript">
     31 
     32 /** Test for Bug 556013 */
     33 
     34 /**
     35 * novalidate should prevent form validation, thus not blocking form submission.
     36 *
     37 * NOTE: if the MozInvalidForm event doesn't get prevented default, the form
     38 * submission will never be blocked and this test might be a false-positive but
     39 * that should not be a problem. We will remove the check for MozInvalidForm
     40 * event, see bug 587671.
     41 */
     42 document.forms[0].addEventListener("submit", function(aEvent) {
     43  ok(true, "novalidate has been correctly used for first form");
     44  document.getElementById('b').click();
     45 }, {once: true});
     46 
     47 document.forms[1].addEventListener("submit", function(aEvent) {
     48  ok(true, "novalidate has been correctly used for second form");
     49  var c = document.getElementById('c');
     50  c.focus();
     51  synthesizeKey("KEY_Enter");
     52 }, {once: true});
     53 
     54 document.forms[2].addEventListener("submit", function(aEvent) {
     55  ok(true, "novalidate has been correctly used for third form");
     56  SimpleTest.executeSoon(SimpleTest.finish);
     57 }, {once: true});
     58 
     59 /**
     60 * We have to be sure invalid events are not send too.
     61 * They should be sent before the submit event so we can just create a test
     62 * failure if we got one. All of them should be catched if sent.
     63 * At worst, we got random green which isn't harmful.
     64 */
     65 function invalidHandling(aEvent)
     66 {
     67  aEvent.target.removeEventListener("invalid", invalidHandling);
     68  ok(false, "invalid event should not be sent");
     69 }
     70 
     71 document.getElementById('av').addEventListener("invalid", invalidHandling);
     72 document.getElementById('bv').addEventListener("invalid", invalidHandling);
     73 document.getElementById('c').addEventListener("invalid", invalidHandling);
     74 
     75 SimpleTest.waitForExplicitFinish();
     76 
     77 // This is going to call all the tests (with a chain reaction).
     78 SimpleTest.waitForFocus(function() {
     79  document.getElementById('a').click();
     80 });
     81 
     82 </script>
     83 </pre>
     84 </body>
     85 </html>