PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/toolkit/content/tests/chrome/test_panelfrommenu.xul

http://github.com/zpao/v8monkey
Unknown | 118 lines | 98 code | 20 blank | 0 comment | 0 complexity | 53dd259448d18afa697688d3e4ecc9b4 MD5 | raw file
  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<window title="Open panel from menuitem"
  6  onload="setTimeout(runTests, 0);"
  7  xmlns:html="http://www.w3.org/1999/xhtml"
  8  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  9
 10  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
 11  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      
 12
 13<!--
 14  This test does the following:
 15   1. Opens the menu, causing the popupshown event to fire, which will call menuOpened.
 16   2. Keyboard events are fired to cause the first item on the menu to be executed.
 17   3. The command event handler for the first menuitem opens the panel.
 18   4. As a menuitem was executed, the menu will roll up, hiding it.
 19   5. The popuphidden event for the menu calls menuClosed which tests the popup states.
 20   6. The panelOpened function tests the popup states again and hides the popup.
 21   7. Once the panel's popuphidden event fires, tests are performed to see if
 22      panels inside buttons and toolbarbuttons work. Each is opened and the closed.
 23  -->
 24
 25<menu id="menu" onpopupshown="menuOpened()" onpopuphidden="menuClosed();">
 26  <menupopup>
 27    <menuitem id="i1" label="One" oncommand="$('panel').openPopup($('menu'), 'after_start');"/>
 28    <menuitem id="i2" label="Two"/>
 29  </menupopup>
 30</menu>
 31
 32<panel id="hiddenpanel" hidden="true"/>
 33
 34<panel id="panel" onpopupshown="panelOpened()"
 35                  onpopuphidden="$('button').focus(); $('button').open = true">
 36  <textbox/>
 37</panel>
 38
 39<button id="button" type="panel" label="Button">
 40  <panel onpopupshown="panelOnButtonOpened(this)"
 41         onpopuphidden="$('tbutton').open = true;">
 42    <button label="OK" oncommand="this.parentNode.parentNode.open = false"/>
 43  </panel>
 44</button>
 45
 46<toolbarbutton id="tbutton" type="panel" label="Toolbarbutton">
 47  <panel onpopupshown="panelOnToolbarbuttonOpened(this)"
 48         onpopuphidden="SimpleTest.finish()">
 49    <textbox/>
 50  </panel>
 51</toolbarbutton>
 52
 53<script class="testbody" type="application/javascript">
 54<![CDATA[
 55
 56SimpleTest.waitForExplicitFinish();
 57
 58function runTests()
 59{
 60  is($("hiddenpanel").state, "closed", "hidden popup is closed");
 61
 62  var menu = $("menu");
 63  menu.open = true;
 64}
 65
 66function menuOpened()
 67{
 68  synthesizeKey("VK_DOWN", { });
 69  synthesizeKey("VK_ENTER", { });
 70}
 71
 72function menuClosed()
 73{
 74  // the panel will be open at this point, but the popupshown event
 75  // still needs to fire
 76  is($("panel").state, "showing", "panel is open after menu hide");
 77  is($("menu").firstChild.state, "closed", "menu is closed after menu hide");
 78}
 79
 80function panelOpened()
 81{
 82  is($("panel").state, "open", "panel is open");
 83  is($("menu").firstChild.state, "closed", "menu is closed");
 84  $("panel").hidePopup();
 85}
 86
 87function panelOnButtonOpened(panel)
 88{
 89  is(panel.state, 'open', 'button panel is open');
 90  is(document.activeElement, document.documentElement, "focus blurred on panel from button open");
 91  synthesizeKey("VK_DOWN", { });
 92  is(document.activeElement, document.documentElement, "focus not modified on cursor down from button");
 93  panel.firstChild.doCommand()
 94}
 95
 96function panelOnToolbarbuttonOpened(panel)
 97{
 98  is(panel.state, 'open', 'toolbarbutton panel is open');
 99  is(document.activeElement, document.documentElement, "focus blurred on panel from toolbarbutton open");
100  panel.firstChild.focus();
101  synthesizeKey("VK_DOWN", { });
102  is(document.activeElement, panel.firstChild.inputField, "focus not modified on cursor down from toolbarbutton");
103  panel.parentNode.open = false;
104}
105
106]]>
107</script>
108
109<body xmlns="http://www.w3.org/1999/xhtml">
110<p id="display">
111</p>
112<div id="content" style="display: none">
113</div>
114<pre id="test">
115</pre>
116</body>
117
118</window>