]> khamidou — GitHub mirrors - electron.git/commitdiff
spec: Test window.opener
authorCheng Zhao <zcbenz@gmail.com>
Tue, 4 Aug 2015 07:46:59 +0000 (15:46 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 4 Aug 2015 07:46:59 +0000 (15:46 +0800)
spec/chromium-spec.coffee
spec/fixtures/pages/window-opener.html [new file with mode: 0644]

index 8ca7e9800fe509abb66ca9fbb59409e171f97cd5..375f98966bea2098dbddc0840c8fc7b05c5e4b29 100644 (file)
@@ -3,6 +3,7 @@ http = require 'http'
 https = require 'https'
 path = require 'path'
 ws = require 'ws'
+remote = require 'remote'
 
 describe 'chromium feature', ->
   fixtures = path.resolve __dirname, 'fixtures'
@@ -39,9 +40,31 @@ describe 'chromium feature', ->
       assert.equal b.constructor.name, 'BrowserWindowProxy'
       b.close()
 
+  describe 'window.opener', ->
+    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.on 'opener', (event, opener) ->
+        done(if opener is null then undefined else opener)
+      BrowserWindow = remote.require 'browser-window'
+      w = new BrowserWindow(show: false)
+      w.loadUrl url
+
+    it 'is not null for window opened by window.open', (done) ->
+      b = window.open url, 'test2', 'show=no'
+      ipc.on 'opener', (event, opener) ->
+        b.close()
+        done(if opener isnt null then undefined else opener)
+
   describe 'creating a Uint8Array under browser side', ->
     it 'does not crash', ->
-      RUint8Array = require('remote').getGlobal 'Uint8Array'
+      RUint8Array = remote.getGlobal 'Uint8Array'
       new RUint8Array
 
   describe 'webgl', ->
diff --git a/spec/fixtures/pages/window-opener.html b/spec/fixtures/pages/window-opener.html
new file mode 100644 (file)
index 0000000..0b5ecd5
--- /dev/null
@@ -0,0 +1,8 @@
+<html>
+<body>
+<script type="text/javascript" charset="utf-8">
+  require('ipc').send('opener', window.opener);
+</script>
+</body>
+</html>
+