WebCore/manual-tests/dom/document-write-synchronous-after-page-load.html
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 04 Oct 2010 01:32:07 +0300
changeset 2 303757a437d3
parent 0 4f2f89ce4247
permissions -rw-r--r--
Revision: 201037 Kit: 201039

<p>This test ensures that document.write after page load is synchronous.</p>
<p>You will get a PASS or FAIL alert message after a few seconds.</p>
<script>
window.onload = function() {

    // Build a very long string to write.
    var LIMIT = 17;
    var str = '<p style="display:none">x</p>';
    for (var i=0; i<LIMIT; ++i)
        str += str;

    // Write the string and check the DOM immediately and after a small delay.
    var doc = document.implementation.createHTMLDocument();
    doc.write(str);
    var immediateElementCount = doc.getElementsByTagName('*').length;
    setTimeout(function() {
        var delayedElementCount = doc.getElementsByTagName('*').length;
        var passOrFail = (immediateElementCount === delayedElementCount ? "PASS" : "FAIL");
        alert(passOrFail);
    }, 100);

}
</script>