Merge pull request #7428 from electron/sandbox-specs
Explicitly close popup window from sandbox spec
This commit is contained in:
commit
4a186069d9
2 changed files with 16 additions and 6 deletions
|
@ -598,7 +598,7 @@ describe('browser-window module', function () {
|
||||||
|
|
||||||
const preload = path.join(fixtures, 'module', 'preload-sandbox.js')
|
const preload = path.join(fixtures, 'module', 'preload-sandbox.js')
|
||||||
|
|
||||||
// http protocol to simulate accessing a another domain. this is required
|
// http protocol to simulate accessing another domain. This is required
|
||||||
// because the code paths for cross domain popups is different.
|
// because the code paths for cross domain popups is different.
|
||||||
function crossDomainHandler (request, callback) {
|
function crossDomainHandler (request, callback) {
|
||||||
callback({
|
callback({
|
||||||
|
@ -698,6 +698,7 @@ describe('browser-window module', function () {
|
||||||
})
|
})
|
||||||
let htmlPath = path.join(fixtures, 'api', 'sandbox.html?window-open-external')
|
let htmlPath = path.join(fixtures, 'api', 'sandbox.html?window-open-external')
|
||||||
const pageUrl = 'file://' + htmlPath
|
const pageUrl = 'file://' + htmlPath
|
||||||
|
let popupWindow
|
||||||
w.loadURL(pageUrl)
|
w.loadURL(pageUrl)
|
||||||
w.webContents.once('new-window', (e, url, frameName, disposition, options) => {
|
w.webContents.once('new-window', (e, url, frameName, disposition, options) => {
|
||||||
assert.equal(url, 'http://www.google.com/#q=electron')
|
assert.equal(url, 'http://www.google.com/#q=electron')
|
||||||
|
@ -710,11 +711,20 @@ describe('browser-window module', function () {
|
||||||
assert.equal(html, '<h1>http://www.google.com/#q=electron</h1>')
|
assert.equal(html, '<h1>http://www.google.com/#q=electron</h1>')
|
||||||
ipcMain.once('answer', function (event, exceptionMessage) {
|
ipcMain.once('answer', function (event, exceptionMessage) {
|
||||||
assert(/Blocked a frame with origin/.test(exceptionMessage))
|
assert(/Blocked a frame with origin/.test(exceptionMessage))
|
||||||
|
|
||||||
|
// FIXME this popup window should be closed in sandbox.html
|
||||||
|
closeWindow(popupWindow).then(() => {
|
||||||
|
popupWindow = null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
w.webContents.send('child-loaded')
|
w.webContents.send('child-loaded')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.once('browser-window-created', function (event, window) {
|
||||||
|
popupWindow = window
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set ipc event sender correctly', function (done) {
|
it('should set ipc event sender correctly', function (done) {
|
||||||
|
|
4
spec/fixtures/api/sandbox.html
vendored
4
spec/fixtures/api/sandbox.html
vendored
|
@ -1,9 +1,9 @@
|
||||||
<html>
|
<html>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
if (window.opener) {
|
if (window.opener) {
|
||||||
window.callback = function() {
|
window.callback = () => {
|
||||||
opener.require('electron').ipcRenderer.send('answer', document.body.innerHTML)
|
opener.require('electron').ipcRenderer.send('answer', document.body.innerHTML)
|
||||||
};
|
}
|
||||||
} else {
|
} else {
|
||||||
const {ipcRenderer} = require('electron')
|
const {ipcRenderer} = require('electron')
|
||||||
const tests = {
|
const tests = {
|
||||||
|
|
Loading…
Reference in a new issue