summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/chrome/test_closemenu_attribute.xul
blob: c1e93734fc06fd8edaff78bf787632c140f382c2 (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
<?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="Menu closemenu Attribute Tests"
  onload="setTimeout(nextTest, 0);"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

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

<button id="menu" type="menu" label="Menu" onpopuphidden="popupHidden(event)">
  <menupopup id="p1" onpopupshown="if (event.target == this) this.firstChild.open = true">
    <menu id="l1" label="One">
      <menupopup id="p2" onpopupshown="if (event.target == this) this.firstChild.open = true">
        <menu id="l2" label="Two">
          <menupopup id="p3" onpopupshown="executeMenuItem()">
            <menuitem id="l3" label="Three"/>
          </menupopup>
        </menu>
      </menupopup>
    </menu>
  </menupopup>
</button>

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

SimpleTest.waitForExplicitFinish();

var gExpectedId = "p3";
var gMode = -1;
var gModes = ["", "auto", "single", "none"];

function nextTest()
{
  gMode++;
  if (gModes[gMode] != "none")
    gExpectedId = "p3";

  if (gMode != 0)
    $("l3").setAttribute("closemenu", gModes[gMode]);
  if (gModes[gMode] == "none")
    $("l2").open = true;
  else
    $("menu").open = true;
}

function executeMenuItem()
{
  synthesizeKey("VK_DOWN", { });
  synthesizeKey("VK_RETURN", { });
  // after a couple of seconds, end the test, as the 'none' closemenu value
  // should not hide any popups
  if (gModes[gMode] == "none")
    setTimeout(function() { $("menu").open = false; }, 2000);
}

function popupHidden(event)
{
  if (gModes[gMode] == "none") {
    if (event.target.id == "p1")
      SimpleTest.finish()
    return;
  }

  is(event.target.id, gExpectedId,
     "Expected event " + gModes[gMode] + " " + gExpectedId);

  gExpectedId = "";
  if (event.target.id == "p3") {
    if (gModes[gMode] == "" || gModes[gMode] == "auto")
      gExpectedId = "p2";
  }
  else if (event.target.id == "p2") {
    if (gModes[gMode] == "" || gModes[gMode] == "auto")
      gExpectedId = "p1";
  }

  if (!gExpectedId)
    nextTest();
}

]]>
</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>