<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../resources/js-test-pre.js"></script>
<script>
window.jsTestIsAsync = true;

var frame;
function test() {
    frame = document.getElementById('frame');
    var doc = frame.contentDocument.open();
    var htmlString = "Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> \
                      Lots of text</br>Lots of text</br> ";

    doc.write(htmlString);
    doc.close();
    frame.contentDocument.body.style.height = "2000px";

    if (window.eventSender) {
        var xPoint = frame.scrollLeft + 100;
        var yPoint = frame.scrollTop + 100;
        eventSender.dragMode = false;
        eventSender.mouseMoveTo(xPoint, yPoint);
        eventSender.mouseDown();
        eventSender.mouseMoveTo(xPoint, frame.offsetHeight + 100);
        setTimeout(testAutoScroll, 100);
        eventSender.keyDown('a');
    } else {
        debug("Test manually that scrolling does not stop if we press a key while autoscroll is happening.");
    }
}

function testAutoScroll() {
    if (frame.contentDocument.body.scrollTop + frame.clientHeight === frame.contentDocument.body.scrollHeight) {
        shouldBe('frame.contentDocument.body.scrollTop + frame.clientHeight', 'frame.contentDocument.body.scrollHeight');
        finishJSTest();
        return;
    }
    setTimeout(testAutoScroll, 100);
}

successfullyParsed = true;
</script> 
</head>
<body onload="test()">
<iframe id="frame" style="height: 400px;" frameborder="0"></iframe>
<div id="console"></div>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
