Title: [217244] trunk/Source/WebKit2
- Revision
- 217244
- Author
- [email protected]
- Date
- 2017-05-22 13:56:49 -0700 (Mon, 22 May 2017)
Log Message
Web Automation: characters produced with shift modifier on QWERTY keyboard should be delivered as shift-down, char-down, char-up, shift-up events
https://bugs.webkit.org/show_bug.cgi?id=172299
<rdar://problem/32277988>
Reviewed by Joseph Pecoraro.
WebDriver tests expect some ASCII characters to be produced using the shift key,
regardless of the actual keyboard layout. Emit extra events when simulating these
keystrokes if the shift key is not already pressed.
* UIProcess/Automation/mac/WebAutomationSessionMac.mm:
(WebKit::characterIsProducedUsingShift):
(WebKit::WebAutomationSession::platformSimulateKeySequence):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (217243 => 217244)
--- trunk/Source/WebKit2/ChangeLog 2017-05-22 20:49:12 UTC (rev 217243)
+++ trunk/Source/WebKit2/ChangeLog 2017-05-22 20:56:49 UTC (rev 217244)
@@ -1,3 +1,19 @@
+2017-05-22 Brian Burg <[email protected]>
+
+ Web Automation: characters produced with shift modifier on QWERTY keyboard should be delivered as shift-down, char-down, char-up, shift-up events
+ https://bugs.webkit.org/show_bug.cgi?id=172299
+ <rdar://problem/32277988>
+
+ Reviewed by Joseph Pecoraro.
+
+ WebDriver tests expect some ASCII characters to be produced using the shift key,
+ regardless of the actual keyboard layout. Emit extra events when simulating these
+ keystrokes if the shift key is not already pressed.
+
+ * UIProcess/Automation/mac/WebAutomationSessionMac.mm:
+ (WebKit::characterIsProducedUsingShift):
+ (WebKit::WebAutomationSession::platformSimulateKeySequence):
+
2017-05-22 Sam Weinig <[email protected]>
[WebIDL] Support callbacks with arbitrary return types
Modified: trunk/Source/WebKit2/UIProcess/Automation/mac/WebAutomationSessionMac.mm (217243 => 217244)
--- trunk/Source/WebKit2/UIProcess/Automation/mac/WebAutomationSessionMac.mm 2017-05-22 20:49:12 UTC (rev 217243)
+++ trunk/Source/WebKit2/UIProcess/Automation/mac/WebAutomationSessionMac.mm 2017-05-22 20:56:49 UTC (rev 217244)
@@ -483,6 +483,47 @@
sendSynthesizedEventsToPage(page, eventsToBeSent.get());
}
+static BOOL characterIsProducedUsingShift(NSString *characters)
+{
+ ASSERT(characters.length == 1);
+
+ // Per the WebDriver specification, keystrokes are assumed to be produced a standard 108-key US keyboard layout.
+ // If this is no longer the case, then we'll need to use system keyboard SPI to decompose modifiers from keystrokes.
+ unichar c = [characters characterAtIndex:0];
+ if (c > 128)
+ return NO;
+
+ if (c >= 'A' && c <= 'Z')
+ return YES;
+
+ switch (c) {
+ case '~':
+ case '!':
+ case '@':
+ case '#':
+ case '$':
+ case '%':
+ case '^':
+ case '&':
+ case '*':
+ case '(':
+ case ')':
+ case '_':
+ case '+':
+ case '{':
+ case '}':
+ case '|':
+ case ':':
+ case '"':
+ case '<':
+ case '>':
+ case '?':
+ return YES;
+ default:
+ return NO;
+ }
+}
+
void WebAutomationSession::platformSimulateKeySequence(WebPageProxy& page, const String& keySequence)
{
auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
@@ -501,8 +542,22 @@
NSPoint eventPosition = NSMakePoint(0, window.frame.size.height);
[text enumerateSubstringsInRange:NSMakeRange(0, text.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
- [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyDown location:eventPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:substring charactersIgnoringModifiers:substring isARepeat:NO keyCode:0]];
- [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyUp location:eventPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:substring charactersIgnoringModifiers:substring isARepeat:NO keyCode:0]];
+
+ // For ASCII characters that are produced using Shift on a US-108 key keyboard layout,
+ // WebDriver expects these to be delivered as [shift-down, key-down, key-up, shift-up]
+ // keystrokes unless the shift key is already pressed down from an earlier interaction.
+ BOOL shiftAlreadyPressed = modifiers & NSEventModifierFlagShift;
+ BOOL shouldPressShift = !shiftAlreadyPressed && substringRange.length == 1 && characterIsProducedUsingShift(substring);
+ NSEventModifierFlags modifiersForKeystroke = shouldPressShift ? modifiers | NSEventModifierFlagShift : modifiers;
+
+ if (shouldPressShift)
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeFlagsChanged location:eventPosition modifierFlags:modifiersForKeystroke timestamp:timestamp windowNumber:windowNumber context:nil characters:@"" charactersIgnoringModifiers:@"" isARepeat:NO keyCode:kVK_Shift]];
+
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyDown location:eventPosition modifierFlags:modifiersForKeystroke timestamp:timestamp windowNumber:windowNumber context:nil characters:substring charactersIgnoringModifiers:substring isARepeat:NO keyCode:0]];
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyUp location:eventPosition modifierFlags:modifiersForKeystroke timestamp:timestamp windowNumber:windowNumber context:nil characters:substring charactersIgnoringModifiers:substring isARepeat:NO keyCode:0]];
+
+ if (shouldPressShift)
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeFlagsChanged location:eventPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:@"" charactersIgnoringModifiers:@"" isARepeat:NO keyCode:kVK_Shift]];
}];
sendSynthesizedEventsToPage(page, eventsToBeSent.get());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes