Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(keyboard): correctly press enter on firefox #1023

Merged
merged 1 commit into from Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/firefox/ffInput.ts
Expand Up @@ -64,6 +64,9 @@ export class RawKeyboardImpl implements input.RawKeyboard {
code = 'OSLeft';
if (code === 'MetaRight')
code = 'OSRight';
// Firefox will figure out Enter by itself
if (text === '\r')
text = '';
await this._client.send('Page.dispatchKeyEvent', {
type: 'keydown',
keyCode: keyCodeWithoutLocation,
Expand Down
26 changes: 17 additions & 9 deletions test/keyboard.spec.js
Expand Up @@ -207,15 +207,23 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT,
await textarea.press('NumpadSubtract');
expect(await page.evaluate('keyLocation')).toBe(3);
});
it.skip(FFOX)('should press Enter', async({page, server}) => {
await page.setContent('<input></input>');
await page.$eval('input', body => body.addEventListener('keydown', event => {
if (event.key === 'Enter')
window.ENTER_DOWN = true;
}, false));
await page.focus('input');
await page.keyboard.press('Enter');
expect(await page.evaluate(() => window.ENTER_DOWN)).toBe(true);
it('should press Enter', async({page, server}) => {
await page.setContent('<textarea></textarea>');
await page.focus('textarea');
await page.evaluate(() => window.addEventListener('keydown', e => window.lastEvent = {key: e.key, code:e.code}));
await testEnterKey('Enter', 'Enter', 'Enter');
await testEnterKey('NumpadEnter', 'Enter', 'NumpadEnter');
await testEnterKey('\n', 'Enter', 'Enter');
await testEnterKey('\r', 'Enter', 'Enter');

async function testEnterKey(key, expectedKey, expectedCode) {
await page.keyboard.press(key);
const lastEvent = await page.evaluate('lastEvent');
expect(lastEvent.key).toBe(expectedKey, `${JSON.stringify(key)} had the wrong key: ${lastEvent.key}`);
expect(lastEvent.code).toBe(expectedCode, `${JSON.stringify(key)} had the wrong code: ${lastEvent.code}`);
expect(await page.$eval('textarea', t => t.value)).toBe('\n', `${JSON.stringify(key)} failed to create a newline`);
await page.$eval('textarea', t => t.value = '');
}
});
it('should throw on unknown keys', async({page, server}) => {
let error = await page.keyboard.press('NotARealKey').catch(e => e);
Expand Down