Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test that pixel lengths don't change based on DPI</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | <div id="display"> |
michael@0 | 10 | |
michael@0 | 11 | <div id="pt" style="width:90pt; height:90pt; background:lime;">pt</div> |
michael@0 | 12 | <div id="pc" style="width:5pc; height:5pc; background:yellow;">pc</div> |
michael@0 | 13 | <div id="mm" style="width:25.4mm; height:25.4mm; background:orange;">mm</div> |
michael@0 | 14 | <div id="cm" style="width:2.54cm; height:2.54cm; background:purple;">cm</div> |
michael@0 | 15 | <div id="in" style="width:1in; height:1in; background:magenta;">in</div> |
michael@0 | 16 | |
michael@0 | 17 | <div id="mozmm" style="width:25.4mozmm; height:25.4mozmm; background:cyan;">mozmm</div> |
michael@0 | 18 | |
michael@0 | 19 | </div> |
michael@0 | 20 | <pre id="test"> |
michael@0 | 21 | <script class="testbody" type="text/javascript"> |
michael@0 | 22 | |
michael@0 | 23 | var oldDPI = SpecialPowers.getIntPref("layout.css.dpi"); |
michael@0 | 24 | var dpi = oldDPI; |
michael@0 | 25 | |
michael@0 | 26 | function check(id, val) { |
michael@0 | 27 | var e = document.getElementById(id); |
michael@0 | 28 | is(Math.round(e.getBoundingClientRect().width), Math.round(val), |
michael@0 | 29 | "Checking width in " + id + " at " + dpi + " DPI"); |
michael@0 | 30 | is(Math.round(e.getBoundingClientRect().height), Math.round(val), |
michael@0 | 31 | "Checking height in " + id + " at " + dpi + " DPI"); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function checkPixelRelativeUnits() { |
michael@0 | 35 | check("pt", 120); |
michael@0 | 36 | check("pc", 80); |
michael@0 | 37 | check("mm", 96); |
michael@0 | 38 | check("cm", 96); |
michael@0 | 39 | check("in", 96); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | checkPixelRelativeUnits(); |
michael@0 | 43 | |
michael@0 | 44 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 45 | |
michael@0 | 46 | SpecialPowers.pushPrefEnv({'set': [['layout.css.dpi', dpi=96]]}, test1); |
michael@0 | 47 | |
michael@0 | 48 | var mozmmSize; |
michael@0 | 49 | function test1() { |
michael@0 | 50 | var mozmm = document.getElementById("mozmm"); |
michael@0 | 51 | mozmmSize = mozmm.getBoundingClientRect().width; |
michael@0 | 52 | is(Math.round(mozmmSize), Math.round(mozmm.getBoundingClientRect().height), |
michael@0 | 53 | "mozmm div should be square"); |
michael@0 | 54 | |
michael@0 | 55 | checkPixelRelativeUnits(); |
michael@0 | 56 | |
michael@0 | 57 | SpecialPowers.pushPrefEnv({'set': [['layout.css.dpi', dpi=192]]}, test2); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function test2() { |
michael@0 | 61 | // At 192 dpi, a one-inch box should be twice the number of device pixels, |
michael@0 | 62 | // and since we haven't changed the device-pixels-per-CSS-pixel ratio, the |
michael@0 | 63 | // mozmm box should be twice the size in CSS pixels. |
michael@0 | 64 | check("mozmm", mozmmSize*2); |
michael@0 | 65 | checkPixelRelativeUnits(); |
michael@0 | 66 | |
michael@0 | 67 | SimpleTest.finish(); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | </script> |
michael@0 | 71 | </pre> |
michael@0 | 72 | </body> |
michael@0 | 73 | </html> |