|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
|
4 |
|
5 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
6 |
|
7 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
8 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
9 |
|
10 <vbox align="start"> |
|
11 <button id="button1" label="Button 1" style="margin-top: 50px;"/> |
|
12 <button id="button2" label="Button 2" style="margin-top: 60px;"/> |
|
13 </vbox> |
|
14 |
|
15 <menupopup id="popup" onpopupshown="popupshown()" onpopuphidden="SimpleTest.finish()"> |
|
16 <menuitem label="One"/> |
|
17 <menuitem label="Two"/> |
|
18 </menupopup> |
|
19 |
|
20 <script> |
|
21 SimpleTest.waitForExplicitFinish(); |
|
22 |
|
23 function runTest(id) |
|
24 { |
|
25 $("popup").openPopup($("button1"), "after_start"); |
|
26 } |
|
27 |
|
28 function popupshown() |
|
29 { |
|
30 var popup = $("popup"); |
|
31 var popupheight = popup.getBoundingClientRect().height; |
|
32 var button1rect = $("button1").getBoundingClientRect(); |
|
33 var button2rect = $("button2").getBoundingClientRect(); |
|
34 |
|
35 checkCoords(popup, button1rect.left, button1rect.bottom, "initial"); |
|
36 |
|
37 popup.moveToAnchor($("button1"), "after_start", 0, 8); |
|
38 checkCoords(popup, button1rect.left, button1rect.bottom + 8, "move anchor top + 8"); |
|
39 |
|
40 popup.moveToAnchor($("button1"), "after_start", 6, -10); |
|
41 checkCoords(popup, button1rect.left + 6, button1rect.bottom - 10, "move anchor left + 6, top - 10"); |
|
42 |
|
43 popup.moveToAnchor($("button1"), "before_start", -2, 0); |
|
44 checkCoords(popup, button1rect.left - 2, button1rect.top - popupheight, "move anchor before_start"); |
|
45 |
|
46 popup.moveToAnchor($("button2"), "before_start"); |
|
47 checkCoords(popup, button2rect.left, button2rect.top - popupheight, "move button2"); |
|
48 |
|
49 popup.moveToAnchor($("button1"), "end_before"); |
|
50 checkCoords(popup, button1rect.right, button1rect.top, "move anchor end_before"); |
|
51 |
|
52 popup.moveToAnchor($("button2"), "after_start", 5, 4); |
|
53 checkCoords(popup, button2rect.left + 5, button2rect.bottom + 4, "move button2 left + 5, top + 4"); |
|
54 |
|
55 popup.moveTo($("button1").boxObject.screenX + 10, $("button1").boxObject.screenY + 12); |
|
56 checkCoords(popup, button1rect.left + 10, button1rect.top + 12, "move to button1 screen with offset"); |
|
57 |
|
58 popup.moveToAnchor($("button1"), "after_start", 1, 2); |
|
59 checkCoords(popup, button1rect.left + 1, button1rect.bottom + 2, "move button2 after screen"); |
|
60 |
|
61 popup.hidePopup(); |
|
62 } |
|
63 |
|
64 function checkCoords(popup, expectedx, expectedy, testid) |
|
65 { |
|
66 var rect = popup.getBoundingClientRect(); |
|
67 is(Math.round(rect.left), Math.round(expectedx), testid + " left"); |
|
68 is(Math.round(rect.top), Math.round(expectedy), testid + " top"); |
|
69 } |
|
70 |
|
71 SimpleTest.waitForFocus(runTest); |
|
72 |
|
73 </script> |
|
74 |
|
75 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
76 <p id="display"> |
|
77 </p> |
|
78 <div id="content" style="display: none"> |
|
79 </div> |
|
80 <pre id="test"> |
|
81 </pre> |
|
82 </body> |
|
83 |
|
84 </window> |