DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1aeaa33a64f9)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=524674
-->
<window title="Mozilla Bug 524674"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=524674"
     target="_blank">Mozilla Bug 524674</a>
  </body>

  <!-- test code goes here -->
  <script type="application/javascript">
  <![CDATA[
  /** Test for Bug 524674 **/

  var els = Cc["@mozilla.org/eventlistenerservice;1"]
              .getService(Ci.nsIEventListenerService);

  function dummyListener() {}

  var runningTest = null;
  var d = document.createElementNS("http://www.w3.org/1999/xhtml", "div");
  var xhr = new XMLHttpRequest();

  // Test also double removals and such.
  var tests = [
    function() {
      els.addListenerChangeListener(changeListener);
      d.addEventListener("foo", dummyListener);
      d.addEventListener("foo", dummyListener);
      xhr.addEventListener("foo", dummyListener);
      tests[0] = [{target: d, listeners: ["onfoo"]},
                  {target: xhr, listeners: ["onfoo"]}];
    },
    function() {
      d.addEventListener("bar", dummyListener);
      d.addEventListener("baz", dummyListener);
      xhr.addEventListener("bar", dummyListener);
      xhr.addEventListener("baz", dummyListener);
      tests[0] = [{target: d, listeners: ["onbaz", "onbar"]},
                  {target: xhr, listeners: ["onbaz", "onbar"]}];
    },
    function() {
      d.onclick = dummyListener;
      d.onclick = dummyListener;
      xhr.onload = dummyListener;
      tests[0] = [{target: d, listeners: ["onclick"]},
                  {target: xhr, listeners: ["onload"]}];
    },
    function() {
      d.onclick = function() {};
      tests[0] = [{target: d, listeners: ["onclick"]}];
    },
    function() {
      d.removeEventListener("foo", dummyListener);
      d.removeEventListener("foo", dummyListener);
      xhr.removeEventListener("foo", dummyListener);
      tests[0] = [{target: d, listeners: ["onfoo"]},
                  {target: xhr, listeners: ["onfoo"]}];
    },
    function() {
      d.removeEventListener("bar", dummyListener);
      d.removeEventListener("baz", dummyListener);
      xhr.removeEventListener("bar", dummyListener);
      xhr.removeEventListener("baz", dummyListener);
      tests[0] = [{target: d, listeners: ["onbar", "onbaz"]},
                  {target: xhr, listeners: ["onbar", "onbaz"]}];
    },
    function() {
      d.onclick = null;
      d.onclick = null;
      xhr.onload = null;
      tests[0] = [{target: d, listeners: ["onclick"]},
                  {target: xhr, listeners: ["onload"]}];
    },
    function() {
      els.removeListenerChangeListener(changeListener);
      // Check that once we've removed the change listener, it isn't called anymore.
      d.addEventListener("foo", dummyListener);
      xhr.addEventListener("foo", dummyListener);
      SimpleTest.executeSoon(function() {
        SimpleTest.finish();
      });
    }
  ];

  SimpleTest.executeSoon(tests[0]);

  function changeListener(array) {
    if (typeof tests[0] == "function") {
      return;
    }
    var expectedEventChanges = tests[0];
    var eventChanges = array.enumerate();
    var i = 0;
    while (eventChanges.hasMoreElements() && i < expectedEventChanges.length) {
      var current;
      try {
        current = eventChanges.getNext().QueryInterface(Ci.nsIEventListenerChange);
        var expected = expectedEventChanges[i];

        if (current.target == expected.target) {
          is(current.target, expected.target, current.target + " = " + expected.target);
          ++i;
        }
      } catch(ex) {
        continue;
      }
    }
    if (expectedEventChanges.length != i) {
      return;
    }

    is(expectedEventChanges.length, i, "Should have got notification for all the changes.");
    tests.shift();

    ok(tests.length);
    SimpleTest.executeSoon(tests[0]);
  }

  SimpleTest.waitForExplicitFinish();
  ]]>
  </script>
</window>