toolkit/content/tests/chrome/test_arrowpanel.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial