<html>
<script>

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function runTest()
{
    var s1 = document.getElementById("s1");
    s1.size = 5;
    s1.size = 1;

    var s2 = document.getElementById("s2");
    s2.size = 5;
    // force layout.
    document.body.offsetTop;
    s2.size = 1;

    var s3 = document.getElementById("s3");
    s3.size = 5;
    setTimeout(function()
    {
        s3.size = 1;
        reportResults();
    }, 0);
}

function reportResults()
{
    var selected1 = s1.selectedIndex;
    var selected2 = s2.selectedIndex;
    var selected3 = s3.selectedIndex;
    document.getElementById("test").innerHTML = "<ul>" +
        "<li>Changing the size of a select element from 1 to 5 and back 1 should acquire selection of the first item: " + (selected1 == 0 ? "PASS" : "FAIL") +
        "<li>Forcing layout should not affect the outcome: " + (selected2 == selected1 ? "PASS" : "FAIL") +
        "<li>And neither should dropping out of the message loop: " + (selected3 == selected1 ? "PASS" : "FAIL") +
        "</ul>";

    if (window.testRunner)
        testRunner.notifyDone();
}

</script>
<body onload="runTest()">
    <div id="test">
        <select id="s1" size="1"><option>test</select>
        <select id="s2" size="1"><option>test</select>
        <select id="s3" size="1"><option>test</select>
    </div>
</body>