summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/scrolling/scrolling-apis-subpixel.html
blob: c80f2e07ab938c805ee661264879e2215f0b2045 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<style>
.spacer {
  height: 1000px;
  width: 1000px;
}
#scroller, body {
  height: 100px;
  width: 100px;
  overflow: scroll;
}

</style>
<body class=scroller>
<div id=console></div>

<div id=scroller>
    <div class=spacer></div>
</div>
<div class=spacer></div>
</body>

<script src="../../resources/js-test.js"></script>
<script>

description("Verifies that scrolling APIs support fractional offsets.");
// Note we current support fractional scrolling only for the special case of
// browser zoom.  When http://crbug.com/414283 is fixed, we should test
// other cases like device scale.

// FIXME: Make this smaller. crbug.com/414283.
var floatPrecision = 0.01;

function testScroll(scrollOffset, expectedScrollOffset) {

    debug('Scrolling DIV with scrollTop/scrollLeft');
    scroller.scrollTop = scrollOffset;
    shouldBeCloseTo('scroller.scrollTop', expectedScrollOffset, floatPrecision);
    scroller.scrollLeft = scrollOffset;
    shouldBeCloseTo('scroller.scrollLeft', expectedScrollOffset, floatPrecision);

    // Note that the body element is a special case - we don't attempt to
    // test it here as it's semantics are in flux (http://goo.gl/BFHtMR).

    debug('Scrolling the document with window.scroll');
    window.scroll(0,0);
    scrollOffset++;
    expectedScrollOffset++;
    window.scroll(scrollOffset, scrollOffset);
    shouldBeCloseTo('window.scrollY', expectedScrollOffset, floatPrecision);
    shouldBeCloseTo('window.scrollX', expectedScrollOffset, floatPrecision);

    debug('Scrolling the document with window.scrollTo');
    window.scroll(0,0);
    window.scrollTo(scrollOffset, scrollOffset);
    shouldBeCloseTo('window.pageYOffset', expectedScrollOffset, floatPrecision);
    shouldBeCloseTo('window.pageXOffset', expectedScrollOffset, floatPrecision);

    debug('Scrolling the document with window.scrollBy');
    window.scroll(1,1);
    window.scrollBy(scrollOffset - 1, scrollOffset - 1);
    shouldBeCloseTo('window.scrollY', expectedScrollOffset, floatPrecision);
    shouldBeCloseTo('window.scrollX', expectedScrollOffset, floatPrecision);

    debug('');
}

function testPageZoom(zoom) {
    debug('---- Testing page zoom = ' + zoom + ' ----');
    eventSender.setPageZoomFactor(zoom);
    testScroll(4, 4);
    testScroll(4.5, 4.5);
}

debug("set PreferCompositingToLCDTextEnabled true");
window.internals.settings.setPreferCompositingToLCDTextEnabled(true);
testScroll(4.2, 4.2);
testPageZoom(2);

// If there is no browser zoom, floating point scroll offsets are truncated.
// If there is browser zoom, we can still get fractional scroll offsets
// through JS.
debug("set PreferCompositingToLCDTextEnabled false");
window.internals.settings.setPreferCompositingToLCDTextEnabled(false);
testScroll(4.2, 4);
testPageZoom(2);
</script>