dom/events/test/test_bug328885.html

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

mercurial