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
|
<!DOCTYPE HTML>
<html>
<head>
<title>DevicePixelRatios with Zoom</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body>
<div>Testing devicePixelRatio with different zoom levels</div>
<script type="application/javascript">
// We're creating a table of zooms and expected devicePixelRatio (DPR) strings.
// The values in the table are specific to the "native" DPR at zoom level 100%.
// If we don't have a table for a native DPR value, we'll trivially report
// a successful test with a note that we didn't have a table.
// For the moment, we only have a table for native DPR of 2.
let zoomsAndDPRsToTest;
const originalZoom = SpecialPowers.getFullZoom(window);
const zoom = 1;
SpecialPowers.setFullZoom(window, zoom);
const dprAtZoom1 = window.devicePixelRatio;
if (dprAtZoom1 == 1) {
zoomsAndDPRsToTest = [
[300, "3"],
[250, "2.5"],
[200, "2"],
[167, "1.6666666666666667"],
[150, "1.5"],
[133, "1.3333333333333333"],
[120, "1.2"],
[110, "1.0909090909090908"],
[100, "1"],
[90, "0.8955223880597015"],
[80, "0.8"],
[67, "0.6666666666666666"],
[50, "0.5"],
];
} else if (dprAtZoom1 == 2) {
zoomsAndDPRsToTest = [
[300, "6"],
[250, "5"],
[200, "4"],
[167, "3.3333333333333335"],
[150, "3"],
[133, "2.608695652173913"], // there's a trailing 0 here unreported by JS
[120, "2.4"],
[110, "2.2222222222222223"],
[100, "2"],
[90, "1.8181818181818181"],
[80, "1.5789473684210527"],
[67, "1.3333333333333333"],
[50, "1"],
];
}
if (!zoomsAndDPRsToTest.length) {
// Need to run at least one test function to keep mochitest harness happy.
ok(true, `No table of data for devicePixelRatio of ${dprAtZoom1} at zoom level 100%.`);
}
for (let i = 0; i < zoomsAndDPRsToTest.length; ++i) {
let data = zoomsAndDPRsToTest[i];
let zoomPercent = data[0];
let targetDPR = data[1];
let relativeZoom = zoom * zoomPercent / 100;
SpecialPowers.setFullZoom(window, relativeZoom);
// Force conversion to string for string comparison to targetDPR.
let actualDPR = window.devicePixelRatio + "";
is(actualDPR, targetDPR, `At ${zoomPercent}% zoom, window.devicePixelRatio is rounded correctly.`);
}
// Reset the zoom when the test is done.
SpecialPowers.setFullZoom(window, originalZoom);
</script>
</body>
</html>
|