PageRenderTime 36ms CodeModel.GetById 22ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/toolkit/content/tests/widgets/window_menubar.xul

http://github.com/zpao/v8monkey
Unknown | 702 lines | 688 code | 14 blank | 0 comment | 0 complexity | d1e9575a2ed1dec73de09ea18de76749 MD5 | raw file
  1<?xml version="1.0"?>
  2<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3
  4<!-- the condition in the focus event handler is because pressing Tab
  5     unfocuses and refocuses the window on Windows -->
  6
  7<window title="Popup Tests"
  8  xmlns:html="http://www.w3.org/1999/xhtml"
  9  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 10
 11  <title>Popup Tests</title>
 12  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>      
 13  <script type="application/javascript" src="popup_shared.js"></script>      
 14
 15<!--
 16  Need to investigate these tests a bit more. Some of the accessibility events
 17  are firing multiple times or in different orders in different circumstances.
 18  Note that this was also the case before bug 279703.
 19  -->
 20
 21<hbox style="margin-left: 275px; margin-top: 275px;">
 22<menubar id="menubar">
 23  <menu id="filemenu" label="File" accesskey="F">
 24    <menupopup id="filepopup">
 25      <menuitem id="item1" label="Open" accesskey="O"/>
 26      <menuitem id="item2" label="Save" accesskey="S"/>
 27      <menuitem id="item3" label="Close" accesskey="C"/>
 28    </menupopup>
 29  </menu>
 30  <menu id="secretmenu" label="Secret Menu" accesskey="S" disabled="true">
 31    <menupopup>
 32      <menuitem label="Secret Command" accesskey="S"/>
 33    </menupopup>
 34  </menu>
 35  <menu id="editmenu" label="Edit" accesskey="E">
 36    <menupopup id="editpopup">
 37      <menuitem id="cut" label="Cut" accesskey="t" disabled="true"/>
 38      <menuitem id="copy" label="Copy" accesskey="C"/>
 39      <menuitem id="paste" label="Paste" accesskey="P"/>
 40    </menupopup>
 41  </menu>
 42  <menu id="viewmenu" label="View" accesskey="V">
 43    <menupopup id="viewpopup">
 44      <menu id="toolbar" label="Toolbar" accesskey="T">
 45        <menupopup id="toolbarpopup">
 46          <menuitem id="navigation" label="Navigation" accesskey="N" disabled="true"/>
 47          <menuitem label="Bookmarks" accesskey="B" disabled="true"/>
 48        </menupopup>
 49      </menu>
 50      <menuitem label="Status Bar" accesskey="S"/>
 51      <menu label="Sidebar" accesskey="d">
 52        <menupopup>
 53          <menuitem label="Bookmarks" accesskey="B"/>
 54          <menuitem label="History" accesskey="H"/>
 55        </menupopup>
 56      </menu>
 57    </menupopup>
 58  </menu>
 59  <menu id="helpmenu" label="Help" accesskey="H">
 60    <menupopup id="helppopup" >
 61      <label value="Unselectable"/>
 62      <menuitem id="contents" label="Contents" accesskey="C"/>
 63      <menuitem label="More Info" accesskey="I"/>
 64      <menuitem id="amenu" label="A Menu" accesskey="M"/>
 65      <menuitem label="Another Menu"/>
 66      <menuitem id="one" label="One"/>
 67      <menu id="only" label="Only Menu">
 68        <menupopup>
 69          <menuitem label="Test Submenu"/>
 70        </menupopup>
 71      </menu>
 72      <menuitem label="Second Menu"/>
 73      <menuitem id="other" disabled="true" label="Other Menu"/>
 74      <menuitem id="third" label="Third Menu"/>
 75      <menuitem label="One Other Menu"/>
 76      <label value="Unselectable"/>
 77      <menuitem id="about" label="About" accesskey="A"/>
 78    </menupopup>
 79  </menu>
 80</menubar>
 81</hbox>
 82
 83<script class="testbody" type="application/javascript">
 84<![CDATA[
 85
 86window.opener.SimpleTest.waitForFocus(function () {
 87  gFilePopup = document.getElementById("filepopup");
 88  var filemenu = document.getElementById("filemenu");
 89  filemenu.focus();
 90  is(filemenu.openedWithKey, false, "initial openedWithKey");
 91  startPopupTests(popupTests);
 92}, window);
 93
 94var popupTests = [
 95{
 96  testname: "press on menu",
 97  events: [ "popupshowing filepopup", "DOMMenuBarActive menubar",
 98            "DOMMenuItemActive filemenu", "popupshown filepopup" ],
 99  test: function() { synthesizeMouse(document.getElementById("filemenu"), 8, 8, { }); },
100  result: function (testname) {
101    checkActive(gFilePopup, "", testname);
102    checkOpen("filemenu", testname);
103    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
104  }
105},
106{
107  // check that pressing cursor down while there is no selection
108  // highlights the first item
109  testname: "cursor down no selection",
110  events: [ "DOMMenuItemActive item1" ],
111  test: function() { synthesizeKey("VK_DOWN", { }); },
112  result: function(testname) { checkActive(gFilePopup, "item1", testname); }
113},
114{
115  // check that pressing cursor up wraps and highlights the last item
116  testname: "cursor up wrap",
117  events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive item3" ],
118  test: function() { synthesizeKey("VK_UP", { }); },
119  result: function(testname) { checkActive(gFilePopup, "item3", testname); }
120},
121{
122  // check that pressing cursor down wraps and highlights the first item
123  testname: "cursor down wrap",
124  events: [ "DOMMenuItemInactive item3", "DOMMenuItemActive item1" ],
125  test: function() { synthesizeKey("VK_DOWN", { }); },
126  result: function(testname) { checkActive(gFilePopup, "item1", testname); }
127},
128{
129  // check that pressing cursor down highlights the second item
130  testname: "cursor down",
131  events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive item2" ],
132  test: function() { synthesizeKey("VK_DOWN", { }); },
133  result: function(testname) { checkActive(gFilePopup, "item2", testname); }
134},
135{
136  // check that pressing cursor up highlights the second item
137  testname: "cursor up",
138  events: [ "DOMMenuItemInactive item2", "DOMMenuItemActive item1" ],
139  test: function() { synthesizeKey("VK_UP", { }); },
140  result: function(testname) { checkActive(gFilePopup, "item1", testname); }
141},
142
143{
144  // cursor right should skip the disabled menu and move to the edit menu
145  testname: "cursor right skip disabled",
146  events: function() {
147    var elist = [
148      // the file menu gets deactivated, the file menu gets hidden, then
149      // the edit menu is activated
150      "DOMMenuItemInactive filemenu", "DOMMenuItemActive editmenu",
151      "popuphiding filepopup", "popuphidden filepopup",
152      // the popupshowing event gets fired when showing the edit menu.
153      // The item from the file menu doesn't get deactivated until the
154      // next item needs to be selected
155      "popupshowing editpopup", "DOMMenuItemInactive item1",
156      // not sure why the menu inactivated event is firing so late
157      "DOMMenuInactive filepopup"
158    ];
159    // finally, the first item is activated and popupshown is fired.
160    // On Windows, don't skip disabled items.
161    if (navigator.platform.indexOf("Win") == 0)
162      elist.push("DOMMenuItemActive cut");
163    else
164      elist.push("DOMMenuItemActive copy");
165    elist.push("popupshown editpopup");
166    return elist;
167  },
168  test: function() { synthesizeKey("VK_RIGHT", { }); },
169  result: function(testname) {
170    var expected = (navigator.platform.indexOf("Win") == 0) ? "cut" : "copy";
171    checkActive(document.getElementById("editpopup"), expected, testname);
172    checkClosed("filemenu", testname);
173    checkOpen("editmenu", testname);
174    is(document.getElementById("editmenu").openedWithKey, false, testname + " openedWithKey");
175  }
176},
177{
178  // on Windows, a disabled item is selected, so pressing ENTER should close
179  // the menu but not fire a command event
180  testname: "enter on disabled",
181  events: function() {
182    if (navigator.platform.indexOf("Win") == 0)
183      return [ "popuphiding editpopup", "popuphidden editpopup",
184               "DOMMenuItemInactive cut", "DOMMenuInactive editpopup",
185               "DOMMenuBarInactive menubar",
186               "DOMMenuItemInactive editmenu", "DOMMenuItemInactive editmenu" ];
187    else
188      return [ "DOMMenuItemInactive copy", "DOMMenuInactive editpopup",
189               "DOMMenuBarInactive menubar",
190               "DOMMenuItemInactive editmenu", "DOMMenuItemInactive editmenu",
191               "command copy", "popuphiding editpopup", "popuphidden editpopup",
192               "DOMMenuItemInactive copy" ];
193  },
194  test: function() { synthesizeKey("VK_ENTER", { }); },
195  result: function(testname) {
196    checkClosed("editmenu", testname);
197    is(document.getElementById("editmenu").openedWithKey, false, testname + " openedWithKey");
198  }
199},
200{
201  // pressing Alt + a key should open the corresponding menu
202  testname: "open with accelerator",
203  events: function() {
204    return [ "DOMMenuBarActive menubar",
205             "popupshowing viewpopup", "DOMMenuItemActive viewmenu",
206             "DOMMenuItemActive toolbar", "popupshown viewpopup" ];
207  },
208  test: function() { synthesizeKey("V", { altKey: true }); },
209  result: function(testname) {
210    checkOpen("viewmenu", testname);
211    is(document.getElementById("viewmenu").openedWithKey, true, testname + " openedWithKey");
212  }
213},
214{
215  // open the submenu with the cursor right key
216  testname: "open submenu with cursor right",
217  events: function() {
218    // on Windows, the disabled 'navigation' item can stll be highlihted
219    if (navigator.platform.indexOf("Win") == 0)
220      return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
221               "popupshown toolbarpopup" ];
222    else
223      return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
224  },
225  test: function() { synthesizeKey("VK_RIGHT", { }); },
226  result: function(testname) {
227    checkOpen("viewmenu", testname);
228    checkOpen("toolbar", testname);
229  }
230},
231{
232  // close the submenu with the cursor left key
233  testname: "close submenu with cursor left",
234  events: function() {
235    if (navigator.platform.indexOf("Win") == 0)
236      return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
237               "DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
238               "DOMMenuItemActive toolbar" ];
239    else
240      return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
241               "DOMMenuInactive toolbarpopup",
242               "DOMMenuItemActive toolbar" ];
243  },
244  test: function() { synthesizeKey("VK_LEFT", { }); },
245  result: function(testname) {
246    checkOpen("viewmenu", testname);
247    checkClosed("toolbar", testname);
248  }
249},
250{
251  // open the submenu with the enter key
252  testname: "open submenu with enter",
253  events: function() {
254    // on Windows, the disabled 'navigation' item can stll be highlihted
255    if (navigator.platform.indexOf("Win") == 0)
256      return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
257               "popupshown toolbarpopup" ];
258    else
259      return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
260  },
261  test: function() { synthesizeKey("VK_ENTER", { }); },
262  result: function(testname) {
263    checkOpen("viewmenu", testname);
264    checkOpen("toolbar", testname);
265  },
266},
267{
268  // close the submenu with the escape key
269  testname: "close submenu with escape",
270  events: function() {
271    if (navigator.platform.indexOf("Win") == 0)
272      return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
273               "DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
274               "DOMMenuItemActive toolbar" ];
275    else
276      return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
277               "DOMMenuInactive toolbarpopup",
278               "DOMMenuItemActive toolbar" ];
279  },
280  test: function() { synthesizeKey("VK_ESCAPE", { }); },
281  result: function(testname) {
282    checkOpen("viewmenu", testname);
283    checkClosed("toolbar", testname);
284  },
285},
286{
287  // close the main menu with the escape key
288  testname: "close menubar menu with escape",
289  events: [ "popuphiding viewpopup", "popuphidden viewpopup",
290            "DOMMenuItemInactive toolbar", "DOMMenuInactive viewpopup",
291            "DOMMenuBarInactive menubar",
292            "DOMMenuItemInactive viewmenu" ],
293  test: function() { synthesizeKey("VK_ESCAPE", { }); },
294  result: function(testname) { checkClosed("viewmenu", testname); },
295},
296{
297  // on Windows, pressing Alt should highlight the first menu but not open it
298  testname: "alt to activate menubar",
299  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
300  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
301  test: function() { synthesizeKey("VK_ALT", { }); },
302  result: function(testname) {
303    is(document.getElementById("filemenu").openedWithKey, true, testname + " openedWithKey");
304    checkClosed("filemenu", testname);
305  },
306},
307{
308  // pressing cursor left should select the previous menu but not open it
309  testname: "cursor left on active menubar",
310  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
311  events: [ "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu" ],
312  test: function() { synthesizeKey("VK_LEFT", { }); },
313  result: function(testname) { checkClosed("helpmenu", testname); },
314},
315{
316  // pressing cursor right should select the previous menu but not open it
317  testname: "cursor right on active menubar",
318  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
319  events: [ "DOMMenuItemInactive helpmenu", "DOMMenuItemActive filemenu" ],
320  test: function() { synthesizeKey("VK_RIGHT", { }); },
321  result: function(testname) { checkClosed("filemenu", testname); },
322},
323{
324  // pressing a character should act as an accelerator and open the menu
325  testname: "accelerator on active menubar",
326  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
327  events: [ "popupshowing helppopup",
328            "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu",
329            "DOMMenuItemActive contents", "popupshown helppopup" ],
330  test: function() { synthesizeKey("H", { }); },
331  result: function(testname) {
332    checkOpen("helpmenu", testname);
333    is(document.getElementById("helpmenu").openedWithKey, true, testname + " openedWithKey");
334  },
335},
336{
337  testname: "open with accelerator again",
338  condition: function() { return (navigator.platform.indexOf("Win") == -1) },
339  events: [ "DOMMenuBarActive menubar", "popupshowing helppopup",
340            "DOMMenuItemActive helpmenu", "DOMMenuItemActive contents",
341            "popupshown helppopup" ],
342  test: function() { synthesizeKey("H", { altKey: true }); },
343  result: function(testname) {
344    checkOpen("helpmenu", testname);
345    is(document.getElementById("helpmenu").openedWithKey, true, testname + " openedWithKey");
346  },
347},
348{
349  // check that pressing cursor up skips non menuitems
350  testname: "cursor up wrap",
351  events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive about" ],
352  test: function() { synthesizeKey("VK_UP", { }); },
353  result: function(testname) { }
354},
355{
356  // check that pressing cursor down skips non menuitems
357  testname: "cursor down wrap",
358  events: [ "DOMMenuItemInactive about", "DOMMenuItemActive contents" ],
359  test: function() { synthesizeKey("VK_DOWN", { }); },
360  result: function(testname) { }
361},
362{
363  // check that pressing a menuitem's accelerator selects it
364  testname: "menuitem accelerator",
365  events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive amenu",
366            "DOMMenuItemInactive amenu", "DOMMenuInactive helppopup",
367            "DOMMenuBarInactive menubar", "DOMMenuItemInactive helpmenu",
368            "DOMMenuItemInactive helpmenu",
369            "command amenu", "popuphiding helppopup", "popuphidden helppopup",
370            "DOMMenuItemInactive amenu",
371           ],
372  test: function() { synthesizeKey("M", { }); },
373  result: function(testname) { checkClosed("helpmenu", testname); }
374},
375{
376  // pressing F10 should highlight the first menu but not open it
377  testname: "F10 to activate menubar",
378  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
379  test: function() { synthesizeKey("VK_F10", { }); },
380  result: function(testname) {
381    is(document.getElementById("filemenu").openedWithKey, true, testname + " openedWithKey");
382    checkClosed("filemenu", testname);
383  },
384},
385{
386  // pressing cursor down should open a menu
387  testname: "cursor down on menu",
388  events: [ 
389            "popupshowing helppopup",
390            "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu",
391            // This is in a different order than the
392            // "accelerator on active menubar" because menus opened from a
393            // shortcut key are fired asynchronously
394            "DOMMenuItemActive contents", "popupshown helppopup" ],
395  test: function() { synthesizeKey("VK_LEFT", { }); synthesizeKey("VK_DOWN", { }); },
396  result: function(testname) {
397    is(document.getElementById("helpmenu").openedWithKey, true, testname + " openedWithKey");
398  }
399},
400{
401  // pressing a letter that doesn't correspond to an accelerator. The menu
402  // should not close because there is more than one item corresponding to
403  // that letter
404  testname: "menuitem with no accelerator",
405  events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive one" ],
406  test: function() { synthesizeKey("O", { }); },
407  result: function(testname) { checkOpen("helpmenu", testname); }
408},
409{
410  // pressing the letter again should select the next one that starts with
411  // that letter
412  testname: "menuitem with no accelerator again",
413  events: [ "DOMMenuItemInactive one", "DOMMenuItemActive only" ],
414  test: function() { synthesizeKey("O", { }); },
415  result: function(testname) {
416    // 'only' is a menu but it should not be open
417    checkOpen("helpmenu", testname);
418    checkClosed("only", testname);
419  }
420},
421{
422  // pressing the letter again when the next item is disabled should still
423  // select the disabled item
424  testname: "menuitem with no accelerator disabled",
425  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
426  events: [ "DOMMenuItemInactive only", "DOMMenuItemActive other" ],
427  test: function() { synthesizeKey("O", { }); },
428  result: function(testname) { }
429},
430{
431  // when only one menuitem starting with that letter exists, it should be
432  // selected and the menu closed
433  testname: "menuitem with no accelerator single",
434  events: function() {
435    var elist = [ "DOMMenuItemInactive other", "DOMMenuItemActive third",
436                  "DOMMenuItemInactive third", "DOMMenuInactive helppopup",
437                  "DOMMenuBarInactive menubar",
438                  "DOMMenuItemInactive helpmenu",
439                  "DOMMenuItemInactive helpmenu",
440                  "command third", "popuphiding helppopup",
441                  "popuphidden helppopup", "DOMMenuItemInactive third",
442                ];
443    if (navigator.platform.indexOf("Win") == -1)
444      elist[0] = "DOMMenuItemInactive only";
445    return elist;
446  },
447  test: function() { synthesizeKey("T", { }); },
448  result: function(testname) { checkClosed("helpmenu", testname); }
449},
450{
451  // pressing F10 should highlight the first menu but not open it
452  testname: "F10 to activate menubar again",
453  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
454  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
455  test: function() { synthesizeKey("VK_F10", { }); },
456  result: function(testname) { checkClosed("filemenu", testname); },
457},
458{
459  // pressing an accelerator for a disabled item should deactivate the menubar
460  testname: "accelerator for disabled menu",
461  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
462  events: [ "DOMMenuItemInactive filemenu", "DOMMenuBarInactive menubar" ],
463  test: function() { synthesizeKey("S", { }); },
464  result: function(testname) {
465    checkClosed("secretmenu", testname);
466    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
467  },
468},
469{
470  testname: "press on disabled menu",
471  test: function() {
472    synthesizeMouse(document.getElementById("secretmenu"), 8, 8, { });
473  },
474  result: function (testname) {
475    checkClosed("secretmenu", testname);
476  }
477},
478{
479  testname: "press on second menu with shift",
480  events: [ "popupshowing editpopup", "DOMMenuBarActive menubar",
481            "DOMMenuItemActive editmenu", "popupshown editpopup" ],
482  test: function() {
483    synthesizeMouse(document.getElementById("editmenu"), 8, 8, { shiftKey : true });
484  },
485  result: function (testname) {
486    checkOpen("editmenu", testname);
487    checkActive(document.getElementById("menubar"), "editmenu", testname);
488  }
489},
490{
491  testname: "press on disabled menuitem",
492  test: function() {
493    synthesizeMouse(document.getElementById("cut"), 8, 8, { });
494  },
495  result: function (testname) {
496    checkOpen("editmenu", testname);
497  }
498},
499{
500  testname: "press on menuitem",
501  events: [ "DOMMenuInactive editpopup",
502            "DOMMenuBarInactive menubar",
503            "DOMMenuItemInactive editmenu",
504            "DOMMenuItemInactive editmenu",
505            "command copy", "popuphiding editpopup", "popuphidden editpopup",
506            "DOMMenuItemInactive copy",
507           ],
508  test: function() {
509    synthesizeMouse(document.getElementById("copy"), 8, 8, { });
510  },
511  result: function (testname) {
512    checkClosed("editmenu", testname);
513  }
514},
515{
516  // this test ensures that the menu can still be opened by clicking after selecting
517  // a menuitem from the menu. See bug 399350.
518  testname: "press on menu after menuitem selected",
519  events: [ "popupshowing editpopup", "DOMMenuBarActive menubar",
520            "DOMMenuItemActive editmenu", "popupshown editpopup" ],
521  test: function() { synthesizeMouse(document.getElementById("editmenu"), 8, 8, { }); },
522  result: function (testname) {
523    checkActive(document.getElementById("editpopup"), "", testname);
524    checkOpen("editmenu", testname);
525  }
526},
527{  // try selecting a different command
528  testname: "press on menuitem again",
529  events: [ "DOMMenuInactive editpopup",
530            "DOMMenuBarInactive menubar",
531            "DOMMenuItemInactive editmenu",
532            "DOMMenuItemInactive editmenu",
533            "command paste", "popuphiding editpopup", "popuphidden editpopup",
534            "DOMMenuItemInactive paste",
535           ],
536  test: function() {
537    synthesizeMouse(document.getElementById("paste"), 8, 8, { });
538  },
539  result: function (testname) {
540    checkClosed("editmenu", testname);
541  }
542},
543{
544  testname: "F10 to activate menubar for tab deactivation",
545  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
546  test: function() { synthesizeKey("VK_F10", { }); },
547},
548{
549  testname: "Deactivate menubar with tab key",
550  events: [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu" ],
551  test: function() { synthesizeKey("VK_TAB", { }); },
552  result: function(testname) {
553    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
554  }
555},
556{
557  testname: "F10 to activate menubar for escape deactivation",
558  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
559  test: function() { synthesizeKey("VK_F10", { }); },
560},
561{
562  testname: "Deactivate menubar with escape key",
563  events: [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu" ],
564  test: function() { synthesizeKey("VK_ESCAPE", { }); },
565  result: function(testname) {
566    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
567  }
568},
569{
570  testname: "F10 to activate menubar for f10 deactivation",
571  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
572  test: function() { synthesizeKey("VK_F10", { }); },
573},
574{
575  testname: "Deactivate menubar with f10 key",
576  events: [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu"  ],
577  test: function() { synthesizeKey("VK_F10", { }); },
578  result: function(testname) {
579    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
580  }
581},
582{
583  testname: "F10 to activate menubar for alt deactivation",
584  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
585  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
586  test: function() { synthesizeKey("VK_F10", { }); },
587},
588{
589  testname: "Deactivate menubar with alt key",
590  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
591  events: [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu"  ],
592  test: function() { synthesizeKey("VK_ALT", { }); },
593  result: function(testname) {
594    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
595  }
596},
597{
598  testname: "Don't activate menubar with mousedown during alt key auto-repeat",
599  test: function() {
600    synthesizeKey("VK_ALT", { type: "keydown" });
601    synthesizeMouse(document.getElementById("menubar"), 8, -30, { type: "mousedown", altKey: true });
602    synthesizeKey("VK_ALT", { type: "keydown" });
603    synthesizeMouse(document.getElementById("menubar"), 8, -30, { type: "mouseup", altKey: true });
604    synthesizeKey("VK_ALT", { type: "keydown" });
605    synthesizeKey("VK_ALT", { type: "keyup" });
606  },
607  result: function (testname) {
608    checkActive(document.getElementById("menubar"), "", testname);
609  }
610},
611
612// Fllowing 4 tests are a test of bug 616797, don't insert any new tests
613// between them.
614{
615  testname: "Open file menu by accelerator",
616  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
617  events: function() {
618    return [ "DOMMenuBarActive menubar", "popupshowing filepopup",
619             "DOMMenuItemActive filemenu", "DOMMenuItemActive item1",
620             "popupshown filepopup" ];
621  },
622  test: function() {
623    synthesizeKey("VK_ALT", { type: "keydown" });
624    synthesizeKey("F", { altKey: true });
625    synthesizeKey("VK_ALT", { type: "keyup" });
626  }
627},
628{
629  testname: "Close file menu by click at outside of popup menu",
630  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
631  events: function() {
632    return [ "popuphiding filepopup", "popuphidden filepopup",
633             "DOMMenuItemInactive item1", "DOMMenuInactive filepopup",
634             "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu",
635             "DOMMenuItemInactive filemenu" ];
636  },
637  test: function() {
638    // XXX hidePopup() causes DOMMenuItemInactive event to be fired twice.
639    document.getElementById("filepopup").hidePopup();
640  }
641},
642{
643  testname: "Alt keydown set focus the menubar",
644  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
645  events: function() {
646    return [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
647  },
648  test: function() {
649    synthesizeKey("VK_ALT", {  });
650  },
651  result: function (testname) {
652    checkClosed("filemenu", testname);
653  }
654},
655{
656  testname: "unset focus the menubar",
657  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
658  events: function() {
659    return [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu" ];
660  },
661  test: function() {
662    synthesizeKey("VK_ALT", {  });
663  }
664},
665
666// bug 625151
667{
668  testname: "Alt key state before deactivating the window shouldn't prevent " +
669            "next Alt key handling",
670  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
671  events: function() {
672    return [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
673  },
674  test: function() {
675    synthesizeKey("VK_ALT", { type: "keydown" });
676    synthesizeKey("VK_TAB", { type: "keydown" }); // cancels the Alt key
677    var thisWindow = window;
678    var newWindow =
679      window.open("data:text/html,", "_blank", "width=100,height=100");
680    newWindow.addEventListener("focus", function () {
681      newWindow.removeEventListener("focus", arguments.callee, false);
682      thisWindow.addEventListener("focus", function () {
683        thisWindow.removeEventListener("focus", arguments.callee, false);
684        setTimeout(function () {
685          synthesizeKey("VK_ALT", { }, thisWindow);
686        }, 0);
687      }, false);
688      newWindow.close();
689      thisWindow.focus();
690      // Note that our window dispatches a hacky key event if IMM is installed
691      // on the system during focus change only if Alt key is pressed.
692      synthesizeKey("`", { type: "keypress" }, thisWindow);
693    }, false);
694  }
695}
696
697];
698
699]]>
700</script>
701
702</window>