Skip to content

Commit a6d8ecc

Browse files
JoelEinbinderaslushnikov
authored andcommitted
fix(firefox): keyboard tests (#4082)
1 parent e8a4963 commit a6d8ecc

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

experimental/puppeteer-firefox/lib/Input.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ class Keyboard {
114114
if (this._modifiers & ~8)
115115
description.text = '';
116116

117-
// Firefox calls the 'Meta' key 'OS' on everything but mac
118-
if (os.platform() !== 'darwin' && description.key === 'Meta')
119-
description.key = 'OS';
120117
if (description.code === 'MetaLeft')
121118
description.code = 'OSLeft';
122119
if (description.code === 'MetaRight')

experimental/puppeteer-firefox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"node": ">=8.9.4"
1010
},
1111
"puppeteer": {
12-
"firefox_revision": "fd63770c54de8a6e4ac28bd9f010405c12105d63"
12+
"firefox_revision": "2f959d575a3d61f5dda12e4e2dca1f46a92ab569"
1313
},
1414
"scripts": {
1515
"install": "node install.js",

test/assets/input/keyboard.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
m.push('Alt')
2525
if (event.ctrlKey)
2626
m.push('Control');
27-
if (event.metaKey)
28-
m.push('Meta')
2927
if (event.shiftKey)
3028
m.push('Shift')
3129
return '[' + m.join(' ') + ']';

test/keyboard.spec.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
8181
await page.keyboard.sendCharacter('a');
8282
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('嗨a');
8383
});
84-
it_fails_ffox('should report shiftKey', async({page, server}) => {
84+
it('should report shiftKey', async({page, server}) => {
8585
await page.goto(server.PREFIX + '/input/keyboard.html');
8686
const keyboard = page.keyboard;
87-
const codeForKey = {'Shift': 16, 'Alt': 18, 'Meta': 91, 'Control': 17};
87+
const codeForKey = {'Shift': 16, 'Alt': 18, 'Control': 17};
8888
for (const modifierKey in codeForKey) {
8989
await keyboard.down(modifierKey);
9090
expect(await page.evaluate(() => getResult())).toBe('Keydown: ' + modifierKey + ' ' + modifierKey + 'Left ' + codeForKey[modifierKey] + ' [' + modifierKey + ']');
@@ -101,21 +101,21 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
101101
expect(await page.evaluate(() => getResult())).toBe('Keyup: ' + modifierKey + ' ' + modifierKey + 'Left ' + codeForKey[modifierKey] + ' []');
102102
}
103103
});
104-
it_fails_ffox('should report multiple modifiers', async({page, server}) => {
104+
it('should report multiple modifiers', async({page, server}) => {
105105
await page.goto(server.PREFIX + '/input/keyboard.html');
106106
const keyboard = page.keyboard;
107107
await keyboard.down('Control');
108108
expect(await page.evaluate(() => getResult())).toBe('Keydown: Control ControlLeft 17 [Control]');
109-
await keyboard.down('Meta');
110-
expect(await page.evaluate(() => getResult())).toBe('Keydown: Meta MetaLeft 91 [Control Meta]');
109+
await keyboard.down('Alt');
110+
expect(await page.evaluate(() => getResult())).toBe('Keydown: Alt AltLeft 18 [Alt Control]');
111111
await keyboard.down(';');
112-
expect(await page.evaluate(() => getResult())).toBe('Keydown: ; Semicolon 186 [Control Meta]');
112+
expect(await page.evaluate(() => getResult())).toBe('Keydown: ; Semicolon 186 [Alt Control]');
113113
await keyboard.up(';');
114-
expect(await page.evaluate(() => getResult())).toBe('Keyup: ; Semicolon 186 [Control Meta]');
114+
expect(await page.evaluate(() => getResult())).toBe('Keyup: ; Semicolon 186 [Alt Control]');
115115
await keyboard.up('Control');
116-
expect(await page.evaluate(() => getResult())).toBe('Keyup: Control ControlLeft 17 [Meta]');
117-
await keyboard.up('Meta');
118-
expect(await page.evaluate(() => getResult())).toBe('Keyup: Meta MetaLeft 91 []');
116+
expect(await page.evaluate(() => getResult())).toBe('Keyup: Control ControlLeft 17 [Alt]');
117+
await keyboard.up('Alt');
118+
expect(await page.evaluate(() => getResult())).toBe('Keyup: Alt AltLeft 18 []');
119119
});
120120
it('should send proper codes while typing', async({page, server}) => {
121121
await page.goto(server.PREFIX + '/input/keyboard.html');
@@ -225,5 +225,30 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
225225
await textarea.type('👹 Tokyo street Japan 🇯🇵');
226226
expect(await frame.$eval('textarea', textarea => textarea.value)).toBe('👹 Tokyo street Japan 🇯🇵');
227227
});
228+
it('should press the meta key', async({page}) => {
229+
await page.evaluate(() => {
230+
window.result = null;
231+
document.addEventListener('keydown', event => {
232+
window.result = [event.key, event.code, event.metaKey];
233+
});
234+
});
235+
await page.keyboard.press('Meta');
236+
const [key, code, metaKey] = await page.evaluate('result');
237+
if (FFOX && os.platform() !== 'darwin')
238+
expect(key).toBe('OS');
239+
else
240+
expect(key).toBe('Meta');
241+
242+
if (FFOX)
243+
expect(code).toBe('OSLeft');
244+
else
245+
expect(code).toBe('MetaLeft');
246+
247+
if (FFOX && os.platform() !== 'darwin')
248+
expect(metaKey).toBe(false);
249+
else
250+
expect(metaKey).toBe(true);
251+
252+
});
228253
});
229254
};

test/mouse.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
const os = require('os');
1617

1718
function dimensions() {
1819
const rect = document.querySelector('textarea').getBoundingClientRect();
@@ -99,7 +100,7 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
99100
await page.hover('#button-6');
100101
expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-6');
101102
});
102-
it_fails_ffox('should set modifier keys on click', async({page, server}) => {
103+
it('should set modifier keys on click', async({page, server}) => {
103104
await page.goto(server.PREFIX + '/input/scrollable.html');
104105
await page.evaluate(() => document.querySelector('#button-3').addEventListener('mousedown', e => window.lastEvent = e, true));
105106
const modifiers = {'Shift': 'shiftKey', 'Control': 'ctrlKey', 'Alt': 'altKey', 'Meta': 'metaKey'};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy