Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / NodeList / invalidate-node-lists-when-parsing.html
blob954ad0585f17d1e2ec43021dfa49e7b4c1a78d0f
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>5360748</title>
7 <script type="text/javascript">
8 if (window.testRunner)
9 testRunner.dumpAsText();
11 function print(message)
13 var paragraph = document.createElement("li");
14 paragraph.appendChild(document.createTextNode(message));
15 document.getElementById("console").appendChild(paragraph);
18 function runTest() {
19 result3 = testForElement("onload", "testElement2"); // expect to see "testElement2"
21 // don't show the results until the tests are finished -- it changes the DOM and could affect the tests
22 print(result1);
23 print(result2);
24 print(result3);
26 function testForElement(testName, elementId) {
27 var found = containsElementWithId(document.body, elementId);
28 if (window.GCController)
29 GCController.collect();
30 else {
31 // create lots of objects to force a garbage collection
32 var i = 0;
33 var s;
34 while (i < 5000) {
35 i = i+1.11;
36 s = s + " ";
40 return testName + ": " + (found ? "found" : "not found");
42 function containsElementWithId(el, id) {
43 var found = false;
45 if (el.id == id) {
46 found = true;
47 } else {
48 var children = el.childNodes;
49 for (var i=0; !found && i < children.length; i++)
50 found = containsElementWithId(children[i], id);
53 return found;
55 </script>
56 </head>
57 <body onload="runTest()">
59 <p>This test checks to see if the DOM ContainerNode's NodeList cache is correctly invalidated when new content is parsed.</p>
60 <p>If the test passes, you should see &quot;before: not found&quot;, &quot;after: found&quot; and &quot;onload: found&quot;.</p>
61 <p>If the cache is not invalidated when the testElement is parsed, both before and after will be &quot;not found&quot;, which is a failure.</p>
62 <hr>
63 <p><ol id=console></ol></p>
65 <script type="text/javascript">
66 result1 = testForElement("before", "testElement"); // expect not to see "testElement"
67 </script>
69 <p id="testElement"></p>
71 <script type="text/javascript">
72 result2 = testForElement("after", "testElement"); // expect to see "testElement"
73 </script>
75 <p id="testElement2"></p>
76 </body>
77 </html>