dom/events/test/test_bug328885.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug328885.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=328885
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 328885</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=328885">Mozilla Bug 328885</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +  
    1.20 +</div>
    1.21 +<input type="text" id="inputelement"
    1.22 +       style="position: absolute; left: 0px; top: 0px;">
    1.23 +<pre id="test">
    1.24 +<script class="testbody" type="text/javascript">
    1.25 +
    1.26 +/** Test for Bug 328885 **/
    1.27 +
    1.28 +  var inputelement = null;
    1.29 +  var mutationCount = 0;
    1.30 +
    1.31 +  function mutationListener(evt) {
    1.32 +    ++mutationCount;
    1.33 +  }
    1.34 +
    1.35 +  function clickTest() {
    1.36 +    inputelement.addEventListener("DOMSubtreeModified", mutationListener, false);
    1.37 +    inputelement.addEventListener("DOMNodeInserted", mutationListener, false);
    1.38 +    inputelement.addEventListener("DOMNodeRemoved", mutationListener, false);
    1.39 +    inputelement.addEventListener("DOMNodeRemovedFromDocument", mutationListener, false);
    1.40 +    inputelement.addEventListener("DOMNodeInsertedIntoDocument", mutationListener, false);
    1.41 +    inputelement.addEventListener("DOMAttrModified", mutationListener, false);
    1.42 +    inputelement.addEventListener("DOMCharacterDataModified", mutationListener, false);
    1.43 +    
    1.44 +    inputelement.addEventListener('click', 
    1.45 +      function(event) {
    1.46 +        var evt = SpecialPowers.wrap(event);
    1.47 +        ok(SpecialPowers.unwrap(evt.originalTarget) instanceof HTMLDivElement,
    1.48 +           "(1) Wrong originalTarget!");
    1.49 +        is(SpecialPowers.unwrap(evt.originalTarget.parentNode), inputelement,
    1.50 +           "(2) Wront parent node!");
    1.51 +        ok(mutationCount == 0, "(3) No mutations should have happened! [" + mutationCount + "]");
    1.52 +        evt.originalTarget.textContent = "foo";
    1.53 +        ok(mutationCount == 0, "(4) Mutation listener shouldn't have been called! [" + mutationCount + "]");
    1.54 +        evt.originalTarget.innerHTML = "foo2";
    1.55 +        ok(mutationCount == 0, "(5) Mutation listener shouldn't have been called! [" + mutationCount + "]");
    1.56 +        evt.originalTarget.lastChild.data = "bar";
    1.57 +        ok(mutationCount == 0, "(6) Mutation listener shouldn't have been called! [" + mutationCount + "]");
    1.58 +
    1.59 +        var r = SpecialPowers.wrap(document.createRange());
    1.60 +        r.selectNodeContents(evt.originalTarget);
    1.61 +        r.deleteContents();
    1.62 +        ok(mutationCount == 0, "(7) Mutation listener shouldn't have been called! [" + mutationCount + "]");
    1.63 +
    1.64 +        evt.originalTarget.textContent = "foo";
    1.65 +        ok(mutationCount == 0, "(8) Mutation listener shouldn't have been called! [" + mutationCount + "]");
    1.66 +        r = SpecialPowers.wrap(document.createRange());
    1.67 +        r.selectNodeContents(evt.originalTarget);
    1.68 +        r.extractContents();
    1.69 +        ok(mutationCount == 0, "(9) Mutation listener shouldn't have been called! [" + mutationCount + "]");
    1.70 +
    1.71 +        evt.originalTarget.setAttribute("foo", "bar");
    1.72 +        ok(mutationCount == 0, "(10) Mutation listener shouldn't have been called! ["+ mutationCount + "]");
    1.73 +
    1.74 +        // Same tests with non-native-anononymous element.
    1.75 +        // mutationCount should be increased by 2 each time, since there is
    1.76 +        // first a mutation specific event and then DOMSubtreeModified.
    1.77 +        inputelement.textContent = "foo";
    1.78 +        ok(mutationCount == 2, "(11) Mutation listener should have been called! [" + mutationCount + "]");
    1.79 +        inputelement.lastChild.data = "bar";
    1.80 +        ok(mutationCount == 4, "(12) Mutation listener should have been called! [" + mutationCount + "]");
    1.81 +
    1.82 +        r = document.createRange();
    1.83 +        r.selectNodeContents(inputelement);
    1.84 +        r.deleteContents();
    1.85 +        ok(mutationCount == 6, "(13) Mutation listener should have been called! [" + mutationCount + "]");
    1.86 +
    1.87 +        inputelement.textContent = "foo";
    1.88 +        ok(mutationCount == 8, "(14) Mutation listener should have been called! [" + mutationCount + "]");
    1.89 +        r = document.createRange();
    1.90 +        r.selectNodeContents(inputelement);
    1.91 +        r.extractContents();
    1.92 +        ok(mutationCount == 10, "(15) Mutation listener should have been called! [" + mutationCount + "]");
    1.93 +
    1.94 +        inputelement.setAttribute("foo", "bar");
    1.95 +        ok(mutationCount == 12, "(16) Mutation listener should have been called! ["+ mutationCount + "]");
    1.96 +
    1.97 +        // Then try some mixed mutations. The mutation handler of non-native-a
    1.98 +        inputelement.addEventListener("DOMAttrModified", 
    1.99 +          function (evt2) {
   1.100 +            evt.originalTarget.setAttribute("foo", "bar" + mutationCount);
   1.101 +            ok(evt.originalTarget.getAttribute("foo") == "bar" + mutationCount,
   1.102 +               "(17) Couldn't update the attribute?!?");
   1.103 +          }
   1.104 +          , false);
   1.105 +        inputelement.setAttribute("foo", "");
   1.106 +        ok(mutationCount == 14, "(18) Mutation listener should have been called! ["+ mutationCount + "]");
   1.107 +
   1.108 +        inputelement.textContent = "foo";
   1.109 +        ok(mutationCount == 16, "(19) Mutation listener should have been called! ["+ mutationCount + "]");
   1.110 +        inputelement.addEventListener("DOMCharacterDataModified",
   1.111 +          function (evt2) {
   1.112 +            evt.originalTarget.textContent =  "bar" + mutationCount;
   1.113 +          }, false);
   1.114 +        // This one deletes and inserts a new node, then DOMSubtreeModified.
   1.115 +        inputelement.textContent = "bar";
   1.116 +        ok(mutationCount == 19, "(20) Mutation listener should have been called! ["+ mutationCount + "]");
   1.117 +      }
   1.118 +    ,false);
   1.119 +    synthesizeMouseAtPoint(5, 5, {}, window);
   1.120 +    SimpleTest.finish();
   1.121 +  }
   1.122 +
   1.123 +  function doTest() {
   1.124 +    inputelement = document.getElementById('inputelement');
   1.125 +    inputelement.focus();
   1.126 +    setTimeout(clickTest, 100);
   1.127 +  }
   1.128 +
   1.129 +  SimpleTest.waitForExplicitFinish();
   1.130 +  addLoadEvent(doTest);
   1.131 +
   1.132 +</script>
   1.133 +</pre>
   1.134 +</body>
   1.135 +</html>
   1.136 +

mercurial