mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
Add failing spec for targetOrigin handling
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const assert = require('assert')
|
||||
const fs = require('fs')
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
const ws = require('ws')
|
||||
@@ -618,6 +619,39 @@ describe('chromium feature', function () {
|
||||
})
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
|
||||
describe('targetOrigin argument', function () {
|
||||
let serverURL
|
||||
let server
|
||||
|
||||
beforeEach(function (done) {
|
||||
server = http.createServer(function (req, res) {
|
||||
res.writeHead(200)
|
||||
const filePath = path.join(fixtures, 'pages', 'window-opener-targetOrigin.html')
|
||||
res.end(fs.readFileSync(filePath, 'utf8'))
|
||||
})
|
||||
server.listen(0, '127.0.0.1', function () {
|
||||
serverURL = `http://127.0.0.1:${server.address().port}`
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
server.close()
|
||||
})
|
||||
|
||||
it('delivers messages that match the origin', function (done) {
|
||||
let b
|
||||
listener = function (event) {
|
||||
window.removeEventListener('message', listener)
|
||||
b.close()
|
||||
assert.equal(event.data, 'second message')
|
||||
done()
|
||||
}
|
||||
window.addEventListener('message', listener)
|
||||
b = window.open(serverURL, '', 'show=no')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('creating a Uint8Array under browser side', function () {
|
||||
|
||||
18
spec/fixtures/pages/window-opener-targetOrigin.html
vendored
Normal file
18
spec/fixtures/pages/window-opener-targetOrigin.html
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
const url = require('url')
|
||||
if (url.parse(window.location.href, true).query.opened != null) {
|
||||
// Ensure origin are properly checked by removing a single character from the end
|
||||
window.opener.postMessage('first message', window.location.origin.substring(0, window.location.origin.length - 1))
|
||||
window.opener.postMessage('second message', window.location.origin)
|
||||
} else {
|
||||
const opened = window.open(`${window.location.href}?opened=true`)
|
||||
window.addEventListener('message', function (event) {
|
||||
window.opener.postMessage(event.data, '*')
|
||||
opened.close()
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user