dom/events/test/test_bug328885.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=328885
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 328885</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=328885">Mozilla Bug 328885</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content" style="display: none">
michael@0 16
michael@0 17 </div>
michael@0 18 <input type="text" id="inputelement"
michael@0 19 style="position: absolute; left: 0px; top: 0px;">
michael@0 20 <pre id="test">
michael@0 21 <script class="testbody" type="text/javascript">
michael@0 22
michael@0 23 /** Test for Bug 328885 **/
michael@0 24
michael@0 25 var inputelement = null;
michael@0 26 var mutationCount = 0;
michael@0 27
michael@0 28 function mutationListener(evt) {
michael@0 29 ++mutationCount;
michael@0 30 }
michael@0 31
michael@0 32 function clickTest() {
michael@0 33 inputelement.addEventListener("DOMSubtreeModified", mutationListener, false);
michael@0 34 inputelement.addEventListener("DOMNodeInserted", mutationListener, false);
michael@0 35 inputelement.addEventListener("DOMNodeRemoved", mutationListener, false);
michael@0 36 inputelement.addEventListener("DOMNodeRemovedFromDocument", mutationListener, false);
michael@0 37 inputelement.addEventListener("DOMNodeInsertedIntoDocument", mutationListener, false);
michael@0 38 inputelement.addEventListener("DOMAttrModified", mutationListener, false);
michael@0 39 inputelement.addEventListener("DOMCharacterDataModified", mutationListener, false);
michael@0 40
michael@0 41 inputelement.addEventListener('click',
michael@0 42 function(event) {
michael@0 43 var evt = SpecialPowers.wrap(event);
michael@0 44 ok(SpecialPowers.unwrap(evt.originalTarget) instanceof HTMLDivElement,
michael@0 45 "(1) Wrong originalTarget!");
michael@0 46 is(SpecialPowers.unwrap(evt.originalTarget.parentNode), inputelement,
michael@0 47 "(2) Wront parent node!");
michael@0 48 ok(mutationCount == 0, "(3) No mutations should have happened! [" + mutationCount + "]");
michael@0 49 evt.originalTarget.textContent = "foo";
michael@0 50 ok(mutationCount == 0, "(4) Mutation listener shouldn't have been called! [" + mutationCount + "]");
michael@0 51 evt.originalTarget.innerHTML = "foo2";
michael@0 52 ok(mutationCount == 0, "(5) Mutation listener shouldn't have been called! [" + mutationCount + "]");
michael@0 53 evt.originalTarget.lastChild.data = "bar";
michael@0 54 ok(mutationCount == 0, "(6) Mutation listener shouldn't have been called! [" + mutationCount + "]");
michael@0 55
michael@0 56 var r = SpecialPowers.wrap(document.createRange());
michael@0 57 r.selectNodeContents(evt.originalTarget);
michael@0 58 r.deleteContents();
michael@0 59 ok(mutationCount == 0, "(7) Mutation listener shouldn't have been called! [" + mutationCount + "]");
michael@0 60
michael@0 61 evt.originalTarget.textContent = "foo";
michael@0 62 ok(mutationCount == 0, "(8) Mutation listener shouldn't have been called! [" + mutationCount + "]");
michael@0 63 r = SpecialPowers.wrap(document.createRange());
michael@0 64 r.selectNodeContents(evt.originalTarget);
michael@0 65 r.extractContents();
michael@0 66 ok(mutationCount == 0, "(9) Mutation listener shouldn't have been called! [" + mutationCount + "]");
michael@0 67
michael@0 68 evt.originalTarget.setAttribute("foo", "bar");
michael@0 69 ok(mutationCount == 0, "(10) Mutation listener shouldn't have been called! ["+ mutationCount + "]");
michael@0 70
michael@0 71 // Same tests with non-native-anononymous element.
michael@0 72 // mutationCount should be increased by 2 each time, since there is
michael@0 73 // first a mutation specific event and then DOMSubtreeModified.
michael@0 74 inputelement.textContent = "foo";
michael@0 75 ok(mutationCount == 2, "(11) Mutation listener should have been called! [" + mutationCount + "]");
michael@0 76 inputelement.lastChild.data = "bar";
michael@0 77 ok(mutationCount == 4, "(12) Mutation listener should have been called! [" + mutationCount + "]");
michael@0 78
michael@0 79 r = document.createRange();
michael@0 80 r.selectNodeContents(inputelement);
michael@0 81 r.deleteContents();
michael@0 82 ok(mutationCount == 6, "(13) Mutation listener should have been called! [" + mutationCount + "]");
michael@0 83
michael@0 84 inputelement.textContent = "foo";
michael@0 85 ok(mutationCount == 8, "(14) Mutation listener should have been called! [" + mutationCount + "]");
michael@0 86 r = document.createRange();
michael@0 87 r.selectNodeContents(inputelement);
michael@0 88 r.extractContents();
michael@0 89 ok(mutationCount == 10, "(15) Mutation listener should have been called! [" + mutationCount + "]");
michael@0 90
michael@0 91 inputelement.setAttribute("foo", "bar");
michael@0 92 ok(mutationCount == 12, "(16) Mutation listener should have been called! ["+ mutationCount + "]");
michael@0 93
michael@0 94 // Then try some mixed mutations. The mutation handler of non-native-a
michael@0 95 inputelement.addEventListener("DOMAttrModified",
michael@0 96 function (evt2) {
michael@0 97 evt.originalTarget.setAttribute("foo", "bar" + mutationCount);
michael@0 98 ok(evt.originalTarget.getAttribute("foo") == "bar" + mutationCount,
michael@0 99 "(17) Couldn't update the attribute?!?");
michael@0 100 }
michael@0 101 , false);
michael@0 102 inputelement.setAttribute("foo", "");
michael@0 103 ok(mutationCount == 14, "(18) Mutation listener should have been called! ["+ mutationCount + "]");
michael@0 104
michael@0 105 inputelement.textContent = "foo";
michael@0 106 ok(mutationCount == 16, "(19) Mutation listener should have been called! ["+ mutationCount + "]");
michael@0 107 inputelement.addEventListener("DOMCharacterDataModified",
michael@0 108 function (evt2) {
michael@0 109 evt.originalTarget.textContent = "bar" + mutationCount;
michael@0 110 }, false);
michael@0 111 // This one deletes and inserts a new node, then DOMSubtreeModified.
michael@0 112 inputelement.textContent = "bar";
michael@0 113 ok(mutationCount == 19, "(20) Mutation listener should have been called! ["+ mutationCount + "]");
michael@0 114 }
michael@0 115 ,false);
michael@0 116 synthesizeMouseAtPoint(5, 5, {}, window);
michael@0 117 SimpleTest.finish();
michael@0 118 }
michael@0 119
michael@0 120 function doTest() {
michael@0 121 inputelement = document.getElementById('inputelement');
michael@0 122 inputelement.focus();
michael@0 123 setTimeout(clickTest, 100);
michael@0 124 }
michael@0 125
michael@0 126 SimpleTest.waitForExplicitFinish();
michael@0 127 addLoadEvent(doTest);
michael@0 128
michael@0 129 </script>
michael@0 130 </pre>
michael@0 131 </body>
michael@0 132 </html>
michael@0 133

mercurial