From 8e4094793890cc060912fffb30849e7f7322cdec Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 6 Oct 2015 15:43:36 +0800 Subject: [PATCH] spec: Make window.open specs more reliable --- spec/chromium-spec.coffee | 41 ++++++++++++-------------- spec/fixtures/pages/window-opener.html | 5 +++- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/spec/chromium-spec.coffee b/spec/chromium-spec.coffee index a782079026a7..2c4853a0d635 100644 --- a/spec/chromium-spec.coffee +++ b/spec/chromium-spec.coffee @@ -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', -> diff --git a/spec/fixtures/pages/window-opener.html b/spec/fixtures/pages/window-opener.html index 0b5ecd556c9b..226b57dbd709 100644 --- a/spec/fixtures/pages/window-opener.html +++ b/spec/fixtures/pages/window-opener.html @@ -1,7 +1,10 @@