feat: enable NodeIntegrationInSubFrames for webview (#17226)
* feat: enable nodeIntegrationInSubFrames for webview * test: add tests * docs: document webview's nodeintegrationinsubframes * lint: fix indent * fix: resolve some merge bloopers
This commit is contained in:
parent
961c9a88a8
commit
43ef561d48
8 changed files with 95 additions and 15 deletions
|
@ -10,6 +10,7 @@ const { BrowserWindow } = remote
|
|||
describe('renderer nodeIntegrationInSubFrames', () => {
|
||||
const generateTests = (description, webPreferences) => {
|
||||
describe(description, () => {
|
||||
const fixtureSuffix = webPreferences.webviewTag ? '-webview' : ''
|
||||
let w
|
||||
|
||||
beforeEach(async () => {
|
||||
|
@ -18,11 +19,7 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
|||
show: false,
|
||||
width: 400,
|
||||
height: 400,
|
||||
webPreferences: {
|
||||
preload: path.resolve(__dirname, 'fixtures/sub-frames/preload.js'),
|
||||
nodeIntegrationInSubFrames: true,
|
||||
...webPreferences
|
||||
}
|
||||
webPreferences
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -34,7 +31,7 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
|||
|
||||
it('should load preload scripts in top level iframes', async () => {
|
||||
const detailsPromise = emittedNTimes(remote.ipcMain, 'preload-ran', 2)
|
||||
w.loadFile(path.resolve(__dirname, 'fixtures/sub-frames/frame-container.html'))
|
||||
w.loadFile(path.resolve(__dirname, `fixtures/sub-frames/frame-container${fixtureSuffix}.html`))
|
||||
const [event1, event2] = await detailsPromise
|
||||
expect(event1[0].frameId).to.not.equal(event2[0].frameId)
|
||||
expect(event1[0].frameId).to.equal(event1[2])
|
||||
|
@ -43,7 +40,7 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
|||
|
||||
it('should load preload scripts in nested iframes', async () => {
|
||||
const detailsPromise = emittedNTimes(remote.ipcMain, 'preload-ran', 3)
|
||||
w.loadFile(path.resolve(__dirname, 'fixtures/sub-frames/frame-with-frame-container.html'))
|
||||
w.loadFile(path.resolve(__dirname, `fixtures/sub-frames/frame-with-frame-container${fixtureSuffix}.html`))
|
||||
const [event1, event2, event3] = await detailsPromise
|
||||
expect(event1[0].frameId).to.not.equal(event2[0].frameId)
|
||||
expect(event1[0].frameId).to.not.equal(event3[0].frameId)
|
||||
|
@ -55,7 +52,7 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
|||
|
||||
it('should correctly reply to the main frame with using event.reply', async () => {
|
||||
const detailsPromise = emittedNTimes(remote.ipcMain, 'preload-ran', 2)
|
||||
w.loadFile(path.resolve(__dirname, 'fixtures/sub-frames/frame-container.html'))
|
||||
w.loadFile(path.resolve(__dirname, `fixtures/sub-frames/frame-container${fixtureSuffix}.html`))
|
||||
const [event1] = await detailsPromise
|
||||
const pongPromise = emittedOnce(remote.ipcMain, 'preload-pong')
|
||||
event1[0].reply('preload-ping')
|
||||
|
@ -65,7 +62,7 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
|||
|
||||
it('should correctly reply to the sub-frames with using event.reply', async () => {
|
||||
const detailsPromise = emittedNTimes(remote.ipcMain, 'preload-ran', 2)
|
||||
w.loadFile(path.resolve(__dirname, 'fixtures/sub-frames/frame-container.html'))
|
||||
w.loadFile(path.resolve(__dirname, `fixtures/sub-frames/frame-container${fixtureSuffix}.html`))
|
||||
const [, event2] = await detailsPromise
|
||||
const pongPromise = emittedOnce(remote.ipcMain, 'preload-pong')
|
||||
event2[0].reply('preload-ping')
|
||||
|
@ -75,7 +72,7 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
|||
|
||||
it('should correctly reply to the nested sub-frames with using event.reply', async () => {
|
||||
const detailsPromise = emittedNTimes(remote.ipcMain, 'preload-ran', 3)
|
||||
w.loadFile(path.resolve(__dirname, 'fixtures/sub-frames/frame-with-frame-container.html'))
|
||||
w.loadFile(path.resolve(__dirname, `fixtures/sub-frames/frame-with-frame-container${fixtureSuffix}.html`))
|
||||
const [, , event3] = await detailsPromise
|
||||
const pongPromise = emittedOnce(remote.ipcMain, 'preload-pong')
|
||||
event3[0].reply('preload-ping')
|
||||
|
@ -85,7 +82,7 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
|||
|
||||
it('should not expose globals in main world', async () => {
|
||||
const detailsPromise = emittedNTimes(remote.ipcMain, 'preload-ran', 2)
|
||||
w.loadFile(path.resolve(__dirname, 'fixtures/sub-frames/frame-container.html'))
|
||||
w.loadFile(path.resolve(__dirname, `fixtures/sub-frames/frame-container${fixtureSuffix}.html`))
|
||||
const details = await detailsPromise
|
||||
const senders = details.map(event => event[0].sender)
|
||||
await new Promise((resolve) => {
|
||||
|
@ -108,8 +105,50 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
|||
})
|
||||
}
|
||||
|
||||
generateTests('without sandbox', {})
|
||||
generateTests('with sandbox', { sandbox: true })
|
||||
generateTests('with contextIsolation', { contextIsolation: true })
|
||||
generateTests('with contextIsolation + sandbox', { contextIsolation: true, sandbox: true })
|
||||
const generateConfigs = (webPreferences, ...permutations) => {
|
||||
const configs = [{ webPreferences, names: [] }]
|
||||
for (let i = 0; i < permutations.length; i++) {
|
||||
const length = configs.length
|
||||
for (let j = 0; j < length; j++) {
|
||||
const newConfig = Object.assign({}, configs[j])
|
||||
newConfig.webPreferences = Object.assign({},
|
||||
newConfig.webPreferences, permutations[i].webPreferences)
|
||||
newConfig.names = newConfig.names.slice(0)
|
||||
newConfig.names.push(permutations[i].name)
|
||||
configs.push(newConfig)
|
||||
}
|
||||
}
|
||||
|
||||
return configs.map(config => {
|
||||
if (config.names.length > 0) {
|
||||
config.title = `with ${config.names.join(', ')} on`
|
||||
} else {
|
||||
config.title = `without anything special turned on`
|
||||
}
|
||||
delete config.names
|
||||
|
||||
return config
|
||||
})
|
||||
}
|
||||
|
||||
generateConfigs(
|
||||
{
|
||||
preload: path.resolve(__dirname, 'fixtures/sub-frames/preload.js'),
|
||||
nodeIntegrationInSubFrames: true
|
||||
},
|
||||
{
|
||||
name: 'sandbox',
|
||||
webPreferences: { sandbox: true }
|
||||
},
|
||||
{
|
||||
name: 'context isolation',
|
||||
webPreferences: { contextIsolation: true }
|
||||
},
|
||||
{
|
||||
name: 'webview',
|
||||
webPreferences: { webviewTag: true, preload: false }
|
||||
}
|
||||
).forEach(config => {
|
||||
generateTests(config.title, config.webPreferences)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue