blob: 3cc1772405c93fa443a0ec8f87c23285de6fe9c4 [file] [log] [blame]
<!DOCTYPE html>
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
'use strict';
// TODO(loonybear): Once WPT supports tests with page zoom in / out, move this
// test to WPT.
// https://github.com/web-platform-tests/wpt/issues/12725#
const srcs = [
"resources/green.jpg",
"resources/green.png",
"resources/green-circle.svg"
];
const ZOOM_MULTIPLER = 1.2;
function round(n) {
return Math.round(n * 100) / 100;
}
for (var src of srcs) {
var img = document.createElement('IMG');
img.intrinsicSize = '400 x 500';
var intrinsic_width = 400;
var intrinsic_height = 500;
var expected_width = intrinsic_width;
var expected_height = intrinsic_height;
document.body.appendChild(img);
img.addEventListener('load', promise_test(async() => {
if (window.eventSender) {
var expected_dpr = window.devicePixelRatio;
for (var i = 0; i < 3; i++) {
eventSender.zoomPageOut();
expected_width *= ZOOM_MULTIPLER;
expected_height *= ZOOM_MULTIPLER;
expected_dpr /= ZOOM_MULTIPLER;
assert_equals(img.width, Math.round(expected_width), 'width (zoomout)');
assert_equals(img.height, Math.round(expected_height), 'height (zoomout)');
assert_equals(img.naturalWidth, intrinsic_width, 'naturalWidth (zoomout)');
assert_equals(img.naturalHeight, intrinsic_height, 'naturalHeight (zoomout)');
assert_equals(round(window.devicePixelRatio), round(expected_dpr), 'devicePixelRatio');
}
for (var i = 0; i < 3; i++) {
eventSender.zoomPageIn();
expected_width /= ZOOM_MULTIPLER;
expected_height /= ZOOM_MULTIPLER;
expected_dpr *= ZOOM_MULTIPLER;
assert_equals(img.width, Math.round(expected_width), 'width (zoomin)');
assert_equals(img.height, Math.round(expected_height), 'height (zoomin)');
assert_equals(img.naturalWidth, intrinsic_width, 'naturalWidth (zoomin)');
assert_equals(img.naturalHeight, intrinsic_height, 'naturalHeight (zoomin)');
assert_equals(round(window.devicePixelRatio), round(expected_dpr), 'devicePixelRatio');
}
}
}, 'Test image ' + src + 'with different zoom in and zoom out'));
img.src = src;
}
</script>
</body>