test_formaction_attribute.html (6056B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=566160 5 --> 6 <head> 7 <title>Test for Bug 566160</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=566160">Mozilla Bug 566160</a> 14 <p id="display"></p> 15 <style> 16 iframe { width: 130px; height: 100px;} 17 </style> 18 <iframe name='frame1' id='frame1'></iframe> 19 <iframe name='frame2' id='frame2'></iframe> 20 <iframe name='frame3' id='frame3'></iframe> 21 <iframe name='frame3bis' id='frame3bis'></iframe> 22 <iframe name='frame4' id='frame4'></iframe> 23 <iframe name='frame5' id='frame5'></iframe> 24 <iframe name='frame6' id='frame6'></iframe> 25 <iframe name='frame7' id='frame7'></iframe> 26 <div id="content"> 27 <!-- submit controls with formaction that are validated with a CLICK --> 28 <form target="frame1" action="FAIL.html" method="GET"> 29 <input name='foo' value='foo'> 30 <input type='submit' id='is' formaction="PASS.html"> 31 </form> 32 <form target="frame2" action="FAIL.html" method="GET"> 33 <input name='bar' value='bar'> 34 <input type='image' id='ii' formaction="PASS.html"> 35 </form> 36 <form target="frame3" action="FAIL.html" method="GET"> 37 <input name='tulip' value='tulip'> 38 <button type='submit' id='bs' formaction="PASS.html">submit</button> 39 </form> 40 <form target="frame3bis" action="FAIL.html" method="GET"> 41 <input name='tulipbis' value='tulipbis'> 42 <button type='submit' id='bsbis' formaction="PASS.html">submit</button> 43 </form> 44 45 <!-- submit controls with formaction that are validated with ENTER --> 46 <form target="frame4" action="FAIL.html" method="GET"> 47 <input name='footulip' value='footulip'> 48 <input type='submit' id='is2' formaction="PASS.html"> 49 </form> 50 <form target="frame5" action="FAIL.html" method="GET"> 51 <input name='foobar' value='foobar'> 52 <input type='image' id='ii2' formaction="PASS.html"> 53 </form> 54 <form target="frame6" action="FAIL.html" method="GET"> 55 <input name='tulip2' value='tulip2'> 56 <button type='submit' id='bs2' formaction="PASS.html">submit</button> 57 </form> 58 59 <!-- check that when submitting a from from an element 60 which is not a submit control, @formaction isn't used --> 61 <form target='frame7' action="PASS.html" method="GET"> 62 <input id='enter' name='input' value='enter' formaction="FAIL.html"> 63 </form> 64 </div> 65 <pre id="test"> 66 <script type="application/javascript"> 67 68 /** Test for Bug 566160 */ 69 70 SimpleTest.waitForExplicitFinish(); 71 SimpleTest.waitForFocus(runTests); 72 73 const BASE_URI = `${location.origin}/tests/dom/html/test/forms/PASS.html`; 74 var gTestResults = { 75 frame1: BASE_URI + "?foo=foo", 76 frame2: BASE_URI + "?bar=bar&x=0&y=0", 77 frame3: BASE_URI + "?tulip=tulip", 78 frame3bis: BASE_URI + "?tulipbis=tulipbis", 79 frame4: BASE_URI + "?footulip=footulip", 80 frame5: BASE_URI + "?foobar=foobar&x=0&y=0", 81 frame6: BASE_URI + "?tulip2=tulip2", 82 frame7: BASE_URI + "?input=enter", 83 }; 84 85 var gPendingLoad = 0; // Has to be set after depending on the frames number. 86 87 function runTests() 88 { 89 // We add a load event for the frames which will be called when the forms 90 // will be submitted. 91 var frames = [ document.getElementById('frame1'), 92 document.getElementById('frame2'), 93 document.getElementById('frame3'), 94 document.getElementById('frame3bis'), 95 document.getElementById('frame4'), 96 document.getElementById('frame5'), 97 document.getElementById('frame6'), 98 document.getElementById('frame7'), 99 ]; 100 gPendingLoad = frames.length; 101 102 for (var i=0; i<frames.length; i++) { 103 frames[i].setAttribute('onload', "frameLoaded(this);"); 104 } 105 106 /** 107 * We are going to focus each element before interacting with either for 108 * simulating the ENTER key (synthesizeKey) or a click (synthesizeMouse) or 109 * using .click(). This because it may be needed (ENTER) and because we want 110 * to have the element visible in the iframe. 111 * 112 * Focusing the first element (id='is') is launching the tests. 113 */ 114 document.getElementById('is').addEventListener('focus', function(aEvent) { 115 synthesizeMouse(document.getElementById('is'), 5, 5, {}); 116 document.getElementById('ii').focus(); 117 }, {once: true}); 118 119 document.getElementById('ii').addEventListener('focus', function(aEvent) { 120 synthesizeMouse(document.getElementById('ii'), 5, 5, {}); 121 document.getElementById('bs').focus(); 122 }, {once: true}); 123 124 document.getElementById('bs').addEventListener('focus', function(aEvent) { 125 synthesizeMouse(document.getElementById('bs'), 5, 5, {}); 126 document.getElementById('bsbis').focus(); 127 }, {once: true}); 128 129 document.getElementById('bsbis').addEventListener('focus', function(aEvent) { 130 document.getElementById('bsbis').click(); 131 document.getElementById('is2').focus(); 132 }, {once: true}); 133 134 document.getElementById('is2').addEventListener('focus', function(aEvent) { 135 synthesizeKey("KEY_Enter"); 136 document.getElementById('ii2').focus(); 137 }, {once: true}); 138 139 document.getElementById('ii2').addEventListener('focus', function(aEvent) { 140 synthesizeKey("KEY_Enter"); 141 document.getElementById('bs2').focus(); 142 }, {once: true}); 143 144 document.getElementById('bs2').addEventListener('focus', function(aEvent) { 145 synthesizeKey("KEY_Enter"); 146 document.getElementById('enter').focus(); 147 }, {once: true}); 148 149 document.getElementById('enter').addEventListener('focus', function(aEvent) { 150 synthesizeKey("KEY_Enter"); 151 }, {once: true}); 152 153 document.getElementById('is').focus(); 154 } 155 156 function frameLoaded(aFrame) { 157 // Check if formaction/action has the correct behavior. 158 is(aFrame.contentWindow.location.href, gTestResults[aFrame.name], 159 "the action attribute doesn't have the correct behavior"); 160 161 if (--gPendingLoad == 0) { 162 SimpleTest.finish(); 163 } 164 } 165 166 </script> 167 </pre> 168 </body> 169 </html>