Browse Source

Update blur parent window spec

Kevin Sawicki 8 years ago
parent
commit
86007fe61d
2 changed files with 17 additions and 15 deletions
  1. 9 7
      spec/api-web-contents-spec.js
  2. 8 8
      spec/fixtures/pages/focus-web-contents.html

+ 9 - 7
spec/api-web-contents-spec.js

@@ -310,14 +310,16 @@ describe('webContents module', function () {
   })
 
   describe('focus()', function () {
-    it('focuses the parent window', function (done) {
-      ipcMain.once('answer', (event, visible, focused) => {
-        assert.equal(visible, true)
-        assert.equal(focused, true)
-        done()
+    describe('when the web contents is hidden', function () {
+      it('does not blur the focused window', function (done) {
+        ipcMain.once('answer', (event, parentFocused, childFocused) => {
+          assert.equal(parentFocused, true)
+          assert.equal(childFocused, false)
+          done()
+        })
+        w.show()
+        w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html'))
       })
-      w.show()
-      w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html'))
     })
   })
 })

+ 8 - 8
spec/fixtures/pages/focus-web-contents.html

@@ -6,16 +6,16 @@
     <script>
       const {ipcRenderer, remote} = require('electron')
 
-      const child = new remote.BrowserWindow({show: false})
-
-      remote.getCurrentWindow().once('blur', () => {
-        ipcRenderer.send('answer', child.isVisible(), child.isFocused())
-        child.close()
-      })
+      remote.getCurrentWindow().focus()
 
+      const child = new remote.BrowserWindow({show: false})
+      child.loadURL('about:blank')
       child.webContents.focus()
-      child.show()
-      child.webContents.focus()
+
+      const currentFocused = remote.getCurrentWindow().isFocused()
+      const childFocused = child.isFocused()
+      child.close()
+      ipcRenderer.send('answer', currentFocused, childFocused)
     </script>
   </head>
   <body>