Bug 1376931 Part 5: Add test to verify that media queries with a resolution set to window.devicePixelRatio dppx match for all zoom values exposed by the UI. r=heycam

MozReview-Commit-ID: Kr7J4ZkZ1hZ

--HG--
extra : rebase_source : 650fb2edc81e673344f31a5d7f672317a0f84026
This commit is contained in:
Brad Werth 2017-09-22 17:00:01 -07:00
parent 1e6eb559aa
commit 1800922d6b
2 changed files with 53 additions and 0 deletions

View File

@ -102,6 +102,7 @@ skip-if = toolkit == 'android' #TIMED_OUT
[test_interfaces.html]
[test_interfaces_secureContext.html]
scheme = https
[test_media_queries_with_zoom.html]
[test_navigation_timing.html]
[test_network_events.html]
skip-if = true

View File

@ -0,0 +1,52 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media Queries with Zoom</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body>
<div>Testing media queries with different zoom levels</div>
<script type="application/javascript">
const originalDPR = window.devicePixelRatio;
const originalZoom = SpecialPowers.getFullZoom(window);
const zoomsToTest = [
300,
240,
200,
170,
150,
133,
120,
110,
100,
90,
80,
67,
50,
30,
];
for (let i = 0; i < zoomsToTest.length; ++i) {
let zoomPercent = zoomsToTest[i];
let relativeZoom = originalZoom * zoomPercent / 100;
SpecialPowers.setFullZoom(window, relativeZoom);
let actualZoom = SpecialPowers.getDeviceFullZoom(window);
let targetDPR = (originalDPR * actualZoom);
let actualDPR = window.devicePixelRatio;
let mql = window.matchMedia(`(resolution: ${targetDPR}dppx)`);
ok(mql.matches, `At ${zoomPercent}% zoom, target ${targetDPR}dppx matches ${actualDPR}dppx.`);
}
// Reset the zoom when the test is done.
SpecialPowers.setFullZoom(window, originalZoom);
</script>
</body>
</html>