toolkit/content/tests/chrome/test_arrowpanel.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
     5 <window title="Arrow Panels"
     6         style="padding: 10px;"
     7         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    11   <script type="application/javascript"
    12           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    14 <stack flex="1">
    15   <label id="topleft" value="Top Left Corner" left="15" top="15"/>
    16   <label id="topright" value="Top Right" right="15" top="15"/>
    17   <label id="bottomleft" value="Bottom Left Corner" left="15" bottom="15"/>
    18   <label id="bottomright" value="Bottom Right" right="15" bottom="15"/>
    19   <!-- Our SimpleTest/TestRunner.js runs tests inside an iframe which sizes are W=500 H=300.
    20        'left' and 'top' values need to be set so that the panel (popup) has enough room to display on its 4 sides. -->
    21   <label id="middle" value="+/- Centered" left="225" top="135"/>
    22   <iframe id="frame" type="content"
    23           src="data:text/html,&lt;input id='input'&gt;" width="100" height="100" left="225" top="120"/>
    24 </stack>
    26 <panel id="panel" type="arrow"
    27        onpopupshown="checkPanelPosition(this)" onpopuphidden="runNextTest.next()">
    28   <label id="panellabel" value="This is some text..." height="65"/>
    29 </panel>
    31 <panel id="bigpanel" type="arrow"
    32        onpopupshown="checkBigPanel(this)" onpopuphidden="runNextTest.next()">
    33   <button label="This is some text..." height="3000"/>
    34 </panel>
    36 <script type="application/javascript">
    37 <![CDATA[
    39 SimpleTest.waitForExplicitFinish();
    41 var expectedAnchor = null;
    42 var expectedSide = "", expectedAnchorEdge = "", expectedPack = "", expectedAlignment = "";
    43 var zoomFactor = 1;
    44 var runNextTest;
    46 function startTest()
    47 {
    48   runNextTest = nextTest();
    49   runNextTest.next();
    50 }
    52 function nextTest()
    53 {
    54   var panel = $("panel");
    56   function openPopup(position, anchor, expected, anchorEdge, pack, alignment)
    57   {
    58     expectedAnchor = anchor instanceof Node ? anchor : $(anchor);
    59     expectedSide = expected;
    60     expectedAnchorEdge = anchorEdge;
    61     expectedPack = pack;
    62     expectedAlignment = alignment == undefined ? position : alignment;
    64     panel.removeAttribute("side");
    65     panel.openPopup(expectedAnchor, position, 0, 0, false, false, null);
    66   }
    68   for (var iter = 0; iter < 2; iter++) {
    69     openPopup("after_start", "topleft", "top", "left", "start");
    70     yield;
    71     openPopup("after_start", "bottomleft", "bottom", "left", "start", "before_start");
    72     yield;
    73     openPopup("before_start", "topleft", "top", "left", "start", "after_start");
    74     yield;
    75     openPopup("before_start", "bottomleft", "bottom", "left", "start");
    76     yield;
    77     openPopup("after_start", "middle", "top", "left", "start");
    78     yield;
    79     openPopup("before_start", "middle", "bottom", "left", "start");
    80     yield;
    82     openPopup("after_start", "topright", "top", "right", "end", "after_end");
    83     yield;
    84     openPopup("after_start", "bottomright", "bottom", "right", "end", "before_end");
    85     yield;
    86     openPopup("before_start", "topright", "top", "right", "end", "after_end");
    87     yield;
    88     openPopup("before_start", "bottomright", "bottom", "right", "end", "before_end");
    89     yield;
    91     openPopup("after_end", "middle", "top", "right", "end");
    92     yield;
    93     openPopup("before_end", "middle", "bottom", "right", "end");
    94     yield;
    96     openPopup("start_before", "topleft", "left", "top", "start", "end_before");
    97     yield;
    98     openPopup("start_before", "topright", "right", "top", "start");
    99     yield;
   100     openPopup("end_before", "topleft", "left", "top", "start");
   101     yield;
   102     openPopup("end_before", "topright", "right", "top", "start", "start_before");
   103     yield;
   104     openPopup("start_before", "middle", "right", "top", "start");
   105     yield;
   106     openPopup("end_before", "middle", "left", "top", "start");
   107     yield;
   109     openPopup("start_before", "bottomleft", "left", "bottom", "end", "end_after");
   110     yield;
   111     openPopup("start_before", "bottomright", "right", "bottom", "end", "start_after");
   112     yield;
   113     openPopup("end_before", "bottomleft", "left", "bottom", "end", "end_after");
   114     yield;
   115     openPopup("end_before", "bottomright", "right", "bottom", "end", "start_after");
   116     yield;
   118     openPopup("start_after", "middle", "right", "bottom", "end");
   119     yield;
   120     openPopup("end_after", "middle", "left", "bottom", "end");
   121     yield;
   123     openPopup("topcenter bottomleft", "bottomleft", "bottom", "center left", "start", "before_start");
   124     yield;
   125     openPopup("bottomcenter topleft", "topleft", "top", "center left", "start", "after_start");
   126     yield;
   127     openPopup("topcenter bottomright", "bottomright", "bottom", "center right", "end", "before_end");
   128     yield;
   129     openPopup("bottomcenter topright", "topright", "top", "center right", "end", "after_end");
   130     yield;
   131     openPopup("topcenter bottomleft", "middle", "bottom", "center left", "start", "before_start");
   132     yield;
   133     openPopup("bottomcenter topleft", "middle", "top", "center left", "start", "after_start");
   134     yield;
   136     openPopup("leftcenter topright", "middle", "right", "center top", "start", "start_before");
   137     yield;
   138     openPopup("rightcenter bottomleft", "middle", "left", "center bottom", "end", "end_after");
   139     yield;
   141 /*
   142     XXXndeakin disable these parts of the test which often cause problems, see bug 626563
   144     openPopup("after_start", frames[0].document.getElementById("input"), "top", "left", "start");
   145     yield;
   147     setScale(frames[0], 1.5);
   148     openPopup("after_start", frames[0].document.getElementById("input"), "top", "left", "start");
   149     yield;
   151     setScale(frames[0], 2.5);
   152     openPopup("before_start", frames[0].document.getElementById("input"), "bottom", "left", "start");
   153     yield;
   155     setScale(frames[0], 1);
   156 */
   158     $("bigpanel").openPopup($("topleft"), "after_start", 0, 0, false, false, null, "start");
   159     yield;
   161     // switch to rtl mode
   162     document.documentElement.style.direction = "rtl";
   163     $("topleft").setAttribute("right", "15");
   164     $("topright").setAttribute("left", "15");
   165     $("bottomleft").setAttribute("right", "15");
   166     $("bottomright").setAttribute("left", "15");
   167     $("topleft").removeAttribute("left");
   168     $("topright").removeAttribute("right");
   169     $("bottomleft").removeAttribute("left");
   170     $("bottomright").removeAttribute("right");
   171   }
   173   SimpleTest.finish()
   174   yield;
   175 }
   177 function setScale(win, scale)
   178 {
   179   var wn = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
   180               .getInterface(Components.interfaces.nsIWebNavigation);
   181   var shell = wn.QueryInterface(Components.interfaces.nsIDocShell);
   182   var docViewer = shell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
   183   docViewer.fullZoom = scale;
   184   zoomFactor = scale;
   185 }
   187 function checkPanelPosition(panel)
   188 {
   189   let anchor = panel.anchorNode;
   190   let adj = 0, hwinpos = 0, vwinpos = 0;
   191   if (anchor.ownerDocument != document) {
   192     var framerect = anchor.ownerDocument.defaultView.frameElement.getBoundingClientRect();
   193     hwinpos = framerect.left;
   194     vwinpos = framerect.top;
   195   }
   197   // Positions are reversed in rtl yet the coordinates used in the computations
   198   // are not, so flip the expected label side and anchor edge.
   199   var isRTL = (window.getComputedStyle(panel).direction == "rtl");
   200   if (isRTL) {
   201     var flipLeftRight = function (val) val == "left" ? "right" : "left";
   202     expectedAnchorEdge = expectedAnchorEdge.replace(/(left|right)/, flipLeftRight);
   203     expectedSide = expectedSide.replace(/(left|right)/, flipLeftRight);
   204   }
   206   var panelRect = panel.getBoundingClientRect();
   207   var anchorRect = anchor.getBoundingClientRect();
   208   var labelBO = $("panellabel").boxObject;
   209   var labelRect = { top: labelBO.y,
   210                     left: labelBO.x,
   211                     bottom: labelBO.y + labelBO.height,
   212                     right: labelBO.x + labelBO.width };
   213   switch (expectedSide) {
   214     case "top":
   215       ok(labelRect.top > vwinpos + anchorRect.bottom * zoomFactor + 5, "panel label is below");
   216       break;
   217     case "bottom":
   218       ok(labelRect.bottom < vwinpos + anchorRect.top * zoomFactor - 5, "panel label is above");
   219       break;
   220     case "left":
   221       ok(labelRect.left > hwinpos + anchorRect.right * zoomFactor + 5, "panel label is right");
   222       break;
   223     case "right":
   224       ok(labelRect.right < hwinpos + anchorRect.left * zoomFactor - 5, "panel label is left");
   225       break;
   226   }
   228   let iscentered = false;
   229   if (expectedAnchorEdge.indexOf("center ") == 0) {
   230     expectedAnchorEdge = expectedAnchorEdge.substring(7);
   231     iscentered = true;
   232   }
   234   switch (expectedAnchorEdge) {
   235     case "top":
   236       adj = vwinpos + parseInt(getComputedStyle(panel, "").marginTop);
   237       if (iscentered)
   238         adj += Math.round(anchorRect.height) / 2;
   239       isWithinHalfPixel(panelRect.top, anchorRect.top * zoomFactor + adj, "anchored on top");
   240       break;
   241     case "bottom":
   242       adj = vwinpos + parseInt(getComputedStyle(panel, "").marginBottom);
   243       if (iscentered)
   244         adj += Math.round(anchorRect.height) / 2;
   245       isWithinHalfPixel(panelRect.bottom, anchorRect.bottom * zoomFactor - adj, "anchored on bottom");
   246       break;
   247     case "left":
   248       adj = hwinpos + parseInt(getComputedStyle(panel, "").marginLeft);
   249       if (iscentered)
   250         adj += Math.round(anchorRect.width) / 2;
   251       isWithinHalfPixel(panelRect.left, anchorRect.left * zoomFactor + adj, "anchored on left ");
   252       break;
   253     case "right":
   254       adj = hwinpos + parseInt(getComputedStyle(panel, "").marginRight);
   255       if (iscentered)
   256         adj += Math.round(anchorRect.width) / 2;
   257       isWithinHalfPixel(panelRect.right, anchorRect.right * zoomFactor - adj, "anchored on right");
   258       break;
   259   }
   261   is(anchor, expectedAnchor, "anchor");
   263   var arrow = document.getAnonymousElementByAttribute(panel, "anonid", "arrow");
   264   is(arrow.getAttribute("side"), expectedSide, "panel arrow side");
   265   is(arrow.hidden, false, "panel hidden");
   266   is(arrow.parentNode.pack, expectedPack, "panel arrow pack");
   267   is(panel.alignmentPosition, expectedAlignment, "panel alignmentPosition");
   269   panel.hidePopup();
   270 }
   272 function isWithinHalfPixel(a, b, desc)
   273 {
   274   ok(Math.abs(a - b) <= 0.5, desc);
   275 }
   277 function checkBigPanel(panel)
   278 {
   279   ok(panel.firstChild.getBoundingClientRect().height < 2800, "big panel height");
   280   panel.hidePopup();
   281 }
   283 SimpleTest.waitForFocus(startTest);
   285 ]]>
   286 </script>
   288 <body xmlns="http://www.w3.org/1999/xhtml"/>
   290 </window>

mercurial