layout/style/test/test_pixel_lengths.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial