Bug 721512 - Widgets: Use EventUtils sendChar() and sendKey(), instead of calling synthesizeKey() directly. r=enn
authorMario Alvarado [:marioalv] <marioalv.mozilla@gmail.com>
Wed, 17 Oct 2012 10:03:24 -0600
changeset 110987 ab8ef7a28e2e31ef70820f7a0319e555b13fd0dd
parent 110986 196860475fa98dc0ffca0e5c593cd07afc0540ac
child 110988 08fa42148eabf61eb052cd33e942c939d6ac8695
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersenn
bugs721512
milestone19.0a1
Bug 721512 - Widgets: Use EventUtils sendChar() and sendKey(), instead of calling synthesizeKey() directly. r=enn
toolkit/content/tests/widgets/tree_shared.js
toolkit/content/tests/widgets/window_menubar.xul
toolkit/content/tests/widgets/window_menubar_gtk.xul
--- a/toolkit/content/tests/widgets/tree_shared.js
+++ b/toolkit/content/tests/widgets/tree_shared.js
@@ -600,17 +600,17 @@ function testtag_tree_TreeSelection_UI(t
   selection.currentIndex = 2;
   if (0) { // XXXndeakin disable these tests for now
     mouseOnCell(tree, 1, tree.columns[1], "mouse on row");
     testtag_tree_TreeSelection_State(tree, testid + "mouse on row", 1, [1], 0,
                                      tree.selType == "cell" ? tree.columns[1] : null);
   }
 
   // restore the scroll position to the start of the page
-  synthesizeKey("VK_HOME", {});
+  sendKey("HOME");
 
   window.removeEventListener("keypress", keyPressListener, false);
   is(keyPressDefaultPrevented, multiple ? 63 : 40, "key press default prevented");
 }
 
 function testtag_tree_UI_editing(tree, testid, rowInfo)
 {
   testid += " editing UI ";
@@ -635,20 +635,20 @@ function testtag_tree_UI_editing(tree, t
   if (tree.selType == "cell")
   {
     tree.stopEditing(false);
     ok(!tree.editingColumn, "Should not be editing tree cell now");
     tree.view.selection.currentColumn = ecolumn;
     tree.currentIndex = rowIndex;
 
     const isMac = (navigator.platform.indexOf("Mac") >= 0);
-    const StartEditingKey = isMac ? "VK_ENTER" : "VK_F2";
-    synthesizeKey(StartEditingKey, {});
+    const StartEditingKey = isMac ? "ENTER" : "F2";
+    sendKey(StartEditingKey);
     is(tree.editingColumn, ecolumn, "Should be editing tree cell now");
-    synthesizeKey("VK_ESCAPE", {});
+    sendKey("ESCAPE");
     ok(!tree.editingColumn, "Should not be editing tree cell now");
     is(tree.currentIndex, rowIndex, "Current index should not have changed");
     is(tree.view.selection.currentColumn, ecolumn, "Current column should not have changed");
   }
 
   mouseDblClickOnCell(tree, rowIndex, ecolumn, testid + "edit on double click");
   is(tree.editingColumn, ecolumn, testid + "editing column");
   is(tree.editingRow, rowIndex, testid + "editing row");
@@ -855,17 +855,17 @@ function testtag_tree_TreeSelection_UI_c
 
     tree.treeBoxObject.scrollToRow(4);
     synthesizeKeyExpectEvent("VK_UP", {}, tree, "!select", "key up unselectable cell");
     testtag_tree_TreeSelection_State(tree, testid + "key up unselectable cell",
                                      3, [3], 3, secondcolumn);
   }
 
   // restore the scroll position to the start of the page
-  synthesizeKey("VK_HOME", {});
+  sendKey("HOME");
 }
 
 function testtag_tree_TreeView(tree, testid, rowInfo)
 {
   testid += " view ";
 
   var columns = tree.columns;
   var view = tree.view;
--- a/toolkit/content/tests/widgets/window_menubar.xul
+++ b/toolkit/content/tests/widgets/window_menubar.xul
@@ -103,45 +103,45 @@ var popupTests = [
     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() { synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("VK_UP", { }); },
+  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() { synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("VK_UP", { }); },
+  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 = [
@@ -160,17 +160,17 @@ var popupTests = [
     // 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() { synthesizeKey("VK_RIGHT", { }); },
+  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");
   }
 },
@@ -186,17 +186,17 @@ var popupTests = [
                "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() { synthesizeKey("VK_ENTER", { }); },
+  test: function() { sendKey("ENTER"); },
   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",
@@ -217,17 +217,17 @@ var popupTests = [
   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() { synthesizeKey("VK_RIGHT", { }); },
+  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",
@@ -236,34 +236,34 @@ var popupTests = [
       return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
                "DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
                "DOMMenuItemActive toolbar" ];
     else
       return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
                "DOMMenuInactive toolbarpopup",
                "DOMMenuItemActive toolbar" ];
   },
-  test: function() { synthesizeKey("VK_LEFT", { }); },
+  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 highlihted
     if (navigator.platform.indexOf("Win") == 0)
       return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
                "popupshown toolbarpopup" ];
     else
       return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
   },
-  test: function() { synthesizeKey("VK_ENTER", { }); },
+  test: function() { sendKey("ENTER"); },
   result: function(testname) {
     checkOpen("viewmenu", testname);
     checkOpen("toolbar", testname);
   },
 },
 {
   // close the submenu with the escape key
   testname: "close submenu with escape",
@@ -272,101 +272,101 @@ var popupTests = [
       return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
                "DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
                "DOMMenuItemActive toolbar" ];
     else
       return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
                "DOMMenuInactive toolbarpopup",
                "DOMMenuItemActive toolbar" ];
   },
-  test: function() { synthesizeKey("VK_ESCAPE", { }); },
+  test: function() { sendKey("ESCAPE"); },
   result: function(testname) {
     checkOpen("viewmenu", testname);
     checkClosed("toolbar", testname);
   },
 },
 {
   // close the main menu with the escape key
   testname: "close menubar menu with escape",
   events: [ "popuphiding viewpopup", "popuphidden viewpopup",
             "DOMMenuItemInactive toolbar", "DOMMenuInactive viewpopup",
             "DOMMenuBarInactive menubar",
             "DOMMenuItemInactive viewmenu" ],
-  test: function() { synthesizeKey("VK_ESCAPE", { }); },
+  test: function() { sendKey("ESCAPE"); },
   result: function(testname) { checkClosed("viewmenu", testname); },
 },
 {
   // on Windows, 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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   test: function() {
     document.addEventListener("keydown", function (aEvent) {
       document.removeEventListener("keydown", arguments.callee, true);
       aEvent.preventDefault();
     }, true);
-    synthesizeKey("VK_ALT", { });
+    sendKey("ALT");
   },
   result: function(testname) {
     ok(!document.getElementById("filemenu").openedWithKey, testname);
     checkClosed("filemenu", testname);
   },
 },
 {
   // on Windows, 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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   test: function() {
     document.addEventListener("keyup", function (aEvent) {
       document.removeEventListener("keyup", arguments.callee, true);
       aEvent.preventDefault();
     }, true);
-    synthesizeKey("VK_ALT", { });
+    sendKey("ALT");
   },
   result: function(testname) {
     ok(!document.getElementById("filemenu").openedWithKey, testname);
     checkClosed("filemenu", testname);
   },
 },
 {
   // on Windows, pressing Alt should highlight the first menu but not open it
   testname: "alt to activate menubar",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
-  test: function() { synthesizeKey("VK_ALT", { }); },
+  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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: [ "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu" ],
-  test: function() { synthesizeKey("VK_LEFT", { }); },
+  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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: [ "DOMMenuItemInactive helpmenu", "DOMMenuItemActive filemenu" ],
-  test: function() { synthesizeKey("VK_RIGHT", { }); },
+  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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: [ "popupshowing helppopup",
             "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu",
             "DOMMenuItemActive contents", "popupshown helppopup" ],
-  test: function() { synthesizeKey("H", { }); },
+  test: function() { sendChar("h"); },
   result: function(testname) {
     checkOpen("helpmenu", testname);
     is(document.getElementById("helpmenu").openedWithKey, true, testname + " openedWithKey");
   },
 },
 {
   testname: "open with accelerator again",
   condition: function() { return (navigator.platform.indexOf("Win") == -1) },
@@ -378,92 +378,92 @@ var popupTests = [
     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() { synthesizeKey("VK_UP", { }); },
+  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() { synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("M", { }); },
+  test: function() { sendChar("m"); },
   result: function(testname) { checkClosed("helpmenu", testname); }
 },
 {
   // pressing F10 should highlight the first menu but not open it
   testname: "F10 to activate menubar",
   events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
   result: function(testname) {
     is(document.getElementById("filemenu").openedWithKey, true, testname + " openedWithKey");
     checkClosed("filemenu", testname);
   },
 },
 {
   // pressing cursor down should open a menu
   testname: "cursor down on menu",
   events: [ 
             "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() { synthesizeKey("VK_LEFT", { }); synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("O", { }); },
+  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() { synthesizeKey("O", { }); },
+  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() { synthesizeKey("O", { }); },
+  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",
@@ -473,33 +473,33 @@ var popupTests = [
                   "DOMMenuItemInactive helpmenu",
                   "command third", "popuphiding helppopup",
                   "popuphidden helppopup", "DOMMenuItemInactive third",
                 ];
     if (navigator.platform.indexOf("Win") == -1)
       elist[0] = "DOMMenuItemInactive only";
     return elist;
   },
-  test: function() { synthesizeKey("T", { }); },
+  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() { synthesizeKey("VK_F10", { }); },
+  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() { synthesizeKey("S", { }); },
+  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() {
@@ -572,63 +572,63 @@ var popupTests = [
   },
   result: function (testname) {
     checkClosed("editmenu", testname);
   }
 },
 {
   testname: "F10 to activate menubar for tab deactivation",
   events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
 },
 {
   testname: "Deactivate menubar with tab key",
   events: [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu" ],
-  test: function() { synthesizeKey("VK_TAB", { }); },
+  test: function() { sendKey("TAB"); },
   result: function(testname) {
     is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
   }
 },
 {
   testname: "F10 to activate menubar for escape deactivation",
   events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
 },
 {
   testname: "Deactivate menubar with escape key",
   events: [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu" ],
-  test: function() { synthesizeKey("VK_ESCAPE", { }); },
+  test: function() { sendKey("ESCAPE"); },
   result: function(testname) {
     is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
   }
 },
 {
   testname: "F10 to activate menubar for f10 deactivation",
   events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
 },
 {
   testname: "Deactivate menubar with f10 key",
   events: [ "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu"  ],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  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() { synthesizeKey("VK_F10", { }); },
+  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() { synthesizeKey("VK_ALT", { }); },
+  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" });
@@ -675,30 +675,30 @@ var popupTests = [
 },
 {
   testname: "Alt keydown set focus the menubar",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: function() {
     return [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
   },
   test: function() {
-    synthesizeKey("VK_ALT", {  });
+    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() {
-    synthesizeKey("VK_ALT", {  });
+    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) },
@@ -711,17 +711,17 @@ var popupTests = [
     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 () {
-          synthesizeKey("VK_ALT", { }, thisWindow);
+          sendKey("ALT", thisWindow);
         }, 0);
       }, false);
       newWindow.close();
       thisWindow.focus();
       // Note that our window dispatches a hacky key event if IMM is installed
       // on the system during focus change only if Alt key is pressed.
       synthesizeKey("`", { type: "keypress" }, thisWindow);
     }, false);
--- a/toolkit/content/tests/widgets/window_menubar_gtk.xul
+++ b/toolkit/content/tests/widgets/window_menubar_gtk.xul
@@ -103,45 +103,45 @@ var popupTests = [
     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() { synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("VK_UP", { }); },
+  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() { synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("VK_UP", { }); },
+  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 = [
@@ -160,17 +160,17 @@ var popupTests = [
     // 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() { synthesizeKey("VK_RIGHT", { }); },
+  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");
   }
 },
@@ -186,17 +186,17 @@ var popupTests = [
                "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() { synthesizeKey("VK_ENTER", { }); },
+  test: function() { sendKey("ENTER"); },
   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",
@@ -217,17 +217,17 @@ var popupTests = [
   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() { synthesizeKey("VK_RIGHT", { }); },
+  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",
@@ -236,34 +236,34 @@ var popupTests = [
       return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
                "DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
                "DOMMenuItemActive toolbar" ];
     else
       return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
                "DOMMenuInactive toolbarpopup",
                "DOMMenuItemActive toolbar" ];
   },
-  test: function() { synthesizeKey("VK_LEFT", { }); },
+  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 highlihted
     if (navigator.platform.indexOf("Win") == 0)
       return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
                "popupshown toolbarpopup" ];
     else
       return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
   },
-  test: function() { synthesizeKey("VK_ENTER", { }); },
+  test: function() { sendKey("ENTER"); },
   result: function(testname) {
     checkOpen("viewmenu", testname);
     checkOpen("toolbar", testname);
   },
 },
 {
   // close the submenu with the escape key
   testname: "close submenu with escape",
@@ -272,101 +272,101 @@ var popupTests = [
       return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
                "DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
                "DOMMenuItemActive toolbar" ];
     else
       return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
                "DOMMenuInactive toolbarpopup",
                "DOMMenuItemActive toolbar" ];
   },
-  test: function() { synthesizeKey("VK_ESCAPE", { }); },
+  test: function() { sendKey("ESCAPE"); },
   result: function(testname) {
     checkOpen("viewmenu", testname);
     checkClosed("toolbar", testname);
   },
 },
 {
   // close the main menu with the escape key
   testname: "close menubar menu with escape",
   events: [ "popuphiding viewpopup", "popuphidden viewpopup",
             "DOMMenuItemInactive toolbar", "DOMMenuInactive viewpopup",
             "DOMMenuBarInactive menubar",
             "DOMMenuItemInactive viewmenu" ],
-  test: function() { synthesizeKey("VK_ESCAPE", { }); },
+  test: function() { sendKey("ESCAPE"); },
   result: function(testname) { checkClosed("viewmenu", testname); },
 },
 {
   // on Windows, 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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   test: function() {
     document.addEventListener("keydown", function (aEvent) {
       document.removeEventListener("keydown", arguments.callee, true);
       aEvent.preventDefault();
     }, true);
-    synthesizeKey("VK_ALT", { });
+    sendKey("ALT");
   },
   result: function(testname) {
     ok(!document.getElementById("filemenu").openedWithKey, testname);
     checkClosed("filemenu", testname);
   },
 },
 {
   // on Windows, 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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   test: function() {
     document.addEventListener("keyup", function (aEvent) {
       document.removeEventListener("keyup", arguments.callee, true);
       aEvent.preventDefault();
     }, true);
-    synthesizeKey("VK_ALT", { });
+    sendKey("ALT");
   },
   result: function(testname) {
     ok(!document.getElementById("filemenu").openedWithKey, testname);
     checkClosed("filemenu", testname);
   },
 },
 {
   // on Windows, pressing Alt should highlight the first menu but not open it
   testname: "alt to activate menubar",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
-  test: function() { synthesizeKey("VK_ALT", { }); },
+  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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: [ "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu" ],
-  test: function() { synthesizeKey("VK_LEFT", { }); },
+  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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: [ "DOMMenuItemInactive helpmenu", "DOMMenuItemActive filemenu" ],
-  test: function() { synthesizeKey("VK_RIGHT", { }); },
+  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",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: [ "popupshowing helppopup",
             "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu",
             "DOMMenuItemActive contents", "popupshown helppopup" ],
-  test: function() { synthesizeKey("H", { }); },
+  test: function() { sendChar("h"); },
   result: function(testname) {
     checkOpen("helpmenu", testname);
     is(document.getElementById("helpmenu").openedWithKey, true, testname + " openedWithKey");
   },
 },
 {
   testname: "open with accelerator again",
   condition: function() { return (navigator.platform.indexOf("Win") == -1) },
@@ -378,44 +378,44 @@ var popupTests = [
     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() { synthesizeKey("VK_UP", { }); },
+  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() { synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("M", { }); },
+  test: function() { sendChar("m"); },
   result: function(testname) { checkClosed("helpmenu", testname); }
 },
 {
   // pressing F10 should highlight the first menu but not open it
   testname: "F10 to activate menubar",
   events: [ "DOMMenuBarActive menubar", "popupshowing filepopup", "DOMMenuItemActive item1", "popupshown filepopup" ],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
   result: function(testname) {
     is(document.getElementById("filemenu").openedWithKey, true, testname + " openedWithKey");
     checkOpen("filemenu", testname);
   },
 },
 {
   // pressing cursor down should open a menu
   testname: "cursor down on menu",
@@ -428,49 +428,49 @@ var popupTests = [
             "popuphidden filepopup",
             "popupshowing helppopup",
             "DOMMenuItemInactive item1",
             "DOMMenuItemActive item2",
             "DOMMenuItemInactive item2",
             "DOMMenuInactive filepopup",
             "DOMMenuItemActive contents",
             "popupshown helppopup" ],
-  test: function() { synthesizeKey("VK_LEFT", { }); synthesizeKey("VK_DOWN", { }); },
+  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() { synthesizeKey("O", { }); },
+  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() { synthesizeKey("O", { }); },
+  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() { synthesizeKey("O", { }); },
+  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",
@@ -480,33 +480,33 @@ var popupTests = [
                   "DOMMenuItemInactive helpmenu",
                   "command third", "popuphiding helppopup",
                   "popuphidden helppopup", "DOMMenuItemInactive third",
                 ];
     if (navigator.platform.indexOf("Win") == -1)
       elist[0] = "DOMMenuItemInactive only";
     return elist;
   },
-  test: function() { synthesizeKey("T", { }); },
+  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", "popupshowing filepopup", "DOMMenuItemActive item1", "popupshown filepopup" ],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
   result: function(testname) { checkOpen("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() { synthesizeKey("S", { }); },
+  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() {
@@ -579,69 +579,69 @@ var popupTests = [
   },
   result: function (testname) {
     checkClosed("editmenu", testname);
   }
 },
 {
   testname: "F10 to activate menubar for tab deactivation",
   events: [ "DOMMenuBarActive menubar", "popupshowing filepopup", "DOMMenuItemActive item1", "popupshown filepopup"],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
 },
 {
   testname: "Deactivate menubar with tab key",
   events: [ "popuphiding filepopup", "popuphidden filepopup", "DOMMenuItemInactive item1",
             "DOMMenuInactive filepopup", "DOMMenuBarInactive menubar",
             "DOMMenuItemInactive filemenu", "DOMMenuItemInactive filemenu"],
-  test: function() { synthesizeKey("VK_TAB", { }); },
+  test: function() { sendKey("TAB"); },
   result: function(testname) {
     is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
   }
 },
 {
   testname: "F10 to activate menubar for escape deactivation",
   events: [ "DOMMenuBarActive menubar", "popupshowing filepopup", "DOMMenuItemActive item1", "popupshown filepopup"],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
 },
 {
   testname: "Deactivate menubar with escape key",
   events: [ "popuphiding filepopup", "popuphidden filepopup", "DOMMenuItemInactive item1",
             "DOMMenuInactive filepopup", "DOMMenuBarInactive menubar",
             "DOMMenuItemInactive filemenu"],
-  test: function() { synthesizeKey("VK_ESCAPE", { }); },
+  test: function() { sendKey("ESCAPE"); },
   result: function(testname) {
     is(document.getElementById("filemenu").openedWithKey, false, testname + " openedWithKey");
   }
 },
 {
   testname: "F10 to activate menubar for f10 deactivation",
   events: [ "DOMMenuBarActive menubar", "popupshowing filepopup", "DOMMenuItemActive item1", "popupshown filepopup"],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  test: function() { sendKey("F10"); },
 },
 {
   testname: "Deactivate menubar with f10 key",
   events: [ "popuphiding filepopup", "popuphidden filepopup", "DOMMenuItemInactive item1",
             "DOMMenuInactive filepopup", "DOMMenuBarInactive menubar",
             "DOMMenuItemInactive filemenu", "DOMMenuItemInactive filemenu"],
-  test: function() { synthesizeKey("VK_F10", { }); },
+  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() { synthesizeKey("VK_F10", { }); },
+  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() { synthesizeKey("VK_ALT", { }); },
+  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" });
@@ -688,30 +688,30 @@ var popupTests = [
 },
 {
   testname: "Alt keydown set focus the menubar",
   condition: function() { return (navigator.platform.indexOf("Win") == 0) },
   events: function() {
     return [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
   },
   test: function() {
-    synthesizeKey("VK_ALT", {  });
+    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() {
-    synthesizeKey("VK_ALT", {  });
+    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) },
@@ -724,17 +724,17 @@ var popupTests = [
     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 () {
-          synthesizeKey("VK_ALT", { }, thisWindow);
+          sendKey("ALT", thisWindow);
         }, 0);
       }, false);
       newWindow.close();
       thisWindow.focus();
       // Note that our window dispatches a hacky key event if IMM is installed
       // on the system during focus change only if Alt key is pressed.
       synthesizeKey("`", { type: "keypress" }, thisWindow);
     }, false);