1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_position.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 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 + XUL Widget Test for positioning 1.9 + --> 1.10 +<window title="position" width="500" height="600" 1.11 + onload="setTimeout(runTest, 0);" 1.12 + style="margin: 0; border: 0; padding; 0;" 1.13 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.14 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.15 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.16 + 1.17 + 1.18 +<hbox id="box1"> 1.19 + <button label="0" width="100" height="40" style="margin: 3px;"/> 1.20 +</hbox> 1.21 +<scrollbox id="box2" orient="vertical" align="start" width="200" height="50" 1.22 + style="overflow: hidden; margin-left: 2px; padding: 1px;"> 1.23 + <deck> 1.24 + <scrollbox id="box3" orient="vertical" align="start" height="100" 1.25 + style="overflow: scroll; margin: 1px; padding: 0;"> 1.26 + <vbox id="innerscroll" width="200" align="start"> 1.27 + <button id="button1" label="1" width="90" maxwidth="100" 1.28 + minheight="25" height="35" maxheight="50" 1.29 + style="min-width: 80px; margin: 5px; border: 4px; padding: 7px; 1.30 + -moz-appearance: none;"/> 1.31 + <menu id="menu"> 1.32 + <menupopup id="popup" style="-moz-appearance: none; margin:0; border: 0; padding: 0;" 1.33 + onpopupshown="menuOpened()" 1.34 + onpopuphidden="if (event.target == this) SimpleTest.finish()"> 1.35 + <menuitem label="One"/> 1.36 + <menu id="submenu" label="Three"> 1.37 + <menupopup id="subpopup" style="-moz-appearance: none; margin:0; border: 0; padding: 0;" 1.38 + onpopupshown="submenuOpened()"> 1.39 + <menuitem label="Four"/> 1.40 + </menupopup> 1.41 + </menu> 1.42 + </menupopup> 1.43 + </menu> 1.44 + <button label="2" maxwidth="100" maxheight="20" style="margin: 5px;"/> 1.45 + <button label="3" maxwidth="100" maxheight="20" style="margin: 5px;"/> 1.46 + <button label="4" maxwidth="100" maxheight="20" style="margin: 5px;"/> 1.47 + </vbox> 1.48 + <box height="200"/> 1.49 + </scrollbox> 1.50 + </deck> 1.51 +</scrollbox> 1.52 + 1.53 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.54 +<p id="display"></p> 1.55 +<div id="content" style="display: none"> 1.56 +</div> 1.57 +<pre id="test"> 1.58 +</pre> 1.59 +</body> 1.60 + 1.61 +<script> 1.62 +<![CDATA[ 1.63 + 1.64 +SimpleTest.waitForExplicitFinish(); 1.65 + 1.66 +function runTest() 1.67 +{ 1.68 + var winwidth = document.documentElement.boxObject.width; 1.69 + var innerscroll = $("innerscroll").boxObject.width; 1.70 + 1.71 + var box1 = $("box1"); 1.72 + checkPosition("box1", box1, 0, 0, winwidth, 46); 1.73 + 1.74 + var box2 = $("box2"); 1.75 + checkPosition("box2", box2, 2, 46, winwidth, 96); 1.76 + 1.77 + // height is height(box1) = 46 + margin-top(box3) = 1 + margin-top(button1) = 5 1.78 + var button1 = $("button1"); 1.79 + checkPosition("button1", button1, 9, 53, 99, 88); 1.80 + 1.81 + var sbo = box2.boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject); 1.82 + sbo.scrollTo(7, 16); 1.83 + 1.84 + // clientRect height is offset from root so is 16 pixels vertically less 1.85 + checkPosition("button1 scrolled", button1, 9, 37, 99, 72); 1.86 + 1.87 + var box3 = $("box3"); 1.88 + sbo = box3.boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject); 1.89 + sbo.scrollTo(1, 2); 1.90 + 1.91 + checkPosition("button1 scrolled", button1, 9, 35, 99, 70); 1.92 + 1.93 + $("menu").open = true; 1.94 +} 1.95 + 1.96 +function menuOpened() 1.97 +{ 1.98 + $("submenu").open = true; 1.99 +} 1.100 + 1.101 +function submenuOpened() 1.102 +{ 1.103 + var menu = $("menu"); 1.104 + var menuleft = Math.round(menu.getBoundingClientRect().left); 1.105 + var menubottom = Math.round(menu.getBoundingClientRect().bottom); 1.106 + 1.107 + var submenu = $("submenu"); 1.108 + var submenutop = Math.round(submenu.getBoundingClientRect().top); 1.109 + var submenuright = Math.round(submenu.getBoundingClientRect().right); 1.110 + 1.111 + checkPosition("popup", $("popup"), menuleft, menubottom, -1, -1); 1.112 + checkPosition("subpopup", $("subpopup"), submenuright, submenutop, -1, -1); 1.113 + 1.114 + menu.open = false; 1.115 +} 1.116 + 1.117 +function checkPosition(testid, elem, cleft, ctop, cright, cbottom) 1.118 +{ 1.119 + // -1 for right or bottom means that the exact size should not be 1.120 + // checked, just ensure it is larger then the left or top position 1.121 + var rect = elem.getBoundingClientRect(); 1.122 + is(Math.round(rect.left), cleft, testid + " client rect left"); 1.123 + if (testid != "popup") 1.124 + is(Math.round(rect.top), ctop, testid + " client rect top"); 1.125 + if (cright >= 0) 1.126 + is(Math.round(rect.right), cright, testid + " client rect right"); 1.127 + else 1.128 + ok(rect.right - rect.left > 20, testid + " client rect right"); 1.129 + if (cbottom >= 0) 1.130 + is(Math.round(rect.bottom), cbottom, testid + " client rect bottom"); 1.131 + else 1.132 + ok(rect.bottom - rect.top > 15, testid + " client rect bottom"); 1.133 +} 1.134 + 1.135 +]]> 1.136 + 1.137 +</script> 1.138 + 1.139 +</window>