dom/tests/mochitest/general/test_innerScreen.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/general/test_innerScreen.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +<!--
     1.8 +  Tests for mozInnerScreenX/Y properties
     1.9 +  -->
    1.10 +<window title="Test mozInnerScreenX/Y Properties"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +
    1.14 +  <!-- test resuls are displayed in the html:body -->
    1.15 +  <body xmlns="http://www.w3.org/1999/xhtml"
    1.16 +        style="height: 400px; position:relative; overflow: auto;">
    1.17 +    <iframe id="f"
    1.18 +            style="position:absolute; left:100px;
    1.19 +                   top:200px; width:200px; height:200px; border:none;"></iframe>
    1.20 +  </body>
    1.21 +
    1.22 +  <!-- test code goes here -->
    1.23 +  <script type="application/javascript"><![CDATA[
    1.24 +
    1.25 +function isRounded(a, b, msg) {
    1.26 +  ok(Math.round(a) == Math.round(b),
    1.27 +     msg + " (rounded), got " + a + ", expected " + b);
    1.28 +}
    1.29 +
    1.30 +function doTests()
    1.31 +{
    1.32 +  var readable = false;
    1.33 +  try
    1.34 +  {
    1.35 +    mozScreenPixelsPerCSSPixel;
    1.36 +    readable = true;
    1.37 +  }
    1.38 +  catch(ex) { }
    1.39 +  ok(!readable, "window pixels per css pixel shouldn't be readable to content");
    1.40 +
    1.41 +  var domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    1.42 +                           .getInterface(Components.interfaces.nsIDOMWindowUtils);
    1.43 +  var devPxPerCSSPx = domWindowUtils.screenPixelsPerCSSPixel;
    1.44 +
    1.45 +  is(window.devicePixelRatio, devPxPerCSSPx, "window.devicePixelRatio");
    1.46 +
    1.47 +  var windowBO = document.documentElement.boxObject;
    1.48 +  isRounded(window.mozInnerScreenX*devPxPerCSSPx, windowBO.screenX,
    1.49 +            "window screen X");
    1.50 +  isRounded(window.mozInnerScreenY*devPxPerCSSPx, windowBO.screenY,
    1.51 +            "window screen Y");
    1.52 +
    1.53 +  var f = document.getElementById("f");
    1.54 +  var fBounds = f.getBoundingClientRect();
    1.55 +
    1.56 +  const CI = Components.interfaces;
    1.57 +  var fshell = f.contentWindow.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIWebNavigation).QueryInterface(CI.nsIDocShell);
    1.58 +  var fmudv = fshell.contentViewer.QueryInterface(CI.nsIMarkupDocumentViewer);
    1.59 +
    1.60 +  isRounded(f.contentWindow.mozInnerScreenX,
    1.61 +            window.mozInnerScreenX + fBounds.left,
    1.62 +            "frame screen X");
    1.63 +  isRounded(f.contentWindow.mozInnerScreenY,
    1.64 +            window.mozInnerScreenY + fBounds.top,
    1.65 +            "frame screen Y");
    1.66 +
    1.67 +  fmudv.fullZoom *= 2;
    1.68 +  var frameDomWindowUtils = f.contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    1.69 +                              .getInterface(Components.interfaces.nsIDOMWindowUtils);
    1.70 +  is(frameDomWindowUtils.screenPixelsPerCSSPixel, 2*devPxPerCSSPx,
    1.71 +     "frame screen pixels per CSS pixel");
    1.72 +
    1.73 +  is(f.contentWindow.devicePixelRatio, 2*devPxPerCSSPx, "frame devicePixelRatio");
    1.74 +
    1.75 +  isRounded(f.contentWindow.mozInnerScreenX*2,
    1.76 +            window.mozInnerScreenX + fBounds.left,
    1.77 +            "zoomed frame screen X");
    1.78 +  isRounded(f.contentWindow.mozInnerScreenY*2,
    1.79 +            window.mozInnerScreenY + fBounds.top,
    1.80 +            "zoomed frame screen Y");
    1.81 +  fmudv.fullZoom = 1.0;
    1.82 +
    1.83 +  SimpleTest.finish();
    1.84 +}
    1.85 +
    1.86 +addLoadEvent(doTests);
    1.87 +SimpleTest.waitForExplicitFinish();
    1.88 +
    1.89 +]]>
    1.90 +</script>
    1.91 +
    1.92 +</window>

mercurial