test_formnovalidate_attribute.html (4493B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=589696 5 --> 6 <head> 7 <title>Test for Bug 589696</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=589696">Mozilla Bug 589696</a> 14 <p id="display"></p> 15 <iframe style='width:50px; height: 50px;' name='t'></iframe> 16 <div id="content"> 17 <!-- Next forms should not submit because formnovalidate isn't set on the 18 element used for the submission. --> 19 <form target='t' action='data:text/html,'> 20 <input id='av' required> 21 <input type='submit' formnovalidate> 22 <input id='a' type='submit'> 23 </form> 24 <form target='t' action='data:text/html,'> 25 <input id='bv' type='checkbox' required> 26 <button type='submit' formnovalidate></button> 27 <button id='b' type='submit'></button> 28 </form> 29 <!-- Next form should not submit because formnovalidate only applies for 30 submit controls. --> 31 <form target='t' action='data:text/html,'> 32 <input id='c' required formnovalidate> 33 </form> 34 <!--- Next forms should submit without any validation check. --> 35 <form target='t' action='data:text/html,'> 36 <input id='dv' required> 37 <input id='d' type='submit' formnovalidate> 38 </form> 39 <form target='t' action='data:text/html,'> 40 <input id='ev' type='checkbox' required> 41 <button id='e' type='submit' formnovalidate></button> 42 </form> 43 </div> 44 <pre id="test"> 45 <script type="application/javascript"> 46 47 /** Test for Bug 589696 */ 48 49 document.getElementById('av').addEventListener("invalid", function(aEvent) { 50 aEvent.target.removeAttribute("invalid", arguments.callee, false); 51 ok(true, "formnovalidate should not apply on if not set on the submit " + 52 "control used for the submission"); 53 document.getElementById('b').click(); 54 }); 55 56 document.getElementById('bv').addEventListener("invalid", function(aEvent) { 57 aEvent.target.removeAttribute("invalid", arguments.callee, false); 58 ok(true, "formnovalidate should not apply on if not set on the submit " + 59 "control used for the submission"); 60 var c = document.getElementById('c'); 61 c.focus(); 62 synthesizeKey("KEY_Enter"); 63 }); 64 65 document.getElementById('c').addEventListener("invalid", function(aEvent) { 66 aEvent.target.removeAttribute("invalid", arguments.callee, false); 67 ok(true, "formnovalidate should only apply on submit controls"); 68 document.getElementById('d').click(); 69 }); 70 71 document.forms[3].addEventListener("submit", function(aEvent) { 72 aEvent.target.removeAttribute("submit", arguments.callee, false); 73 ok(true, "formnovalidate applies if set on the submit control used for the submission"); 74 document.getElementById('e').click(); 75 }); 76 77 document.forms[4].addEventListener("submit", function(aEvent) { 78 aEvent.target.removeAttribute("submit", arguments.callee, false); 79 ok(true, "formnovalidate applies if set on the submit control used for the submission"); 80 SimpleTest.executeSoon(SimpleTest.finish); 81 }); 82 83 /** 84 * We have to be sure invalid events behave as expected. 85 * They should be sent before the submit event so we can just create a test 86 * failure if we got one when unexpected. All of them should be caught if 87 * sent. 88 * At worst, we got random green which isn't harmful. 89 * If expected, they will be part of the chain reaction. 90 */ 91 function unexpectedInvalid(aEvent) 92 { 93 aEvent.target.removeAttribute("invalid", unexpectedInvalid, false); 94 ok(false, "invalid event should not be sent"); 95 } 96 97 document.getElementById('dv').addEventListener("invalid", unexpectedInvalid); 98 document.getElementById('ev').addEventListener("invalid", unexpectedInvalid); 99 100 /** 101 * Some submission have to be canceled. In that case, the submit events should 102 * not be sent. 103 * Same behavior as unexpected invalid events. 104 */ 105 function unexpectedSubmit(aEvent) 106 { 107 aEvent.target.removeAttribute("submit", unexpectedSubmit, false); 108 ok(false, "submit event should not be sent"); 109 } 110 111 document.forms[0].addEventListener("submit", unexpectedSubmit); 112 document.forms[1].addEventListener("submit", unexpectedSubmit); 113 document.forms[2].addEventListener("submit", unexpectedSubmit); 114 115 SimpleTest.waitForExplicitFinish(); 116 117 // This is going to call all the tests (with a chain reaction). 118 SimpleTest.waitForFocus(function() { 119 document.getElementById('a').click(); 120 }); 121 122 </script> 123 </pre> 124 </body> 125 </html>