From bf78b93428f9772e273ea67639400bcd27d2f491 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Wed, 20 Nov 2019 15:30:02 -0800 Subject: [PATCH] pass all webkit keyboard tests --- src/USKeyboardLayout.ts | 21 +++++++++++---------- src/webkit/Input.ts | 14 +++++++------- test/keyboard.spec.js | 6 +++--- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/USKeyboardLayout.ts b/src/USKeyboardLayout.ts index fc046d5c3c..67be3d9d60 100644 --- a/src/USKeyboardLayout.ts +++ b/src/USKeyboardLayout.ts @@ -23,7 +23,8 @@ type KeyDefinition = { code?: string text?: string shiftText?: string - location ?: number + location ?: number, + windowsVirtualKeyCode?: number; } export const keyDefinitions: { [s: string]: KeyDefinition; } = { @@ -48,12 +49,12 @@ export const keyDefinitions: { [s: string]: KeyDefinition; } = { 'Enter': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'}, '\r': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'}, '\n': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'}, - 'ShiftLeft': {'keyCode': 16, 'code': 'ShiftLeft', 'key': 'Shift', 'location': 1}, - 'ShiftRight': {'keyCode': 16, 'code': 'ShiftRight', 'key': 'Shift', 'location': 2}, - 'ControlLeft': {'keyCode': 17, 'code': 'ControlLeft', 'key': 'Control', 'location': 1}, - 'ControlRight': {'keyCode': 17, 'code': 'ControlRight', 'key': 'Control', 'location': 2}, - 'AltLeft': {'keyCode': 18, 'code': 'AltLeft', 'key': 'Alt', 'location': 1}, - 'AltRight': {'keyCode': 18, 'code': 'AltRight', 'key': 'Alt', 'location': 2}, + 'ShiftLeft': {'keyCode': 16, 'code': 'ShiftLeft', 'key': 'Shift', 'location': 1, 'windowsVirtualKeyCode': 160}, + 'ShiftRight': {'keyCode': 16, 'code': 'ShiftRight', 'key': 'Shift', 'location': 2, 'windowsVirtualKeyCode': 161}, + 'ControlLeft': {'keyCode': 17, 'code': 'ControlLeft', 'key': 'Control', 'location': 1, 'windowsVirtualKeyCode': 162}, + 'ControlRight': {'keyCode': 17, 'code': 'ControlRight', 'key': 'Control', 'location': 2, 'windowsVirtualKeyCode': 163}, + 'AltLeft': {'keyCode': 18, 'code': 'AltLeft', 'key': 'Alt', 'location': 1, 'windowsVirtualKeyCode': 164}, + 'AltRight': {'keyCode': 18, 'code': 'AltRight', 'key': 'Alt', 'location': 2, 'windowsVirtualKeyCode': 165}, 'Pause': {'keyCode': 19, 'code': 'Pause', 'key': 'Pause'}, 'CapsLock': {'keyCode': 20, 'code': 'CapsLock', 'key': 'CapsLock'}, 'Escape': {'keyCode': 27, 'code': 'Escape', 'key': 'Escape'}, @@ -175,9 +176,9 @@ export const keyDefinitions: { [s: string]: KeyDefinition; } = { 'Props': {'keyCode': 247, 'code': 'Props', 'key': 'CrSel'}, 'Cancel': {'keyCode': 3, 'key': 'Cancel', 'code': 'Abort'}, 'Clear': {'keyCode': 12, 'key': 'Clear', 'code': 'Numpad5', 'location': 3}, - 'Shift': {'keyCode': 16, 'key': 'Shift', 'code': 'ShiftLeft', 'location': 1}, - 'Control': {'keyCode': 17, 'key': 'Control', 'code': 'ControlLeft', 'location': 1}, - 'Alt': {'keyCode': 18, 'key': 'Alt', 'code': 'AltLeft', 'location': 1}, + 'Shift': {'keyCode': 16, 'key': 'Shift', 'code': 'ShiftLeft', 'location': 1, 'windowsVirtualKeyCode': 160}, + 'Control': {'keyCode': 17, 'key': 'Control', 'code': 'ControlLeft', 'location': 1, 'windowsVirtualKeyCode': 162}, + 'Alt': {'keyCode': 18, 'key': 'Alt', 'code': 'AltLeft', 'location': 1, 'windowsVirtualKeyCode': 164}, 'Accept': {'keyCode': 30, 'key': 'Accept'}, 'ModeChange': {'keyCode': 31, 'key': 'ModeChange'}, ' ': {'keyCode': 32, 'key': ' ', 'code': 'Space'}, diff --git a/src/webkit/Input.ts b/src/webkit/Input.ts index ff75aed1f3..c6277c408e 100644 --- a/src/webkit/Input.ts +++ b/src/webkit/Input.ts @@ -24,7 +24,7 @@ type KeyDescription = { key: string, text: string, code: string, - location: number, + isKeypad: boolean }; export type Modifier = 'Alt' | 'Control' | 'Meta' | 'Shift'; @@ -58,7 +58,7 @@ export class Keyboard { text: text, unmodifiedText: text, autoRepeat, - isKeypad: description.location === 3, + isKeypad: description.isKeypad, }); } @@ -86,7 +86,7 @@ export class Keyboard { keyCode: 0, code: '', text: '', - location: 0 + isKeypad: false }; const definition = keyDefinitions[keyString]; @@ -98,15 +98,13 @@ export class Keyboard { description.key = definition.shiftKey; if (definition.keyCode) - description.keyCode = definition.keyCode; + description.keyCode = definition.windowsVirtualKeyCode || definition.keyCode; if (shift && definition.shiftKeyCode) description.keyCode = definition.shiftKeyCode; if (definition.code) description.code = definition.code; - if (definition.location) - description.location = definition.location; if (description.key.length === 1) description.text = description.key; @@ -117,9 +115,11 @@ export class Keyboard { description.text = definition.shiftText; // if any modifiers besides shift are pressed, no text should be sent - if (this._modifiers & ~8) + if (this._modifiers & ~1) description.text = ''; + description.isKeypad = definition.location === 3; + return description; } diff --git a/test/keyboard.spec.js b/test/keyboard.spec.js index 306f470fd9..a7d0f92bf9 100644 --- a/test/keyboard.spec.js +++ b/test/keyboard.spec.js @@ -82,7 +82,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) { await page.keyboard.sendCharacter('a'); expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('嗨a'); }); - it.skip(WEBKIT)('should report shiftKey', async({page, server}) => { + it('should report shiftKey', async({page, server}) => { await page.goto(server.PREFIX + '/input/keyboard.html'); const keyboard = page.keyboard; const codeForKey = {'Shift': 16, 'Alt': 18, 'Control': 17}; @@ -131,7 +131,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) { 'Keypress: ^ Digit6 94 94 []', 'Keyup: ^ Digit6 54 []'].join('\n')); }); - it.skip(WEBKIT)('should send proper codes while typing with shift', async({page, server}) => { + it('should send proper codes while typing with shift', async({page, server}) => { await page.goto(server.PREFIX + '/input/keyboard.html'); const keyboard = page.keyboard; await keyboard.down('Shift'); @@ -184,7 +184,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) { await page.keyboard.type(text); expect(await page.evaluate('result')).toBe(text); }); - it.skip(WEBKIT)('should specify location', async({page, server}) => { + it('should specify location', async({page, server}) => { await page.goto(server.PREFIX + '/input/textarea.html'); await page.evaluate(() => { window.addEventListener('keydown', event => window.keyLocation = event.location, true);