toolkit/content/tests/chrome/test_arrowpanel.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_arrowpanel.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,290 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +
     1.8 +<window title="Arrow Panels"
     1.9 +        style="padding: 10px;"
    1.10 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.11 +
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.14 +  <script type="application/javascript"
    1.15 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.16 +
    1.17 +<stack flex="1">
    1.18 +  <label id="topleft" value="Top Left Corner" left="15" top="15"/>
    1.19 +  <label id="topright" value="Top Right" right="15" top="15"/>
    1.20 +  <label id="bottomleft" value="Bottom Left Corner" left="15" bottom="15"/>
    1.21 +  <label id="bottomright" value="Bottom Right" right="15" bottom="15"/>
    1.22 +  <!-- Our SimpleTest/TestRunner.js runs tests inside an iframe which sizes are W=500 H=300.
    1.23 +       'left' and 'top' values need to be set so that the panel (popup) has enough room to display on its 4 sides. -->
    1.24 +  <label id="middle" value="+/- Centered" left="225" top="135"/>
    1.25 +  <iframe id="frame" type="content"
    1.26 +          src="data:text/html,&lt;input id='input'&gt;" width="100" height="100" left="225" top="120"/>
    1.27 +</stack>
    1.28 +
    1.29 +<panel id="panel" type="arrow"
    1.30 +       onpopupshown="checkPanelPosition(this)" onpopuphidden="runNextTest.next()">
    1.31 +  <label id="panellabel" value="This is some text..." height="65"/>
    1.32 +</panel>
    1.33 +
    1.34 +<panel id="bigpanel" type="arrow"
    1.35 +       onpopupshown="checkBigPanel(this)" onpopuphidden="runNextTest.next()">
    1.36 +  <button label="This is some text..." height="3000"/>
    1.37 +</panel>
    1.38 +
    1.39 +<script type="application/javascript">
    1.40 +<![CDATA[
    1.41 +
    1.42 +SimpleTest.waitForExplicitFinish();
    1.43 +
    1.44 +var expectedAnchor = null;
    1.45 +var expectedSide = "", expectedAnchorEdge = "", expectedPack = "", expectedAlignment = "";
    1.46 +var zoomFactor = 1;
    1.47 +var runNextTest;
    1.48 +
    1.49 +function startTest()
    1.50 +{
    1.51 +  runNextTest = nextTest();
    1.52 +  runNextTest.next();
    1.53 +}
    1.54 +
    1.55 +function nextTest()
    1.56 +{
    1.57 +  var panel = $("panel");
    1.58 +
    1.59 +  function openPopup(position, anchor, expected, anchorEdge, pack, alignment)
    1.60 +  {
    1.61 +    expectedAnchor = anchor instanceof Node ? anchor : $(anchor);
    1.62 +    expectedSide = expected;
    1.63 +    expectedAnchorEdge = anchorEdge;
    1.64 +    expectedPack = pack;
    1.65 +    expectedAlignment = alignment == undefined ? position : alignment;
    1.66 +
    1.67 +    panel.removeAttribute("side");
    1.68 +    panel.openPopup(expectedAnchor, position, 0, 0, false, false, null);
    1.69 +  }
    1.70 +
    1.71 +  for (var iter = 0; iter < 2; iter++) {
    1.72 +    openPopup("after_start", "topleft", "top", "left", "start");
    1.73 +    yield;
    1.74 +    openPopup("after_start", "bottomleft", "bottom", "left", "start", "before_start");
    1.75 +    yield;
    1.76 +    openPopup("before_start", "topleft", "top", "left", "start", "after_start");
    1.77 +    yield;
    1.78 +    openPopup("before_start", "bottomleft", "bottom", "left", "start");
    1.79 +    yield;
    1.80 +    openPopup("after_start", "middle", "top", "left", "start");
    1.81 +    yield;
    1.82 +    openPopup("before_start", "middle", "bottom", "left", "start");
    1.83 +    yield;
    1.84 +
    1.85 +    openPopup("after_start", "topright", "top", "right", "end", "after_end");
    1.86 +    yield;
    1.87 +    openPopup("after_start", "bottomright", "bottom", "right", "end", "before_end");
    1.88 +    yield;
    1.89 +    openPopup("before_start", "topright", "top", "right", "end", "after_end");
    1.90 +    yield;
    1.91 +    openPopup("before_start", "bottomright", "bottom", "right", "end", "before_end");
    1.92 +    yield;
    1.93 +
    1.94 +    openPopup("after_end", "middle", "top", "right", "end");
    1.95 +    yield;
    1.96 +    openPopup("before_end", "middle", "bottom", "right", "end");
    1.97 +    yield;
    1.98 +
    1.99 +    openPopup("start_before", "topleft", "left", "top", "start", "end_before");
   1.100 +    yield;
   1.101 +    openPopup("start_before", "topright", "right", "top", "start");
   1.102 +    yield;
   1.103 +    openPopup("end_before", "topleft", "left", "top", "start");
   1.104 +    yield;
   1.105 +    openPopup("end_before", "topright", "right", "top", "start", "start_before");
   1.106 +    yield;
   1.107 +    openPopup("start_before", "middle", "right", "top", "start");
   1.108 +    yield;
   1.109 +    openPopup("end_before", "middle", "left", "top", "start");
   1.110 +    yield;
   1.111 +
   1.112 +    openPopup("start_before", "bottomleft", "left", "bottom", "end", "end_after");
   1.113 +    yield;
   1.114 +    openPopup("start_before", "bottomright", "right", "bottom", "end", "start_after");
   1.115 +    yield;
   1.116 +    openPopup("end_before", "bottomleft", "left", "bottom", "end", "end_after");
   1.117 +    yield;
   1.118 +    openPopup("end_before", "bottomright", "right", "bottom", "end", "start_after");
   1.119 +    yield;
   1.120 +
   1.121 +    openPopup("start_after", "middle", "right", "bottom", "end");
   1.122 +    yield;
   1.123 +    openPopup("end_after", "middle", "left", "bottom", "end");
   1.124 +    yield;
   1.125 +
   1.126 +    openPopup("topcenter bottomleft", "bottomleft", "bottom", "center left", "start", "before_start");
   1.127 +    yield;
   1.128 +    openPopup("bottomcenter topleft", "topleft", "top", "center left", "start", "after_start");
   1.129 +    yield;
   1.130 +    openPopup("topcenter bottomright", "bottomright", "bottom", "center right", "end", "before_end");
   1.131 +    yield;
   1.132 +    openPopup("bottomcenter topright", "topright", "top", "center right", "end", "after_end");
   1.133 +    yield;
   1.134 +    openPopup("topcenter bottomleft", "middle", "bottom", "center left", "start", "before_start");
   1.135 +    yield;
   1.136 +    openPopup("bottomcenter topleft", "middle", "top", "center left", "start", "after_start");
   1.137 +    yield;
   1.138 +
   1.139 +    openPopup("leftcenter topright", "middle", "right", "center top", "start", "start_before");
   1.140 +    yield;
   1.141 +    openPopup("rightcenter bottomleft", "middle", "left", "center bottom", "end", "end_after");
   1.142 +    yield;
   1.143 +
   1.144 +/*
   1.145 +    XXXndeakin disable these parts of the test which often cause problems, see bug 626563
   1.146 +
   1.147 +    openPopup("after_start", frames[0].document.getElementById("input"), "top", "left", "start");
   1.148 +    yield;
   1.149 +
   1.150 +    setScale(frames[0], 1.5);
   1.151 +    openPopup("after_start", frames[0].document.getElementById("input"), "top", "left", "start");
   1.152 +    yield;
   1.153 +
   1.154 +    setScale(frames[0], 2.5);
   1.155 +    openPopup("before_start", frames[0].document.getElementById("input"), "bottom", "left", "start");
   1.156 +    yield;
   1.157 +
   1.158 +    setScale(frames[0], 1);
   1.159 +*/
   1.160 +
   1.161 +    $("bigpanel").openPopup($("topleft"), "after_start", 0, 0, false, false, null, "start");
   1.162 +    yield;
   1.163 +
   1.164 +    // switch to rtl mode
   1.165 +    document.documentElement.style.direction = "rtl";
   1.166 +    $("topleft").setAttribute("right", "15");
   1.167 +    $("topright").setAttribute("left", "15");
   1.168 +    $("bottomleft").setAttribute("right", "15");
   1.169 +    $("bottomright").setAttribute("left", "15");
   1.170 +    $("topleft").removeAttribute("left");
   1.171 +    $("topright").removeAttribute("right");
   1.172 +    $("bottomleft").removeAttribute("left");
   1.173 +    $("bottomright").removeAttribute("right");
   1.174 +  }
   1.175 +
   1.176 +  SimpleTest.finish()
   1.177 +  yield;
   1.178 +}
   1.179 +
   1.180 +function setScale(win, scale)
   1.181 +{
   1.182 +  var wn = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
   1.183 +              .getInterface(Components.interfaces.nsIWebNavigation);
   1.184 +  var shell = wn.QueryInterface(Components.interfaces.nsIDocShell);
   1.185 +  var docViewer = shell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
   1.186 +  docViewer.fullZoom = scale;
   1.187 +  zoomFactor = scale;
   1.188 +}
   1.189 +
   1.190 +function checkPanelPosition(panel)
   1.191 +{
   1.192 +  let anchor = panel.anchorNode;
   1.193 +  let adj = 0, hwinpos = 0, vwinpos = 0;
   1.194 +  if (anchor.ownerDocument != document) {
   1.195 +    var framerect = anchor.ownerDocument.defaultView.frameElement.getBoundingClientRect();
   1.196 +    hwinpos = framerect.left;
   1.197 +    vwinpos = framerect.top;
   1.198 +  }
   1.199 +
   1.200 +  // Positions are reversed in rtl yet the coordinates used in the computations
   1.201 +  // are not, so flip the expected label side and anchor edge.
   1.202 +  var isRTL = (window.getComputedStyle(panel).direction == "rtl");
   1.203 +  if (isRTL) {
   1.204 +    var flipLeftRight = function (val) val == "left" ? "right" : "left";
   1.205 +    expectedAnchorEdge = expectedAnchorEdge.replace(/(left|right)/, flipLeftRight);
   1.206 +    expectedSide = expectedSide.replace(/(left|right)/, flipLeftRight);
   1.207 +  }
   1.208 +
   1.209 +  var panelRect = panel.getBoundingClientRect();
   1.210 +  var anchorRect = anchor.getBoundingClientRect();
   1.211 +  var labelBO = $("panellabel").boxObject;
   1.212 +  var labelRect = { top: labelBO.y,
   1.213 +                    left: labelBO.x,
   1.214 +                    bottom: labelBO.y + labelBO.height,
   1.215 +                    right: labelBO.x + labelBO.width };
   1.216 +  switch (expectedSide) {
   1.217 +    case "top":
   1.218 +      ok(labelRect.top > vwinpos + anchorRect.bottom * zoomFactor + 5, "panel label is below");
   1.219 +      break;
   1.220 +    case "bottom":
   1.221 +      ok(labelRect.bottom < vwinpos + anchorRect.top * zoomFactor - 5, "panel label is above");
   1.222 +      break;
   1.223 +    case "left":
   1.224 +      ok(labelRect.left > hwinpos + anchorRect.right * zoomFactor + 5, "panel label is right");
   1.225 +      break;
   1.226 +    case "right":
   1.227 +      ok(labelRect.right < hwinpos + anchorRect.left * zoomFactor - 5, "panel label is left");
   1.228 +      break;
   1.229 +  }
   1.230 +
   1.231 +  let iscentered = false;
   1.232 +  if (expectedAnchorEdge.indexOf("center ") == 0) {
   1.233 +    expectedAnchorEdge = expectedAnchorEdge.substring(7);
   1.234 +    iscentered = true;
   1.235 +  }
   1.236 +
   1.237 +  switch (expectedAnchorEdge) {
   1.238 +    case "top":
   1.239 +      adj = vwinpos + parseInt(getComputedStyle(panel, "").marginTop);
   1.240 +      if (iscentered)
   1.241 +        adj += Math.round(anchorRect.height) / 2;
   1.242 +      isWithinHalfPixel(panelRect.top, anchorRect.top * zoomFactor + adj, "anchored on top");
   1.243 +      break;
   1.244 +    case "bottom":
   1.245 +      adj = vwinpos + parseInt(getComputedStyle(panel, "").marginBottom);
   1.246 +      if (iscentered)
   1.247 +        adj += Math.round(anchorRect.height) / 2;
   1.248 +      isWithinHalfPixel(panelRect.bottom, anchorRect.bottom * zoomFactor - adj, "anchored on bottom");
   1.249 +      break;
   1.250 +    case "left":
   1.251 +      adj = hwinpos + parseInt(getComputedStyle(panel, "").marginLeft);
   1.252 +      if (iscentered)
   1.253 +        adj += Math.round(anchorRect.width) / 2;
   1.254 +      isWithinHalfPixel(panelRect.left, anchorRect.left * zoomFactor + adj, "anchored on left ");
   1.255 +      break;
   1.256 +    case "right":
   1.257 +      adj = hwinpos + parseInt(getComputedStyle(panel, "").marginRight);
   1.258 +      if (iscentered)
   1.259 +        adj += Math.round(anchorRect.width) / 2;
   1.260 +      isWithinHalfPixel(panelRect.right, anchorRect.right * zoomFactor - adj, "anchored on right");
   1.261 +      break;
   1.262 +  }
   1.263 +
   1.264 +  is(anchor, expectedAnchor, "anchor");
   1.265 +
   1.266 +  var arrow = document.getAnonymousElementByAttribute(panel, "anonid", "arrow");
   1.267 +  is(arrow.getAttribute("side"), expectedSide, "panel arrow side");
   1.268 +  is(arrow.hidden, false, "panel hidden");
   1.269 +  is(arrow.parentNode.pack, expectedPack, "panel arrow pack");
   1.270 +  is(panel.alignmentPosition, expectedAlignment, "panel alignmentPosition");
   1.271 +
   1.272 +  panel.hidePopup();
   1.273 +}
   1.274 +
   1.275 +function isWithinHalfPixel(a, b, desc)
   1.276 +{
   1.277 +  ok(Math.abs(a - b) <= 0.5, desc);
   1.278 +}
   1.279 +
   1.280 +function checkBigPanel(panel)
   1.281 +{
   1.282 +  ok(panel.firstChild.getBoundingClientRect().height < 2800, "big panel height");
   1.283 +  panel.hidePopup();
   1.284 +}
   1.285 +
   1.286 +SimpleTest.waitForFocus(startTest);
   1.287 +
   1.288 +]]>
   1.289 +</script>
   1.290 +
   1.291 +<body xmlns="http://www.w3.org/1999/xhtml"/>
   1.292 +
   1.293 +</window>

mercurial