Browse Source

Add webContents.focus() spec

Kevin Sawicki 8 years ago
parent
commit
35908ac398
2 changed files with 36 additions and 0 deletions
  1. 12 0
      spec/api-web-contents-spec.js
  2. 24 0
      spec/fixtures/pages/focus-web-contents.html

+ 12 - 0
spec/api-web-contents-spec.js

@@ -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'))
+    })
+  })
 })

+ 24 - 0
spec/fixtures/pages/focus-web-contents.html

@@ -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>