1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_moz_device_pixel_ratio.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=474356 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 474356</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.13 + <style>.zoom-test { visibility: hidden; }</style> 1.14 + <style><!-- placeholder for dynamic additions --></style> 1.15 +</head> 1.16 +<body onload="run()"> 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=474356">Mozilla Bug 474356</a> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<script type="text/javascript"> 1.22 +</script> 1.23 +<pre id="test"> 1.24 +<div id="zoom1" class="zoom-test"></div> 1.25 +<div id="zoom2" class="zoom-test"></div> 1.26 +<div id="zoom3" class="zoom-test"></div> 1.27 +<script class="testbody" type="application/javascript"> 1.28 + 1.29 +/** Test for Bug 474356 **/ 1.30 + 1.31 +SimpleTest.waitForExplicitFinish(); 1.32 + 1.33 +function run() { 1.34 + function zoom(factor) { 1.35 + var previous = SpecialPowers.getFullZoom(window); 1.36 + SpecialPowers.setFullZoom(window, factor); 1.37 + return previous; 1.38 + } 1.39 + 1.40 + function isVisible(divName) { 1.41 + return window.getComputedStyle(document.getElementById(divName), null).visibility == "visible"; 1.42 + } 1.43 + 1.44 + function getScreenPixelsPerCSSPixel() { 1.45 + return SpecialPowers.DOMWindowUtils.screenPixelsPerCSSPixel; 1.46 + } 1.47 + 1.48 + var screenPixelsPerCSSPixel = getScreenPixelsPerCSSPixel(); 1.49 + var baseRatio = 1.0 * screenPixelsPerCSSPixel; 1.50 + var doubleRatio = 2.0 * screenPixelsPerCSSPixel; 1.51 + var halfRatio = 0.5 * screenPixelsPerCSSPixel; 1.52 + var styleElem = document.getElementsByTagName("style")[1]; 1.53 + styleElem.textContent = 1.54 + ["@media all and (-moz-device-pixel-ratio: " + baseRatio + ") {", 1.55 + "#zoom1 { visibility: visible; }", 1.56 + "}", 1.57 + "@media all and (-moz-device-pixel-ratio: " + doubleRatio + ") {", 1.58 + "#zoom2 { visibility: visible; }", 1.59 + "}", 1.60 + "@media all and (-moz-device-pixel-ratio: " + halfRatio + ") {", 1.61 + "#zoom3 { visibility: visible; }", 1.62 + "}" 1.63 + ].join("\n"); 1.64 + 1.65 + ok(isVisible("zoom1"), "Base ratio rule should apply at base zoom level"); 1.66 + ok(!isVisible("zoom2") && !isVisible("zoom3"), "no other rules should apply"); 1.67 + var origZoom = zoom(2); 1.68 + ok(isVisible("zoom2"), "Double ratio rule should apply at double zoom level"); 1.69 + ok(!isVisible("zoom1") && !isVisible("zoom3"), "no other rules should apply"); 1.70 + zoom(0.5); 1.71 + ok(isVisible("zoom3"), "Half ratio rule should apply at half zoom level"); 1.72 + ok(!isVisible("zoom1") && !isVisible("zoom2"), "no other rules should apply"); 1.73 + zoom(origZoom); 1.74 + 1.75 + SimpleTest.finish(); 1.76 +} 1.77 +</script> 1.78 +</pre> 1.79 +</body> 1.80 +</html>