1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_popup_scaled.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 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 +<window title="Popups in Scaled Content" 1.9 + onload="setTimeout(runTests, 0);" 1.10 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.11 + 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.14 + 1.15 +<!-- This test checks that the position is correct in two cases: 1.16 + - a popup anchored at an element in a scaled document 1.17 + - a popup opened at a screen coordinate in a scaled window 1.18 + --> 1.19 + 1.20 +<iframe id="frame" width="60" height="140" 1.21 + src="data:text/html,<html><body><input size='4' id='one'><input size='4' id='two'></body></html>"/> 1.22 + 1.23 +<menupopup id="popup" onpopupshown="shown()" onpopuphidden="nextTest()"> 1.24 + <menuitem label="One"/> 1.25 +</menupopup> 1.26 + 1.27 +<script class="testbody" type="application/javascript"> 1.28 +<![CDATA[ 1.29 + 1.30 +var screenTest = false; 1.31 +var screenx = -1, screeny = -1; 1.32 + 1.33 +SimpleTest.waitForExplicitFinish(); 1.34 + 1.35 +function runTests() 1.36 +{ 1.37 + setScale($("frame").contentWindow, 2); 1.38 + 1.39 + var anchor = $("frame").contentDocument.getElementById("two"); 1.40 + anchor.getBoundingClientRect(); // flush to update display after scale change 1.41 + $("popup").openPopup(anchor, "after_start"); 1.42 +} 1.43 + 1.44 +function setScale(win, scale) 1.45 +{ 1.46 + var wn = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor) 1.47 + .getInterface(Components.interfaces.nsIWebNavigation); 1.48 + var shell = wn.QueryInterface(Components.interfaces.nsIDocShell); 1.49 + var docViewer = shell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer); 1.50 + docViewer.fullZoom = scale; 1.51 +} 1.52 + 1.53 +function shown() 1.54 +{ 1.55 + if (screenTest) { 1.56 + var box = $("popup").boxObject; 1.57 + is(box.screenX, screenx, "screen left position"); 1.58 + is(box.screenY, screeny, "screen top position"); 1.59 + } 1.60 + else { 1.61 + var anchor = $("frame").contentDocument.getElementById("two"); 1.62 + 1.63 + is(Math.round(anchor.getBoundingClientRect().left * 2), 1.64 + Math.round($("popup").getBoundingClientRect().left), "anchored left position"); 1.65 + is(Math.round(anchor.getBoundingClientRect().bottom * 2), 1.66 + Math.round($("popup").getBoundingClientRect().top), "anchored top position"); 1.67 + } 1.68 + 1.69 + $("popup").hidePopup(); 1.70 +} 1.71 + 1.72 +function nextTest() 1.73 +{ 1.74 + if (screenTest) { 1.75 + setScale(window, 1); 1.76 + SimpleTest.finish(); 1.77 + } 1.78 + else { 1.79 + screenTest = true; 1.80 + var box = document.documentElement.boxObject; 1.81 + 1.82 + // - the iframe is at 4×, but out here css pixels are only 2× device pixels 1.83 + // - the popup manager rounds off (or truncates) the coordinates to 1.84 + // integers, so ensure we pass in even numbers to openPopupAtScreen 1.85 + screenx = (x = even(box.screenX + 120))/2; 1.86 + screeny = (y = even(box.screenY + 120))/2; 1.87 + setScale(window, 2); 1.88 + $("popup").openPopupAtScreen(x, y); 1.89 + } 1.90 +} 1.91 + 1.92 +function even(n) 1.93 +{ 1.94 + return (n % 2) ? n+1 : n; 1.95 +} 1.96 +]]> 1.97 +</script> 1.98 + 1.99 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.100 +<p id="display"> 1.101 +</p> 1.102 +<div id="content" style="display: none"> 1.103 +</div> 1.104 +<pre id="test"> 1.105 +</pre> 1.106 +</body> 1.107 + 1.108 +</window>