Add spec for devtools extension
authorKevin Sawicki <kevinsawicki@gmail.com>
Tue, 17 May 2016 21:52:45 +0000 (14:52 -0700)
committerKevin Sawicki <kevinsawicki@gmail.com>
Tue, 17 May 2016 21:52:45 +0000 (14:52 -0700)
spec/api-browser-window-spec.js
spec/fixtures/devtools-extensions/foo/foo.html [new file with mode: 0644]
spec/fixtures/devtools-extensions/foo/index.html [new file with mode: 0644]
spec/fixtures/devtools-extensions/foo/manifest.json

index a8dd8a3..168aceb 100644 (file)
@@ -824,6 +824,30 @@ describe('browser-window module', function () {
   })
 
   describe('dev tool extensions', function () {
+    describe('BrowserWindow.addDevToolsExtension', function () {
+      it('creates the extension', function (done) {
+        var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
+        BrowserWindow.addDevToolsExtension(extensionPath)
+
+        w.webContents.on('devtools-opened', () => {
+          var inputEventIntervalId = setInterval(function () {
+            if (w && w.devToolsWebContents) {
+              w.devToolsWebContents.sendInputEvent({type: 'keyDown', keyCode:'[', modifiers: ['meta']})
+            } else {
+              clearInterval(inputEventIntervalId)
+            }
+          }, 250)
+        })
+        w.loadURL('about:blank')
+        w.webContents.openDevTools({mode: 'bottom'})
+
+        ipcMain.once('answer', function (event, message) {
+          assert.equal(message, 'extension loaded')
+          done()
+        })
+      })
+    })
+
     it('serializes the registered extensions on quit', function () {
       var extensionName = 'foo'
       var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName)
diff --git a/spec/fixtures/devtools-extensions/foo/foo.html b/spec/fixtures/devtools-extensions/foo/foo.html
new file mode 100644 (file)
index 0000000..a326639
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>foo</title>
+    <script>
+      chrome.devtools.panels.create('Foo', 'foo.png', 'index.html')
+    </script>
+  </head>
+</html>
diff --git a/spec/fixtures/devtools-extensions/foo/index.html b/spec/fixtures/devtools-extensions/foo/index.html
new file mode 100644 (file)
index 0000000..4e74394
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title></title>
+    <script>
+      var sendMessage = `require('electron').ipcRenderer.send('answer', 'extension loaded')`
+      window.chrome.devtools.inspectedWindow.eval(sendMessage, function () {})
+    </script>
+  </head>
+  <body>
+    a custom devtools extension
+  </body>
+</html>
index bde99de..413853e 100644 (file)
@@ -1,3 +1,5 @@
 {
-  "name": "foo"
+  "name": "foo",
+  "version": "1.0",
+  "devtools_page": "foo.html"
 }