dom/tests/mochitest/bugs/test_bug456151.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_bug456151.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=456151
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 456151</title>
    1.11 +  <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=456151">Mozilla Bug 456151</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content" style="display: none">
    1.20 +  
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script type="application/javascript">
    1.24 +
    1.25 +/** Test for Bug 456151 **/
    1.26 +var intercepted = false;
    1.27 +
    1.28 +// Set up our new addEventListener
    1.29 +var proto = HTMLParagraphElement.prototype;
    1.30 +proto.oldAdd = proto.addEventListener;
    1.31 +proto.addEventListener = function(ev, list, capt) {
    1.32 +  intercepted = true;
    1.33 +  this.oldAdd(ev, list, capt);
    1.34 +}
    1.35 +proto.oldRemove = proto.removeEventListener;
    1.36 +proto.removeEventListener = function(ev, list, capt) {
    1.37 +  intercepted = true;
    1.38 +  this.oldRemove(ev, list, capt);
    1.39 +}
    1.40 +
    1.41 +var called = false;
    1.42 +
    1.43 +var func = function() { called = true; };
    1.44 +$("display").addEventListener("click", func, false);
    1.45 +is(intercepted, true, "Should have interecepted addEventListener call");
    1.46 +
    1.47 +sendMouseEvent({type: "click"}, "display");
    1.48 +is(called, true, "Should have called event listener");
    1.49 +
    1.50 +interecepted = false;
    1.51 +called = false;
    1.52 +
    1.53 +$("display").removeEventListener("click", func, false);
    1.54 +is(intercepted, true, "Should have interecepted removeEventListener call");
    1.55 +
    1.56 +sendMouseEvent({type: "click"}, "display");
    1.57 +is(called, false, "Should have removed event listener");
    1.58 +
    1.59 +// And now some simple sanity tests
    1.60 +var recursion = false;
    1.61 +var x = document.createElement("span");
    1.62 +HTMLSpanElement.prototype.addEventListener =
    1.63 +  function(a, b, c) {
    1.64 +    return x.addEventListener(a,b,c);
    1.65 +  }
    1.66 +try {
    1.67 +  x.addEventListener("click", function() { called = true; }, false);
    1.68 +} catch (e) {
    1.69 +  recursion = e.message.match(/recursion/);
    1.70 +}
    1.71 +SimpleTest.isDeeply(recursion, ["recursion"], "Caught infinite recursion");
    1.72 +
    1.73 +</script>
    1.74 +</pre>
    1.75 +</body>
    1.76 +</html>

mercurial