fix: handle shortcuts by default if no WebPreferences object exists (#14766)
DevTools webcontents do not have webpreferences Fixes #14685
This commit is contained in:
parent
0d2a0c7583
commit
6be69048e6
6 changed files with 581 additions and 43 deletions
|
@ -9,7 +9,7 @@ const { emittedOnce } = require('./events-helpers')
|
|||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
|
||||
const { ipcRenderer, remote } = require('electron')
|
||||
const { ipcRenderer, remote, clipboard } = require('electron')
|
||||
const { BrowserWindow, webContents, ipcMain, session } = remote
|
||||
const { expect } = chai
|
||||
|
||||
|
@ -255,6 +255,61 @@ describe('webContents module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('devtools window', () => {
|
||||
let testFn = it
|
||||
if (process.platform === 'darwin' && isCi) {
|
||||
testFn = it.skip
|
||||
}
|
||||
try {
|
||||
// We have other tests that check if native modules work, if we fail to require
|
||||
// robotjs let's skip this test to avoid false negatives
|
||||
require('robotjs')
|
||||
} catch (err) {
|
||||
testFn = it.skip
|
||||
}
|
||||
|
||||
testFn('can receive and handle menu events', async function () {
|
||||
this.timeout(5000)
|
||||
w.show()
|
||||
w.loadFile(path.join(fixtures, 'pages', 'key-events.html'))
|
||||
// Ensure the devtools are loaded
|
||||
w.webContents.closeDevTools()
|
||||
const opened = emittedOnce(w.webContents, 'devtools-opened')
|
||||
w.webContents.openDevTools()
|
||||
await opened
|
||||
await emittedOnce(w.webContents.devToolsWebContents, 'did-finish-load')
|
||||
w.webContents.devToolsWebContents.focus()
|
||||
|
||||
// Focus an input field
|
||||
await w.webContents.devToolsWebContents.executeJavaScript(
|
||||
`const input = document.createElement('input');
|
||||
document.body.innerHTML = '';
|
||||
document.body.appendChild(input)
|
||||
input.focus();`
|
||||
)
|
||||
|
||||
// Write something to the clipboard
|
||||
clipboard.writeText('test value')
|
||||
|
||||
// Fake a paste request using robotjs to emulate a REAL keyboard paste event
|
||||
require('robotjs').keyTap('v', process.platform === 'darwin' ? ['command'] : ['control'])
|
||||
|
||||
const start = Date.now()
|
||||
let val
|
||||
|
||||
// Check every now and again for the pasted value (paste is async)
|
||||
while (val !== 'test value' && Date.now() - start <= 1000) {
|
||||
val = await w.webContents.devToolsWebContents.executeJavaScript(
|
||||
`document.querySelector('input').value`
|
||||
)
|
||||
await new Promise(resolve => setTimeout(resolve, 10))
|
||||
}
|
||||
|
||||
// Once we're done expect the paste to have been successful
|
||||
expect(val).to.equal('test value', 'value should eventually become the pasted value')
|
||||
})
|
||||
})
|
||||
|
||||
describe('sendInputEvent(event)', () => {
|
||||
beforeEach((done) => {
|
||||
w.loadFile(path.join(fixtures, 'pages', 'key-events.html'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue