Add spec for reloading opened window cross-origin
This commit is contained in:
parent
0c8f773dec
commit
3925bfde8e
5 changed files with 87 additions and 0 deletions
|
@ -1400,6 +1400,31 @@ describe('BrowserWindow module', function () {
|
||||||
})
|
})
|
||||||
w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`)
|
w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('retains the original web preferences when window.location is changed to a new origin', async function () {
|
||||||
|
await serveFileFromProtocol('foo', path.join(fixtures, 'api', 'window-open-location-change.html'))
|
||||||
|
await serveFileFromProtocol('bar', path.join(fixtures, 'api', 'window-open-location-final.html'))
|
||||||
|
|
||||||
|
w.destroy()
|
||||||
|
w = new BrowserWindow({
|
||||||
|
show: true,
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: false,
|
||||||
|
nativeWindowOpen: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', path.join(fixtures, 'api', 'window-open-preload.js'))
|
||||||
|
ipcMain.once('answer', (event, args, typeofProcess) => {
|
||||||
|
assert.equal(args.includes('--node-integration=false'), true)
|
||||||
|
assert.equal(args.includes('--native-window-open'), true)
|
||||||
|
assert.equal(typeofProcess, 'undefined')
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
w.loadURL(`file://${path.join(fixtures, 'api', 'window-open-location-open.html')}`)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2780,3 +2805,20 @@ const isScaleFactorRounding = () => {
|
||||||
// Return true if scale factor is odd number above 2
|
// Return true if scale factor is odd number above 2
|
||||||
return scaleFactor > 2 && scaleFactor % 2 === 1
|
return scaleFactor > 2 && scaleFactor % 2 === 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serveFileFromProtocol (protocolName, filePath) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
protocol.registerBufferProtocol(protocolName, (request, callback) => {
|
||||||
|
callback({
|
||||||
|
mimeType: 'text/html',
|
||||||
|
data: fs.readFileSync(filePath)
|
||||||
|
})
|
||||||
|
}, (error) => {
|
||||||
|
if (error != null) {
|
||||||
|
reject(error)
|
||||||
|
} else {
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
15
spec/fixtures/api/window-open-location-change.html
vendored
Normal file
15
spec/fixtures/api/window-open-location-change.html
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
foo
|
||||||
|
<script type="text/javascript">
|
||||||
|
setTimeout(function () {
|
||||||
|
window.location = 'bar://page'
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
10
spec/fixtures/api/window-open-location-final.html
vendored
Normal file
10
spec/fixtures/api/window-open-location-final.html
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
bar
|
||||||
|
</body>
|
||||||
|
</html>
|
12
spec/fixtures/api/window-open-location-open.html
vendored
Normal file
12
spec/fixtures/api/window-open-location-open.html
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
window.open('foo://page')
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
8
spec/fixtures/api/window-open-preload.js
vendored
Normal file
8
spec/fixtures/api/window-open-preload.js
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
const {ipcRenderer} = require('electron')
|
||||||
|
|
||||||
|
setImmediate(function () {
|
||||||
|
if (window.location.toString() === 'bar://page') {
|
||||||
|
ipcRenderer.send('answer', process.argv, typeof global.process)
|
||||||
|
window.close()
|
||||||
|
}
|
||||||
|
})
|
Loading…
Add table
Add a link
Reference in a new issue