test_bug557087-2.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=557087
  5. -->
  6. <head>
  7. <title>Test for Bug 557087</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. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557087">Mozilla Bug 557087</a>
  14. <p id="display"></p>
  15. <div id="content" style="display:none;">
  16. </div>
  17. <pre id="test">
  18. <script type="application/javascript">
  19. /** Test for Bug 557087 **/
  20. SimpleTest.waitForExplicitFinish();
  21. var elementsPreventingClick = [ "input", "button", "select", "textarea", "fieldset" ];
  22. var elementsWithClick = [ "option", "optgroup", "output", "label", "object" ];
  23. var gHandled = 0;
  24. function clickShouldNotHappenHandler(aEvent)
  25. {
  26. aEvent.target.removeEventListener("click", clickShouldNotHappenHandler, false);
  27. ok(false, "click event should be prevented! (test1)");
  28. if (++gHandled >= elementsWithClick.length) {
  29. test2();
  30. }
  31. }
  32. function clickShouldNotHappenHandler2(aEvent)
  33. {
  34. aEvent.target.removeEventListener("click", clickShouldNotHappenHandler3, false);
  35. ok(false, "click event should be prevented! (test2)");
  36. if (++gHandled >= elementsWithClick.length) {
  37. test3();
  38. }
  39. }
  40. function clickShouldNotHappenHandler5(aEvent)
  41. {
  42. aEvent.target.removeEventListener("click", clickShouldNotHappenHandler5, false);
  43. ok(false, "click event should be prevented! (test5)");
  44. if (++gHandled >= elementsWithClick.length) {
  45. test6();
  46. }
  47. }
  48. function clickShouldNotHappenHandler7(aEvent)
  49. {
  50. aEvent.target.removeEventListener("click", clickShouldNotHappenHandler7, false);
  51. ok(false, "click event should be prevented! (test7)");
  52. if (++gHandled >= elementsWithClick.length) {
  53. test8();
  54. }
  55. }
  56. function clickShouldHappenHandler(aEvent)
  57. {
  58. aEvent.target.removeEventListener("click", clickShouldHappenHandler, false);
  59. ok(true, "click event has been correctly received (test1)");
  60. if (++gHandled >= elementsWithClick.length) {
  61. test2();
  62. }
  63. }
  64. function clickShouldHappenHandler2(aEvent)
  65. {
  66. aEvent.target.removeEventListener("click", clickShouldHappenHandler2, false);
  67. ok(true, "click event has been correctly received (test2)");
  68. if (++gHandled >= elementsWithClick.length) {
  69. test3();
  70. }
  71. }
  72. function clickShouldHappenHandler3(aEvent)
  73. {
  74. aEvent.target.removeEventListener("click", clickShouldHappenHandler3, false);
  75. ok(true, "click event has been correctly received (test3)");
  76. if (++gHandled >= (elementsWithClick.length +
  77. elementsPreventingClick.length)) {
  78. test4();
  79. }
  80. }
  81. function clickShouldHappenHandler4(aEvent)
  82. {
  83. aEvent.target.removeEventListener("click", clickShouldHappenHandler4, false);
  84. ok(true, "click event has been correctly received (test4)");
  85. if (++gHandled >= (elementsWithClick.length +
  86. elementsPreventingClick.length)) {
  87. test5();
  88. }
  89. }
  90. function clickShouldHappenHandler5(aEvent)
  91. {
  92. aEvent.target.removeEventListener("click", clickShouldHappenHandler5, false);
  93. ok(true, "click event has been correctly received (test5)");
  94. if (++gHandled >= elementsWithClick.length) {
  95. test6();
  96. }
  97. }
  98. function clickShouldHappenHandler6(aEvent)
  99. {
  100. aEvent.target.removeEventListener("click", clickShouldHappenHandler6, false);
  101. ok(true, "click event has been correctly received (test6)");
  102. if (++gHandled >= (elementsWithClick.length +
  103. elementsPreventingClick.length)) {
  104. test7();
  105. }
  106. }
  107. function clickShouldHappenHandler7(aEvent)
  108. {
  109. aEvent.target.removeEventListener("click", clickShouldHappenHandler7, false);
  110. ok(true, "click event has been correctly received (test5)");
  111. if (++gHandled >= elementsWithClick.length) {
  112. test8();
  113. }
  114. }
  115. function clickShouldHappenHandler8(aEvent)
  116. {
  117. aEvent.target.removeEventListener("click", clickShouldHappenHandler8, false);
  118. ok(true, "click event has been correctly received (test8)");
  119. if (++gHandled >= (elementsWithClick.length +
  120. elementsPreventingClick.length)) {
  121. SimpleTest.finish();
  122. }
  123. }
  124. var fieldset1 = document.createElement("fieldset");
  125. var fieldset2 = document.createElement("fieldset");
  126. var legendA = document.createElement("legend");
  127. var legendB = document.createElement("legend");
  128. var content = document.getElementById('content');
  129. fieldset1.disabled = true;
  130. content.appendChild(fieldset1);
  131. fieldset1.appendChild(fieldset2);
  132. function clean()
  133. {
  134. var count = fieldset2.children.length;
  135. for (var i=0; i<count; ++i) {
  136. if (fieldset2.children[i] != legendA &&
  137. fieldset2.children[i] != legendB) {
  138. fieldset2.removeChild(fieldset2.children[i]);
  139. }
  140. }
  141. }
  142. function test1()
  143. {
  144. gHandled = 0;
  145. // Initialize children without click expected.
  146. for (var name of elementsPreventingClick) {
  147. var element = document.createElement(name);
  148. fieldset2.appendChild(element);
  149. element.addEventListener("click", clickShouldNotHappenHandler, false);
  150. sendMouseEvent({type:'click'}, element);
  151. }
  152. // Initialize children with click expected.
  153. for (var name of elementsWithClick) {
  154. var element = document.createElement(name);
  155. fieldset2.appendChild(element);
  156. element.addEventListener("click", clickShouldHappenHandler, false);
  157. sendMouseEvent({type:'click'}, element);
  158. }
  159. }
  160. function test2()
  161. {
  162. gHandled = 0;
  163. fieldset1.disabled = false;
  164. fieldset2.disabled = true;
  165. // Initialize children without click expected.
  166. for (var name of elementsPreventingClick) {
  167. var element = document.createElement(name);
  168. fieldset2.appendChild(element);
  169. element.addEventListener("click", clickShouldNotHappenHandler2, false);
  170. sendMouseEvent({type:'click'}, element);
  171. }
  172. // Initialize children with click expected.
  173. for (var name of elementsWithClick) {
  174. var element = document.createElement(name);
  175. fieldset2.appendChild(element);
  176. element.addEventListener("click", clickShouldHappenHandler2, false);
  177. sendMouseEvent({type:'click'}, element);
  178. }
  179. }
  180. function test3()
  181. {
  182. gHandled = 0;
  183. fieldset1.disabled = false;
  184. fieldset2.disabled = false;
  185. // All elements should accept the click.
  186. for (var name of elementsPreventingClick) {
  187. var element = document.createElement(name);
  188. fieldset2.appendChild(element);
  189. element.addEventListener("click", clickShouldHappenHandler3, false);
  190. sendMouseEvent({type:'click'}, element);
  191. }
  192. // Initialize children with click expected.
  193. for (var name of elementsWithClick) {
  194. var element = document.createElement(name);
  195. fieldset2.appendChild(element);
  196. element.addEventListener("click", clickShouldHappenHandler3, false);
  197. sendMouseEvent({type:'click'}, element);
  198. }
  199. }
  200. function test4()
  201. {
  202. gHandled = 0;
  203. fieldset1.disabled = false;
  204. fieldset2.disabled = true;
  205. fieldset2.appendChild(legendA);
  206. // All elements should accept the click.
  207. for (var name of elementsPreventingClick) {
  208. var element = document.createElement(name);
  209. legendA.appendChild(element);
  210. element.addEventListener("click", clickShouldHappenHandler4, false);
  211. sendMouseEvent({type:'click'}, element);
  212. }
  213. // Initialize children with click expected.
  214. for (var name of elementsWithClick) {
  215. var element = document.createElement(name);
  216. legendA.appendChild(element);
  217. element.addEventListener("click", clickShouldHappenHandler4, false);
  218. sendMouseEvent({type:'click'}, element);
  219. }
  220. }
  221. function test5()
  222. {
  223. gHandled = 0;
  224. fieldset2.insertBefore(legendB, legendA);
  225. // Initialize children without click expected.
  226. for (var name of elementsPreventingClick) {
  227. var element = document.createElement(name);
  228. legendA.appendChild(element);
  229. element.addEventListener("click", clickShouldNotHappenHandler5, false);
  230. sendMouseEvent({type:'click'}, element);
  231. }
  232. // Initialize children with click expected.
  233. for (var name of elementsWithClick) {
  234. var element = document.createElement(name);
  235. legendA.appendChild(element);
  236. element.addEventListener("click", clickShouldHappenHandler5, false);
  237. sendMouseEvent({type:'click'}, element);
  238. }
  239. }
  240. function test6()
  241. {
  242. gHandled = 0;
  243. fieldset2.removeChild(legendB);
  244. fieldset1.disabled = true;
  245. fieldset2.disabled = false;
  246. fieldset1.appendChild(legendA);
  247. legendA.appendChild(fieldset2);
  248. // All elements should accept the click.
  249. for (var name of elementsPreventingClick) {
  250. var element = document.createElement(name);
  251. fieldset2.appendChild(element);
  252. element.addEventListener("click", clickShouldHappenHandler6, false);
  253. sendMouseEvent({type:'click'}, element);
  254. }
  255. // Initialize children with click expected.
  256. for (var name of elementsWithClick) {
  257. var element = document.createElement(name);
  258. fieldset2.appendChild(element);
  259. element.addEventListener("click", clickShouldHappenHandler6, false);
  260. sendMouseEvent({type:'click'}, element);
  261. }
  262. }
  263. function test7()
  264. {
  265. gHandled = 0;
  266. fieldset1.disabled = true;
  267. fieldset2.disabled = false;
  268. fieldset1.appendChild(fieldset2);
  269. fieldset2.appendChild(legendA);
  270. // All elements should accept the click.
  271. for (var name of elementsPreventingClick) {
  272. var element = document.createElement(name);
  273. legendA.appendChild(element);
  274. element.addEventListener("click", clickShouldNotHappenHandler7, false);
  275. sendMouseEvent({type:'click'}, element);
  276. }
  277. // Initialize children with click expected.
  278. for (var name of elementsWithClick) {
  279. var element = document.createElement(name);
  280. legendA.appendChild(element);
  281. element.addEventListener("click", clickShouldHappenHandler7, false);
  282. sendMouseEvent({type:'click'}, element);
  283. }
  284. }
  285. function test8()
  286. {
  287. gHandled = 0;
  288. fieldset1.disabled = true;
  289. fieldset2.disabled = true;
  290. fieldset1.appendChild(legendA);
  291. legendA.appendChild(fieldset2);
  292. fieldset2.appendChild(legendB);
  293. // All elements should accept the click.
  294. for (var name of elementsPreventingClick) {
  295. var element = document.createElement(name);
  296. legendB.appendChild(element);
  297. element.addEventListener("click", clickShouldHappenHandler8, false);
  298. sendMouseEvent({type:'click'}, element);
  299. }
  300. // Initialize children with click expected.
  301. for (var name of elementsWithClick) {
  302. var element = document.createElement(name);
  303. legendB.appendChild(element);
  304. element.addEventListener("click", clickShouldHappenHandler8, false);
  305. sendMouseEvent({type:'click'}, element);
  306. }
  307. }
  308. test1();
  309. </script>
  310. </pre>
  311. </body>
  312. </html>