|
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 type="text/javascript" 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 domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) |
|
39 .getInterface(Components.interfaces.nsIDOMWindowUtils); |
|
40 var devPxPerCSSPx = domWindowUtils.screenPixelsPerCSSPixel; |
|
41 |
|
42 is(window.devicePixelRatio, devPxPerCSSPx, "window.devicePixelRatio"); |
|
43 |
|
44 var windowBO = document.documentElement.boxObject; |
|
45 isRounded(window.mozInnerScreenX*devPxPerCSSPx, windowBO.screenX, |
|
46 "window screen X"); |
|
47 isRounded(window.mozInnerScreenY*devPxPerCSSPx, windowBO.screenY, |
|
48 "window screen Y"); |
|
49 |
|
50 var f = document.getElementById("f"); |
|
51 var fBounds = f.getBoundingClientRect(); |
|
52 |
|
53 const CI = Components.interfaces; |
|
54 var fshell = f.contentWindow.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIWebNavigation).QueryInterface(CI.nsIDocShell); |
|
55 var fmudv = fshell.contentViewer.QueryInterface(CI.nsIMarkupDocumentViewer); |
|
56 |
|
57 isRounded(f.contentWindow.mozInnerScreenX, |
|
58 window.mozInnerScreenX + fBounds.left, |
|
59 "frame screen X"); |
|
60 isRounded(f.contentWindow.mozInnerScreenY, |
|
61 window.mozInnerScreenY + fBounds.top, |
|
62 "frame screen Y"); |
|
63 |
|
64 fmudv.fullZoom *= 2; |
|
65 var frameDomWindowUtils = f.contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor) |
|
66 .getInterface(Components.interfaces.nsIDOMWindowUtils); |
|
67 is(frameDomWindowUtils.screenPixelsPerCSSPixel, 2*devPxPerCSSPx, |
|
68 "frame screen pixels per CSS pixel"); |
|
69 |
|
70 is(f.contentWindow.devicePixelRatio, 2*devPxPerCSSPx, "frame devicePixelRatio"); |
|
71 |
|
72 isRounded(f.contentWindow.mozInnerScreenX*2, |
|
73 window.mozInnerScreenX + fBounds.left, |
|
74 "zoomed frame screen X"); |
|
75 isRounded(f.contentWindow.mozInnerScreenY*2, |
|
76 window.mozInnerScreenY + fBounds.top, |
|
77 "zoomed frame screen Y"); |
|
78 fmudv.fullZoom = 1.0; |
|
79 |
|
80 SimpleTest.finish(); |
|
81 } |
|
82 |
|
83 addLoadEvent(doTests); |
|
84 SimpleTest.waitForExplicitFinish(); |
|
85 |
|
86 ]]> |
|
87 </script> |
|
88 |
|
89 </window> |