chore: remove legacy checks in keyboard tests (#10995)

This commit is contained in:
jrandolf 2023-09-22 05:22:10 -07:00 committed by GitHub
parent 01c33e8177
commit f21e903633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 251 deletions

View File

@ -119,6 +119,12 @@
"parameters": ["webDriverBiDi"], "parameters": ["webDriverBiDi"],
"expectations": ["PASS"] "expectations": ["PASS"]
}, },
{
"testIdPattern": "[keyboard.spec] Keyboard *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.launch *", "testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.launch *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -642,100 +648,10 @@
"expectations": ["FAIL", "PASS"] "expectations": ["FAIL", "PASS"]
}, },
{ {
"testIdPattern": "[keyboard.spec] Keyboard ElementHandle.press should not support |text| option", "testIdPattern": "[keyboard.spec] Keyboard should send a character with sendCharacter",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"], "parameters": ["webDriverBiDi"],
"expectations": ["PASS"] "expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should move with the arrow keys",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should not type canceled events",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the meta key",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the metaKey",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should send a character with ElementHandle.press",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should send proper codes while typing",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should send proper codes while typing with shift",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should specify location",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should specify repeat property",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should throw on unknown keys",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should trigger commands of keyboard shortcuts",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should type all kinds of characters",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should type emoji",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should type emoji into an iframe",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should type into a textarea",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
}, },
{ {
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Browser.disconnect should reject navigation when browser closes", "testIdPattern": "[launcher.spec] Launcher specs Puppeteer Browser.disconnect should reject navigation when browser closes",
@ -2147,72 +2063,6 @@
"parameters": ["cdp", "chrome"], "parameters": ["cdp", "chrome"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[keyboard.spec] Keyboard ElementHandle.press should support |text| option",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the meta key",
"platforms": ["linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the meta key",
"platforms": ["linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the meta key",
"platforms": ["darwin"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the metaKey",
"platforms": ["linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the metaKey",
"platforms": ["linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the metaKey",
"platforms": ["darwin"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should report multiple modifiers",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should report shiftKey",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should report shiftKey",
"platforms": ["darwin"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should report shiftKey",
"platforms": ["linux"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[keyboard.spec] Keyboard should send a character with sendCharacter", "testIdPattern": "[keyboard.spec] Keyboard should send a character with sendCharacter",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -2237,12 +2087,6 @@
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[keyboard.spec] Keyboard should type all kinds of characters",
"platforms": ["linux"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[keyboard.spec] Keyboard should type emoji", "testIdPattern": "[keyboard.spec] Keyboard should type emoji",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],

View File

@ -10,13 +10,13 @@
let textarea = document.querySelector('textarea'); let textarea = document.querySelector('textarea');
textarea.focus(); textarea.focus();
textarea.addEventListener('keydown', event => { textarea.addEventListener('keydown', event => {
log('Keydown:', event.key, event.code, event.which, modifiers(event)); log('Keydown:', event.key, event.code, modifiers(event));
}); });
textarea.addEventListener('keypress', event => { textarea.addEventListener('input', event => {
log('Keypress:', event.key, event.code, event.which, event.charCode, modifiers(event)); log('input:', event.data, event.inputType, event.isComposing);
}); });
textarea.addEventListener('keyup', event => { textarea.addEventListener('keyup', event => {
log('Keyup:', event.key, event.code, event.which, modifiers(event)); log('Keyup:', event.key, event.code, modifiers(event));
}); });
function modifiers(event) { function modifiers(event) {
let m = []; let m = [];

View File

@ -41,21 +41,6 @@ describe('Keyboard', function () {
}) })
).toBe(text); ).toBe(text);
}); });
it('should press the metaKey', async () => {
const {page, isFirefox} = await getTestState();
await page.evaluate(() => {
(window as any).keyPromise = new Promise(resolve => {
return document.addEventListener('keydown', event => {
return resolve(event.key);
});
});
});
await page.keyboard.press('Meta');
expect(await page.evaluate('keyPromise')).toBe(
isFirefox && os.platform() !== 'darwin' ? 'OS' : 'Meta'
);
});
it('should move with the arrow keys', async () => { it('should move with the arrow keys', async () => {
const {page, server} = await getTestState(); const {page, server} = await getTestState();
@ -188,48 +173,29 @@ describe('Keyboard', function () {
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 = new Map<KeyInput, number>([ const codeForKey = new Set<KeyInput>(['Shift', 'Alt', 'Control']);
['Shift', 16], for (const modifierKey of codeForKey) {
['Alt', 18],
['Control', 17],
]);
for (const [modifierKey, modifierCode] of codeForKey) {
await keyboard.down(modifierKey); await keyboard.down(modifierKey);
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe( ).toBe(`Keydown: ${modifierKey} ${modifierKey}Left [${modifierKey}]`);
'Keydown: ' +
modifierKey +
' ' +
modifierKey +
'Left ' +
modifierCode +
' [' +
modifierKey +
']'
);
await keyboard.down('!'); await keyboard.down('!');
// Shift+! will generate a keypress
if (modifierKey === 'Shift') { if (modifierKey === 'Shift') {
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe( ).toBe(
'Keydown: ! Digit1 49 [' + `Keydown: ! Digit1 [${modifierKey}]\n` + `input: ! insertText false`
modifierKey +
']\nKeypress: ! Digit1 33 33 [' +
modifierKey +
']'
); );
} else { } else {
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe('Keydown: ! Digit1 49 [' + modifierKey + ']'); ).toBe(`Keydown: ! Digit1 [${modifierKey}]`);
} }
await keyboard.up('!'); await keyboard.up('!');
@ -237,21 +203,13 @@ describe('Keyboard', function () {
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe('Keyup: ! Digit1 49 [' + modifierKey + ']'); ).toBe(`Keyup: ! Digit1 [${modifierKey}]`);
await keyboard.up(modifierKey); await keyboard.up(modifierKey);
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe( ).toBe(`Keyup: ${modifierKey} ${modifierKey}Left []`);
'Keyup: ' +
modifierKey +
' ' +
modifierKey +
'Left ' +
modifierCode +
' []'
);
} }
}); });
it('should report multiple modifiers', async () => { it('should report multiple modifiers', async () => {
@ -264,37 +222,37 @@ describe('Keyboard', function () {
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe('Keydown: Control ControlLeft 17 [Control]'); ).toBe('Keydown: Control ControlLeft [Control]');
await keyboard.down('Alt'); await keyboard.down('Alt');
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe('Keydown: Alt AltLeft 18 [Alt Control]'); ).toBe('Keydown: Alt AltLeft [Alt Control]');
await keyboard.down(';'); await keyboard.down(';');
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe('Keydown: ; Semicolon 186 [Alt Control]'); ).toBe('Keydown: ; Semicolon [Alt Control]');
await keyboard.up(';'); await keyboard.up(';');
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe('Keyup: ; Semicolon 186 [Alt Control]'); ).toBe('Keyup: ; Semicolon [Alt Control]');
await keyboard.up('Control'); await keyboard.up('Control');
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe('Keyup: Control ControlLeft 17 [Alt]'); ).toBe('Keyup: Control ControlLeft [Alt]');
await keyboard.up('Alt'); await keyboard.up('Alt');
expect( expect(
await page.evaluate(() => { await page.evaluate(() => {
return (globalThis as any).getResult(); return (globalThis as any).getResult();
}) })
).toBe('Keyup: Alt AltLeft 18 []'); ).toBe('Keyup: Alt AltLeft []');
}); });
it('should send proper codes while typing', async () => { it('should send proper codes while typing', async () => {
const {page, server} = await getTestState(); const {page, server} = await getTestState();
@ -307,9 +265,9 @@ describe('Keyboard', function () {
}) })
).toBe( ).toBe(
[ [
'Keydown: ! Digit1 49 []', 'Keydown: ! Digit1 []',
'Keypress: ! Digit1 33 33 []', 'input: ! insertText false',
'Keyup: ! Digit1 49 []', 'Keyup: ! Digit1 []',
].join('\n') ].join('\n')
); );
await page.keyboard.type('^'); await page.keyboard.type('^');
@ -319,9 +277,9 @@ describe('Keyboard', function () {
}) })
).toBe( ).toBe(
[ [
'Keydown: ^ Digit6 54 []', 'Keydown: ^ Digit6 []',
'Keypress: ^ Digit6 94 94 []', 'input: ^ insertText false',
'Keyup: ^ Digit6 54 []', 'Keyup: ^ Digit6 []',
].join('\n') ].join('\n')
); );
}); });
@ -338,10 +296,10 @@ describe('Keyboard', function () {
}) })
).toBe( ).toBe(
[ [
'Keydown: Shift ShiftLeft 16 [Shift]', 'Keydown: Shift ShiftLeft [Shift]',
'Keydown: ~ Backquote 192 [Shift]', // 192 is ` keyCode 'Keydown: ~ Backquote [Shift]',
'Keypress: ~ Backquote 126 126 [Shift]', // 126 is ~ charCode 'input: ~ insertText false',
'Keyup: ~ Backquote 192 [Shift]', 'Keyup: ~ Backquote [Shift]',
].join('\n') ].join('\n')
); );
await keyboard.up('Shift'); await keyboard.up('Shift');
@ -499,7 +457,11 @@ describe('Keyboard', function () {
).toBe('👹 Tokyo street Japan 🇯🇵'); ).toBe('👹 Tokyo street Japan 🇯🇵');
}); });
it('should press the meta key', async () => { it('should press the meta key', async () => {
const {page, isFirefox} = await getTestState(); // This test only makes sense on macOS.
if (os.platform() !== 'darwin') {
return;
}
const {page} = await getTestState();
await page.evaluate(() => { await page.evaluate(() => {
(globalThis as any).result = null; (globalThis as any).result = null;
@ -517,22 +479,8 @@ describe('Keyboard', function () {
string, string,
boolean, boolean,
]; ];
if (isFirefox && os.platform() !== 'darwin') { expect(key).toBe('Meta');
expect(key).toBe('OS'); expect(code).toBe('MetaLeft');
} else { expect(metaKey).toBe(true);
expect(key).toBe('Meta');
}
if (isFirefox) {
expect(code).toBe('OSLeft');
} else {
expect(code).toBe('MetaLeft');
}
if (isFirefox && os.platform() !== 'darwin') {
expect(metaKey).toBe(false);
} else {
expect(metaKey).toBe(true);
}
}); });
}); });