test: fix flaky before-input-event test (#16027)
This commit is contained in:
parent
48abef27d8
commit
1152fecb75
1 changed files with 65 additions and 68 deletions
|
@ -292,12 +292,12 @@ describe('webContents module', () => {
|
||||||
w.loadFile(path.join(fixtures, 'pages', 'key-events.html'))
|
w.loadFile(path.join(fixtures, 'pages', 'key-events.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has the correct properties', (done) => {
|
it('has the correct properties', async () => {
|
||||||
w.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
|
await w.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
|
||||||
w.webContents.once('did-finish-load', () => {
|
const testBeforeInput = (opts) => {
|
||||||
const testBeforeInput = (opts) => {
|
return new Promise((resolve, reject) => {
|
||||||
return new Promise((resolve, reject) => {
|
w.webContents.once('before-input-event', (event, input) => {
|
||||||
w.webContents.once('before-input-event', (event, input) => {
|
try {
|
||||||
assert.strictEqual(input.type, opts.type)
|
assert.strictEqual(input.type, opts.type)
|
||||||
assert.strictEqual(input.key, opts.key)
|
assert.strictEqual(input.key, opts.key)
|
||||||
assert.strictEqual(input.code, opts.code)
|
assert.strictEqual(input.code, opts.code)
|
||||||
|
@ -307,72 +307,69 @@ describe('webContents module', () => {
|
||||||
assert.strictEqual(input.alt, opts.alt)
|
assert.strictEqual(input.alt, opts.alt)
|
||||||
assert.strictEqual(input.meta, opts.meta)
|
assert.strictEqual(input.meta, opts.meta)
|
||||||
resolve()
|
resolve()
|
||||||
})
|
} catch (e) {
|
||||||
|
reject(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const modifiers = []
|
const modifiers = []
|
||||||
if (opts.shift) modifiers.push('shift')
|
if (opts.shift) modifiers.push('shift')
|
||||||
if (opts.control) modifiers.push('control')
|
if (opts.control) modifiers.push('control')
|
||||||
if (opts.alt) modifiers.push('alt')
|
if (opts.alt) modifiers.push('alt')
|
||||||
if (opts.meta) modifiers.push('meta')
|
if (opts.meta) modifiers.push('meta')
|
||||||
if (opts.isAutoRepeat) modifiers.push('isAutoRepeat')
|
if (opts.isAutoRepeat) modifiers.push('isAutoRepeat')
|
||||||
|
|
||||||
w.webContents.sendInputEvent({
|
w.webContents.sendInputEvent({
|
||||||
type: opts.type,
|
type: opts.type,
|
||||||
keyCode: opts.keyCode,
|
keyCode: opts.keyCode,
|
||||||
modifiers: modifiers
|
modifiers: modifiers
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
Promise.resolve().then(() => {
|
await testBeforeInput({
|
||||||
return testBeforeInput({
|
type: 'keyDown',
|
||||||
type: 'keyDown',
|
key: 'A',
|
||||||
key: 'A',
|
code: 'KeyA',
|
||||||
code: 'KeyA',
|
keyCode: 'a',
|
||||||
keyCode: 'a',
|
shift: true,
|
||||||
shift: true,
|
control: true,
|
||||||
control: true,
|
alt: true,
|
||||||
alt: true,
|
meta: true,
|
||||||
meta: true,
|
isAutoRepeat: true
|
||||||
isAutoRepeat: true
|
})
|
||||||
})
|
await testBeforeInput({
|
||||||
}).then(() => {
|
type: 'keyUp',
|
||||||
return testBeforeInput({
|
key: '.',
|
||||||
type: 'keyUp',
|
code: 'Period',
|
||||||
key: '.',
|
keyCode: '.',
|
||||||
code: 'Period',
|
shift: false,
|
||||||
keyCode: '.',
|
control: true,
|
||||||
shift: false,
|
alt: true,
|
||||||
control: true,
|
meta: false,
|
||||||
alt: true,
|
isAutoRepeat: false
|
||||||
meta: false,
|
})
|
||||||
isAutoRepeat: false
|
await testBeforeInput({
|
||||||
})
|
type: 'keyUp',
|
||||||
}).then(() => {
|
key: '!',
|
||||||
return testBeforeInput({
|
code: 'Digit1',
|
||||||
type: 'keyUp',
|
keyCode: '1',
|
||||||
key: '!',
|
shift: true,
|
||||||
code: 'Digit1',
|
control: false,
|
||||||
keyCode: '1',
|
alt: false,
|
||||||
shift: true,
|
meta: true,
|
||||||
control: false,
|
isAutoRepeat: false
|
||||||
alt: false,
|
})
|
||||||
meta: true,
|
await testBeforeInput({
|
||||||
isAutoRepeat: false
|
type: 'keyUp',
|
||||||
})
|
key: 'Tab',
|
||||||
}).then(() => {
|
code: 'Tab',
|
||||||
return testBeforeInput({
|
keyCode: 'Tab',
|
||||||
type: 'keyUp',
|
shift: false,
|
||||||
key: 'Tab',
|
control: true,
|
||||||
code: 'Tab',
|
alt: false,
|
||||||
keyCode: 'Tab',
|
meta: false,
|
||||||
shift: false,
|
isAutoRepeat: true
|
||||||
control: true,
|
|
||||||
alt: false,
|
|
||||||
meta: false,
|
|
||||||
isAutoRepeat: true
|
|
||||||
})
|
|
||||||
}).then(done).catch(done)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue