test_bug613634.html (2406B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=613634 5 --> 6 <head> 7 <title>Test for Bug 613634</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=613634">Mozilla Bug 613634</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 </div> 17 <pre id="test"> 18 <script type="application/javascript"> 19 20 /** Test for Bug 613634 */ 21 22 var eventCount = 0; 23 function l(e) { 24 if (e.eventPhase != Event.CAPTURING_PHASE) { 25 ++eventCount; 26 } else { 27 ok(false, "Listener shouldn't be called!"); 28 } 29 } 30 31 var d1 = document.createElement("div"); 32 var d2 = document.createElement("div"); 33 34 d1.appendChild(d2); 35 36 var x = new XMLHttpRequest(); 37 38 try { 39 d1.addEventListener("foo", l); 40 document.addEventListener("foo", l); 41 window.addEventListener("foo", l); 42 x.addEventListener("foo", l); 43 } catch(ex) { 44 ok(false, "Shouldn't throw " + ex); 45 } 46 47 var ev = document.createEvent("Event"); 48 ev.initEvent("foo", true, true); 49 d2.dispatchEvent(ev); 50 is(eventCount, 1, "Event listener should have been called!"); 51 52 ev = document.createEvent("Event"); 53 ev.initEvent("foo", false, false); 54 d2.dispatchEvent(ev); 55 is(eventCount, 1, "Event listener shouldn't have been called!"); 56 57 d1.removeEventListener("foo", l); 58 ev = document.createEvent("Event"); 59 ev.initEvent("foo", true, true); 60 d2.dispatchEvent(ev); 61 is(eventCount, 1, "Event listener shouldn't have been called!"); 62 63 64 ev = document.createEvent("Event"); 65 ev.initEvent("foo", true, true); 66 document.body.dispatchEvent(ev); 67 is(eventCount, 3, "Event listener should have been called on document and window!"); 68 69 document.removeEventListener("foo", l); 70 window.removeEventListener("foo", l); 71 ev = document.createEvent("Event"); 72 ev.initEvent("foo", true, true); 73 document.body.dispatchEvent(ev); 74 is(eventCount, 3, "Event listener shouldn't have been called on document and window!"); 75 76 ev = document.createEvent("Event"); 77 ev.initEvent("foo", true, true); 78 x.dispatchEvent(ev); 79 is(eventCount, 4, "Event listener should have been called on XMLHttpRequest!"); 80 81 x.removeEventListener("foo", l); 82 ev = document.createEvent("Event"); 83 ev.initEvent("foo", true, true); 84 x.dispatchEvent(ev); 85 is(eventCount, 4, "Event listener shouldn't have been called on XMLHttpRequest!"); 86 87 </script> 88 </pre> 89 </body> 90 </html>