dom/events/test/test_bug613634.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug613634.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=613634
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 613634</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=613634">Mozilla Bug 613634</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 613634 **/
    1.24 +
    1.25 +var eventCount = 0;
    1.26 +function l(e) {
    1.27 +  if (e.eventPhase != Event.CAPTURING_PHASE) {
    1.28 +    ++eventCount;
    1.29 +  } else {
    1.30 +    ok(false, "Listener shouldn't be called!");
    1.31 +  }
    1.32 +}
    1.33 +
    1.34 +var d1 = document.createElement("div");
    1.35 +var d2 = document.createElement("div");
    1.36 +
    1.37 +d1.appendChild(d2);
    1.38 +
    1.39 +var x = new XMLHttpRequest();
    1.40 +
    1.41 +try {
    1.42 +d1.addEventListener("foo", l);
    1.43 +document.addEventListener("foo", l);
    1.44 +window.addEventListener("foo", l);
    1.45 +x.addEventListener("foo", l);
    1.46 +} catch(ex) {
    1.47 +  ok(false, "Shouldn't throw " + ex);
    1.48 +}
    1.49 +
    1.50 +var ev = document.createEvent("Event");
    1.51 +ev.initEvent("foo", true, true);
    1.52 +d2.dispatchEvent(ev);
    1.53 +is(eventCount, 1, "Event listener should have been called!");
    1.54 +
    1.55 +ev = document.createEvent("Event");
    1.56 +ev.initEvent("foo", false, false);
    1.57 +d2.dispatchEvent(ev);
    1.58 +is(eventCount, 1, "Event listener shouldn't have been called!");
    1.59 +
    1.60 +d1.removeEventListener("foo", l);
    1.61 +ev = document.createEvent("Event");
    1.62 +ev.initEvent("foo", true, true);
    1.63 +d2.dispatchEvent(ev);
    1.64 +is(eventCount, 1, "Event listener shouldn't have been called!");
    1.65 +
    1.66 +
    1.67 +ev = document.createEvent("Event");
    1.68 +ev.initEvent("foo", true, true);
    1.69 +document.body.dispatchEvent(ev);
    1.70 +is(eventCount, 3, "Event listener should have been called on document and window!");
    1.71 +
    1.72 +document.removeEventListener("foo", l);
    1.73 +window.removeEventListener("foo", l, false);
    1.74 +ev = document.createEvent("Event");
    1.75 +ev.initEvent("foo", true, true);
    1.76 +document.body.dispatchEvent(ev);
    1.77 +is(eventCount, 3, "Event listener shouldn't have been called on document and window!");
    1.78 +
    1.79 +ev = document.createEvent("Event");
    1.80 +ev.initEvent("foo", true, true);
    1.81 +x.dispatchEvent(ev);
    1.82 +is(eventCount, 4, "Event listener should have been called on XMLHttpRequest!");
    1.83 +
    1.84 +x.removeEventListener("foo", l);
    1.85 +ev = document.createEvent("Event");
    1.86 +ev.initEvent("foo", true, true);
    1.87 +x.dispatchEvent(ev);
    1.88 +is(eventCount, 4, "Event listener shouldn't have been called on XMLHttpRequest!");
    1.89 +
    1.90 +</script>
    1.91 +</pre>
    1.92 +</body>
    1.93 +</html>

mercurial