toolkit/content/tests/widgets/window_menubar.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial