8000 test: fix flaky before-input-event test by nornagon · Pull Request #16027 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: fix flaky before-input-event test #16027

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

Merged
merged 1 commit into from
Dec 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 66 additions & 69 deletions spec/api-web-contents-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ describe('webContents module', () => {
w.loadFile(path.join(fixtures, 'pages', 'key-events.html'))
})

it('has the correct properties', (done) => {
w.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
w.webContents.once('did-finish-load', () => {
const testBeforeInput = (opts) => {
return new Promise((resolve, reject) => {
w.webContents.once('before-input-event', (event, input) => {
it('has the correct properties', async () => {
await w.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
const testBeforeInput = (opts) => {
return new Promise((resolve, reject) => {
w.webContents.once('before-input-event', (event, input) => {
try {
assert.strictEqual(input.type, opts.type)
assert.strictEqual(input.key, opts.key)
assert.strictEqual(input.code, opts.code)
Expand All @@ -307,72 +307,69 @@ describe('webContents module', () => {
assert.strictEqual(input.alt, opts.alt)
assert.strictEqual(input.meta, opts.meta)
resolve()
})

const modifiers = []
if (opts.shift) modifiers.push('shift')
if (opts.control) modifiers.push('control')
if (opts.alt) modifiers.push('alt')
if (opts.meta) modifiers.push('meta')
if (opts.isAutoRepeat) modifiers.push('isAutoRepeat')

w.webContents.sendInputEvent({
type: opts.type,
keyCode: opts.keyCode,
modifiers: modifiers
})
} catch (e) {
reject(e)
}
})
}

Promise.resolve().then(() => {
return testBeforeInput({
type: 'keyDown',
key: 'A',
code: 'KeyA',
keyCode: 'a',
shift: true,
control: true,
alt: true,
meta: true,
isAutoRepeat: true
const modifiers = []
if (opts.shift) modifiers.push('shift')
if (opts.control) modifiers.push('control')
if (opts.alt) modifiers.push('alt')
if (opts.meta) modifiers.push('meta')
if (opts.isAutoRepeat) modifiers.push('isAutoRepeat')

w.webContents.sendInputEvent({
type: opts.type,
keyCode: opts.keyCode,
modifiers: modifiers
})
}).then(() => {
return testBeforeInput({
type: 'keyUp',
key: '.',
code: 'Period',
keyCode: '.',
shift: false,
control: true,
alt: true,
meta: false,
isAutoRepeat: false
})
}).then(() => {
return testBeforeInput({
type: 'keyUp',
key: '!',
code: 'Digit1',
keyCode: '1',
shift: true,
control: false,
alt: false,
meta: true,
isAutoRepeat: false
})
}).then(() => {
return testBeforeInput({
type: 'keyUp',
key: 'Tab',
code: 'Tab',
keyCode: 'Tab',
shift: false,
control: true,
alt: false,
meta: false,
isAutoRepeat: true
})
}).then(done).catch(done)
})
}

await testBeforeInput({
type: 'keyDown',
key: 'A',
code: 'KeyA',
keyCode: 'a',
shift: true,
control: true,
alt: true,
meta: true,
isAutoRepeat: true
})
await testBeforeInput({
type: 'keyUp',
key: '.',
code: 'Period',
keyCode: '.',
shift: false,
control: true,
alt: true,
meta: false,
isAutoRepeat: false
})
await testBeforeInput({
type: 'keyUp',
key: '!',
code: 'Digit1',
keyCode: '1',
shift: true,
control: false,
alt: false,
meta: true,
isAutoRepeat: false
})
await testBeforeInput({
type: 'keyUp',
key: 'Tab',
code: 'Tab',
keyCode: 'Tab',
shift: false,
control: true,
alt: false,
meta: false,
isAutoRepeat: true
})
})
})
Expand Down
0