|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=456151 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 456151</title> |
|
8 <script type="application/javascript" src="/MochiKit/MochiKit.js"></script> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=456151">Mozilla Bug 456151</a> |
|
15 <p id="display"></p> |
|
16 <div id="content" style="display: none"> |
|
17 |
|
18 </div> |
|
19 <pre id="test"> |
|
20 <script type="application/javascript"> |
|
21 |
|
22 /** Test for Bug 456151 **/ |
|
23 var intercepted = false; |
|
24 |
|
25 // Set up our new addEventListener |
|
26 var proto = HTMLParagraphElement.prototype; |
|
27 proto.oldAdd = proto.addEventListener; |
|
28 proto.addEventListener = function(ev, list, capt) { |
|
29 intercepted = true; |
|
30 this.oldAdd(ev, list, capt); |
|
31 } |
|
32 proto.oldRemove = proto.removeEventListener; |
|
33 proto.removeEventListener = function(ev, list, capt) { |
|
34 intercepted = true; |
|
35 this.oldRemove(ev, list, capt); |
|
36 } |
|
37 |
|
38 var called = false; |
|
39 |
|
40 var func = function() { called = true; }; |
|
41 $("display").addEventListener("click", func, false); |
|
42 is(intercepted, true, "Should have interecepted addEventListener call"); |
|
43 |
|
44 sendMouseEvent({type: "click"}, "display"); |
|
45 is(called, true, "Should have called event listener"); |
|
46 |
|
47 interecepted = false; |
|
48 called = false; |
|
49 |
|
50 $("display").removeEventListener("click", func, false); |
|
51 is(intercepted, true, "Should have interecepted removeEventListener call"); |
|
52 |
|
53 sendMouseEvent({type: "click"}, "display"); |
|
54 is(called, false, "Should have removed event listener"); |
|
55 |
|
56 // And now some simple sanity tests |
|
57 var recursion = false; |
|
58 var x = document.createElement("span"); |
|
59 HTMLSpanElement.prototype.addEventListener = |
|
60 function(a, b, c) { |
|
61 return x.addEventListener(a,b,c); |
|
62 } |
|
63 try { |
|
64 x.addEventListener("click", function() { called = true; }, false); |
|
65 } catch (e) { |
|
66 recursion = e.message.match(/recursion/); |
|
67 } |
|
68 SimpleTest.isDeeply(recursion, ["recursion"], "Caught infinite recursion"); |
|
69 |
|
70 </script> |
|
71 </pre> |
|
72 </body> |
|
73 </html> |