1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_menu_anchored.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 1.7 +<!-- 1.8 + Test for menus with the anchor attribute set 1.9 + --> 1.10 +<window title="Anchored Menus Test" 1.11 + align="start" 1.12 + onload="setTimeout(runTest, 0,'tb1');" 1.13 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.14 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.15 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.16 + <script type="application/javascript" src="xul_selectcontrol.js"/> 1.17 + 1.18 +<hbox> 1.19 + 1.20 +<toolbarbutton id="tb1" type="menu-button" label="Open" anchor="dropmarker"> 1.21 + <menupopup id="popup1" 1.22 + onpopupshown="checkPopup(this, document.getAnonymousElementByAttribute(this.parentNode, 'anonid', 'dropmarker'))" 1.23 + onpopuphidden="runTest('tb2')"> 1.24 + <menuitem label="Item"/> 1.25 + </menupopup> 1.26 +</toolbarbutton> 1.27 + 1.28 +<toolbarbutton id="tb2" type="menu-button" label="Open" anchor="someanchor"> 1.29 + <menupopup id="popup2" onpopupshown="checkPopup(this, $('someanchor'))" onpopuphidden="runTest('tb3')"> 1.30 + <menuitem label="Item"/> 1.31 + </menupopup> 1.32 +</toolbarbutton> 1.33 + 1.34 +<toolbarbutton id="tb3" type="menu-button" label="Open" anchor="noexist"> 1.35 + <menupopup id="popup3" onpopupshown="checkPopup(this, this.parentNode)" onpopuphidden="SimpleTest.finish()"> 1.36 + <menuitem label="Item"/> 1.37 + </menupopup> 1.38 +</toolbarbutton> 1.39 + 1.40 +</hbox> 1.41 + 1.42 +<hbox pack="end" width="180"> 1.43 + <button id="someanchor" label="Anchor"/> 1.44 +</hbox> 1.45 + 1.46 +<!-- test results are displayed in the html:body --> 1.47 +<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> 1.48 + 1.49 +<script type="application/javascript"><![CDATA[ 1.50 + 1.51 +function runTest(menuid) 1.52 +{ 1.53 + let menu = $(menuid); 1.54 + let dropmarker = document.getAnonymousElementByAttribute(menu, "anonid", "dropmarker"); 1.55 + 1.56 + synthesizeMouseAtCenter(dropmarker, { }); 1.57 +} 1.58 + 1.59 +function isWithinHalfPixel(a, b) 1.60 +{ 1.61 + return Math.abs(a - b) <= 0.5; 1.62 +} 1.63 + 1.64 +function checkPopup(popup, anchor) 1.65 +{ 1.66 + let popupRect = popup.getBoundingClientRect(); 1.67 + let anchorRect = anchor.getBoundingClientRect(); 1.68 + 1.69 + ok(isWithinHalfPixel(popupRect.left, anchorRect.left), popup.id + " left"); 1.70 + ok(isWithinHalfPixel(popupRect.top, anchorRect.bottom), popup.id + " top"); 1.71 + 1.72 + popup.hidePopup(); 1.73 +} 1.74 + 1.75 +SimpleTest.waitForExplicitFinish(); 1.76 + 1.77 +]]> 1.78 +</script> 1.79 + 1.80 +</window>