fix(firefox): keyboard tests (#4082)

This commit is contained in:
Joel Einbinder 2019-02-27 15:13:17 -08:00 committed by Andrey Lushnikov
parent e8a49633d9
commit a6d8ecce6f
5 changed files with 38 additions and 17 deletions

View File

@ -114,9 +114,6 @@ class Keyboard {
if (this._modifiers & ~8)
description.text = '';
// Firefox calls the 'Meta' key 'OS' on everything but mac
if (os.platform() !== 'darwin' && description.key === 'Meta')
description.key = 'OS';
if (description.code === 'MetaLeft')
description.code = 'OSLeft';
if (description.code === 'MetaRight')

View File

@ -9,7 +9,7 @@
"node": ">=8.9.4"
},
"puppeteer": {
"firefox_revision": "fd63770c54de8a6e4ac28bd9f010405c12105d63"
"firefox_revision": "2f959d575a3d61f5dda12e4e2dca1f46a92ab569"
},
"scripts": {
"install": "node install.js",

View File

@ -24,8 +24,6 @@
m.push('Alt')
if (event.ctrlKey)
m.push('Control');
if (event.metaKey)
m.push('Meta')
if (event.shiftKey)
m.push('Shift')
return '[' + m.join(' ') + ']';

View File

@ -81,10 +81,10 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
await page.keyboard.sendCharacter('a');
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('嗨a');
});
it_fails_ffox('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, 'Meta': 91, 'Control': 17};
const codeForKey = {'Shift': 16, 'Alt': 18, 'Control': 17};
for (const modifierKey in codeForKey) {
await keyboard.down(modifierKey);
expect(await page.evaluate(() => getResult())).toBe('Keydown: ' + modifierKey + ' ' + modifierKey + 'Left ' + codeForKey[modifierKey] + ' [' + modifierKey + ']');
@ -101,21 +101,21 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
expect(await page.evaluate(() => getResult())).toBe('Keyup: ' + modifierKey + ' ' + modifierKey + 'Left ' + codeForKey[modifierKey] + ' []');
}
});
it_fails_ffox('should report multiple modifiers', async({page, server}) => {
it('should report multiple modifiers', async({page, server}) => {
await page.goto(server.PREFIX + '/input/keyboard.html');
const keyboard = page.keyboard;
await keyboard.down('Control');
expect(await page.evaluate(() => getResult())).toBe('Keydown: Control ControlLeft 17 [Control]');
await keyboard.down('Meta');
expect(await page.evaluate(() => getResult())).toBe('Keydown: Meta MetaLeft 91 [Control Meta]');
await keyboard.down('Alt');
expect(await page.evaluate(() => getResult())).toBe('Keydown: Alt AltLeft 18 [Alt Control]');
await keyboard.down(';');
expect(await page.evaluate(() => getResult())).toBe('Keydown: ; Semicolon 186 [Control Meta]');
expect(await page.evaluate(() => getResult())).toBe('Keydown: ; Semicolon 186 [Alt Control]');
await keyboard.up(';');
expect(await page.evaluate(() => getResult())).toBe('Keyup: ; Semicolon 186 [Control Meta]');
expect(await page.evaluate(() => getResult())).toBe('Keyup: ; Semicolon 186 [Alt Control]');
await keyboard.up('Control');
expect(await page.evaluate(() => getResult())).toBe('Keyup: Control ControlLeft 17 [Meta]');
await keyboard.up('Meta');
expect(await page.evaluate(() => getResult())).toBe('Keyup: Meta MetaLeft 91 []');
expect(await page.evaluate(() => getResult())).toBe('Keyup: Control ControlLeft 17 [Alt]');
await keyboard.up('Alt');
expect(await page.evaluate(() => getResult())).toBe('Keyup: Alt AltLeft 18 []');
});
it('should send proper codes while typing', async({page, server}) => {
await page.goto(server.PREFIX + '/input/keyboard.html');
@ -225,5 +225,30 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
await textarea.type('👹 Tokyo street Japan 🇯🇵');
expect(await frame.$eval('textarea', textarea => textarea.value)).toBe('👹 Tokyo street Japan 🇯🇵');
});
it('should press the meta key', async({page}) => {
await page.evaluate(() => {
window.result = null;
document.addEventListener('keydown', event => {
window.result = [event.key, event.code, event.metaKey];
});
});
await page.keyboard.press('Meta');
const [key, code, metaKey] = await page.evaluate('result');
if (FFOX && os.platform() !== 'darwin')
expect(key).toBe('OS');
else
expect(key).toBe('Meta');
if (FFOX)
expect(code).toBe('OSLeft');
else
expect(code).toBe('MetaLeft');
if (FFOX && os.platform() !== 'darwin')
expect(metaKey).toBe(false);
else
expect(metaKey).toBe(true);
});
});
};

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const os = require('os');
function dimensions() {
const rect = document.querySelector('textarea').getBoundingClientRect();
@ -99,7 +100,7 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
await page.hover('#button-6');
expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-6');
});
it_fails_ffox('should set modifier keys on click', async({page, server}) => {
it('should set modifier keys on click', async({page, server}) => {
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.evaluate(() => document.querySelector('#button-3').addEventListener('mousedown', e => window.lastEvent = e, true));
const modifiers = {'Shift': 'shiftKey', 'Control': 'ctrlKey', 'Alt': 'altKey', 'Meta': 'metaKey'};