123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- <!DOCTYPE HTML>
- <html>
- <!--
- https://bugzilla.mozilla.org/show_bug.cgi?id=557087
- -->
- <head>
- <title>Test for Bug 557087</title>
- <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
- <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
- <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
- </head>
- <body>
- <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557087">Mozilla Bug 557087</a>
- <p id="display"></p>
- <div id="content" style="display:none;">
- </div>
- <pre id="test">
- <script type="application/javascript">
- /** Test for Bug 557087 **/
- SimpleTest.waitForExplicitFinish();
- var elementsPreventingClick = [ "input", "button", "select", "textarea", "fieldset" ];
- var elementsWithClick = [ "option", "optgroup", "output", "label", "object" ];
- var gHandled = 0;
- function clickShouldNotHappenHandler(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldNotHappenHandler, false);
- ok(false, "click event should be prevented! (test1)");
- if (++gHandled >= elementsWithClick.length) {
- test2();
- }
- }
- function clickShouldNotHappenHandler2(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldNotHappenHandler3, false);
- ok(false, "click event should be prevented! (test2)");
- if (++gHandled >= elementsWithClick.length) {
- test3();
- }
- }
- function clickShouldNotHappenHandler5(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldNotHappenHandler5, false);
- ok(false, "click event should be prevented! (test5)");
- if (++gHandled >= elementsWithClick.length) {
- test6();
- }
- }
- function clickShouldNotHappenHandler7(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldNotHappenHandler7, false);
- ok(false, "click event should be prevented! (test7)");
- if (++gHandled >= elementsWithClick.length) {
- test8();
- }
- }
- function clickShouldHappenHandler(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldHappenHandler, false);
- ok(true, "click event has been correctly received (test1)");
- if (++gHandled >= elementsWithClick.length) {
- test2();
- }
- }
- function clickShouldHappenHandler2(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldHappenHandler2, false);
- ok(true, "click event has been correctly received (test2)");
- if (++gHandled >= elementsWithClick.length) {
- test3();
- }
- }
- function clickShouldHappenHandler3(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldHappenHandler3, false);
- ok(true, "click event has been correctly received (test3)");
- if (++gHandled >= (elementsWithClick.length +
- elementsPreventingClick.length)) {
- test4();
- }
- }
- function clickShouldHappenHandler4(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldHappenHandler4, false);
- ok(true, "click event has been correctly received (test4)");
- if (++gHandled >= (elementsWithClick.length +
- elementsPreventingClick.length)) {
- test5();
- }
- }
- function clickShouldHappenHandler5(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldHappenHandler5, false);
- ok(true, "click event has been correctly received (test5)");
- if (++gHandled >= elementsWithClick.length) {
- test6();
- }
- }
- function clickShouldHappenHandler6(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldHappenHandler6, false);
- ok(true, "click event has been correctly received (test6)");
- if (++gHandled >= (elementsWithClick.length +
- elementsPreventingClick.length)) {
- test7();
- }
- }
- function clickShouldHappenHandler7(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldHappenHandler7, false);
- ok(true, "click event has been correctly received (test5)");
- if (++gHandled >= elementsWithClick.length) {
- test8();
- }
- }
- function clickShouldHappenHandler8(aEvent)
- {
- aEvent.target.removeEventListener("click", clickShouldHappenHandler8, false);
- ok(true, "click event has been correctly received (test8)");
- if (++gHandled >= (elementsWithClick.length +
- elementsPreventingClick.length)) {
- SimpleTest.finish();
- }
- }
- var fieldset1 = document.createElement("fieldset");
- var fieldset2 = document.createElement("fieldset");
- var legendA = document.createElement("legend");
- var legendB = document.createElement("legend");
- var content = document.getElementById('content');
- fieldset1.disabled = true;
- content.appendChild(fieldset1);
- fieldset1.appendChild(fieldset2);
- function clean()
- {
- var count = fieldset2.children.length;
- for (var i=0; i<count; ++i) {
- if (fieldset2.children[i] != legendA &&
- fieldset2.children[i] != legendB) {
- fieldset2.removeChild(fieldset2.children[i]);
- }
- }
- }
- function test1()
- {
- gHandled = 0;
- // Initialize children without click expected.
- for (var name of elementsPreventingClick) {
- var element = document.createElement(name);
- fieldset2.appendChild(element);
- element.addEventListener("click", clickShouldNotHappenHandler, false);
- sendMouseEvent({type:'click'}, element);
- }
- // Initialize children with click expected.
- for (var name of elementsWithClick) {
- var element = document.createElement(name);
- fieldset2.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler, false);
- sendMouseEvent({type:'click'}, element);
- }
- }
- function test2()
- {
- gHandled = 0;
- fieldset1.disabled = false;
- fieldset2.disabled = true;
- // Initialize children without click expected.
- for (var name of elementsPreventingClick) {
- var element = document.createElement(name);
- fieldset2.appendChild(element);
- element.addEventListener("click", clickShouldNotHappenHandler2, false);
- sendMouseEvent({type:'click'}, element);
- }
- // Initialize children with click expected.
- for (var name of elementsWithClick) {
- var element = document.createElement(name);
- fieldset2.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler2, false);
- sendMouseEvent({type:'click'}, element);
- }
- }
- function test3()
- {
- gHandled = 0;
- fieldset1.disabled = false;
- fieldset2.disabled = false;
- // All elements should accept the click.
- for (var name of elementsPreventingClick) {
- var element = document.createElement(name);
- fieldset2.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler3, false);
- sendMouseEvent({type:'click'}, element);
- }
- // Initialize children with click expected.
- for (var name of elementsWithClick) {
- var element = document.createElement(name);
- fieldset2.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler3, false);
- sendMouseEvent({type:'click'}, element);
- }
- }
- function test4()
- {
- gHandled = 0;
- fieldset1.disabled = false;
- fieldset2.disabled = true;
- fieldset2.appendChild(legendA);
- // All elements should accept the click.
- for (var name of elementsPreventingClick) {
- var element = document.createElement(name);
- legendA.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler4, false);
- sendMouseEvent({type:'click'}, element);
- }
- // Initialize children with click expected.
- for (var name of elementsWithClick) {
- var element = document.createElement(name);
- legendA.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler4, false);
- sendMouseEvent({type:'click'}, element);
- }
- }
- function test5()
- {
- gHandled = 0;
- fieldset2.insertBefore(legendB, legendA);
- // Initialize children without click expected.
- for (var name of elementsPreventingClick) {
- var element = document.createElement(name);
- legendA.appendChild(element);
- element.addEventListener("click", clickShouldNotHappenHandler5, false);
- sendMouseEvent({type:'click'}, element);
- }
- // Initialize children with click expected.
- for (var name of elementsWithClick) {
- var element = document.createElement(name);
- legendA.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler5, false);
- sendMouseEvent({type:'click'}, element);
- }
- }
- function test6()
- {
- gHandled = 0;
- fieldset2.removeChild(legendB);
- fieldset1.disabled = true;
- fieldset2.disabled = false;
- fieldset1.appendChild(legendA);
- legendA.appendChild(fieldset2);
- // All elements should accept the click.
- for (var name of elementsPreventingClick) {
- var element = document.createElement(name);
- fieldset2.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler6, false);
- sendMouseEvent({type:'click'}, element);
- }
- // Initialize children with click expected.
- for (var name of elementsWithClick) {
- var element = document.createElement(name);
- fieldset2.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler6, false);
- sendMouseEvent({type:'click'}, element);
- }
- }
- function test7()
- {
- gHandled = 0;
- fieldset1.disabled = true;
- fieldset2.disabled = false;
- fieldset1.appendChild(fieldset2);
- fieldset2.appendChild(legendA);
- // All elements should accept the click.
- for (var name of elementsPreventingClick) {
- var element = document.createElement(name);
- legendA.appendChild(element);
- element.addEventListener("click", clickShouldNotHappenHandler7, false);
- sendMouseEvent({type:'click'}, element);
- }
- // Initialize children with click expected.
- for (var name of elementsWithClick) {
- var element = document.createElement(name);
- legendA.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler7, false);
- sendMouseEvent({type:'click'}, element);
- }
- }
- function test8()
- {
- gHandled = 0;
- fieldset1.disabled = true;
- fieldset2.disabled = true;
- fieldset1.appendChild(legendA);
- legendA.appendChild(fieldset2);
- fieldset2.appendChild(legendB);
- // All elements should accept the click.
- for (var name of elementsPreventingClick) {
- var element = document.createElement(name);
- legendB.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler8, false);
- sendMouseEvent({type:'click'}, element);
- }
- // Initialize children with click expected.
- for (var name of elementsWithClick) {
- var element = document.createElement(name);
- legendB.appendChild(element);
- element.addEventListener("click", clickShouldHappenHandler8, false);
- sendMouseEvent({type:'click'}, element);
- }
- }
- test1();
- </script>
- </pre>
- </body>
- </html>
|