dom/tests/mochitest/bugs/test_bug456151.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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">
    18 </div>
    19 <pre id="test">
    20 <script type="application/javascript">
    22 /** Test for Bug 456151 **/
    23 var intercepted = false;
    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 }
    38 var called = false;
    40 var func = function() { called = true; };
    41 $("display").addEventListener("click", func, false);
    42 is(intercepted, true, "Should have interecepted addEventListener call");
    44 sendMouseEvent({type: "click"}, "display");
    45 is(called, true, "Should have called event listener");
    47 interecepted = false;
    48 called = false;
    50 $("display").removeEventListener("click", func, false);
    51 is(intercepted, true, "Should have interecepted removeEventListener call");
    53 sendMouseEvent({type: "click"}, "display");
    54 is(called, false, "Should have removed event listener");
    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");
    70 </script>
    71 </pre>
    72 </body>
    73 </html>

mercurial