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
|
<?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"?>
<window 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>
<vbox align="start">
<button id="button1" label="Button 1" style="margin-top: 50px;"/>
<button id="button2" label="Button 2" style="margin-top: 60px;"/>
</vbox>
<menupopup id="popup" onpopupshown="popupshown()" onpopuphidden="SimpleTest.finish()">
<menuitem label="One"/>
<menuitem label="Two"/>
</menupopup>
<script>
SimpleTest.waitForExplicitFinish();
function runTest(id)
{
$("popup").openPopup($("button1"), "after_start");
}
function popupshown()
{
var popup = $("popup");
var popupheight = popup.getBoundingClientRect().height;
var button1rect = $("button1").getBoundingClientRect();
var button2rect = $("button2").getBoundingClientRect();
checkCoords(popup, button1rect.left, button1rect.bottom, "initial");
popup.moveToAnchor($("button1"), "after_start", 0, 8);
checkCoords(popup, button1rect.left, button1rect.bottom + 8, "move anchor top + 8");
popup.moveToAnchor($("button1"), "after_start", 6, -10);
checkCoords(popup, button1rect.left + 6, button1rect.bottom - 10, "move anchor left + 6, top - 10");
popup.moveToAnchor($("button1"), "before_start", -2, 0);
checkCoords(popup, button1rect.left - 2, button1rect.top - popupheight, "move anchor before_start");
popup.moveToAnchor($("button2"), "before_start");
checkCoords(popup, button2rect.left, button2rect.top - popupheight, "move button2");
popup.moveToAnchor($("button1"), "end_before");
checkCoords(popup, button1rect.right, button1rect.top, "move anchor end_before");
popup.moveToAnchor($("button2"), "after_start", 5, 4);
checkCoords(popup, button2rect.left + 5, button2rect.bottom + 4, "move button2 left + 5, top + 4");
popup.moveTo($("button1").boxObject.screenX + 10, $("button1").boxObject.screenY + 12);
checkCoords(popup, button1rect.left + 10, button1rect.top + 12, "move to button1 screen with offset");
popup.moveToAnchor($("button1"), "after_start", 1, 2);
checkCoords(popup, button1rect.left + 1, button1rect.bottom + 2, "move button2 after screen");
popup.hidePopup();
}
function checkCoords(popup, expectedx, expectedy, testid)
{
var rect = popup.getBoundingClientRect();
is(Math.round(rect.left), Math.round(expectedx), testid + " left");
is(Math.round(rect.top), Math.round(expectedy), testid + " top");
}
SimpleTest.waitForFocus(runTest);
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>
|