<html>
<head>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function log(msg) {
    document.getElementById("log").innerHTML += msg;
}
</script>
</head>
<body>
<div>
<p>
Test that a synchronous script tag is executed in the right order, even if it's
removed from the document before it was loaded.
</p>
<p>
This test passes if the number "4123" is displayed below.
</p>
</div>
<div id="log"></div>
<script>
    // All these scripts should be executed after the next script tag.
    var s1 = document.createElement("script");
    s1.src = "resources/delayed-log.py?delay=3&msg=1";
    s1.async = false;
    document.body.appendChild(s1);

    var s2 = document.createElement("script");
    s2.src = "resources/delayed-log.py?delay=2&msg=2";
    s2.async = false;
    document.body.appendChild(s2);

    var s3 = document.createElement("script");
    s3.src = "resources/delayed-log.py?delay=1&msg=3&done=1";
    s3.async = false;
    document.body.appendChild(s3);

    // s1 should still execute, and it should execute before s2 and s3.
    document.body.removeChild(s1);
</script>
<script>log("4");</script>
</body>
</html>
