spec: add test for syncronous access to blink APIs (#14637)
This test should ensure we catch a regression of #13787
This commit is contained in:
parent
e6242d5ef8
commit
50a4a8e9c3
3 changed files with 42 additions and 3 deletions
|
@ -1286,6 +1286,21 @@ describe('BrowserWindow module', () => {
|
||||||
})
|
})
|
||||||
w.loadFile(path.join(fixtures, 'api', 'preload.html'))
|
w.loadFile(path.join(fixtures, 'api', 'preload.html'))
|
||||||
})
|
})
|
||||||
|
it('has synchronous access to all eventual window APIs', async () => {
|
||||||
|
const preload = path.join(fixtures, 'module', 'access-blink-apis.js')
|
||||||
|
const w = await openTheWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
preload: preload
|
||||||
|
}
|
||||||
|
})
|
||||||
|
w.loadFile(path.join(fixtures, 'api', 'preload.html'))
|
||||||
|
const [, test] = await emittedOnce(ipcMain, 'answer')
|
||||||
|
expect(test).to.be.an('object')
|
||||||
|
expect(test.atPreload).to.be.an('array')
|
||||||
|
expect(test.atLoad).to.be.an('array')
|
||||||
|
expect(test.atPreload).to.deep.equal(test.atLoad, 'should have access to the same window APIs')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('session preload scripts', function () {
|
describe('session preload scripts', function () {
|
||||||
|
|
13
spec/fixtures/api/preload.html
vendored
13
spec/fixtures/api/preload.html
vendored
|
@ -1,9 +1,16 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
if (!window.test)
|
const send = () => {
|
||||||
window.test = 'window'
|
if (!window.test)
|
||||||
require('electron').ipcRenderer.send('answer', window.test);
|
window.test = 'window'
|
||||||
|
require('electron').ipcRenderer.send('answer', window.test);
|
||||||
|
}
|
||||||
|
if (window.delayed) {
|
||||||
|
window.addEventListener('load', send)
|
||||||
|
} else {
|
||||||
|
send()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
17
spec/fixtures/module/access-blink-apis.js
vendored
Normal file
17
spec/fixtures/module/access-blink-apis.js
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
window.delayed = true
|
||||||
|
|
||||||
|
global.getGlobalNames = () => {
|
||||||
|
return Object.getOwnPropertyNames(global)
|
||||||
|
.filter(key => typeof global[key] === 'function')
|
||||||
|
.filter(key => key !== 'WebView')
|
||||||
|
.sort()
|
||||||
|
}
|
||||||
|
|
||||||
|
const atPreload = global.getGlobalNames()
|
||||||
|
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
window.test = {
|
||||||
|
atPreload,
|
||||||
|
atLoad: global.getGlobalNames()
|
||||||
|
}
|
||||||
|
})
|
Loading…
Add table
Add a link
Reference in a new issue