|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 |
|
4 <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
5 |
|
6 <script type="application/javascript" |
|
7 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
|
8 |
|
9 <menupopup id="popup" onpopupshowing="if (isSecondTest) popupShowing(event)" onpopupshown="popupShown()" |
|
10 onpopuphidden="nextTest()"> |
|
11 <menuitem label="One"/> |
|
12 <menuitem label="Two"/> |
|
13 </menupopup> |
|
14 |
|
15 <button id="button" label="OK" popup="popup"/> |
|
16 |
|
17 <script class="testbody" type="application/javascript"> |
|
18 <![CDATA[ |
|
19 |
|
20 var isSecondTest = false; |
|
21 |
|
22 function openPopup() |
|
23 { |
|
24 document.getElementById("popup").openPopup(parent.document.getElementById("outerbutton"), "after_start", 3, 1); |
|
25 } |
|
26 |
|
27 function popupShowing(event) |
|
28 { |
|
29 var buttonrect = document.getElementById("button").getBoundingClientRect(); |
|
30 parent.opener.wrappedJSObject.SimpleTest.is(event.clientX, buttonrect.left + 6, "popup clientX with mouse"); |
|
31 parent.opener.wrappedJSObject.SimpleTest.is(event.clientY, buttonrect.top + 6, "popup clientY with mouse"); |
|
32 } |
|
33 |
|
34 function popupShown() |
|
35 { |
|
36 var left, top; |
|
37 var popuprect = document.getElementById("popup").getBoundingClientRect(); |
|
38 if (isSecondTest) { |
|
39 var buttonrect = document.getElementById("button").getBoundingClientRect(); |
|
40 left = buttonrect.left + 6; |
|
41 top = buttonrect.top + 6; |
|
42 } |
|
43 else { |
|
44 var iframerect = parent.document.getElementById("frame").getBoundingClientRect(); |
|
45 var buttonrect = parent.document.getElementById("outerbutton").getBoundingClientRect(); |
|
46 |
|
47 // The popup should appear anchored on the bottom left edge of the button, however |
|
48 // the client rectangle is relative to the iframe's document. Thus the coordinates |
|
49 // are: |
|
50 // left = iframe's left - anchor button's left - 3 pixel offset passed to openPopup + |
|
51 // iframe border (17px) + iframe padding (0) |
|
52 // top = iframe's top - anchor button's bottom - 1 pixel offset passed to openPopup + |
|
53 // iframe border (0) + iframe padding (3px); |
|
54 left = -(Math.round(iframerect.left) - Math.round(buttonrect.left) + 14); |
|
55 top = -(Math.round(iframerect.top) - Math.round(buttonrect.bottom) + 2); |
|
56 } |
|
57 |
|
58 var testid = isSecondTest ? "with mouse" : "anchored to parent frame"; |
|
59 parent.opener.wrappedJSObject.SimpleTest.is(Math.round(popuprect.left), left, "popup left " + testid); |
|
60 parent.opener.wrappedJSObject.SimpleTest.is(Math.round(popuprect.top), top, "popup top " + testid); |
|
61 |
|
62 document.getElementById("popup").hidePopup(); |
|
63 } |
|
64 |
|
65 function nextTest() |
|
66 { |
|
67 if (isSecondTest) { |
|
68 parent.opener.wrappedJSObject.SimpleTest.finish(); |
|
69 parent.close(); |
|
70 } |
|
71 else { |
|
72 // this second test ensures that the popupshowing coordinates when a popup in |
|
73 // a frame is opened are correct |
|
74 isSecondTest = true; |
|
75 synthesizeMouse(document.getElementById("button"), 6, 6, { }); |
|
76 } |
|
77 } |
|
78 |
|
79 ]]> |
|
80 </script> |
|
81 |
|
82 </page> |