Browse Source

Merge pull request #5574 from electron/devtools-extension-test

Add test that loads a devtools extension
Cheng Zhao 9 years ago
parent
commit
242508e22f

+ 48 - 0
spec/api-browser-window-spec.js

@@ -824,6 +824,54 @@ describe('browser-window module', function () {
   })
 
   describe('dev tool extensions', function () {
+    describe('BrowserWindow.addDevToolsExtension', function () {
+      this.timeout(10000)
+
+      beforeEach(function () {
+        BrowserWindow.removeDevToolsExtension('foo')
+
+        var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
+        BrowserWindow.addDevToolsExtension(extensionPath)
+
+        w.webContents.on('devtools-opened', function () {
+          var showPanelIntevalId = setInterval(function () {
+            if (w && w.devToolsWebContents) {
+              w.devToolsWebContents.executeJavaScript('(' + (function () {
+                var lastPanelId = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id
+                WebInspector.inspectorView.showPanel(lastPanelId)
+              }).toString() + ')()')
+            } else {
+              clearInterval(showPanelIntevalId)
+            }
+          }, 100)
+        })
+
+        w.loadURL('about:blank')
+      })
+
+      describe('when the devtools is docked', function () {
+        it('creates the extension', function (done) {
+          w.webContents.openDevTools({mode: 'bottom'})
+
+          ipcMain.once('answer', function (event, message) {
+            assert.equal(message, 'extension loaded')
+            done()
+          })
+        })
+      })
+
+      describe('when the devtools is undocked', function () {
+        it('creates the extension', function (done) {
+          w.webContents.openDevTools({mode: 'undocked'})
+
+          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)

+ 10 - 0
spec/fixtures/devtools-extensions/foo/foo.html

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

+ 14 - 0
spec/fixtures/devtools-extensions/foo/index.html

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

+ 3 - 1
spec/fixtures/devtools-extensions/foo/manifest.json

@@ -1,3 +1,5 @@
 {
-  "name": "foo"
+  "name": "foo",
+  "version": "1.0",
+  "devtools_page": "foo.html"
 }