electron/spec/fixtures/api/sandbox.html

107 lines
3.2 KiB
HTML
Raw Normal View History

2016-09-26 20:40:45 +00:00
<html>
<script type="text/javascript" charset="utf-8">
function timeout(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
async function invokeGc () {
// it seems calling window.gc once does not guarantee garbage will be
// collected, so we repeat 10 times with interval of 100 ms
for (let i = 0; i < 10; i++) {
window.gc()
await timeout(100)
}
}
2017-05-15 12:17:07 +00:00
const [,test] = window.location.href.split('?')
if (window.opener && test !== 'reload-remote') {
2016-09-30 15:36:51 +00:00
window.callback = () => {
2016-09-26 20:40:45 +00:00
opener.require('electron').ipcRenderer.send('answer', document.body.innerHTML)
2016-09-30 15:36:51 +00:00
}
2016-09-26 20:40:45 +00:00
} else {
2017-05-15 12:17:07 +00:00
const {ipcRenderer, remote} = require('electron')
2016-09-26 20:40:45 +00:00
const tests = {
2017-05-15 12:17:07 +00:00
'reload-remote-child': () => {
open(`${location.protocol}//${location.pathname}?reload-remote`)
},
'reload-remote': async () => {
const p = ipcRenderer.sendSync('get-remote-module-path')
const Hello = remote.require(p)
if (!ipcRenderer.sendSync('reloaded')) {
ipcRenderer.send('reload')
return
}
await invokeGc()
ipcRenderer.send('answer', new Hello().say())
},
2016-09-26 20:40:45 +00:00
'window-events': () => {
document.title = 'changed'
},
'webcontents-stop': () => {
stop()
},
'webcontents-events': () => {
addEventListener('load', () => {
location.hash = 'in-page-navigate'
setTimeout(() => {
location.reload()
}, 50)
})
},
'exit-event': () => {
process.on('exit', () => {
ipcRenderer.send('answer', location.href)
})
location.assign('http://www.google.com')
},
'window-open': () => {
addEventListener('load', () => {
popup = open(window.location.href, 'popup!', 'top=60,left=50,width=500,height=600')
popup.addEventListener('DOMContentLoaded', () => {
popup.document.write('<h1>scripting from opener</h1>')
popup.callback()
}, false)
})
},
'window-open-external': () => {
addEventListener('load', () => {
fix: use appropriate site instance for cross-site nav's (#15821) * fix: use Chromium's determined new site instance as candidate when navigating. When navigating to a new address, consider using Chromium's determined site instance for the new page as it should belong to an existing browsing instance when the navigation was triggered by window.open(). fixes 8100. * Revert "fix: use Chromium's determined new site instance as candidate when navigating." This reverts commit eb95f935654a2c4d4457821297670836c10fdfd5. * fix: delegate site instance creation back to content when sandboxed. * fix: ensure site isolation is on * test: adapt ut for cross-site navigation * fix: register pending processes during a navigation. * refactor: dont call loadURL for a window constructed from an existing webContents. * test: add sandboxed affinity UT's. * fix: check affinity before deciding if to force a new site instance. * chore: adapt subsequent patch. * refactor: constify logically const methods. * fix: do not reuse site instances when navigation redirects cross-site. * test: ensure localStorage accessible after x-site redirect. * test: adapt localStorage acess denied UT for site isolation. * fix: do not send render-view-deleted for speculative frames. * chore: amend tests after rebase. * test: add ut for webContents' render-view-deleted emission * fix: introduce current-render-view-deleted for current RVH's deletions. Revert render-view-deleted to being emitted with any RVH's deletion. current-render-view-deleted is emitted only when the RVH being deleted is the current one. * refactor: style and comments fixed.
2018-12-05 08:03:39 +00:00
ipcRenderer.once('open-the-popup', (event, url) => {
popup = open(url, '', 'top=65,left=55,width=505,height=605')
})
ipcRenderer.once('touch-the-popup', () => {
let errorMessage = null
2016-09-26 20:40:45 +00:00
try {
const childDoc = popup.document
} catch (error) {
errorMessage = error.message
2016-09-26 20:40:45 +00:00
}
ipcRenderer.send('answer', errorMessage)
2016-09-26 20:40:45 +00:00
})
fix: use appropriate site instance for cross-site nav's (#15821) * fix: use Chromium's determined new site instance as candidate when navigating. When navigating to a new address, consider using Chromium's determined site instance for the new page as it should belong to an existing browsing instance when the navigation was triggered by window.open(). fixes 8100. * Revert "fix: use Chromium's determined new site instance as candidate when navigating." This reverts commit eb95f935654a2c4d4457821297670836c10fdfd5. * fix: delegate site instance creation back to content when sandboxed. * fix: ensure site isolation is on * test: adapt ut for cross-site navigation * fix: register pending processes during a navigation. * refactor: dont call loadURL for a window constructed from an existing webContents. * test: add sandboxed affinity UT's. * fix: check affinity before deciding if to force a new site instance. * chore: adapt subsequent patch. * refactor: constify logically const methods. * fix: do not reuse site instances when navigation redirects cross-site. * test: ensure localStorage accessible after x-site redirect. * test: adapt localStorage acess denied UT for site isolation. * fix: do not send render-view-deleted for speculative frames. * chore: amend tests after rebase. * test: add ut for webContents' render-view-deleted emission * fix: introduce current-render-view-deleted for current RVH's deletions. Revert render-view-deleted to being emitted with any RVH's deletion. current-render-view-deleted is emitted only when the RVH being deleted is the current one. * refactor: style and comments fixed.
2018-12-05 08:03:39 +00:00
ipcRenderer.send('opener-loaded')
2016-09-26 20:40:45 +00:00
})
},
'verify-ipc-sender': () => {
popup = open()
ipcRenderer.once('verified', () => {
ipcRenderer.send('parent-answer')
})
popup.ipcRenderer.once('verified', () => {
popup.ipcRenderer.send('child-answer')
})
ipcRenderer.send('parent-ready')
popup.ipcRenderer.send('child-ready')
2016-09-26 20:40:45 +00:00
}
}
addEventListener('unload', () => {
if (window.popup)
popup.close()
}, false)
2016-09-30 15:36:51 +00:00
if (tests.hasOwnProperty(test))
tests[test]()
2016-09-26 20:40:45 +00:00
}
</script>
</html>