[Win][DumpRenderTree][WebKitTestRunner] eventSender.keyDown should support function...
authorHironori.Fujii@sony.com <Hironori.Fujii@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Nov 2019 01:54:21 +0000 (01:54 +0000)
committerHironori.Fujii@sony.com <Hironori.Fujii@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Nov 2019 01:54:21 +0000 (01:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204146

Reviewed by Ross Kirsling.

Tools:

Changed eventSender.keyDown of DRT and WTR to support sending
function keys.

In addition to that, this change set correct scan code to LPARAM
for all key events. Unfortunately, there is no API to get a
correct extended scan code from a virtual key because
MapVirtualKey and MapVirtualKeyEx doesn't work as expected.
makeKeyDataForScanCode turns on KF_EXTENDED flag for some keys
explicitly for the workaround.
<http://www.setnode.com/blog/mapvirtualkey-getkeynametext-and-a-story-of-how-to/>

* DumpRenderTree/win/EventSender.cpp:
(makeKeyDataForScanCode):
(keyDownCallback):
* WebKitTestRunner/win/EventSenderProxyWin.cpp:
(WTR::makeKeyDataForScanCode):
(WTR::EventSenderProxy::keyDown):

LayoutTests:

* platform/win/TestExpectations:
* platform/wincairo/TestExpectations:
Unskipped fast/events/keydown-function-keys.html and fast/events/keydown-leftright-keys.html.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252441 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/win/TestExpectations
LayoutTests/platform/wincairo/TestExpectations
Tools/ChangeLog
Tools/DumpRenderTree/win/EventSender.cpp
Tools/WebKitTestRunner/win/EventSenderProxyWin.cpp

index 12da970..2a32104 100644 (file)
@@ -1,3 +1,14 @@
+2019-11-13  Fujii Hironori  <Hironori.Fujii@sony.com>
+
+        [Win][DumpRenderTree][WebKitTestRunner] eventSender.keyDown should support function keys
+        https://bugs.webkit.org/show_bug.cgi?id=204146
+
+        Reviewed by Ross Kirsling.
+
+        * platform/win/TestExpectations:
+        * platform/wincairo/TestExpectations:
+        Unskipped fast/events/keydown-function-keys.html and fast/events/keydown-leftright-keys.html.
+
 2019-11-13  youenn fablet  <youenn@apple.com>
 
         Layout Tests in imported/w3c/web-platform-tests/websockets/ are flakey failures after r246406
index 5222878..08e297a 100644 (file)
@@ -233,9 +233,6 @@ http/tests/local/blob/send-sliced-data-blob.html [ Skip ]
 # TODO BlodBuilder is not enabled
 http/tests/local/blob/send-data-blob.html [ Skip ]
 
-# TODO A test that failed because eventSender cannot send function-key events.
-fast/events/keydown-function-keys.html [ Skip ]
-
 # TODO No support for WebArchives in WebKitWin <rdar://problem/6436020>
 webarchive [ Skip ]
 svg/webarchive [ Skip ]
@@ -2786,8 +2783,6 @@ fast/dynamic/window-resize-scrollbars-test.html [ Failure Timeout ]
 fast/encoding/parser-tests-110.html [ Pass Timeout ]
 
 webkit.org/b/103043 fast/events/frame-scroll-fake-mouse-move.html [ Skip ]
-webkit.org/b/97026 [ Release ] fast/events/keydown-leftright-keys.html [ Failure ]
-webkit.org/b/97026 [ Debug ] fast/events/keydown-leftright-keys.html [ Skip ] # Debug Assertion
 # fast/events/page-visibility tests timeout.
 webkit.org/b/121509 fast/events/wheelevent-mousewheel-interaction.html [ Skip ] #  [ Timeout ]
 fast/events/special-key-events-in-input-text.html [ Failure ]
index 7b8b4db..99af270 100644 (file)
@@ -1675,8 +1675,6 @@ fast/events/key-events-in-input-button.html [ Failure ]
 fast/events/key-events-in-input-text.html [ Failure ]
 fast/events/keyboardevent-code.html [ Failure ]
 fast/events/keyboardevent-key.html [ Failure ]
-fast/events/keydown-function-keys.html [ Failure ]
-fast/events/keydown-leftright-keys.html [ Failure ]
 fast/events/keydown-numpad-keys.html [ Failure ]
 fast/events/mouse-cursor-image-set.html [ Failure ]
 fast/events/mouseover-button.html [ Failure ]
index 85167bb..9401a25 100644 (file)
@@ -1,3 +1,28 @@
+2019-11-13  Fujii Hironori  <Hironori.Fujii@sony.com>
+
+        [Win][DumpRenderTree][WebKitTestRunner] eventSender.keyDown should support function keys
+        https://bugs.webkit.org/show_bug.cgi?id=204146
+
+        Reviewed by Ross Kirsling.
+
+        Changed eventSender.keyDown of DRT and WTR to support sending
+        function keys.
+
+        In addition to that, this change set correct scan code to LPARAM
+        for all key events. Unfortunately, there is no API to get a
+        correct extended scan code from a virtual key because
+        MapVirtualKey and MapVirtualKeyEx doesn't work as expected.
+        makeKeyDataForScanCode turns on KF_EXTENDED flag for some keys
+        explicitly for the workaround.
+        <http://www.setnode.com/blog/mapvirtualkey-getkeynametext-and-a-story-of-how-to/>
+
+        * DumpRenderTree/win/EventSender.cpp:
+        (makeKeyDataForScanCode):
+        (keyDownCallback):
+        * WebKitTestRunner/win/EventSenderProxyWin.cpp:
+        (WTR::makeKeyDataForScanCode):
+        (WTR::EventSenderProxy::keyDown):
+
 2019-11-13  Jonathan Bedard  <jbedard@apple.com>
 
         Python 3: Add support in webkitpy.style.checkers
index 3abb95d..72b0d59 100644 (file)
@@ -441,14 +441,39 @@ void replaySavedEvents(HRESULT* oleDragAndDropReturnValue)
     replayingSavedEvents = false;
 }
 
-static int makeKeyDataForScanCode(int virtualKeyCode)
+static unsigned makeKeyDataForScanCode(int virtualKeyCode)
 {
     unsigned scancode = MapVirtualKey(virtualKeyCode, MAPVK_VK_TO_VSC);
     int keyData = scancode & 0xFF;
+
+    bool forceExtended = false;
+    switch (virtualKeyCode) {
+    case VK_LEFT:
+    case VK_UP:
+    case VK_RIGHT:
+    case VK_DOWN:
+    case VK_PRIOR:
+    case VK_NEXT:
+    case VK_END:
+    case VK_HOME:
+    case VK_INSERT:
+    case VK_DELETE:
+    case VK_DIVIDE:
+    case VK_NUMLOCK:
+    case VK_RCONTROL:
+    case VK_RMENU:
+        // Some keys need to turn on KF_EXTENDED explicitly
+        forceExtended = true;
+        break;
+    default:
+        break;
+    }
+
     scancode = scancode >> 8;
-    if (scancode == 0xe0 || scancode == 0xe1)
+    if (scancode == 0xe0 || scancode == 0xe1 || forceExtended)
         keyData += KF_EXTENDED;
-    return keyData << 16;
+    unsigned repeat = 1;
+    return keyData << 16 | repeat;
 }
 
 static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
@@ -464,23 +489,18 @@ static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JS
     
     JSStringRef character = JSValueToStringCopy(context, arguments[0], exception);
     ASSERT(!*exception);
-    int virtualKeyCode;
+    int virtualKeyCode = 0;
     int charCode = 0;
-    int keyData = 1;
     bool needsShiftKeyModifier = false;
-    if (JSStringIsEqualToUTF8CString(character, "leftArrow")) {
+    if (JSStringIsEqualToUTF8CString(character, "leftArrow"))
         virtualKeyCode = VK_LEFT;
-        keyData += KF_EXTENDED << 16; // In this case, extended means "not keypad".
-    } else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) {
+    else if (JSStringIsEqualToUTF8CString(character, "rightArrow"))
         virtualKeyCode = VK_RIGHT;
-        keyData += KF_EXTENDED << 16;
-    } else if (JSStringIsEqualToUTF8CString(character, "upArrow")) {
+    else if (JSStringIsEqualToUTF8CString(character, "upArrow"))
         virtualKeyCode = VK_UP;
-        keyData += KF_EXTENDED << 16;
-    } else if (JSStringIsEqualToUTF8CString(character, "downArrow")) {
+    else if (JSStringIsEqualToUTF8CString(character, "downArrow"))
         virtualKeyCode = VK_DOWN;
-        keyData += KF_EXTENDED << 16;
-    } else if (JSStringIsEqualToUTF8CString(character, "pageUp"))
+    else if (JSStringIsEqualToUTF8CString(character, "pageUp"))
         virtualKeyCode = VK_PRIOR;
     else if (JSStringIsEqualToUTF8CString(character, "pageDown"))
         virtualKeyCode = VK_NEXT;
@@ -496,32 +516,54 @@ static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JS
         virtualKeyCode = VK_SNAPSHOT;
     else if (JSStringIsEqualToUTF8CString(character, "menu"))
         virtualKeyCode = VK_APPS;
-    else if (JSStringIsEqualToUTF8CString(character, "leftControl")) {
-        virtualKeyCode = VK_CONTROL;
-        keyData += makeKeyDataForScanCode(VK_LCONTROL);
-    } else if (JSStringIsEqualToUTF8CString(character, "leftShift")) {
-        virtualKeyCode = VK_SHIFT;
-        keyData += makeKeyDataForScanCode(VK_LSHIFT);
-    } else if (JSStringIsEqualToUTF8CString(character, "leftAlt")) {
-        virtualKeyCode = VK_MENU;
-        keyData += makeKeyDataForScanCode(VK_LMENU);
-    } else if (JSStringIsEqualToUTF8CString(character, "rightControl")) {
+    else if (JSStringIsEqualToUTF8CString(character, "leftControl"))
+        virtualKeyCode = VK_LCONTROL;
+    else if (JSStringIsEqualToUTF8CString(character, "leftShift"))
+        virtualKeyCode = VK_LSHIFT;
+    else if (JSStringIsEqualToUTF8CString(character, "leftAlt"))
+        virtualKeyCode = VK_LMENU;
+    else if (JSStringIsEqualToUTF8CString(character, "rightControl"))
+        virtualKeyCode = VK_RCONTROL;
+    else if (JSStringIsEqualToUTF8CString(character, "rightShift"))
+        virtualKeyCode = VK_RSHIFT;
+    else if (JSStringIsEqualToUTF8CString(character, "rightAlt"))
+        virtualKeyCode = VK_RMENU;
+    else {
+        size_t characterLength = JSStringGetLength(character);
+        static const char shiftedUSCharacters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?";
+        const wchar_t* characterPtr = JSStringGetCharactersPtr(character);
+        if (characterLength == 1) {
+            charCode = characterPtr[0];
+            virtualKeyCode = LOBYTE(VkKeyScan(charCode));
+            if (strchr(shiftedUSCharacters, charCode))
+                needsShiftKeyModifier = true;
+        } else if (characterPtr[0] == 'F') {
+            if (characterLength == 2 && isASCIIDigit(characterPtr[1]))
+                virtualKeyCode = VK_F1 + characterPtr[1] - '1';
+            else if (characterLength == 3 && characterPtr[1] == '1' && isASCIIDigit(characterPtr[2]))
+                virtualKeyCode = VK_F10 + characterPtr[2] - '0';
+        }
+    }
+    JSStringRelease(character);
+
+    unsigned keyData = makeKeyDataForScanCode(virtualKeyCode);
+
+    switch (virtualKeyCode) {
+    case VK_LCONTROL:
+    case VK_RCONTROL:
         virtualKeyCode = VK_CONTROL;
-        keyData += makeKeyDataForScanCode(VK_RCONTROL);
-    } else if (JSStringIsEqualToUTF8CString(character, "rightShift")) {
+        break;
+    case VK_LSHIFT:
+    case VK_RSHIFT:
         virtualKeyCode = VK_SHIFT;
-        keyData += makeKeyDataForScanCode(VK_RSHIFT);
-    } else if (JSStringIsEqualToUTF8CString(character, "rightAlt")) {
+        break;
+    case VK_LMENU:
+    case VK_RMENU:
         virtualKeyCode = VK_MENU;
-        keyData += makeKeyDataForScanCode(VK_RMENU);
-    } else {
-        static const char shiftedUSCharacters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?";
-        charCode = JSStringGetCharactersPtr(character)[0];
-        virtualKeyCode = LOBYTE(VkKeyScan(charCode));
-        if (strchr(shiftedUSCharacters, charCode))
-            needsShiftKeyModifier = true;
+        break;
+    default:
+        break;
     }
-    JSStringRelease(character);
 
     BYTE keyState[256];
     if (argumentCount > 1 || needsShiftKeyModifier) {
index 0888d3a..06f1926 100644 (file)
@@ -152,14 +152,39 @@ void EventSenderProxy::leapForward(int milliseconds)
     m_time += milliseconds / 1000.0;
 }
 
-static int makeKeyDataForScanCode(int virtualKeyCode)
+static unsigned makeKeyDataForScanCode(int virtualKeyCode)
 {
     unsigned scancode = MapVirtualKey(virtualKeyCode, MAPVK_VK_TO_VSC);
     int keyData = scancode & 0xFF;
+
+    bool forceExtended = false;
+    switch (virtualKeyCode) {
+    case VK_LEFT:
+    case VK_UP:
+    case VK_RIGHT:
+    case VK_DOWN:
+    case VK_PRIOR:
+    case VK_NEXT:
+    case VK_END:
+    case VK_HOME:
+    case VK_INSERT:
+    case VK_DELETE:
+    case VK_DIVIDE:
+    case VK_NUMLOCK:
+    case VK_RCONTROL:
+    case VK_RMENU:
+        // Some keys need to turn on KF_EXTENDED explicitly
+        forceExtended = true;
+        break;
+    default:
+        break;
+    }
+
     scancode = scancode >> 8;
-    if (scancode == 0xe0 || scancode == 0xe1)
+    if (scancode == 0xe0 || scancode == 0xe1 || forceExtended)
         keyData += KF_EXTENDED;
-    return keyData << 16;
+    unsigned repeat = 1;
+    return keyData << 16 | repeat;
 }
 
 static void pumpMessageQueue()
@@ -173,23 +198,19 @@ static void pumpMessageQueue()
 
 void EventSenderProxy::keyDown(WKStringRef keyRef, WKEventModifiers wkModifiers, unsigned location)
 {
-    int virtualKeyCode;
+    int virtualKeyCode = 0;
     int charCode = 0;
-    int keyData = 1;
+
     bool needsShiftKeyModifier = false;
-    if (WKStringIsEqualToUTF8CString(keyRef, "leftArrow")) {
+    if (WKStringIsEqualToUTF8CString(keyRef, "leftArrow"))
         virtualKeyCode = VK_LEFT;
-        keyData += KF_EXTENDED << 16; // In this case, extended means "not keypad".
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "rightArrow")) {
+    else if (WKStringIsEqualToUTF8CString(keyRef, "rightArrow"))
         virtualKeyCode = VK_RIGHT;
-        keyData += KF_EXTENDED << 16;
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "upArrow")) {
+    else if (WKStringIsEqualToUTF8CString(keyRef, "upArrow"))
         virtualKeyCode = VK_UP;
-        keyData += KF_EXTENDED << 16;
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "downArrow")) {
+    else if (WKStringIsEqualToUTF8CString(keyRef, "downArrow"))
         virtualKeyCode = VK_DOWN;
-        keyData += KF_EXTENDED << 16;
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "pageUp"))
+    else if (WKStringIsEqualToUTF8CString(keyRef, "pageUp"))
         virtualKeyCode = VK_PRIOR;
     else if (WKStringIsEqualToUTF8CString(keyRef, "pageDown"))
         virtualKeyCode = VK_NEXT;
@@ -205,32 +226,53 @@ void EventSenderProxy::keyDown(WKStringRef keyRef, WKEventModifiers wkModifiers,
         virtualKeyCode = VK_SNAPSHOT;
     else if (WKStringIsEqualToUTF8CString(keyRef, "menu"))
         virtualKeyCode = VK_APPS;
-    else if (WKStringIsEqualToUTF8CString(keyRef, "leftControl")) {
-        virtualKeyCode = VK_CONTROL;
-        keyData += makeKeyDataForScanCode(VK_LCONTROL);
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "leftShift")) {
-        virtualKeyCode = VK_SHIFT;
-        keyData += makeKeyDataForScanCode(VK_LSHIFT);
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "leftAlt")) {
-        virtualKeyCode = VK_MENU;
-        keyData += makeKeyDataForScanCode(VK_LMENU);
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "rightControl")) {
+    else if (WKStringIsEqualToUTF8CString(keyRef, "leftControl"))
+        virtualKeyCode = VK_LCONTROL;
+    else if (WKStringIsEqualToUTF8CString(keyRef, "leftShift"))
+        virtualKeyCode = VK_LSHIFT;
+    else if (WKStringIsEqualToUTF8CString(keyRef, "leftAlt"))
+        virtualKeyCode = VK_LMENU;
+    else if (WKStringIsEqualToUTF8CString(keyRef, "rightControl"))
+        virtualKeyCode = VK_RCONTROL;
+    else if (WKStringIsEqualToUTF8CString(keyRef, "rightShift"))
+        virtualKeyCode = VK_RSHIFT;
+    else if (WKStringIsEqualToUTF8CString(keyRef, "rightAlt"))
+        virtualKeyCode = VK_RMENU;
+    else {
+        size_t keyLength = WKStringGetLength(keyRef);
+        static const char shiftedUSCharacters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?";
+        wchar_t keyStr[3];
+        WKStringGetCharacters(keyRef, keyStr, _countof(keyStr));
+        if (keyLength == 1) {
+            charCode = keyStr[0];
+            virtualKeyCode = LOBYTE(VkKeyScan(charCode));
+            if (strchr(shiftedUSCharacters, charCode))
+                needsShiftKeyModifier = true;
+        } else if (keyStr[0] == 'F') {
+            if (keyLength == 2 && isASCIIDigit(keyStr[1]))
+                virtualKeyCode = VK_F1 + keyStr[1] - '1';
+            else if (keyLength == 3 && keyStr[1] == '1' && isASCIIDigit(keyStr[2]))
+                virtualKeyCode = VK_F10 + keyStr[2] - '0';
+        }
+    }
+
+    unsigned keyData = makeKeyDataForScanCode(virtualKeyCode);
+
+    switch (virtualKeyCode) {
+    case VK_LCONTROL:
+    case VK_RCONTROL:
         virtualKeyCode = VK_CONTROL;
-        keyData += makeKeyDataForScanCode(VK_RCONTROL);
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "rightShift")) {
+        break;
+    case VK_LSHIFT:
+    case VK_RSHIFT:
         virtualKeyCode = VK_SHIFT;
-        keyData += makeKeyDataForScanCode(VK_RSHIFT);
-    } else if (WKStringIsEqualToUTF8CString(keyRef, "rightAlt")) {
+        break;
+    case VK_LMENU:
+    case VK_RMENU:
         virtualKeyCode = VK_MENU;
-        keyData += makeKeyDataForScanCode(VK_RMENU);
-    } else {
-        static const char shiftedUSCharacters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?";
-        wchar_t buff[1];
-        WKStringGetCharacters(keyRef, buff, _countof(buff));
-        charCode = buff[0];
-        virtualKeyCode = LOBYTE(VkKeyScan(charCode));
-        if (strchr(shiftedUSCharacters, charCode))
-            needsShiftKeyModifier = true;
+        break;
+    default:
+        break;
     }
 
     bool isSysKey = false;