|
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 Test for menus with the anchor attribute set |
|
6 --> |
|
7 <window title="Anchored Menus Test" |
|
8 align="start" |
|
9 onload="setTimeout(runTest, 0,'tb1');" |
|
10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
12 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
13 <script type="application/javascript" src="xul_selectcontrol.js"/> |
|
14 |
|
15 <hbox> |
|
16 |
|
17 <toolbarbutton id="tb1" type="menu-button" label="Open" anchor="dropmarker"> |
|
18 <menupopup id="popup1" |
|
19 onpopupshown="checkPopup(this, document.getAnonymousElementByAttribute(this.parentNode, 'anonid', 'dropmarker'))" |
|
20 onpopuphidden="runTest('tb2')"> |
|
21 <menuitem label="Item"/> |
|
22 </menupopup> |
|
23 </toolbarbutton> |
|
24 |
|
25 <toolbarbutton id="tb2" type="menu-button" label="Open" anchor="someanchor"> |
|
26 <menupopup id="popup2" onpopupshown="checkPopup(this, $('someanchor'))" onpopuphidden="runTest('tb3')"> |
|
27 <menuitem label="Item"/> |
|
28 </menupopup> |
|
29 </toolbarbutton> |
|
30 |
|
31 <toolbarbutton id="tb3" type="menu-button" label="Open" anchor="noexist"> |
|
32 <menupopup id="popup3" onpopupshown="checkPopup(this, this.parentNode)" onpopuphidden="SimpleTest.finish()"> |
|
33 <menuitem label="Item"/> |
|
34 </menupopup> |
|
35 </toolbarbutton> |
|
36 |
|
37 </hbox> |
|
38 |
|
39 <hbox pack="end" width="180"> |
|
40 <button id="someanchor" label="Anchor"/> |
|
41 </hbox> |
|
42 |
|
43 <!-- test results are displayed in the html:body --> |
|
44 <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> |
|
45 |
|
46 <script type="application/javascript"><![CDATA[ |
|
47 |
|
48 function runTest(menuid) |
|
49 { |
|
50 let menu = $(menuid); |
|
51 let dropmarker = document.getAnonymousElementByAttribute(menu, "anonid", "dropmarker"); |
|
52 |
|
53 synthesizeMouseAtCenter(dropmarker, { }); |
|
54 } |
|
55 |
|
56 function isWithinHalfPixel(a, b) |
|
57 { |
|
58 return Math.abs(a - b) <= 0.5; |
|
59 } |
|
60 |
|
61 function checkPopup(popup, anchor) |
|
62 { |
|
63 let popupRect = popup.getBoundingClientRect(); |
|
64 let anchorRect = anchor.getBoundingClientRect(); |
|
65 |
|
66 ok(isWithinHalfPixel(popupRect.left, anchorRect.left), popup.id + " left"); |
|
67 ok(isWithinHalfPixel(popupRect.top, anchorRect.bottom), popup.id + " top"); |
|
68 |
|
69 popup.hidePopup(); |
|
70 } |
|
71 |
|
72 SimpleTest.waitForExplicitFinish(); |
|
73 |
|
74 ]]> |
|
75 </script> |
|
76 |
|
77 </window> |