test: expand window.opener test and move to main process (#20549)

This commit is contained in:
Jeremy Apthorp 2019-10-14 09:00:34 -07:00 committed by GitHub
parent dfac05805d
commit d67f25ce43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 48 deletions

View file

@ -195,53 +195,6 @@ describe('chromium feature', () => {
})
})
describe('window.opener access from BrowserWindow', () => {
const scheme = 'other'
const url = `${scheme}://${fixtures}/pages/window-opener-location.html`
let w = null
before((done) => {
protocol.registerFileProtocol(scheme, (request, callback) => {
callback(`${fixtures}/pages/window-opener-location.html`)
}, (error) => done(error))
})
after(() => {
protocol.unregisterProtocol(scheme)
})
afterEach(() => {
w.close()
})
it('fails when origin of current window does not match opener', (done) => {
listener = (event) => {
expect(event.data).to.equal(null)
done()
}
window.addEventListener('message', listener)
w = window.open(url, '', 'show=no,nodeIntegration=no')
})
it('works when origin matches', (done) => {
listener = (event) => {
expect(event.data).to.equal(location.href)
done()
}
window.addEventListener('message', listener)
w = window.open(`file://${fixtures}/pages/window-opener-location.html`, '', 'show=no,nodeIntegration=no')
})
it('works when origin does not match opener but has node integration', (done) => {
listener = (event) => {
expect(event.data).to.equal(location.href)
done()
}
window.addEventListener('message', listener)
w = window.open(url, '', 'show=no,nodeIntegration=yes')
})
})
describe('window.opener access from <webview>', () => {
const scheme = 'other'
const srcPath = `${fixtures}/pages/webview-opener-postMessage.html`