layout/style/test/test_moz_device_pixel_ratio.html

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:5ca9798c723a
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=474356
5 -->
6 <head>
7 <title>Test for Bug 474356</title>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
10 <style>.zoom-test { visibility: hidden; }</style>
11 <style><!-- placeholder for dynamic additions --></style>
12 </head>
13 <body onload="run()">
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=474356">Mozilla Bug 474356</a>
15 <div id="content" style="display: none">
16
17 </div>
18 <script type="text/javascript">
19 </script>
20 <pre id="test">
21 <div id="zoom1" class="zoom-test"></div>
22 <div id="zoom2" class="zoom-test"></div>
23 <div id="zoom3" class="zoom-test"></div>
24 <script class="testbody" type="application/javascript">
25
26 /** Test for Bug 474356 **/
27
28 SimpleTest.waitForExplicitFinish();
29
30 function run() {
31 function zoom(factor) {
32 var previous = SpecialPowers.getFullZoom(window);
33 SpecialPowers.setFullZoom(window, factor);
34 return previous;
35 }
36
37 function isVisible(divName) {
38 return window.getComputedStyle(document.getElementById(divName), null).visibility == "visible";
39 }
40
41 function getScreenPixelsPerCSSPixel() {
42 return SpecialPowers.DOMWindowUtils.screenPixelsPerCSSPixel;
43 }
44
45 var screenPixelsPerCSSPixel = getScreenPixelsPerCSSPixel();
46 var baseRatio = 1.0 * screenPixelsPerCSSPixel;
47 var doubleRatio = 2.0 * screenPixelsPerCSSPixel;
48 var halfRatio = 0.5 * screenPixelsPerCSSPixel;
49 var styleElem = document.getElementsByTagName("style")[1];
50 styleElem.textContent =
51 ["@media all and (-moz-device-pixel-ratio: " + baseRatio + ") {",
52 "#zoom1 { visibility: visible; }",
53 "}",
54 "@media all and (-moz-device-pixel-ratio: " + doubleRatio + ") {",
55 "#zoom2 { visibility: visible; }",
56 "}",
57 "@media all and (-moz-device-pixel-ratio: " + halfRatio + ") {",
58 "#zoom3 { visibility: visible; }",
59 "}"
60 ].join("\n");
61
62 ok(isVisible("zoom1"), "Base ratio rule should apply at base zoom level");
63 ok(!isVisible("zoom2") && !isVisible("zoom3"), "no other rules should apply");
64 var origZoom = zoom(2);
65 ok(isVisible("zoom2"), "Double ratio rule should apply at double zoom level");
66 ok(!isVisible("zoom1") && !isVisible("zoom3"), "no other rules should apply");
67 zoom(0.5);
68 ok(isVisible("zoom3"), "Half ratio rule should apply at half zoom level");
69 ok(!isVisible("zoom1") && !isVisible("zoom2"), "no other rules should apply");
70 zoom(origZoom);
71
72 SimpleTest.finish();
73 }
74 </script>
75 </pre>
76 </body>
77 </html>

mercurial