summaryrefslogtreecommitdiff
path: root/toolkit/content/tests/widgets/window_menubar.xul
blob: b7669e0b37bda48ef17190ec4c695e623477e17c (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>

<!-- the condition in the focus event handler is because pressing Tab
     unfocuses and refocuses the window on Windows -->

<window title="Popup Tests"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

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

<!--
  Need to investigate these tests a bit more. Some of the accessibility events
  are firing multiple times or in different orders in different circumstances.
  Note that this was also the case before bug 279703.
  -->

<hbox style="margin-left: 275px; margin-top: 275px;">
<menubar id="menubar">
  <menu id="filemenu" label="File" accesskey="F">
    <menupopup id="filepopup">
      <menuitem id="item1" label="Open" accesskey="O"/>
      <menuitem id="item2" label="Save" accesskey="S"/>
      <menuitem id="item3" label="Close" accesskey="C"/>
    </menupopup>
  </menu>
  <menu id="secretmenu" label="Secret Menu" accesskey="S" disabled="true">
    <menupopup>
      <menuitem label="Secret Command" accesskey="S"/>
    </menupopup>
  </menu>
  <menu id="editmenu" label="Edit" accesskey="E">
    <menupopup id="editpopup">
      <menuitem id="cut" label="Cut" accesskey="t" disabled="true"/>
      <menuitem id="copy" label="Copy" accesskey="C"/>
      <menuitem id="paste" label="Paste" accesskey="P"/>
    </menupopup>
  </menu>
  <menu id="viewmenu" label="View" accesskey="V">
    <menupopup id="viewpopup">
      <menu id="toolbar" label="Toolbar" accesskey="T">
        <menupopup id="toolbarpopup">
          <menuitem id="navigation" label="Navigation" accesskey="N" disabled="true"/>
          <menuitem label="Bookmarks" accesskey="B" disabled="true"/>
        </menupopup>
      </menu>
      <menuitem label="Status Bar" accesskey="S"/>
      <menu label="Sidebar" accesskey="d">
        <menupopup>
          <menuitem label="Bookmarks" accesskey="B"/>
          <menuitem label="History" accesskey="H"/>
        </menupopup>
      </menu>
    </menupopup>
  </menu>
  <menu id="helpmenu" label="Help" accesskey="H">
    <menupopup id="helppopup" >
      <label value="Unselectable"/>
      <menuitem id="contents" label="Contents" accesskey="C"/>
      <menuitem label="More Info" accesskey="I"/>
      <menuitem id="amenu" label="A Menu" accesskey="M"/>
      <menuitem label="Another Menu"/>
      <menuitem id="one" label="One"/>
      <menu id="only" label="Only Menu">
        <menupopup>
          <menuitem label="Test Submenu"/>
        </menupopup>
      </menu>
      <menuitem label="Second Menu"/>
      <menuitem id="other" disabled="true" label="Other Menu"/>
      <menuitem id="third" label="Third Menu"/>
      <menuitem label="One Other Menu"/>
      <label value="Unselectable"/>
      <menuitem id="about" label="About" accesskey="A"/>
    </menupopup>
  </menu>
</menubar>
</hbox>

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

window.opener.SimpleTest.waitForFocus(function () {
  gFilePopup = document.getElementById("filepopup");
  var filemenu = document.getElementById("filemenu");
  filemenu.focus();
  is(filemenu.openedWithKey, false, "initial openedWithKey");
  startPopupTests(popupTests);
}, window);

// On Linux, the first menu opens when F10 is pressed, but on other platforms
// the menubar is focused but no menu is opened. This means that different events
// fire.
function pressF10Events()
{
  return navigator.platform.indexOf("Linux") >= 0 ?
    [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu", "popupshowing filepopup", "DOMMenuItemActive item1", "popupshown filepopup"] :
    [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
}

function closeAfterF10Events(extraInactive)
{
  if (navigator.platform.indexOf("Linux") >= 0) {
    var events = [ "popuphiding filepopup", "popuphidden filepopup", "DOMMenuItemInactive item1",
                   "DOMMenuInactive filepopup", "DOMMenuBarInactive menubar",
                   "DOMMenuItemInactive filemenu" ];
    if (extraInactive)
      events.push("DOMMenuItemInactive filemenu");
    return events;
  }

  return [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu" ];
}

var popupTests = [
{
  testname: "press on menu",
  events: [ "popupshowing filepopup", "DOMMenuBarActive menubar",
            "DOMMenuItemActive filemenu", "popupshown filepopup" ],
  test: function() { synthesizeMouse(document.getElementById("filemenu"), 8, 8, { }); },
  result: function (testname) {
    checkActive(gFilePopup, "", testname);
    checkOpen("filemenu", testname);
    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
  }
},
{
  // check that pressing cursor down while there is no selection
  // highlights the first item
  testname: "cursor down no selection",
  events: [ "DOMMenuItemActive item1" ],
  test: function() { sendKey("DOWN"); },
  result: function(testname) { checkActive(gFilePopup, "item1", testname); }
},
{
  // check that pressing cursor up wraps and highlights the last item
  testname: "cursor up wrap",
  events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive item3" ],
  test: function() { sendKey("UP"); },
  result: function(testname) { checkActive(gFilePopup, "item3", testname); }
},
{
  // check that pressing cursor down wraps and highlights the first item
  testname: "cursor down wrap",
  events: [ "DOMMenuItemInactive item3", "DOMMenuItemActive item1" ],
  test: function() { sendKey("DOWN"); },
  result: function(testname) { checkActive(gFilePopup, "item1", testname); }
},
{
  // check that pressing cursor down highlights the second item
  testname: "cursor down",
  events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive item2" ],
  test: function() { sendKey("DOWN"); },
  result: function(testname) { checkActive(gFilePopup, "item2", testname); }
},
{
  // check that pressing cursor up highlights the second item
  testname: "cursor up",
  events: [ "DOMMenuItemInactive item2", "DOMMenuItemActive item1" ],
  test: function() { sendKey("UP"); },
  result: function(testname) { checkActive(gFilePopup, "item1", testname); }
},

{
  // cursor right should skip the disabled menu and move to the edit menu
  testname: "cursor right skip disabled",
  events: function() {
    var elist = [
      // the file menu gets deactivated, the file menu gets hidden, then
      // the edit menu is activated
      "DOMMenuItemInactive filemenu", "DOMMenuItemActive editmenu",
      "popuphiding filepopup", "popuphidden filepopup",
      // the popupshowing event gets fired when showing the edit menu.
      // The item from the file menu doesn't get deactivated until the
      // next item needs to be selected
      "popupshowing editpopup", "DOMMenuItemInactive item1",
      // not sure why the menu inactivated event is firing so late
      "DOMMenuInactive filepopup"
    ];
    // finally, the first item is activated and popupshown is fired.
    // On Windows, don't skip disabled items.
    if (navigator.platform.indexOf("Win") == 0)
      elist.push("DOMMenuItemActive cut");
    else
      elist.push("DOMMenuItemActive copy");
    elist.push("popupshown editpopup");
    return elist;
  },
  test: function() { sendKey("RIGHT"); },
  result: function(testname) {
    var expected = (navigator.platform.indexOf("Win") == 0) ? "cut" : "copy";
    checkActive(document.getElementById("editpopup"), expected, testname);
    checkClosed("filemenu", testname);
    checkOpen("editmenu", testname);
    is(document.getElementById("editmenu").openedWithKey, false, testname + " openedWithKey");
  }
},
{
  // on Windows, a disabled item is selected, so pressing RETURN should close
  // the menu but not fire a command event
  testname: "enter on disabled",
  events: function() {
    if (navigator.platform.indexOf("Win") == 0)
      return [ "popuphiding editpopup", "popuphidden editpopup",
               "DOMMenuItemInactive cut", "DOMMenuInactive editpopup",
               "DOMMenuBarInactive menubar",
               "DOMMenuItemInactive editmenu", "DOMMenuItemInactive editmenu" ];
    else
      return [ "DOMMenuItemInactive copy", "DOMMenuInactive editpopup",
               "DOMMenuBarInactive menubar",
               "DOMMenuItemInactive editmenu", "DOMMenuItemInactive editmenu",
               "command copy", "popuphiding editpopup", "popuphidden editpopup",
               "DOMMenuItemInactive copy" ];
  },
  test: function() { sendKey("RETURN"); },
  result: function(testname) {
    checkClosed("editmenu", testname);
    is(document.getElementById("editmenu").openedWithKey, false, testname + " openedWithKey");
  }
},
{
  // pressing Alt + a key should open the corresponding menu
  testname: "open with accelerator",
  events: function() {
    return [ "DOMMenuBarActive menubar",
             "popupshowing viewpopup", "DOMMenuItemActive viewmenu",
             "DOMMenuItemActive toolbar", "popupshown viewpopup" ];
  },
  test: function() { synthesizeKey("V", { altKey: true }); },
  result: function(testname) {
    checkOpen("viewmenu", testname);
    is(document.getElementById("viewmenu").openedWithKey, true, testname + " openedWithKey");
  }
},
{
  // open the submenu with the cursor right key
  testname: "open submenu with cursor right",
  events: function() {
    // on Windows, the disabled 'navigation' item can stll be highlihted
    if (navigator.platform.indexOf("Win") == 0)
      return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
               "popupshown toolbarpopup" ];
    else
      return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
  },
  test: function() { sendKey("RIGHT"); },
  result: function(testname) {
    checkOpen("viewmenu", testname);
    checkOpen("toolbar", testname);
  }
},
{
  // close the submenu with the cursor left key
  testname: "close submenu with cursor left",
  events: function() {
    if (navigator.platform.indexOf("Win") == 0)
      return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
               "DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
               "DOMMenuItemActive toolbar" ];
    else
      return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
               "DOMMenuInactive toolbarpopup",
               "DOMMenuItemActive toolbar" ];
  },
  test: function() { sendKey("LEFT"); },
  result: function(testname) {
    checkOpen("viewmenu", testname);
    checkClosed("toolbar", testname);
  }
},
{
  // open the submenu with the enter key
  testname: "open submenu with enter",
  events: function() {
    // on Windows, the disabled 'navigation' item can stll be highlighted
    if (navigator.platform.indexOf("Win") == 0)
      return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
               "popupshown toolbarpopup" ];
    else
      return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
  },
  test: function() { sendKey("RETURN"); },
  result: function(testname) {
    checkOpen("viewmenu", testname);
    checkOpen("toolbar", testname);
  },
},
{
  // close the submenu with the escape key
  testname: "close submenu with escape",
  events: function() {
    if (navigator.platform.indexOf("Win") == 0)
      return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
               "DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
               "DOMMenuItemActive toolbar" ];
    else
      return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
               "DOMMenuInactive toolbarpopup",
               "DOMMenuItemActive toolbar" ];
  },
  test: function() { sendKey("ESCAPE"); },
  result: function(testname) {
    checkOpen("viewmenu", testname);
    checkClosed("toolbar", testname);
  },
},
{
  // open the submenu with the enter key again
  testname: "open submenu with enter again",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: function() {
    // on Windows, the disabled 'navigation' item can stll be highlighted
    if (navigator.platform.indexOf("Win") == 0)
      return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
               "popupshown toolbarpopup" ];
    else
      return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
  },
  test: function() { sendKey("RETURN"); },
  result: function(testname) {
    checkOpen("viewmenu", testname);
    checkOpen("toolbar", testname);
  },
},
{
  // while a submenu is open, switch to the next toplevel menu with the cursor right key
  testname: "while a submenu is open, switch to the next menu with the cursor right",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: [ "DOMMenuItemInactive viewmenu", "DOMMenuItemActive helpmenu",
            "popuphiding toolbarpopup", "popuphidden toolbarpopup",
            "popuphiding viewpopup", "popuphidden viewpopup",
            "popupshowing helppopup", "DOMMenuItemInactive navigation",
            "DOMMenuInactive toolbarpopup", "DOMMenuItemInactive toolbar",
            "DOMMenuInactive viewpopup", "DOMMenuItemActive contents",
            "popupshown helppopup" ],
  test: function() { sendKey("RIGHT"); },
  result: function(testname) {
    checkOpen("helpmenu", testname);
    checkClosed("toolbar", testname);
    checkClosed("viewmenu", testname);
  }
},
{
  // close the main menu with the escape key
  testname: "close menubar menu with escape",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: [ "popuphiding helppopup", "popuphidden helppopup",
            "DOMMenuItemInactive contents", "DOMMenuInactive helppopup",
            "DOMMenuBarInactive menubar", "DOMMenuItemInactive helpmenu" ],
  test: function() { sendKey("ESCAPE"); },
  result: function(testname) { checkClosed("viewmenu", testname); },
},
{
  // close the main menu with the escape key
  testname: "close menubar menu with escape",
  condition: function() { return (navigator.platform.indexOf("Win") != 0) },
  events: [ "popuphiding viewpopup", "popuphidden viewpopup",
            "DOMMenuItemInactive toolbar", "DOMMenuInactive viewpopup",
            "DOMMenuBarInactive menubar",
            "DOMMenuItemInactive viewmenu" ],
  test: function() { sendKey("ESCAPE"); },
  result: function(testname) { checkClosed("viewmenu", testname); },
},
{
  // Pressing Alt should highlight the first menu but not open it,
  // but it should be ignored if the alt keydown event is consumed.
  testname: "alt shouldn't activate menubar if keydown event is consumed",
  test: function() {
    document.addEventListener("keydown", function (aEvent) {
      document.removeEventListener("keydown", arguments.callee, true);
      aEvent.preventDefault();
    }, true);
    sendKey("ALT");
  },
  result: function(testname) {
    ok(!document.getElementById("filemenu").openedWithKey, testname);
    checkClosed("filemenu", testname);
  },
},
{
  // Pressing Alt should highlight the first menu but not open it,
  // but it should be ignored if the alt keyup event is consumed.
  testname: "alt shouldn't activate menubar if keyup event is consumed",
  test: function() {
    document.addEventListener("keyup", function (aEvent) {
      document.removeEventListener("keyup", arguments.callee, true);
      aEvent.preventDefault();
    }, true);
    sendKey("ALT");
  },
  result: function(testname) {
    ok(!document.getElementById("filemenu").openedWithKey, testname);
    checkClosed("filemenu", testname);
  },
},
{
  // Pressing Alt should highlight the first menu but not open it.
  testname: "alt to activate menubar",
  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
  test: function() { sendKey("ALT"); },
  result: function(testname) {
    is(document.getElementById("filemenu").openedWithKey, true, testname + " openedWithKey");
    checkClosed("filemenu", testname);
  },
},
{
  // pressing cursor left should select the previous menu but not open it
  testname: "cursor left on active menubar",
  events: [ "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu" ],
  test: function() { sendKey("LEFT"); },
  result: function(testname) { checkClosed("helpmenu", testname); },
},
{
  // pressing cursor right should select the previous menu but not open it
  testname: "cursor right on active menubar",
  events: [ "DOMMenuItemInactive helpmenu", "DOMMenuItemActive filemenu" ],
  test: function() { sendKey("RIGHT"); },
  result: function(testname) { checkClosed("filemenu", testname); },
},
{
  // pressing a character should act as an accelerator and open the menu
  testname: "accelerator on active menubar",
  events: [ "popupshowing helppopup",
            "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu",
            "DOMMenuItemActive contents", "popupshown helppopup" ],
  test: function() { sendChar("h"); },
  result: function(testname) {
    checkOpen("helpmenu", testname);
    is(document.getElementById("helpmenu").openedWithKey, true, testname + " openedWithKey");
  },
},
{
  // check that pressing cursor up skips non menuitems
  testname: "cursor up wrap",
  events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive about" ],
  test: function() { sendKey("UP"); },
  result: function(testname) { }
},
{
  // check that pressing cursor down skips non menuitems
  testname: "cursor down wrap",
  events: [ "DOMMenuItemInactive about", "DOMMenuItemActive contents" ],
  test: function() { sendKey("DOWN"); },
  result: function(testname) { }
},
{
  // check that pressing a menuitem's accelerator selects it
  testname: "menuitem accelerator",
  events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive amenu",
            "DOMMenuItemInactive amenu", "DOMMenuInactive helppopup",
            "DOMMenuBarInactive menubar", "DOMMenuItemInactive helpmenu",
            "DOMMenuItemInactive helpmenu",
            "command amenu", "popuphiding helppopup", "popuphidden helppopup",
            "DOMMenuItemInactive amenu",
           ],
  test: function() { sendChar("m"); },
  result: function(testname) { checkClosed("helpmenu", testname); }
},
{
  // pressing F10 should highlight the first menu. On Linux, the menu is opened.
  testname: "F10 to activate menubar",
  events: pressF10Events(),
  test: function() { sendKey("F10"); },
  result: function(testname) {
    is(document.getElementById("filemenu").openedWithKey, true, testname + " openedWithKey");
    if (navigator.platform.indexOf("Linux") >= 0)
      checkOpen("filemenu", testname);
    else
      checkClosed("filemenu", testname);
  },
},
{
  // pressing cursor left then down should open a menu
  testname: "cursor down on menu",
  events: (navigator.platform.indexOf("Linux") >= 0) ?
            [  "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu",
               // This is in a different order than the
               // "accelerator on active menubar" because menus opened from a
               // shortcut key are fired asynchronously
               "popuphiding filepopup", "popuphidden filepopup",
               "popupshowing helppopup", "DOMMenuItemInactive item1",
               "DOMMenuItemActive item2", "DOMMenuItemInactive item2",
               "DOMMenuInactive filepopup", "DOMMenuItemActive contents",
               "popupshown helppopup" ] :
            [ "popupshowing helppopup", "DOMMenuItemInactive filemenu",
              "DOMMenuItemActive helpmenu",
              // This is in a different order than the
              // "accelerator on active menubar" because menus opened from a
              // shortcut key are fired asynchronously
              "DOMMenuItemActive contents", "popupshown helppopup" ],
  test: function() { sendKey("LEFT"); sendKey("DOWN"); },
  result: function(testname) {
    is(document.getElementById("helpmenu").openedWithKey, true, testname + " openedWithKey");
  }
},
{
  // pressing a letter that doesn't correspond to an accelerator. The menu
  // should not close because there is more than one item corresponding to
  // that letter
  testname: "menuitem with no accelerator",
  events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive one" ],
  test: function() { sendChar("o"); },
  result: function(testname) { checkOpen("helpmenu", testname); }
},
{
  // pressing the letter again should select the next one that starts with
  // that letter
  testname: "menuitem with no accelerator again",
  events: [ "DOMMenuItemInactive one", "DOMMenuItemActive only" ],
  test: function() { sendChar("o"); },
  result: function(testname) {
    // 'only' is a menu but it should not be open
    checkOpen("helpmenu", testname);
    checkClosed("only", testname);
  }
},
{
  // pressing the letter again when the next item is disabled should still
  // select the disabled item
  testname: "menuitem with no accelerator disabled",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: [ "DOMMenuItemInactive only", "DOMMenuItemActive other" ],
  test: function() { sendChar("o"); },
  result: function(testname) { }
},
{
  // when only one menuitem starting with that letter exists, it should be
  // selected and the menu closed
  testname: "menuitem with no accelerator single",
  events: function() {
    var elist = [ "DOMMenuItemInactive other", "DOMMenuItemActive third",
                  "DOMMenuItemInactive third", "DOMMenuInactive helppopup",
                  "DOMMenuBarInactive menubar",
                  "DOMMenuItemInactive helpmenu",
                  "DOMMenuItemInactive helpmenu",
                  "command third", "popuphiding helppopup",
                  "popuphidden helppopup", "DOMMenuItemInactive third",
                ];
    if (navigator.platform.indexOf("Win") == -1)
      elist[0] = "DOMMenuItemInactive only";
    return elist;
  },
  test: function() { sendChar("t"); },
  result: function(testname) { checkClosed("helpmenu", testname); }
},
{
  // pressing F10 should highlight the first menu but not open it
  testname: "F10 to activate menubar again",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
  test: function() { sendKey("F10"); },
  result: function(testname) { checkClosed("filemenu", testname); },
},
{
  // pressing an accelerator for a disabled item should deactivate the menubar
  testname: "accelerator for disabled menu",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: [ "DOMMenuItemInactive filemenu", "DOMMenuBarInactive menubar" ],
  test: function() { sendChar("s"); },
  result: function(testname) {
    checkClosed("secretmenu", testname);
    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
  },
},
{
  testname: "press on disabled menu",
  test: function() {
    synthesizeMouse(document.getElementById("secretmenu"), 8, 8, { });
  },
  result: function (testname) {
    checkClosed("secretmenu", testname);
  }
},
{
  testname: "press on second menu with shift",
  events: [ "popupshowing editpopup", "DOMMenuBarActive menubar",
            "DOMMenuItemActive editmenu", "popupshown editpopup" ],
  test: function() {
    synthesizeMouse(document.getElementById("editmenu"), 8, 8, { shiftKey : true });
  },
  result: function (testname) {
    checkOpen("editmenu", testname);
    checkActive(document.getElementById("menubar"), "editmenu", testname);
  }
},
{
  testname: "press on disabled menuitem",
  test: function() {
    synthesizeMouse(document.getElementById("cut"), 8, 8, { });
  },
  result: function (testname) {
    checkOpen("editmenu", testname);
  }
},
{
  testname: "press on menuitem",
  events: [ "DOMMenuInactive editpopup",
            "DOMMenuBarInactive menubar",
            "DOMMenuItemInactive editmenu",
            "DOMMenuItemInactive editmenu",
            "command copy", "popuphiding editpopup", "popuphidden editpopup",
            "DOMMenuItemInactive copy",
           ],
  test: function() {
    synthesizeMouse(document.getElementById("copy"), 8, 8, { });
  },
  result: function (testname) {
    checkClosed("editmenu", testname);
  }
},
{
  // this test ensures that the menu can still be opened by clicking after selecting
  // a menuitem from the menu. See bug 399350.
  testname: "press on menu after menuitem selected",
  events: [ "popupshowing editpopup", "DOMMenuBarActive menubar",
            "DOMMenuItemActive editmenu", "popupshown editpopup" ],
  test: function() { synthesizeMouse(document.getElementById("editmenu"), 8, 8, { }); },
  result: function (testname) {
    checkActive(document.getElementById("editpopup"), "", testname);
    checkOpen("editmenu", testname);
  }
},
{  // try selecting a different command
  testname: "press on menuitem again",
  events: [ "DOMMenuInactive editpopup",
            "DOMMenuBarInactive menubar",
            "DOMMenuItemInactive editmenu",
            "DOMMenuItemInactive editmenu",
            "command paste", "popuphiding editpopup", "popuphidden editpopup",
            "DOMMenuItemInactive paste",
           ],
  test: function() {
    synthesizeMouse(document.getElementById("paste"), 8, 8, { });
  },
  result: function (testname) {
    checkClosed("editmenu", testname);
  }
},
{
  testname: "F10 to activate menubar for tab deactivation",
  events: pressF10Events(),
  test: function() { sendKey("F10"); },
},
{
  testname: "Deactivate menubar with tab key",
  events: closeAfterF10Events(true),
  test: function() { sendKey("TAB"); },
  result: function(testname) {
    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
  }
},
{
  testname: "F10 to activate menubar for escape deactivation",
  events: pressF10Events(),
  test: function() { sendKey("F10"); },
},
{
  testname: "Deactivate menubar with escape key",
  events: closeAfterF10Events(false),
  test: function() { sendKey("ESCAPE"); },
  result: function(testname) {
    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
  }
},
{
  testname: "F10 to activate menubar for f10 deactivation",
  events: pressF10Events(),
  test: function() { sendKey("F10"); },
},
{
  testname: "Deactivate menubar with f10 key",
  events: closeAfterF10Events(true),
  test: function() { sendKey("F10"); },
  result: function(testname) {
    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
  }
},
{
  testname: "F10 to activate menubar for alt deactivation",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
  test: function() { sendKey("F10"); },
},
{
  testname: "Deactivate menubar with alt key",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu"  ],
  test: function() { sendKey("ALT"); },
  result: function(testname) {
    is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
  }
},
{
  testname: "Don't activate menubar with mousedown during alt key auto-repeat",
  test: function() {
    synthesizeKey("VK_ALT", { type: "keydown" });
    synthesizeMouse(document.getElementById("menubar"), 8, -30, { type: "mousedown", altKey: true });
    synthesizeKey("VK_ALT", { type: "keydown" });
    synthesizeMouse(document.getElementById("menubar"), 8, -30, { type: "mouseup", altKey: true });
    synthesizeKey("VK_ALT", { type: "keydown" });
    synthesizeKey("VK_ALT", { type: "keyup" });
  },
  result: function (testname) {
    checkActive(document.getElementById("menubar"), "", testname);
  }
},

{
  testname: "Open menu and press alt key by itself - open menu",
  events: [ "DOMMenuBarActive menubar",
            "popupshowing filepopup", "DOMMenuItemActive filemenu",
            "DOMMenuItemActive item1", "popupshown filepopup" ],
  test: function() { synthesizeKey("F", { altKey: true }); },
  result: function (testname) {
    checkOpen("filemenu", testname);
  }
},
{
  testname: "Open menu and press alt key by itself - close menu",
  events: [ "popuphiding filepopup", "popuphidden filepopup",
            "DOMMenuItemInactive item1", "DOMMenuInactive filepopup",
            "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu",
            "DOMMenuItemInactive filemenu" ],
  test: function() {
    synthesizeKey("VK_ALT", { });
  },
  result: function (testname) {
    checkClosed("filemenu", testname);
  }
},

// Fllowing 4 tests are a test of bug 616797, don't insert any new tests
// between them.
{
  testname: "Open file menu by accelerator",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: function() {
    return [ "DOMMenuBarActive menubar", "popupshowing filepopup",
             "DOMMenuItemActive filemenu", "DOMMenuItemActive item1",
             "popupshown filepopup" ];
  },
  test: function() {
    synthesizeKey("VK_ALT", { type: "keydown" });
    synthesizeKey("F", { altKey: true });
    synthesizeKey("VK_ALT", { type: "keyup" });
  }
},
{
  testname: "Close file menu by click at outside of popup menu",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: function() {
    return [ "popuphiding filepopup", "popuphidden filepopup",
             "DOMMenuItemInactive item1", "DOMMenuInactive filepopup",
             "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu",
             "DOMMenuItemInactive filemenu" ];
  },
  test: function() {
    // XXX hidePopup() causes DOMMenuItemInactive event to be fired twice.
    document.getElementById("filepopup").hidePopup();
  }
},
{
  testname: "Alt keydown set focus the menubar",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: function() {
    return [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
  },
  test: function() {
    sendKey("ALT");
  },
  result: function (testname) {
    checkClosed("filemenu", testname);
  }
},
{
  testname: "unset focus the menubar",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: function() {
    return [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu" ];
  },
  test: function() {
    sendKey("ALT");
  }
},

// bug 625151
{
  testname: "Alt key state before deactivating the window shouldn't prevent " +
            "next Alt key handling",
  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
  events: function() {
    return [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
  },
  test: function() {
    synthesizeKey("VK_ALT", { type: "keydown" });
    synthesizeKey("VK_TAB", { type: "keydown" }); // cancels the Alt key
    var thisWindow = window;
    var newWindow =
      window.open("data:text/html,", "_blank", "width=100,height=100");
    newWindow.addEventListener("focus", function () {
      newWindow.removeEventListener("focus", arguments.callee, false);
      thisWindow.addEventListener("focus", function () {
        thisWindow.removeEventListener("focus", arguments.callee, false);
        setTimeout(function () {
          sendKey("ALT", thisWindow);
        }, 0);
      }, false);
      newWindow.close();
      thisWindow.focus();
    }, false);
  }
}

];

]]>
</script>

</window>