mirror of
https://github.com/electron/electron.git
synced 2026-01-10 07:58:08 -05:00
Add spec for cross-origin blockage
This commit is contained in:
@@ -1285,6 +1285,14 @@ describe('BrowserWindow module', function () {
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-file.html'))
|
||||
})
|
||||
|
||||
it('blocks accessing cross-origin frames', (done) => {
|
||||
ipcMain.once('answer', (event, content) => {
|
||||
assert.equal(content, 'Blocked a frame with origin "file://" from accessing a cross-origin frame.')
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-cross-origin.html'))
|
||||
})
|
||||
|
||||
it('opens window from <iframe> tags', (done) => {
|
||||
ipcMain.once('answer', (event, content) => {
|
||||
assert.equal(content, 'Hello')
|
||||
|
||||
19
spec/fixtures/api/native-window-open-cross-origin.html
vendored
Normal file
19
spec/fixtures/api/native-window-open-cross-origin.html
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
const {ipcRenderer} = require('electron')
|
||||
const popup = window.open('http://host')
|
||||
const intervalID = setInterval(function () {
|
||||
try {
|
||||
if (popup.location.toString() !== 'about:blank') {
|
||||
clearInterval(intervalID)
|
||||
ipcRenderer.send('answer', 'did not throw error')
|
||||
}
|
||||
} catch (error) {
|
||||
clearInterval(intervalID)
|
||||
ipcRenderer.send('answer', error.message)
|
||||
}
|
||||
}, 10)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user