<!DOCTYPE html>
<html>
<head>
    <style>
        body    { position: relative; height: 2000px; }
    </style>
    <script src="../../resources/js-test-pre.js"></script>
    <script>
        description('This tests that window.scrollBy respects the page\'s zoom and scale factor when scrolling.');

        function zoomBy(zoomFactor)
        {
            while (zoomFactor > 0) {
                window.eventSender.zoomPageIn();
                zoomFactor--;
            }
            while (zoomFactor < 0) {
                window.eventSender.zoomPageOut();
                zoomFactor++;
            }
        }
        function testScroll(zoomFactor, scaleFactor) {
            debug('Testing at zoom ' + zoomFactor + ' and scale ' + scaleFactor);
            if (window.testRunner && window.eventSender) {
                var y = 221;
                eventSender.scalePageBy(scaleFactor, 0, 0);
                zoomBy(zoomFactor);
                window.scrollTo(10, 10);
                window.scrollBy(0, y);
                shouldBeCloseTo('window.pageYOffset', y+10, 3, false);
                zoomBy(-zoomFactor);
            }
            else
                testFailed('This test only operates in DumpRenderTree.');
        }

        function runTests() {
            testScroll(-1,1.2);
            var zoomLevels = [-3, -2, -1, 0, 1, 3, 5];
            var scaleLevels = [0.75, 1, 1.2, 1.6];
            for (zoom in zoomLevels)
                for (scale in scaleLevels)
                    testScroll(zoomLevels[zoom], scaleLevels[scale]);

            wasPostTestScriptParsed = true;
            finishJSTest();
        }
    </script>
</head>

<body onload="runTests()">
    <div id="target"></div>
</body>
</html>

