Fix: Remove key codes from _pressedKeys Set after keyboard.up() is called (#1928)
keyboard.down() and keyboard.up() both use the _pressedKeys Set, however keyboard.down() adds and searches for the key code, whereas keyboard.up() attempts to delete based on the key rather than the key code. Fixes #1901
This commit is contained in:
parent
b275e66594
commit
f3ba436239
@ -133,7 +133,7 @@ class Keyboard {
|
||||
const description = this._keyDescriptionForString(key);
|
||||
|
||||
this._modifiers &= ~this._modifierBit(description.key);
|
||||
this._pressedKeys.delete(description.key);
|
||||
this._pressedKeys.delete(description.code);
|
||||
await this._client.send('Input.dispatchKeyEvent', {
|
||||
type: 'keyUp',
|
||||
modifiers: this._modifiers,
|
||||
|
12
test/test.js
12
test/test.js
@ -2350,6 +2350,18 @@ describe('Page', function() {
|
||||
await page.keyboard.type('Hello World!');
|
||||
expect(await page.evaluate(() => textarea.value)).toBe('He Wrd!');
|
||||
});
|
||||
it('should remove keys from _pressedKeys after keyboard.up()', async({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||
await page.focus('textarea');
|
||||
await page.keyboard.down('w');
|
||||
expect(await page.keyboard._pressedKeys.size).toEqual(1);
|
||||
await page.keyboard.down('1');
|
||||
expect(await page.keyboard._pressedKeys.size).toEqual(2);
|
||||
await page.keyboard.up('w');
|
||||
expect(await page.keyboard._pressedKeys.size).toEqual(1);
|
||||
await page.keyboard.up('1');
|
||||
expect(await page.keyboard._pressedKeys.size).toEqual(0);
|
||||
});
|
||||
it('keyboard.modifiers()', async({page, server}) => {
|
||||
const keyboard = page.keyboard;
|
||||
expect(keyboard._modifiers).toBe(0);
|
||||
|
Loading…
Reference in New Issue
Block a user