summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/chrome/test_position.xul
blob: 695c1bf22c3356b1226b533aacb40e05278e5ac4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
  XUL Widget Test for positioning
  -->
<window title="position" width="500" height="600"
        onload="setTimeout(runTest, 0);"
        style="margin: 0; border: 0; padding; 0;"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>  
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>  


<hbox id="box1">
  <button label="0" width="100" height="40" style="margin: 3px;"/>
</hbox>
<scrollbox id="box2" orient="vertical" align="start" width="200" height="50"
           style="overflow: hidden; margin-left: 2px; padding: 1px;">
  <deck>
    <scrollbox id="box3" orient="vertical" align="start" height="100"
               style="overflow: scroll; margin: 1px; padding: 0;">
      <vbox id="innerscroll" width="200" align="start">
        <button id="button1" label="1" width="90" maxwidth="100"
                minheight="25" height="35" maxheight="50"
                style="min-width: 80px; margin: 5px; border: 4px; padding: 7px;
                       -moz-appearance: none;"/>
        <menu id="menu">
          <menupopup id="popup" style="-moz-appearance: none; margin:0; border: 0; padding: 0;"
                                onpopupshown="menuOpened()"
                                onpopuphidden="if (event.target == this) SimpleTest.finish()">
            <menuitem label="One"/>
            <menu id="submenu" label="Three">
              <menupopup id="subpopup" style="-moz-appearance: none; margin:0; border: 0; padding: 0;"
                         onpopupshown="submenuOpened()">
                <menuitem label="Four"/>
              </menupopup>
            </menu>
          </menupopup>
        </menu>
        <button label="2" maxwidth="100" maxheight="20" style="margin: 5px;"/>
        <button label="3" maxwidth="100" maxheight="20" style="margin: 5px;"/>
        <button label="4" maxwidth="100" maxheight="20" style="margin: 5px;"/>
      </vbox>
      <box height="200"/>
    </scrollbox>
  </deck>
</scrollbox>

<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>

<script>
<![CDATA[

SimpleTest.waitForExplicitFinish();

function runTest()
{
  var winwidth = document.documentElement.boxObject.width;
  var innerscroll = $("innerscroll").boxObject.width;

  var box1 = $("box1");
  checkPosition("box1", box1, 0, 0, winwidth, 46);

  var box2 = $("box2");
  checkPosition("box2", box2, 2, 46, winwidth, 96);

  // height is height(box1) = 46 + margin-top(box3) = 1 + margin-top(button1) = 5
  var button1 = $("button1");
  checkPosition("button1", button1, 9, 53, 99, 88);

  var sbo = box2.boxObject;
  sbo.scrollTo(7, 16);

  // clientRect height is offset from root so is 16 pixels vertically less
  checkPosition("button1 scrolled", button1, 9, 37, 99, 72);

  var box3 = $("box3");
  sbo = box3.boxObject;
  sbo.scrollTo(1, 2);

  checkPosition("button1 scrolled", button1, 9, 35, 99, 70);

  $("menu").open = true;
}

function menuOpened()
{
  $("submenu").open = true;
}

function submenuOpened()
{
  var menu = $("menu");
  var menuleft = Math.round(menu.getBoundingClientRect().left);
  var menubottom = Math.round(menu.getBoundingClientRect().bottom);

  var submenu = $("submenu");
  var submenutop = Math.round(submenu.getBoundingClientRect().top);
  var submenuright = Math.round(submenu.getBoundingClientRect().right);

  checkPosition("popup", $("popup"), menuleft, menubottom, -1, -1);
  checkPosition("subpopup", $("subpopup"), submenuright, submenutop, -1, -1);

  menu.open = false;
}

function checkPosition(testid, elem, cleft, ctop, cright, cbottom)
{
  // -1 for right or bottom means that the exact size should not be
  // checked, just ensure it is larger then the left or top position
  var rect = elem.getBoundingClientRect();
  is(Math.round(rect.left), cleft, testid + " client rect left");
  if (testid != "popup")
    is(Math.round(rect.top), ctop, testid + " client rect top");
  if (cright >= 0)
    is(Math.round(rect.right), cright, testid + " client rect right");
  else
    ok(rect.right - rect.left > 20, testid + " client rect right");
  if (cbottom >= 0)
    is(Math.round(rect.bottom), cbottom, testid + " client rect bottom");
  else
    ok(rect.bottom - rect.top > 15, testid + " client rect bottom");
}

]]>

</script>

</window>