spec: Make window.open specs more reliable

This commit is contained in:
Cheng Zhao 2015-10-06 15:43:36 +08:00
parent 898db4d6bd
commit 8e40947938
2 changed files with 23 additions and 23 deletions

View file

@ -4,10 +4,17 @@ https = require 'https'
path = require 'path'
ws = require 'ws'
remote = require 'remote'
BrowserWindow = remote.require 'browser-window'
describe 'chromium feature', ->
fixtures = path.resolve __dirname, 'fixtures'
listener = null
afterEach ->
if listener?
window.removeEventListener 'message', listener
listener = null
xdescribe 'heap snapshot', ->
it 'does not crash', ->
process.atomBinding('v8_util').takeHeapSnapshot()
@ -24,20 +31,17 @@ describe 'chromium feature', ->
$.get "http://127.0.0.1:#{port}"
describe 'document.hidden', ->
BrowserWindow = remote.require 'browser-window'
ipc = remote.require 'ipc'
url = "file://#{fixtures}/pages/document-hidden.html"
w = null
afterEach ->
w?.destroy()
ipc.removeAllListeners 'hidden'
it 'is set correctly when window is not shown', (done) ->
ipc.once 'hidden', (event, hidden) ->
assert hidden
done()
w = new BrowserWindow(show:false)
w.webContents.on 'ipc-message', (event, args) ->
assert.deepEqual args, ['hidden', true]
done()
w.loadUrl url
describe 'navigator.webkitGetUserMedia', ->
@ -52,8 +56,6 @@ describe 'chromium feature', ->
assert.notEqual navigator.language, ''
describe 'window.open', ->
@timeout 10000
it 'returns a BrowserWindowProxy object', ->
b = window.open 'about:blank', '', 'show=no'
assert.equal b.closed, false
@ -62,46 +64,41 @@ describe 'chromium feature', ->
it 'accepts "node-integration" as feature', (done) ->
listener = (event) ->
window.removeEventListener 'message', listener
b.close()
assert.equal event.data, 'undefined'
b.close()
done()
window.addEventListener 'message', listener
b = window.open "file://#{fixtures}/pages/window-opener-node.html", '', 'node-integration=no,show=no'
it 'inherit options of parent window', (done) ->
listener = (event) ->
window.removeEventListener 'message', listener
b.close()
size = remote.getCurrentWindow().getSize()
assert.equal event.data, "size: #{size.width} #{size.height}"
b.close()
done()
window.addEventListener 'message', listener
b = window.open "file://#{fixtures}/pages/window-open-size.html", '', 'show=no'
describe 'window.opener', ->
@timeout 10000
ipc = remote.require 'ipc'
url = "file://#{fixtures}/pages/window-opener.html"
w = null
afterEach ->
w?.destroy()
ipc.removeAllListeners 'opener'
it 'is null for main window', (done) ->
ipc.once 'opener', (event, opener) ->
assert.equal opener, null
done()
BrowserWindow = remote.require 'browser-window'
w = new BrowserWindow(show: false)
w.webContents.on 'ipc-message', (event, args) ->
assert.deepEqual args, ['opener', null]
done()
w.loadUrl url
it 'is not null for window opened by window.open', (done) ->
ipc.once 'opener', (event, opener) ->
listener = (event) ->
assert.equal event.data, 'object'
b.close()
done(if opener isnt null then undefined else opener)
done()
window.addEventListener 'message', listener
b = window.open url, '', 'show=no'
describe 'window.opener.postMessage', ->

View file

@ -1,7 +1,10 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
require('ipc').send('opener', window.opener);
if (window.opener !== null)
window.opener.postMessage(typeof window.opener, '*');
else
require('ipc').send('opener', window.opener);
</script>
</body>
</html>