Add webContents.focus() spec
authorKevin Sawicki <kevinsawicki@gmail.com>
Tue, 14 Feb 2017 02:11:37 +0000 (18:11 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Wed, 15 Feb 2017 16:28:55 +0000 (08:28 -0800)
spec/api-web-contents-spec.js
spec/fixtures/pages/focus-web-contents.html [new file with mode: 0644]

index f80e04ac7c84f07177150e6da85542a278bab8cc..07faa93e615afa21d8e2bcc02454c98dcad0065f 100644 (file)
@@ -308,4 +308,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()
+      })
+      w.show()
+      w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html'))
+    })
+  })
 })
diff --git a/spec/fixtures/pages/focus-web-contents.html b/spec/fixtures/pages/focus-web-contents.html
new file mode 100644 (file)
index 0000000..8411439
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title></title>
+    <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()
+      })
+
+      child.webContents.focus()
+      child.show()
+      child.webContents.focus()
+    </script>
+  </head>
+  <body>
+
+  </body>
+</html>