|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=311681 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 311681</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=311681">Mozilla Bug 311681</a> |
|
13 <script class="testbody" type="text/javascript"> |
|
14 // Setup script |
|
15 SimpleTest.waitForExplicitFinish(); |
|
16 |
|
17 // Make sure to trigger the hashtable case by asking for enough elements |
|
18 // by ID. |
|
19 for (var i = 0; i < 256; ++i) { |
|
20 var x = document.getElementById(i); |
|
21 } |
|
22 |
|
23 // save off the document.getElementById function, since getting it as a |
|
24 // property off the document it causes a content flush. |
|
25 var fun = document.getElementById; |
|
26 |
|
27 // Slot for our initial element with id "content" |
|
28 var testNode; |
|
29 |
|
30 function getCont() { |
|
31 return fun.call(document, "content"); |
|
32 } |
|
33 |
|
34 function testClone() { |
|
35 // Test to make sure that if we have multiple nodes with the same ID in |
|
36 // a document we don't forget about one of them when the other is |
|
37 // removed. |
|
38 var newParent = $("display"); |
|
39 var node = testNode.cloneNode(true); |
|
40 isnot(node, testNode, "Clone should be a different node"); |
|
41 |
|
42 newParent.appendChild(node); |
|
43 |
|
44 // Check what getElementById returns, no flushing |
|
45 is(getCont(), node, "Should be getting new node pre-flush 1"); |
|
46 |
|
47 // Trigger a layout flush, just in case. |
|
48 var itemHeight = newParent.offsetHeight/10; |
|
49 |
|
50 // Check what getElementById returns now. |
|
51 is(getCont(), node, "Should be getting new node post-flush 1"); |
|
52 |
|
53 clear(newParent); |
|
54 |
|
55 // Check what getElementById returns, no flushing |
|
56 is(getCont(), testNode, "Should be getting orig node pre-flush 2"); |
|
57 |
|
58 // Trigger a layout flush, just in case. |
|
59 var itemHeight = newParent.offsetHeight/10; |
|
60 |
|
61 // Check what getElementById returns now. |
|
62 is(getCont(), testNode, "Should be getting orig node post-flush 2"); |
|
63 |
|
64 node = testNode.cloneNode(true); |
|
65 newParent.appendChild(node); |
|
66 testNode.parentNode.removeChild(testNode); |
|
67 |
|
68 // Check what getElementById returns, no flushing |
|
69 is(getCont(), node, "Should be getting clone pre-flush"); |
|
70 |
|
71 // Trigger a layout flush, just in case. |
|
72 var itemHeight = newParent.offsetHeight/10; |
|
73 |
|
74 // Check what getElementById returns now. |
|
75 is(getCont(), node, "Should be getting clone post-flush"); |
|
76 |
|
77 } |
|
78 |
|
79 function clear(node) { |
|
80 while (node.hasChildNodes()) { |
|
81 node.removeChild(node.firstChild); |
|
82 } |
|
83 } |
|
84 |
|
85 addLoadEvent(testClone); |
|
86 addLoadEvent(SimpleTest.finish); |
|
87 </script> |
|
88 <p id="display"></p> |
|
89 <div id="content" style="display: none"> |
|
90 <script class="testbody" type="text/javascript"> |
|
91 testNode = fun.call(document, "content"); |
|
92 isnot(testNode, null, "Should have node here"); |
|
93 </script> |
|
94 </div> |
|
95 <pre id="test"> |
|
96 </pre> |
|
97 </body> |
|
98 </html> |
|
99 |