layout/xul/test/test_stack.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="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4
michael@0 5 <window align="start" title="XUL stack tests" onload="runTest()"
michael@0 6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 7 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 8
michael@0 9 <!-- a * before an expected value means an offset from the right or bottom edge -->
michael@0 10 <stack id="stack">
michael@0 11 <hbox id="left-top" left="10" top="12" width="20" height="24"
michael@0 12 expectedleft="10" expectedtop="12" expectedright="30" expectedbottom="36"
michael@0 13 stackwidth="30" stackheight="36"/>
michael@0 14 <hbox id="start-top" start="10" top="12" width="20" height="24"
michael@0 15 expectedleft="10" expectedtop="12" expectedright="30" expectedbottom="36"
michael@0 16 stackwidth="30" stackheight="36"/>
michael@0 17 <hbox id="right-bottom" right="10" bottom="12" width="20" height="24"
michael@0 18 expectedleft="*30" expectedtop="*36" expectedright="*10" expectedbottom="*12"
michael@0 19 stackwidth="30" stackheight="36"/>
michael@0 20 <hbox id="end-bottom" end="10" bottom="12" width="20" height="24"
michael@0 21 expectedleft="*30" expectedtop="*36" expectedright="*10" expectedbottom="*12"
michael@0 22 stackwidth="30" stackheight="36"/>
michael@0 23 <hbox id="left-bottom" left="18" bottom="15" width="16" height="19"
michael@0 24 expectedleft="18" expectedtop="*34" expectedright="34" expectedbottom="*15"
michael@0 25 stackwidth="34" stackheight="34"/>
michael@0 26 <hbox id="start-bottom" start="18" bottom="15" width="16" height="19"
michael@0 27 expectedleft="18" expectedtop="*34" expectedright="34" expectedbottom="*15"
michael@0 28 stackwidth="34" stackheight="34"/>
michael@0 29 <hbox id="right-top" right="5" top="8" width="10" height="11"
michael@0 30 expectedleft="*15" expectedtop="8" expectedright="*5" expectedbottom="19"
michael@0 31 stackwidth="15" stackheight="19"/>
michael@0 32 <hbox id="end-top" end="5" top="8" width="10" height="11"
michael@0 33 expectedleft="*15" expectedtop="8" expectedright="*5" expectedbottom="19"
michael@0 34 stackwidth="15" stackheight="19"/>
michael@0 35 <hbox id="left-right" left="12" right="9" width="15" height="6"
michael@0 36 expectedleft="12" expectedtop="0" expectedright="*9" expectedbottom="*0"
michael@0 37 stackwidth="36" stackheight="6"/>
michael@0 38 <hbox id="start-right" start="12" right="9" width="15" height="6"
michael@0 39 expectedleft="12" expectedtop="0" expectedright="*9" expectedbottom="*0"
michael@0 40 stackwidth="36" stackheight="6"/>
michael@0 41 <hbox id="left-end" start="12" end="9" width="15" height="6"
michael@0 42 expectedleft="12" expectedtop="0" expectedright="*9" expectedbottom="*0"
michael@0 43 stackwidth="36" stackheight="6"/>
michael@0 44 <hbox id="start-end" start="12" end="9" width="15" height="6"
michael@0 45 expectedleft="12" expectedtop="0" expectedright="*9" expectedbottom="*0"
michael@0 46 stackwidth="36" stackheight="6"/>
michael@0 47 <hbox id="top-bottom" top="20" bottom="39" width="15" height="6"
michael@0 48 expectedleft="0" expectedtop="20" expectedright="*0" expectedbottom="*39"
michael@0 49 stackwidth="15" stackheight="65"/>
michael@0 50 <hbox id="left-right-top-bottom" style="left: 5px; top: 5px; right: 8px; bottom: 8px;"
michael@0 51 left="16" top="20" right="20" bottom="35" width="7" height="8"
michael@0 52 expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
michael@0 53 stackwidth="43" stackheight="63"/>
michael@0 54 <hbox id="start-right-top-bottom" style="left: 5px; top: 5px; right: 8px; bottom: 8px;"
michael@0 55 start="16" top="20" right="20" bottom="35" width="7" height="8"
michael@0 56 expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
michael@0 57 stackwidth="43" stackheight="63"/>
michael@0 58 <hbox id="left-end-top-bottom" style="left: 5px; top: 5px; right: 8px; bottom: 8px;"
michael@0 59 left="16" top="20" end="20" bottom="35" width="7" height="8"
michael@0 60 expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
michael@0 61 stackwidth="43" stackheight="63"/>
michael@0 62 <hbox id="start-end-top-bottom" style="left: 5px; top: 5px; right: 8px; bottom: 8px;"
michael@0 63 start="16" top="20" end="20" bottom="35" width="7" height="8"
michael@0 64 expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
michael@0 65 stackwidth="43" stackheight="63"/>
michael@0 66 <hbox id="left-right-top-bottom-nosize" left="16" top="20" right="20" bottom="35"
michael@0 67 expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
michael@0 68 stackwidth="36" stackheight="55"/>
michael@0 69 <hbox id="start-right-top-bottom-nosize" start="16" top="20" right="20" bottom="35"
michael@0 70 expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
michael@0 71 stackwidth="36" stackheight="55"/>
michael@0 72 <hbox id="left-end-top-bottom-nosize" left="16" top="20" end="20" bottom="35"
michael@0 73 expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
michael@0 74 stackwidth="36" stackheight="55"/>
michael@0 75 <hbox id="start-end-top-bottom-nosize" start="16" top="20" end="20" bottom="35"
michael@0 76 expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
michael@0 77 stackwidth="36" stackheight="55"/>
michael@0 78 <hbox id="none" width="10" height="12" expectedleft="0" expectedtop="0" expectedright="*0" expectedbottom="*0"
michael@0 79 stackwidth="10" stackheight="12"/>
michael@0 80 <hbox id="none-nosize" expectedleft="0" expectedtop="0" expectedright="*0" expectedbottom="*0"
michael@0 81 stackwidth="0" stackheight="0"/>
michael@0 82 <hbox id="style-left-right-top-bottom"
michael@0 83 style="left: 17px; top: 20px;" right="20" bottom="35" width="7" height="8"
michael@0 84 expectedleft="*27" expectedtop="*43" expectedright="*20" expectedbottom="*35"
michael@0 85 stackwidth="27" stackheight="43"/>
michael@0 86 <hbox id="style-left-right-top-bottom-nosize"
michael@0 87 style="left: 16px; top: 20px; right: 20px; bottom: 35px;"
michael@0 88 expectedleft="0" expectedtop="0" expectedright="*0" expectedbottom="*0"
michael@0 89 stackwidth="0" stackheight="0"/>
michael@0 90 <hbox id="left-large-right" left="20" right="1000" height="6"
michael@0 91 expectedleft="20" expectedtop="0" expectedright="20" expectedbottom="*0"
michael@0 92 stackwidth="1020" stackheight="6"/>
michael@0 93 <hbox id="left-top-with-margin" left="8" top="17" width="20" height="24"
michael@0 94 style="margin: 1px 2px 3px 4px;"
michael@0 95 expectedleft="12" expectedtop="18" expectedright="32" expectedbottom="42"
michael@0 96 stackwidth="34" stackheight="45"/>
michael@0 97 <hbox id="right-bottom-with-margin" right="6" bottom="15" width="10" height="14"
michael@0 98 style="margin: 1px 2px 3px 4px;"
michael@0 99 expectedleft="*18" expectedtop="*32" expectedright="*8" expectedbottom="*18"
michael@0 100 stackwidth="22" stackheight="33"/>
michael@0 101 <hbox id="left-top-right-bottom-with-margin" left="14" right="6" top="8" bottom="15" width="10" height="14"
michael@0 102 style="margin: 1px 2px 3px 4px;"
michael@0 103 expectedleft="18" expectedtop="9" expectedright="*8" expectedbottom="*18"
michael@0 104 stackwidth="36" stackheight="41"/>
michael@0 105 <hbox id="none-with-margin"
michael@0 106 style="margin: 1px 2px 3px 4px;"
michael@0 107 expectedleft="4" expectedtop="1" expectedright="*2" expectedbottom="*3"
michael@0 108 stackwidth="6" stackheight="4"/>
michael@0 109 </stack>
michael@0 110
michael@0 111 <stack id="stack-with-size" width="12" height="14">
michael@0 112 <hbox id="left-top-with-stack-size" left="10" top="12" width="20" height="24"
michael@0 113 expectedleft="10" expectedtop="12" expectedright="30" expectedbottom="36"/>
michael@0 114 </stack>
michael@0 115
michael@0 116 <stack id="stack-with-start-end" width="30">
michael@0 117 <hbox id="start-with-start-end" start="10" top="12" width="20" height="24"
michael@0 118 expectedstart="10" expectedend="30"/>
michael@0 119 <hbox id="end-width-start-end" end="5" top="12" width="20" height="24"
michael@0 120 expectedstart="5" expectedend="25"/>
michael@0 121 <hbox id="start-end-width-start-end" start="12" end="9" width="20" top="12" height="24"
michael@0 122 expectedstart="12" expectedend="21"/>
michael@0 123 </stack>
michael@0 124
michael@0 125 <stack id="stack-with-border"
michael@0 126 style="border-left: 4px solid black; border-top: 2px solid black; border-right: 1px solid black; border-bottom: 3px solid black;">
michael@0 127 <hbox id="left-top-with-border" left="10" top="14" width="20" height="24"
michael@0 128 expectedleft="14" expectedtop="16" expectedright="34" expectedbottom="40"/>
michael@0 129 <hbox id="start-top-with-border" start="10" top="14" width="20" height="24"
michael@0 130 expectedleft="14" expectedtop="16" expectedright="34" expectedbottom="40"/>
michael@0 131 <hbox id="right-bottom-with-border" right="5" bottom="8" width="6" height="10"
michael@0 132 expectedleft="*12" expectedtop="*21" expectedright="*6" expectedbottom="*11"/>
michael@0 133 <hbox id="end-bottom-with-border" end="5" bottom="8" width="6" height="10"
michael@0 134 expectedleft="*12" expectedtop="*21" expectedright="*6" expectedbottom="*11"/>
michael@0 135 <hbox id="left-top-right-bottom-with-border" left="12" right="5" top="18" bottom="8"
michael@0 136 expectedleft="16" expectedtop="20" expectedright="*6" expectedbottom="*11"/>
michael@0 137 <hbox id="start-top-right-bottom-with-border" start="12" right="5" top="18" bottom="8"
michael@0 138 expectedleft="16" expectedtop="20" expectedright="*6" expectedbottom="*11"/>
michael@0 139 <hbox id="left-top-end-bottom-with-border" left="12" end="5" top="18" bottom="8"
michael@0 140 expectedleft="16" expectedtop="20" expectedright="*6" expectedbottom="*11"/>
michael@0 141 <hbox id="start-top-end-bottom-with-border" start="12" end="5" top="18" bottom="8"
michael@0 142 expectedleft="16" expectedtop="20" expectedright="*6" expectedbottom="*11"/>
michael@0 143 <hbox id="none-with-with-border"
michael@0 144 expectedleft="4" expectedtop="2" expectedright="*1" expectedbottom="*3"/>
michael@0 145 </stack>
michael@0 146
michael@0 147 <stack id="stack-dyn"/>
michael@0 148 <stack id="stack-dyn-sized" width="12" height="14"/>
michael@0 149
michael@0 150 <body xmlns="http://www.w3.org/1999/xhtml"/>
michael@0 151
michael@0 152 <script><![CDATA[
michael@0 153 SimpleTest.waitForExplicitFinish();
michael@0 154
michael@0 155 var stackRect;
michael@0 156 var dynStack;
michael@0 157
michael@0 158 function compareSide(child, actual, side, dyn, direction)
michael@0 159 {
michael@0 160 var clientRect = child.getBoundingClientRect();
michael@0 161 var vertical = (side == "top" || side == "bottom");
michael@0 162 var expectedval = child.getAttribute("expected" + side);
michael@0 163 if (expectedval.indexOf("*") == 0)
michael@0 164 expectedval = (vertical ? stackRect.bottom : stackRect.right) - Number(expectedval.substring(1));
michael@0 165 else if (direction == "rtl")
michael@0 166 expectedval = (vertical ? stackRect.top : -stackRect.width + clientRect.right + clientRect.left) + Number(expectedval);
michael@0 167 else
michael@0 168 expectedval = (vertical ? stackRect.top : stackRect.left) + Number(expectedval);
michael@0 169
michael@0 170 is(actual, expectedval, child.id + " " + side + (dyn ? " dynamic" : ""));
michael@0 171 }
michael@0 172
michael@0 173 function runTest()
michael@0 174 {
michael@0 175 runTestForStack("stack", false);
michael@0 176 runTestForStack("stack-with-size", false);
michael@0 177 runTestForStartEndAttributes("stack-with-start-end", "ltr");
michael@0 178 runTestForStartEndAttributes("stack-with-start-end", "rtl");
michael@0 179
michael@0 180 var stackWithSize = $("stack-with-size");
michael@0 181
michael@0 182 var sizedStackRect = stackWithSize.getBoundingClientRect();
michael@0 183 is(sizedStackRect.width, 30, "stack size stretched width");
michael@0 184 is(sizedStackRect.height, 36, "stack size stretched height");
michael@0 185
michael@0 186 // set -moz-stack-sizing: ignore and ensure that the stack does not grow
michael@0 187 // to include the child
michael@0 188 var item = $("left-top-with-stack-size");
michael@0 189 item.style.MozStackSizing = "ignore";
michael@0 190 var parent = item.parentNode;
michael@0 191 parent.removeChild(item);
michael@0 192 parent.appendChild(item);
michael@0 193
michael@0 194 sizedStackRect = stackWithSize.getBoundingClientRect();
michael@0 195 is(sizedStackRect.width, 12, "stack size not stretched width");
michael@0 196 is(sizedStackRect.height, 14, "stack size not stretched height");
michael@0 197
michael@0 198 testPositionChanges(stackWithSize, true);
michael@0 199 item.style.MozStackSizing = "";
michael@0 200 testPositionChanges(stackWithSize, false);
michael@0 201
michael@0 202 // now test adding stack children dynamically to ensure that
michael@0 203 // the size of the stack adjusts accordingly
michael@0 204 dynStack = $("stack-dyn");
michael@0 205 runTestForStack("stack", true);
michael@0 206
michael@0 207 SimpleTest.finish();
michael@0 208 }
michael@0 209
michael@0 210 function runTestForStartEndAttributes(stackid, aDirection)
michael@0 211 {
michael@0 212 // Change the direction of the layout to RTL to ensure start/end are
michael@0 213 // working as expected
michael@0 214 var stack = $(stackid);
michael@0 215 stack.style.direction = aDirection;
michael@0 216
michael@0 217 var stackRect = stack.getBoundingClientRect();
michael@0 218 var children = stack.childNodes;
michael@0 219 for (var c = children.length - 1; c >= 0; c--) {
michael@0 220 var child = children[c];
michael@0 221
michael@0 222 // do tests only for elements that have a rtl-enabled mode
michael@0 223 if (!child.hasAttribute("start") && !child.hasAttribute("end"))
michael@0 224 continue;
michael@0 225
michael@0 226 var childrect = child.getBoundingClientRect();
michael@0 227 compareSide(child, childrect.right, "end", false, aDirection);
michael@0 228 compareSide(child, childrect.left, "start", false, aDirection);
michael@0 229 }
michael@0 230
michael@0 231 // Reset the direction
michael@0 232 stack.style.direction = "ltr";
michael@0 233 }
michael@0 234
michael@0 235 function runTestForStack(stackid, dyn)
michael@0 236 {
michael@0 237 var stack = $(stackid);
michael@0 238 if (!dyn)
michael@0 239 stackRect = stack.getBoundingClientRect();
michael@0 240 var children = stack.childNodes;
michael@0 241 for (var c = children.length - 1; c >= 0; c--) {
michael@0 242 var child = children[c];
michael@0 243 if (dyn) {
michael@0 244 // for dynamic tests, get the size after appending the child as the
michael@0 245 // stack size will be effected by it
michael@0 246 dynStack.appendChild(child);
michael@0 247 stackRect = dynStack.getBoundingClientRect();
michael@0 248 is(stackRect.width, child.getAttribute("stackwidth"), child.id + " stack width" + (dyn ? " dynamic" : ""));
michael@0 249 is(stackRect.height, child.getAttribute("stackheight"), child.id + " stack height" + (dyn ? " dynamic" : ""));
michael@0 250 }
michael@0 251
michael@0 252 var childrect = child.getBoundingClientRect();
michael@0 253 compareSide(child, childrect.left, "left", dyn);
michael@0 254 compareSide(child, childrect.top, "top", dyn);
michael@0 255 compareSide(child, childrect.right, "right", dyn);
michael@0 256 compareSide(child, childrect.bottom, "bottom", dyn);
michael@0 257 if (dyn)
michael@0 258 dynStack.removeChild(child);
michael@0 259 }
michael@0 260 }
michael@0 261
michael@0 262 function testPositionChanges(stack, ignoreStackSizing)
michael@0 263 {
michael@0 264 var add = ignoreStackSizing ? " ignore stack sizing" : "";
michael@0 265
michael@0 266 // ensure that changing left/top/right/bottom/start/end works
michael@0 267 var stackchild = document.getElementById("left-top-with-stack-size");
michael@0 268 stackchild.left = 18;
michael@0 269 is(stackchild.getBoundingClientRect().left, stack.getBoundingClientRect().left + 18, "left changed" + add);
michael@0 270 is(stack.getBoundingClientRect().width, ignoreStackSizing ? 12 : 38, "left changed stack width" + add);
michael@0 271
michael@0 272 stackchild.left = "";
michael@0 273 stackchild.setAttribute("start", "19");
michael@0 274 is(stackchild.getBoundingClientRect().left, stack.getBoundingClientRect().left + 19, "left changed" + add);
michael@0 275 is(stack.getBoundingClientRect().width, ignoreStackSizing ? 12 : 39, "left changed stack width" + add);
michael@0 276 stackchild.removeAttribute("start");
michael@0 277 stackchild.left = 18;
michael@0 278
michael@0 279 stackchild.top = 22;
michael@0 280 is(stackchild.getBoundingClientRect().top, stack.getBoundingClientRect().top + 22, "top changed" + add);
michael@0 281 is(stack.getBoundingClientRect().height, ignoreStackSizing ? 14 : 46, "left changed stack height" + add);
michael@0 282
michael@0 283 stackchild.setAttribute("right", "6");
michael@0 284 is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().left + 18, "right changed" + add);
michael@0 285 // the width is only 12 pixels in ignoreStackSizing mode, so don't check the offset
michael@0 286 // from the right edge in this case
michael@0 287 if (!ignoreStackSizing)
michael@0 288 is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().right - 6,
michael@0 289 "right changed from right edge" + add);
michael@0 290 is(stack.getBoundingClientRect().width, ignoreStackSizing ? 12 : 24, "right changed stack width" + add);
michael@0 291
michael@0 292 stackchild.removeAttribute("right");
michael@0 293 stackchild.setAttribute("end", "7");
michael@0 294 is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().left + 18, "right changed" + add);
michael@0 295 // the width is only 12 pixels in ignoreStackSizing mode, so don't check the offset
michael@0 296 // from the right edge in this case
michael@0 297 if (!ignoreStackSizing)
michael@0 298 is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().right - 7,
michael@0 299 "right changed from right edge" + add);
michael@0 300 is(stack.getBoundingClientRect().width, ignoreStackSizing ? 12 : 25, "right changed stack width" + add);
michael@0 301 stackchild.removeAttribute("end");
michael@0 302 stackchild.setAttribute("right", "6");
michael@0 303
michael@0 304 stackchild.setAttribute("bottom", "9");
michael@0 305 is(stackchild.getBoundingClientRect().bottom, stack.getBoundingClientRect().top + 22, "bottom changed" + add);
michael@0 306 is(stack.getBoundingClientRect().height, ignoreStackSizing ? 14 : 31, "bottom changed stack height" + add);
michael@0 307 if (!ignoreStackSizing)
michael@0 308 is(stackchild.getBoundingClientRect().bottom, stack.getBoundingClientRect().bottom - 9,
michael@0 309 "right changed from bottom edge" + add);
michael@0 310
michael@0 311 stackchild.left = "";
michael@0 312 is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().right - 6, "right changed" + add);
michael@0 313 is(stack.getBoundingClientRect().width, ignoreStackSizing ? 12 : 26, "right changed no left stack width" + add);
michael@0 314
michael@0 315 stackchild.removeAttribute("right");
michael@0 316 is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().right, "right cleared" + add);
michael@0 317 is(stack.getBoundingClientRect().width, 12, "right cleared stack height" + add);
michael@0 318
michael@0 319 // reset the values
michael@0 320 stackchild.removeAttribute("bottom");
michael@0 321 stackchild.left = 10;
michael@0 322 stackchild.top = 12;
michael@0 323 }
michael@0 324
michael@0 325
michael@0 326 ]]></script>
michael@0 327 </window>

mercurial