dom/events/test/test_bug288392.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=288392
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 288392</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=288392">Mozilla Bug 288392</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15 <div id="mutationTarget">
michael@0 16 </div>
michael@0 17 </div>
michael@0 18 <pre id="test">
michael@0 19 <script class="testbody" type="text/javascript">
michael@0 20
michael@0 21 /** Test for Bug 288392 **/
michael@0 22 var subtreeModifiedCount;
michael@0 23
michael@0 24 function subtreeModified(e)
michael@0 25 {
michael@0 26 ++subtreeModifiedCount;
michael@0 27 }
michael@0 28
michael@0 29 function doTest() {
michael@0 30 var targetNode = document.getElementById("mutationTarget");
michael@0 31 targetNode.addEventListener("DOMSubtreeModified", subtreeModified, false);
michael@0 32
michael@0 33 subtreeModifiedCount = 0;
michael@0 34 var temp = document.createElement("DIV");
michael@0 35 targetNode.appendChild(temp);
michael@0 36 is(subtreeModifiedCount, 1,
michael@0 37 "Appending a child node should have dispatched a DOMSubtreeModified event");
michael@0 38
michael@0 39 subtreeModifiedCount = 0;
michael@0 40 temp.setAttribute("foo", "bar");
michael@0 41 is(subtreeModifiedCount, 1,
michael@0 42 "Setting an attribute should have dispatched a DOMSubtreeModified event");
michael@0 43
michael@0 44 subtreeModifiedCount = 0;
michael@0 45 targetNode.removeChild(temp);
michael@0 46 is(subtreeModifiedCount, 1,
michael@0 47 "Removing a child node should have dispatched a DOMSubtreeModified event");
michael@0 48
michael@0 49 // Testing events in a subtree, which is not in the document.
michael@0 50 var subtree = document.createElement("div");
michael@0 51 var s = "<e1 attr1='value1'>Something1</e1><e2 attr2='value2'>Something2</e2>";
michael@0 52 subtree.innerHTML = s;
michael@0 53 subtree.addEventListener("DOMSubtreeModified", subtreeModified, false);
michael@0 54
michael@0 55 subtreeModifiedCount = 0;
michael@0 56 subtree.firstChild.firstChild.data = "foo";
michael@0 57 is(subtreeModifiedCount, 1,
michael@0 58 "Editing character data should have dispatched a DOMSubtreeModified event");
michael@0 59
michael@0 60 subtreeModifiedCount = 0;
michael@0 61 subtree.firstChild.removeChild(subtree.firstChild.firstChild);
michael@0 62 is(subtreeModifiedCount, 1,
michael@0 63 "Removing a child node should have dispatched a DOMSubtreeModified event");
michael@0 64
michael@0 65 subtreeModifiedCount = 0;
michael@0 66 subtree.firstChild.setAttribute("foo", "bar");
michael@0 67 is(subtreeModifiedCount, 1,
michael@0 68 "Setting an attribute should have dispatched a DOMSubtreeModified event");
michael@0 69
michael@0 70 subtreeModifiedCount = 0;
michael@0 71 subtree.textContent = "foobar";
michael@0 72 is(subtreeModifiedCount, 1,
michael@0 73 "Setting .textContent should have dispatched a DOMSubtreeModified event");
michael@0 74
michael@0 75 subtreeModifiedCount = 0;
michael@0 76 subtree.innerHTML = s;
michael@0 77 is(subtreeModifiedCount, 1,
michael@0 78 "Setting .innerHTML should have dispatched a DOMSubtreeModified event");
michael@0 79
michael@0 80 subtreeModifiedCount = 0;
michael@0 81 subtree.removeEventListener("DOMSubtreeModified", subtreeModified, false);
michael@0 82 subtree.appendChild(document.createTextNode(""));
michael@0 83 subtree.addEventListener("DOMSubtreeModified", subtreeModified, false);
michael@0 84 subtree.normalize();
michael@0 85 is(subtreeModifiedCount, 1,
michael@0 86 "Calling normalize() should have dispatched a DOMSubtreeModified event");
michael@0 87 }
michael@0 88
michael@0 89 SimpleTest.waitForExplicitFinish();
michael@0 90 addLoadEvent(doTest);
michael@0 91 addLoadEvent(SimpleTest.finish);
michael@0 92
michael@0 93 </script>
michael@0 94 </pre>
michael@0 95 </body>
michael@0 96 </html>
michael@0 97

mercurial