test_bug561636.html (2926B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=561636 5 --> 6 <head> 7 <title>Test for Bug 561636</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=561636">Mozilla Bug 561636</a> 14 <p id="display"></p> 15 <iframe style='width:50px; height: 50px;' name='t'></iframe> 16 <iframe style='width:50px; height: 50px;' name='t2' id='i'></iframe> 17 <div id="content"> 18 <form target='t' action='data:text/html,'> 19 <input required> 20 <input id='a' type='submit'> 21 </form> 22 <form target='t' action='data:text/html,'> 23 <input type='checkbox' required> 24 <button id='b' type='submit'></button> 25 </form> 26 <form target='t' action='data:text/html,'> 27 <input id='c' required> 28 </form> 29 <form target='t' action='data:text/html,'> 30 <input> 31 <input id='s2' type='submit'> 32 </form> 33 <form target='t2' action='data:text/html,'> 34 <input required> 35 </form> 36 </div> 37 <pre id="test"> 38 <script type="application/javascript"> 39 40 /** Test for Bug 561636 */ 41 42 SimpleTest.waitForExplicitFinish(); 43 addLoadEvent(runTest); 44 45 function runTest() 46 { 47 var formSubmitted = [ false, false ]; 48 var invalidHandled = false; 49 50 // Initialize 51 document.forms[0].addEventListener('submit', function(aEvent) { 52 formSubmitted[0] = true; 53 }, {once: true}); 54 55 document.forms[1].addEventListener('submit', function(aEvent) { 56 formSubmitted[1] = true; 57 }, {once: true}); 58 59 document.forms[2].addEventListener('submit', function(aEvent) { 60 formSubmitted[2] = true; 61 }, {once: true}); 62 63 document.forms[3].addEventListener('submit', function(aEvent) { 64 formSubmitted[3] = true; 65 66 ok(!formSubmitted[0], "Form 1 should not have been submitted because invalid"); 67 ok(!formSubmitted[1], "Form 2 should not have been submitted because invalid"); 68 ok(!formSubmitted[2], "Form 3 should not have been submitted because invalid"); 69 ok(formSubmitted[3], "Form 4 should have been submitted because valid"); 70 71 // Next test. 72 document.forms[4].submit(); 73 }, {once: true}); 74 75 document.forms[4].elements[0].addEventListener('invalid', function(aEvent) { 76 invalidHandled = true; 77 }, {once: true}); 78 79 document.getElementById('i').addEventListener('load', function(aEvent) { 80 SimpleTest.executeSoon(function () { 81 ok(true, "Form 5 should have been submitted because submit() has been used even if invalid"); 82 ok(!invalidHandled, "Invalid event should not have been sent"); 83 84 SimpleTest.finish(); 85 }); 86 }, {once: true}); 87 88 document.getElementById('a').click(); 89 document.getElementById('b').click(); 90 var c = document.getElementById('c'); 91 c.focus(); 92 synthesizeKey("KEY_Enter"); 93 document.getElementById('s2').click(); 94 } 95 96 </script> 97 </pre> 98 </body> 99 </html>