summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/chrome/test_panelfrommenu.xhtml
blob: 4a00dc58aba17164460dc3f96ee3196cae464b29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>

<window title="Open panel from menuitem"
  onload="setTimeout(runTests, 0);"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  xmlns:html="http://www.w3.org/1999/xhtml">

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>

<!--
  This test does the following:
   1. Opens the menu, causing the popupshown event to fire, which will call menuOpened.
   2. Keyboard events are fired to cause the first item on the menu to be executed.
   3. The command event handler for the first menuitem opens the panel.
   4. As a menuitem was executed, the menu will roll up, hiding it.
   5. The popuphidden event for the menu calls menuClosed which tests the popup states.
   6. The panelOpened function tests the popup states again and hides the popup.
   7. Once the panel's popuphidden event fires, tests are performed to see if
      panels inside buttons and toolbarbuttons work. Each is opened and the closed.
  -->

<menu id="menu" onpopupshown="menuOpened()" onpopuphidden="menuClosed();">
  <menupopup>
    <menuitem id="i1" label="One" oncommand="$('panel').openPopup($('menu'), 'after_start');"/>
    <menuitem id="i2" label="Two"/>
  </menupopup>
</menu>

<panel id="hiddenpanel" hidden="true"/>

<panel id="panel" onpopupshown="panelOpened()"
                  onpopuphidden="$('button').focus(); $('button').open = true">
  <html:input/>
</panel>

<button id="button" type="menu" label="Button">
  <panel onpopupshown="panelOnButtonOpened(this)"
         onpopuphidden="$('tbutton').open = true;">
    <button label="OK" oncommand="this.parentNode.parentNode.open = false"/>
  </panel>
</button>

<toolbarbutton id="tbutton" type="menu" label="Toolbarbutton">
  <panel onpopupshown="panelOnToolbarbuttonOpened(this)"
         onpopuphidden="SimpleTest.finish()">
    <html:input/>
  </panel>
</toolbarbutton>

<script class="testbody" type="application/javascript">
<![CDATA[

SimpleTest.waitForExplicitFinish();

function runTests()
{
  is($("hiddenpanel").state, "closed", "hidden popup is closed");

  var menu = $("menu");
  menu.open = true;
}

function menuOpened()
{
  synthesizeKey("KEY_ArrowDown");
  synthesizeKey("KEY_Enter");
}

function menuClosed()
{
  // the panel will be open at this point, but the popupshown event
  // still needs to fire
  is($("panel").state, "showing", "panel is open after menu hide");
  is($("menu").menupopup.state, "closed", "menu is closed after menu hide");
}

function panelOpened()
{
  is($("panel").state, "open", "panel is open");
  is($("menu").menupopup.state, "closed", "menu is closed");
  $("panel").hidePopup();
}

function panelOnButtonOpened(panel)
{
  is(panel.state, 'open', 'button panel is open');
  is(document.activeElement, document.documentElement, "focus blurred on panel from button open");
  synthesizeKey("KEY_ArrowDown");
  is(document.activeElement, document.documentElement, "focus not modified on cursor down from button");
  panel.firstChild.doCommand()
}

function panelOnToolbarbuttonOpened(panel)
{
  is(panel.state, 'open', 'toolbarbutton panel is open');
  is(document.activeElement, document.documentElement, "focus blurred on panel from toolbarbutton open");
  panel.firstChild.focus();
  synthesizeKey("KEY_ArrowDown");
  is(document.activeElement, panel.firstChild, "focus not modified on cursor down from toolbarbutton");
  panel.parentNode.open = false;
}

]]>
</script>

<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>

</window>