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