chromium/third_party/blink/web_tests/fast/dom/NodeList/invalidate-node-lists-when-parsing.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>5360748</title>

        <script type="text/javascript">
            if (window.testRunner)
                testRunner.dumpAsText();

            function print(message)
            {
                var paragraph = document.createElement("li");
                paragraph.appendChild(document.createTextNode(message));
                document.getElementById("console").appendChild(paragraph);
            }

            function runTest() {
                result3 = testForElement("onload", "testElement2");    // expect to see "testElement2"
                
                // don't show the results until the tests are finished -- it changes the DOM and could affect the tests
                print(result1);
                print(result2);
                print(result3);
            }
            function testForElement(testName, elementId) {
                var found = containsElementWithId(document.body, elementId);
                if (window.GCController)
                    GCController.collect();
                else {
                    // create lots of objects to force a garbage collection
                    var i = 0;
                    var s;
                    while (i < 5000) {
                        i = i+1.11;
                        s = s + " ";
                    }
                }
                    
                return testName + ": " + (found ? "found" : "not found");
            }
            function containsElementWithId(el, id) {
                var found = false;
    
                if (el.id == id) {
                    found = true;
                } else {
                    var children = el.childNodes;
                    for (var i=0; !found && i < children.length; i++)
                        found = containsElementWithId(children[i], id);            
                }
                
                return found;
            }
        </script>        
    </head>
    <body onload="runTest()">

    <p>This test checks to see if the DOM ContainerNode's NodeList cache is correctly invalidated when new content is parsed.</p>
    <p>If the test passes, you should see &quot;before: not found&quot;, &quot;after: found&quot; and &quot;onload: found&quot;.</p>
    <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>
    <hr>
    <p><ol id=console></ol></p>

    <script type="text/javascript">
        result1 = testForElement("before", "testElement");    // expect not to see "testElement"
    </script>

    <p id="testElement"></p>
    
    <script type="text/javascript">
        result2 = testForElement("after", "testElement");    // expect to see "testElement"
    </script>

    <p id="testElement2"></p>
</body>
</html>