Skip to content

Commit

Permalink
Add test for scroll offsets with fractional zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
mrego committed Feb 5, 2025
1 parent ebccc9d commit 769fb79
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions css/cssom-view/scroll-offsets-fractional-zoom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#extension-to-the-element-interface">
<meta name="assert" content="This test checks that the scroll offsets behave as expected on fractional zoom situations.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.scrollable-area {
width: 100px;
height: 100px;
overflow: scroll;
}
.content {
width: 500px;
height: 500px;
background: lightgrey;
}
</style>
<div id="target" class="scrollable-area">
<div class="content"></div>
</div>
<script>
function runTest(zoom, x, y) {
target.scrollTo(x, y);
test(() => {
assert_equals(target.scrollLeft, x, `scrollLeft should be ${x}`);
}, `scrollLeft after scrollTo(${x}, ${y}) with 'zoom: ${zoom}'`);
test(() => {
assert_equals(target.scrollTop, y, `scrollTop should be ${y}`);
}, `scrollTop after scrollTo(${x}, ${y}) with 'zoom: ${zoom}'`);
}

function runTests(zoom) {
target.style.zoom = zoom;

runTest(zoom, 0, 0);
runTest(zoom, 1, 2);
runTest(zoom, 13, 61);
runTest(zoom, 75, 100);
}

runTests(0.75);
runTests(0.9);
runTests(1);
runTests(1.13);
runTests(1.25);
runTests(1.5);
runTests(1.9);
runTests(2);
runTests(3.33);
</script>

0 comments on commit 769fb79

Please sign in to comment.