tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_innerScreen.xhtml (2561B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
      4 <!--
      5  Tests for mozInnerScreenX/Y properties
      6  -->
      7 <window title="Test mozInnerScreenX/Y Properties"
      8        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     10 
     11  <!-- test resuls are displayed in the html:body -->
     12  <body xmlns="http://www.w3.org/1999/xhtml"
     13        style="height: 400px; position:relative; overflow: auto;">
     14    <iframe id="f"
     15            style="position:absolute; left:100px;
     16                   top:200px; width:200px; height:200px; border:none;"></iframe>
     17  </body>
     18 
     19  <!-- test code goes here -->
     20  <script type="application/javascript"><![CDATA[
     21 
     22 function isRounded(a, b, msg) {
     23  ok(Math.round(a) == Math.round(b),
     24     msg + " (rounded), got " + a + ", expected " + b);
     25 }
     26 
     27 function doTests()
     28 {
     29  var readable = false;
     30  try
     31  {
     32    mozScreenPixelsPerCSSPixel;
     33    readable = true;
     34  }
     35  catch(ex) { }
     36  ok(!readable, "window pixels per css pixel shouldn't be readable to content");
     37 
     38  var devPxPerCSSPx = window.devicePixelRatio;
     39 
     40  is(window.devicePixelRatio, devPxPerCSSPx, "window.devicePixelRatio");
     41 
     42  var rootElement = document.documentElement;
     43  isRounded(window.mozInnerScreenX*devPxPerCSSPx, rootElement.screenX,
     44            "window screen X");
     45  isRounded(window.mozInnerScreenY*devPxPerCSSPx, rootElement.screenY,
     46            "window screen Y");
     47 
     48  var f = document.getElementById("f");
     49  var fBounds = f.getBoundingClientRect();
     50 
     51  var fbc = f.contentWindow.docShell.browsingContext;
     52 
     53  isRounded(f.contentWindow.mozInnerScreenX,
     54            window.mozInnerScreenX + fBounds.left,
     55            "frame screen X");
     56  isRounded(f.contentWindow.mozInnerScreenY,
     57            window.mozInnerScreenY + fBounds.top,
     58            "frame screen Y");
     59 
     60  fbc.fullZoom *= 2;
     61  is(f.contentWindow.devicePixelRatio, 2*devPxPerCSSPx,
     62     "frame screen pixels per CSS pixel");
     63 
     64  is(f.contentWindow.devicePixelRatio, 2*devPxPerCSSPx, "frame devicePixelRatio");
     65 
     66  isRounded(f.contentWindow.mozInnerScreenX*2,
     67            window.mozInnerScreenX + fBounds.left,
     68            "zoomed frame screen X");
     69  isRounded(f.contentWindow.mozInnerScreenY*2,
     70            window.mozInnerScreenY + fBounds.top,
     71            "zoomed frame screen Y");
     72  fbc.fullZoom = 1.0;
     73 
     74  SimpleTest.finish();
     75 }
     76 
     77 addLoadEvent(doTests);
     78 SimpleTest.waitForExplicitFinish();
     79 
     80 ]]>
     81 </script>
     82 
     83 </window>