1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_panelfrommenu.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 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 +<window title="Open panel from menuitem" 1.9 + onload="setTimeout(runTests, 0);" 1.10 + xmlns:html="http://www.w3.org/1999/xhtml" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.15 + 1.16 +<!-- 1.17 + This test does the following: 1.18 + 1. Opens the menu, causing the popupshown event to fire, which will call menuOpened. 1.19 + 2. Keyboard events are fired to cause the first item on the menu to be executed. 1.20 + 3. The command event handler for the first menuitem opens the panel. 1.21 + 4. As a menuitem was executed, the menu will roll up, hiding it. 1.22 + 5. The popuphidden event for the menu calls menuClosed which tests the popup states. 1.23 + 6. The panelOpened function tests the popup states again and hides the popup. 1.24 + 7. Once the panel's popuphidden event fires, tests are performed to see if 1.25 + panels inside buttons and toolbarbuttons work. Each is opened and the closed. 1.26 + --> 1.27 + 1.28 +<menu id="menu" onpopupshown="menuOpened()" onpopuphidden="menuClosed();"> 1.29 + <menupopup> 1.30 + <menuitem id="i1" label="One" oncommand="$('panel').openPopup($('menu'), 'after_start');"/> 1.31 + <menuitem id="i2" label="Two"/> 1.32 + </menupopup> 1.33 +</menu> 1.34 + 1.35 +<panel id="hiddenpanel" hidden="true"/> 1.36 + 1.37 +<panel id="panel" onpopupshown="panelOpened()" 1.38 + onpopuphidden="$('button').focus(); $('button').open = true"> 1.39 + <textbox/> 1.40 +</panel> 1.41 + 1.42 +<button id="button" type="panel" label="Button"> 1.43 + <panel onpopupshown="panelOnButtonOpened(this)" 1.44 + onpopuphidden="$('tbutton').open = true;"> 1.45 + <button label="OK" oncommand="this.parentNode.parentNode.open = false"/> 1.46 + </panel> 1.47 +</button> 1.48 + 1.49 +<toolbarbutton id="tbutton" type="panel" label="Toolbarbutton"> 1.50 + <panel onpopupshown="panelOnToolbarbuttonOpened(this)" 1.51 + onpopuphidden="SimpleTest.finish()"> 1.52 + <textbox/> 1.53 + </panel> 1.54 +</toolbarbutton> 1.55 + 1.56 +<script class="testbody" type="application/javascript"> 1.57 +<![CDATA[ 1.58 + 1.59 +SimpleTest.waitForExplicitFinish(); 1.60 + 1.61 +function runTests() 1.62 +{ 1.63 + is($("hiddenpanel").state, "closed", "hidden popup is closed"); 1.64 + 1.65 + var menu = $("menu"); 1.66 + menu.open = true; 1.67 +} 1.68 + 1.69 +function menuOpened() 1.70 +{ 1.71 + synthesizeKey("VK_DOWN", { }); 1.72 + synthesizeKey("VK_RETURN", { }); 1.73 +} 1.74 + 1.75 +function menuClosed() 1.76 +{ 1.77 + // the panel will be open at this point, but the popupshown event 1.78 + // still needs to fire 1.79 + is($("panel").state, "showing", "panel is open after menu hide"); 1.80 + is($("menu").firstChild.state, "closed", "menu is closed after menu hide"); 1.81 +} 1.82 + 1.83 +function panelOpened() 1.84 +{ 1.85 + is($("panel").state, "open", "panel is open"); 1.86 + is($("menu").firstChild.state, "closed", "menu is closed"); 1.87 + $("panel").hidePopup(); 1.88 +} 1.89 + 1.90 +function panelOnButtonOpened(panel) 1.91 +{ 1.92 + is(panel.state, 'open', 'button panel is open'); 1.93 + is(document.activeElement, document.documentElement, "focus blurred on panel from button open"); 1.94 + synthesizeKey("VK_DOWN", { }); 1.95 + is(document.activeElement, document.documentElement, "focus not modified on cursor down from button"); 1.96 + panel.firstChild.doCommand() 1.97 +} 1.98 + 1.99 +function panelOnToolbarbuttonOpened(panel) 1.100 +{ 1.101 + is(panel.state, 'open', 'toolbarbutton panel is open'); 1.102 + is(document.activeElement, document.documentElement, "focus blurred on panel from toolbarbutton open"); 1.103 + panel.firstChild.focus(); 1.104 + synthesizeKey("VK_DOWN", { }); 1.105 + is(document.activeElement, panel.firstChild.inputField, "focus not modified on cursor down from toolbarbutton"); 1.106 + panel.parentNode.open = false; 1.107 +} 1.108 + 1.109 +]]> 1.110 +</script> 1.111 + 1.112 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.113 +<p id="display"> 1.114 +</p> 1.115 +<div id="content" style="display: none"> 1.116 +</div> 1.117 +<pre id="test"> 1.118 +</pre> 1.119 +</body> 1.120 + 1.121 +</window>