fix: emit IPC event in correct context if isolation and sandbox enabled (#16352)
* fix: emit IPC event in correct context if isolation and sandbox enabled IPC events were not being delivered to renderer processes when both `contextIsolation` and `sandbox` were enabled. This is because the `AtomSandboxedRenderFrameObserver` class was incorrectly using the `MainWorldScriptContext`, rather than conditionally selecting the context based on if isolation was enabled. Fixes #11922
This commit is contained in:
parent
134792a594
commit
dcb670fa46
5 changed files with 58 additions and 70 deletions
|
@ -138,63 +138,54 @@ describe('ipc renderer module', () => {
|
|||
contents = null
|
||||
})
|
||||
|
||||
it('sends message to WebContents', done => {
|
||||
contents = webContents.create({
|
||||
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js')
|
||||
const generateSpecs = (description, webPreferences) => {
|
||||
describe(description, () => {
|
||||
it('sends message to WebContents', done => {
|
||||
contents = webContents.create({
|
||||
preload: path.join(fixtures, 'module', 'preload-ipc-ping-pong.js'),
|
||||
...webPreferences
|
||||
})
|
||||
|
||||
const payload = 'Hello World!'
|
||||
|
||||
ipcRenderer.once('pong', (event, data) => {
|
||||
expect(payload).to.equal(data)
|
||||
done()
|
||||
})
|
||||
|
||||
contents.once('did-finish-load', () => {
|
||||
ipcRenderer.sendTo(contents.id, 'ping', payload)
|
||||
})
|
||||
|
||||
contents.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
|
||||
})
|
||||
|
||||
it('sends message to WebContents (channel has special chars)', done => {
|
||||
contents = webContents.create({
|
||||
preload: path.join(fixtures, 'module', 'preload-ipc-ping-pong.js'),
|
||||
...webPreferences
|
||||
})
|
||||
|
||||
const payload = 'Hello World!'
|
||||
|
||||
ipcRenderer.once('pong-æøåü', (event, data) => {
|
||||
expect(payload).to.equal(data)
|
||||
done()
|
||||
})
|
||||
|
||||
contents.once('did-finish-load', () => {
|
||||
ipcRenderer.sendTo(contents.id, 'ping-æøåü', payload)
|
||||
})
|
||||
|
||||
contents.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const payload = 'Hello World!'
|
||||
|
||||
ipcRenderer.once('pong', (event, data) => {
|
||||
expect(payload).to.equal(data)
|
||||
done()
|
||||
})
|
||||
|
||||
contents.once('did-finish-load', () => {
|
||||
ipcRenderer.sendTo(contents.id, 'ping', payload)
|
||||
})
|
||||
|
||||
contents.loadFile(path.join(fixtures, 'pages', 'ping-pong.html'))
|
||||
})
|
||||
|
||||
it('sends message to WebContents (sanboxed renderer)', done => {
|
||||
contents = webContents.create({
|
||||
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js'),
|
||||
sandbox: true
|
||||
})
|
||||
|
||||
const payload = 'Hello World!'
|
||||
|
||||
ipcRenderer.once('pong', (event, data) => {
|
||||
expect(payload).to.equal(data)
|
||||
done()
|
||||
})
|
||||
|
||||
contents.once('did-finish-load', () => {
|
||||
ipcRenderer.sendTo(contents.id, 'ping', payload)
|
||||
})
|
||||
|
||||
contents.loadFile(path.join(fixtures, 'pages', 'ping-pong.html'))
|
||||
})
|
||||
|
||||
it('sends message to WebContents (channel has special chars)', done => {
|
||||
contents = webContents.create({
|
||||
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js')
|
||||
})
|
||||
|
||||
const payload = 'Hello World!'
|
||||
|
||||
ipcRenderer.once('pong-æøåü', (event, data) => {
|
||||
expect(payload).to.equal(data)
|
||||
done()
|
||||
})
|
||||
|
||||
contents.once('did-finish-load', () => {
|
||||
ipcRenderer.sendTo(contents.id, 'ping-æøåü', payload)
|
||||
})
|
||||
|
||||
contents.loadFile(path.join(fixtures, 'pages', 'ping-pong.html'))
|
||||
})
|
||||
generateSpecs('without sandbox', {})
|
||||
generateSpecs('with sandbox', { sandbox: true })
|
||||
generateSpecs('with contextIsolation', { contextIsolation: true })
|
||||
generateSpecs('with contextIsolation + sandbox', { contextIsolation: true, sandbox: true })
|
||||
})
|
||||
|
||||
describe('remote listeners', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue