pass all webkit keyboard tests

This commit is contained in:
Joel Einbinder 2019-11-20 15:30:02 -08:00
parent d5aac044ca
commit bf78b93428
3 changed files with 21 additions and 20 deletions

View file

@ -23,7 +23,8 @@ type KeyDefinition = {
code?: string code?: string
text?: string text?: string
shiftText?: string shiftText?: string
location ?: number location ?: number,
windowsVirtualKeyCode?: number;
} }
export const keyDefinitions: { [s: string]: KeyDefinition; } = { 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'}, 'Enter': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'},
'\r': {'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'}, '\n': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'},
'ShiftLeft': {'keyCode': 16, 'code': 'ShiftLeft', 'key': 'Shift', 'location': 1}, 'ShiftLeft': {'keyCode': 16, 'code': 'ShiftLeft', 'key': 'Shift', 'location': 1, 'windowsVirtualKeyCode': 160},
'ShiftRight': {'keyCode': 16, 'code': 'ShiftRight', 'key': 'Shift', 'location': 2}, 'ShiftRight': {'keyCode': 16, 'code': 'ShiftRight', 'key': 'Shift', 'location': 2, 'windowsVirtualKeyCode': 161},
'ControlLeft': {'keyCode': 17, 'code': 'ControlLeft', 'key': 'Control', 'location': 1}, 'ControlLeft': {'keyCode': 17, 'code': 'ControlLeft', 'key': 'Control', 'location': 1, 'windowsVirtualKeyCode': 162},
'ControlRight': {'keyCode': 17, 'code': 'ControlRight', 'key': 'Control', 'location': 2}, 'ControlRight': {'keyCode': 17, 'code': 'ControlRight', 'key': 'Control', 'location': 2, 'windowsVirtualKeyCode': 163},
'AltLeft': {'keyCode': 18, 'code': 'AltLeft', 'key': 'Alt', 'location': 1}, 'AltLeft': {'keyCode': 18, 'code': 'AltLeft', 'key': 'Alt', 'location': 1, 'windowsVirtualKeyCode': 164},
'AltRight': {'keyCode': 18, 'code': 'AltRight', 'key': 'Alt', 'location': 2}, 'AltRight': {'keyCode': 18, 'code': 'AltRight', 'key': 'Alt', 'location': 2, 'windowsVirtualKeyCode': 165},
'Pause': {'keyCode': 19, 'code': 'Pause', 'key': 'Pause'}, 'Pause': {'keyCode': 19, 'code': 'Pause', 'key': 'Pause'},
'CapsLock': {'keyCode': 20, 'code': 'CapsLock', 'key': 'CapsLock'}, 'CapsLock': {'keyCode': 20, 'code': 'CapsLock', 'key': 'CapsLock'},
'Escape': {'keyCode': 27, 'code': 'Escape', 'key': 'Escape'}, 'Escape': {'keyCode': 27, 'code': 'Escape', 'key': 'Escape'},
@ -175,9 +176,9 @@ export const keyDefinitions: { [s: string]: KeyDefinition; } = {
'Props': {'keyCode': 247, 'code': 'Props', 'key': 'CrSel'}, 'Props': {'keyCode': 247, 'code': 'Props', 'key': 'CrSel'},
'Cancel': {'keyCode': 3, 'key': 'Cancel', 'code': 'Abort'}, 'Cancel': {'keyCode': 3, 'key': 'Cancel', 'code': 'Abort'},
'Clear': {'keyCode': 12, 'key': 'Clear', 'code': 'Numpad5', 'location': 3}, 'Clear': {'keyCode': 12, 'key': 'Clear', 'code': 'Numpad5', 'location': 3},
'Shift': {'keyCode': 16, 'key': 'Shift', 'code': 'ShiftLeft', 'location': 1}, 'Shift': {'keyCode': 16, 'key': 'Shift', 'code': 'ShiftLeft', 'location': 1, 'windowsVirtualKeyCode': 160},
'Control': {'keyCode': 17, 'key': 'Control', 'code': 'ControlLeft', 'location': 1}, 'Control': {'keyCode': 17, 'key': 'Control', 'code': 'ControlLeft', 'location': 1, 'windowsVirtualKeyCode': 162},
'Alt': {'keyCode': 18, 'key': 'Alt', 'code': 'AltLeft', 'location': 1}, 'Alt': {'keyCode': 18, 'key': 'Alt', 'code': 'AltLeft', 'location': 1, 'windowsVirtualKeyCode': 164},
'Accept': {'keyCode': 30, 'key': 'Accept'}, 'Accept': {'keyCode': 30, 'key': 'Accept'},
'ModeChange': {'keyCode': 31, 'key': 'ModeChange'}, 'ModeChange': {'keyCode': 31, 'key': 'ModeChange'},
' ': {'keyCode': 32, 'key': ' ', 'code': 'Space'}, ' ': {'keyCode': 32, 'key': ' ', 'code': 'Space'},

View file

@ -24,7 +24,7 @@ type KeyDescription = {
key: string, key: string,
text: string, text: string,
code: string, code: string,
location: number, isKeypad: boolean
}; };
export type Modifier = 'Alt' | 'Control' | 'Meta' | 'Shift'; export type Modifier = 'Alt' | 'Control' | 'Meta' | 'Shift';
@ -58,7 +58,7 @@ export class Keyboard {
text: text, text: text,
unmodifiedText: text, unmodifiedText: text,
autoRepeat, autoRepeat,
isKeypad: description.location === 3, isKeypad: description.isKeypad,
}); });
} }
@ -86,7 +86,7 @@ export class Keyboard {
keyCode: 0, keyCode: 0,
code: '', code: '',
text: '', text: '',
location: 0 isKeypad: false
}; };
const definition = keyDefinitions[keyString]; const definition = keyDefinitions[keyString];
@ -98,15 +98,13 @@ export class Keyboard {
description.key = definition.shiftKey; description.key = definition.shiftKey;
if (definition.keyCode) if (definition.keyCode)
description.keyCode = definition.keyCode; description.keyCode = definition.windowsVirtualKeyCode || definition.keyCode;
if (shift && definition.shiftKeyCode) if (shift && definition.shiftKeyCode)
description.keyCode = definition.shiftKeyCode; description.keyCode = definition.shiftKeyCode;
if (definition.code) if (definition.code)
description.code = definition.code; description.code = definition.code;
if (definition.location)
description.location = definition.location;
if (description.key.length === 1) if (description.key.length === 1)
description.text = description.key; description.text = description.key;
@ -117,9 +115,11 @@ export class Keyboard {
description.text = definition.shiftText; description.text = definition.shiftText;
// if any modifiers besides shift are pressed, no text should be sent // if any modifiers besides shift are pressed, no text should be sent
if (this._modifiers & ~8) if (this._modifiers & ~1)
description.text = ''; description.text = '';
description.isKeypad = definition.location === 3;
return description; return description;
} }

View file

@ -82,7 +82,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
await page.keyboard.sendCharacter('a'); await page.keyboard.sendCharacter('a');
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('嗨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'); await page.goto(server.PREFIX + '/input/keyboard.html');
const keyboard = page.keyboard; const keyboard = page.keyboard;
const codeForKey = {'Shift': 16, 'Alt': 18, 'Control': 17}; 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 []', 'Keypress: ^ Digit6 94 94 []',
'Keyup: ^ Digit6 54 []'].join('\n')); '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'); await page.goto(server.PREFIX + '/input/keyboard.html');
const keyboard = page.keyboard; const keyboard = page.keyboard;
await keyboard.down('Shift'); await keyboard.down('Shift');
@ -184,7 +184,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
await page.keyboard.type(text); await page.keyboard.type(text);
expect(await page.evaluate('result')).toBe(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.goto(server.PREFIX + '/input/textarea.html');
await page.evaluate(() => { await page.evaluate(() => {
window.addEventListener('keydown', event => window.keyLocation = event.location, true); window.addEventListener('keydown', event => window.keyLocation = event.location, true);