Bug 501496 part.9 EventUtils and some tests shouldn't synthesize keypress event if precede keydown event is consumed r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 25 Jul 2013 15:09:29 +0900
changeset 139928 441c1fc13ebdc8e30ca97f2ca87e1995d6b1f5e8
parent 139927 ab40003ed2dc4d01ace1386c36806b2f76ea5e74
child 139929 d5dc2d51f0028a7099555378c209c8b8a6b8ec61
push id31524
push usermasayuki@d-toybox.com
push dateThu, 25 Jul 2013 06:09:36 +0000
treeherdermozilla-inbound@949a5e125a8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs501496
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 501496 part.9 EventUtils and some tests shouldn't synthesize keypress event if precede keydown event is consumed r=smaug
browser/devtools/styleeditor/StyleSheetEditor.jsm
content/events/test/test_dom_keyboard_event.html
layout/forms/test/test_bug348236.html
testing/mochitest/tests/SimpleTest/EventUtils.js
testing/mochitest/tests/test_sanity.html
toolkit/components/passwordmgr/test/pwmgr_common.js
toolkit/components/satchel/test/satchel_common.js
--- a/browser/devtools/styleeditor/StyleSheetEditor.jsm
+++ b/browser/devtools/styleeditor/StyleSheetEditor.jsm
@@ -533,16 +533,18 @@ function setupBracketCompletion(sourceEd
 
     // We detected an open bracket, sending closing character
     let keyCode = pair.closeKeyCode;
     let charCode = pair.closeString.charCodeAt(0);
     let modifiers = 0;
     let utils = editorElement.ownerDocument.defaultView.
                   QueryInterface(Ci.nsIInterfaceRequestor).
                   getInterface(Ci.nsIDOMWindowUtils);
-    let handled = utils.sendKeyEvent("keydown", keyCode, 0, modifiers);
-    utils.sendKeyEvent("keypress", 0, charCode, modifiers, !handled);
+                  
+    if (utils.sendKeyEvent("keydown", keyCode, 0, modifiers)) {
+      utils.sendKeyEvent("keypress", 0, charCode, modifiers);
+    }
     utils.sendKeyEvent("keyup", keyCode, 0, modifiers);
     // and rewind caret
     sourceEditor.setCaretOffset(sourceEditor.getCaretOffset() - 1);
   }, false);
 }
 
--- a/content/events/test/test_dom_keyboard_event.html
+++ b/content/events/test/test_dom_keyboard_event.html
@@ -268,17 +268,20 @@ function testSynthesizedKeyLocation()
   var currentTest, description;
   var events = { keydown: false, keypress: false, keyup: false };
 
   function handler(aEvent)
   {
     is(aEvent.location, currentTest.event.location,
        description + "location of " + aEvent.type + " was invalid");
     events[aEvent.type] = true;
-    aEvent.preventDefault();
+    if (aEvent.type != "keydown" ||
+        (currentTest.event.isModifier && aEvent.type == "keydown")) {
+      aEvent.preventDefault();
+    }
   }
 
   window.addEventListener("keydown", handler, true);
   window.addEventListener("keypress", handler, true);
   window.addEventListener("keyup", handler, true);
 
   for (var i = 0; i < kTests.length; i++) {
     currentTest = kTests[i];
--- a/layout/forms/test/test_bug348236.html
+++ b/layout/forms/test/test_bug348236.html
@@ -42,19 +42,19 @@ addLoadEvent(function test() {
         sec = netscape.security,
         eSelect = $("eSelect"),
         IDOMEvent = CI.nsIDOMEvent,
         IDOMKeyEvent = CI.nsIDOMKeyEvent,
         timeout = 0 // Choose a larger value like 500 ms if you want to see what's happening.
 
     function keypressOnSelect(key, modifiers) {
         WinUtils.focus(eSelect)
-        WinUtils.sendKeyEvent("keyup", key, 0, modifiers, WinUtils.KEY_FLAG_PREVENT_DEFAULT)
-        WinUtils.sendKeyEvent("keypress", key, 0, modifiers, WinUtils.KEY_FLAG_PREVENT_DEFAULT)
-        WinUtils.sendKeyEvent("keydown", key, 0, modifiers, WinUtils.KEY_FLAG_PREVENT_DEFAULT)
+        WinUtils.sendKeyEvent("keyup", key, 0, modifiers)
+        WinUtils.sendKeyEvent("keypress", key, 0, modifiers)
+        WinUtils.sendKeyEvent("keydown", key, 0, modifiers)
     }
 
     function testKey(key, modifiers, keyString, functionToContinue) {
         var selectGotClick
         function clickListener() { selectGotClick = true }
         eSelect.selectedIndex = 0
         eSelect.onchangeCount = 0
 
--- a/testing/mochitest/tests/SimpleTest/EventUtils.js
+++ b/testing/mochitest/tests/SimpleTest/EventUtils.js
@@ -547,20 +547,17 @@ function synthesizeKey(aKey, aEvent, aWi
           break;
       }
     }
 
     if (!("type" in aEvent) || !aEvent.type) {
       // Send keydown + (optional) keypress + keyup events.
       var keyDownDefaultHappened =
         utils.sendKeyEvent("keydown", keyCode, 0, modifiers, flags);
-      if (isKeypressFiredKey(keyCode)) {
-        if (!keyDownDefaultHappened) {
-          flags |= utils.KEY_FLAG_PREVENT_DEFAULT;
-        }
+      if (isKeypressFiredKey(keyCode) && keyDownDefaultHappened) {
         utils.sendKeyEvent("keypress", keyCode, charCode, modifiers, flags);
       }
       utils.sendKeyEvent("keyup", keyCode, 0, modifiers, flags);
     } else if (aEvent.type == "keypress") {
       // Send standalone keypress event.
       utils.sendKeyEvent(aEvent.type, keyCode, charCode, modifiers, flags);
     } else {
       // Send other standalone event than keypress.
--- a/testing/mochitest/tests/test_sanity.html
+++ b/testing/mochitest/tests/test_sanity.html
@@ -35,28 +35,28 @@ var press1 = false;
 synthesizeKey("x", {});
 is($("testKeyEvent1").value, "x", "synthesizeKey should work");
 is(press1, true, "synthesizeKey should dispatch keyPress");
 
 var press2 = false;
 $("testKeyEvent2").focus();
 synthesizeKey("x", {});
 is($("testKeyEvent2").value, "", "synthesizeKey should respect keydown preventDefault");
-is(press2, true, "synthesizeKey should dispatch keyPress with default prevented");
+is(press2, false, "synthesizeKey should not dispatch keyPress with default prevented");
 
 var press3 = false;
 $("testKeyEvent3").focus();
 sendChar("x")
 is($("testKeyEvent3").value, "x", "sendChar should work");
 is(press3, true, "sendChar should dispatch keyPress");
 
 var press4 = false;
 $("testKeyEvent4").focus();
 sendChar("x")
 is($("testKeyEvent4").value, "", "sendChar should respect keydown preventDefault");
-is(press4, true, "sendChar should dispatch keyPress with default prevented");
+is(press4, false, "sendChar should not dispatch keyPress with default prevented");
 
 
 </script>
 </pre>
 </body>
 </html>
 
--- a/toolkit/components/passwordmgr/test/pwmgr_common.js
+++ b/toolkit/components/passwordmgr/test/pwmgr_common.js
@@ -118,18 +118,19 @@ function doKey(aKey, modifier) {
     // undefined --> null
     if (!modifier)
         modifier = null;
 
     // Window utils for sending fake sey events.
     var wutils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
                           getInterface(Components.interfaces.nsIDOMWindowUtils);
 
-    wutils.sendKeyEvent("keydown",  key, 0, modifier);
-    wutils.sendKeyEvent("keypress", key, 0, modifier);
+    if (wutils.sendKeyEvent("keydown",  key, 0, modifier)) {
+      wutils.sendKeyEvent("keypress", key, 0, modifier);
+    }
     wutils.sendKeyEvent("keyup",    key, 0, modifier);
 }
 
 // Init with a common login
 function commonInit() {
     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
     var pwmgr = Components.classes["@mozilla.org/login-manager;1"].
--- a/toolkit/components/satchel/test/satchel_common.js
+++ b/toolkit/components/satchel/test/satchel_common.js
@@ -42,18 +42,19 @@ function doKey(aKey, modifier) {
 
     // undefined --> null
     if (!modifier)
         modifier = null;
 
     // Window utils for sending fake sey events.
     var wutils = SpecialPowers.getDOMWindowUtils(window);
 
-    wutils.sendKeyEvent("keydown",  key, 0, modifier);
-    wutils.sendKeyEvent("keypress", key, 0, modifier);
+    if (wutils.sendKeyEvent("keydown",  key, 0, modifier)) {
+      wutils.sendKeyEvent("keypress", key, 0, modifier);
+    }
     wutils.sendKeyEvent("keyup",    key, 0, modifier);
 }
 
 
 function getAutocompletePopup() {
     var Ci = SpecialPowers.Ci;
     chromeWin = SpecialPowers.wrap(window)
                     .QueryInterface(Ci.nsIInterfaceRequestor)