test_bug566046.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=566046
  5. -->
  6. <head>
  7. <title>Test for Bug 566046</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. <base>
  12. <base target='frame2'>
  13. <base target=''>
  14. </head>
  15. <body>
  16. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=566046">Mozilla Bug 566046</a>
  17. <p id="display"></p>
  18. <style>
  19. iframe { width: 130px; height: 100px;}
  20. </style>
  21. <iframe name='frame1' id='frame1'></iframe>
  22. <iframe name='frame2' id='frame2'></iframe>
  23. <iframe name='frame3' id='frame3'></iframe>
  24. <iframe name='frame4' id='frame4'></iframe>
  25. <iframe name='frame5' id='frame5'></iframe>
  26. <iframe name='frame5bis' id='frame5bis'></iframe>
  27. <iframe name='frame6' id='frame6'></iframe>
  28. <iframe name='frame7' id='frame7'></iframe>
  29. <iframe name='frame8' id='frame8'></iframe>
  30. <iframe name='frame9' id='frame9'></iframe>
  31. <div id="content">
  32. <form target='frame1' action="data:text/html," method="GET">
  33. <input name='foo' value='foo'>
  34. </form>
  35. <form action="data:text/html," method="GET">
  36. <input name='bar' value='bar'>
  37. </form>
  38. <form target="">
  39. </form>
  40. <!-- submit controls with formtarget that are validated with a CLICK -->
  41. <form target="tulip" action="data:text/html," method="GET">
  42. <input name='tulip' value='tulip'>
  43. <input type='submit' id='is' formtarget='frame3'>
  44. </form>
  45. <form action="data:text/html," method="GET">
  46. <input name='foobar' value='foobar'>
  47. <input type='image' id='ii' formtarget='frame4'>
  48. </form>
  49. <form action="data:text/html," method="GET">
  50. <input name='tulip2' value='tulip2'>
  51. <button type='submit' id='bs' formtarget='frame5'>submit</button>
  52. </form>
  53. <form action="data:text/html," method="GET">
  54. <input name='tulip3' value='tulip3'>
  55. <button type='submit' id='bsbis' formtarget='frame5bis'>submit</button>
  56. </form>
  57. <!-- submit controls with formtarget that are validated with ENTER -->
  58. <form target="tulip" action="data:text/html," method="GET">
  59. <input name='footulip' value='footulip'>
  60. <input type='submit' id='is2' formtarget='frame6'>
  61. </form>
  62. <form action="data:text/html," method="GET">
  63. <input name='tulipfoobar' value='tulipfoobar'>
  64. <input type='image' id='ii2' formtarget='frame7'>
  65. </form>
  66. <form action="data:text/html," method="GET">
  67. <input name='tulipbar' value='tulipbar'>
  68. <button type='submit' id='bs2' formtarget='frame8'>submit</button>
  69. </form>
  70. <!-- check that a which is not a submit control do not use @formtarget -->
  71. <form target='frame9' action="data:text/html," method="GET">
  72. <input id='enter' name='input' value='enter' formtarget='frame6'>
  73. </form>
  74. </div>
  75. <pre id="test">
  76. <script type="application/javascript">
  77. /** Test for Bug 566046 **/
  78. SimpleTest.waitForExplicitFinish();
  79. addLoadEvent(function() {
  80. setTimeout(runTests, 0);
  81. });
  82. var gTestResults = {
  83. frame1: "data:text/html,?foo=foo",
  84. frame2: "data:text/html,?bar=bar",
  85. frame3: "data:text/html,?tulip=tulip",
  86. frame4: "data:text/html,?foobar=foobar&x=0&y=0",
  87. frame5: "data:text/html,?tulip2=tulip2",
  88. frame5bis: "data:text/html,?tulip3=tulip3",
  89. frame6: "data:text/html,?footulip=footulip",
  90. frame7: "data:text/html,?tulipfoobar=tulipfoobar&x=0&y=0",
  91. frame8: "data:text/html,?tulipbar=tulipbar",
  92. frame9: "data:text/html,?input=enter",
  93. };
  94. var gPendingLoad = 0; // Has to be set after depending on the frames number.
  95. function runTests()
  96. {
  97. // Check the target IDL attribute.
  98. for (var i=0; i<document.forms.length; ++i) {
  99. var testValue = document.forms[i].getAttribute('target');
  100. is(document.forms[i].target, testValue ? testValue : "",
  101. "target IDL attribute should reflect the target content attribute");
  102. }
  103. // We add a load event for the frames which will be called when the forms
  104. // will be submitted.
  105. var frames = [ document.getElementById('frame1'),
  106. document.getElementById('frame2'),
  107. document.getElementById('frame3'),
  108. document.getElementById('frame4'),
  109. document.getElementById('frame5'),
  110. document.getElementById('frame5bis'),
  111. document.getElementById('frame6'),
  112. document.getElementById('frame7'),
  113. document.getElementById('frame8'),
  114. document.getElementById('frame9'),
  115. ];
  116. gPendingLoad = frames.length;
  117. for (var i=0; i<frames.length; i++) {
  118. frames[i].setAttribute('onload', "frameLoaded(this);");
  119. }
  120. // Submitting only the forms with a valid target.
  121. document.forms[0].submit();
  122. document.forms[1].submit();
  123. /**
  124. * We are going to focus each element before interacting with either for
  125. * simulating the ENTER key (synthesizeKey) or a click (synthesizeMouse) or
  126. * using .click(). This because it may be needed (ENTER) and because we want
  127. * to have the element visible in the iframe.
  128. *
  129. * Focusing the first element (id='is') is launching the tests.
  130. */
  131. document.getElementById('is').addEventListener('focus', function(aEvent) {
  132. aEvent.target.removeEventListener('focus', arguments.callee, false);
  133. synthesizeMouse(document.getElementById('is'), 5, 5, {});
  134. document.getElementById('ii').focus();
  135. }, false);
  136. document.getElementById('ii').addEventListener('focus', function(aEvent) {
  137. aEvent.target.removeEventListener('focus', arguments.callee, false);
  138. synthesizeMouse(document.getElementById('ii'), 5, 5, {});
  139. document.getElementById('bs').focus();
  140. }, false);
  141. document.getElementById('bs').addEventListener('focus', function(aEvent) {
  142. aEvent.target.removeEventListener('focus', arguments.callee, false);
  143. synthesizeMouse(document.getElementById('bs'), 5, 5, {});
  144. document.getElementById('bsbis').focus();
  145. }, false);
  146. document.getElementById('bsbis').addEventListener('focus', function(aEvent) {
  147. aEvent.target.removeEventListener('focus', arguments.callee, false);
  148. document.getElementById('bsbis').click();
  149. document.getElementById('is2').focus();
  150. }, false);
  151. document.getElementById('is2').addEventListener('focus', function(aEvent) {
  152. aEvent.target.removeEventListener('focus', arguments.callee, false);
  153. synthesizeKey("VK_RETURN", {});
  154. document.getElementById('ii2').focus();
  155. }, false);
  156. document.getElementById('ii2').addEventListener('focus', function(aEvent) {
  157. aEvent.target.removeEventListener('focus', arguments.callee, false);
  158. synthesizeKey("VK_RETURN", {});
  159. document.getElementById('bs2').focus();
  160. }, false);
  161. document.getElementById('bs2').addEventListener('focus', function(aEvent) {
  162. aEvent.target.removeEventListener('focus', arguments.callee, false);
  163. synthesizeKey("VK_RETURN", {});
  164. document.getElementById('enter').focus();
  165. }, false);
  166. document.getElementById('enter').addEventListener('focus', function(aEvent) {
  167. aEvent.target.removeEventListener('focus', arguments.callee, false);
  168. synthesizeKey("VK_RETURN", {});
  169. }, false);
  170. document.getElementById('is').focus();
  171. }
  172. function frameLoaded(aFrame) {
  173. // Check if when target is unspecified, it fallback correctly to the base
  174. // element target attribute.
  175. is(aFrame.contentWindow.location.href, gTestResults[aFrame.name],
  176. "the target attribute doesn't have the correct behavior");
  177. if (--gPendingLoad == 0) {
  178. SimpleTest.finish();
  179. }
  180. }
  181. </script>
  182. </pre>
  183. </body>
  184. </html>