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

Add test that loads a devtools extension
This commit is contained in:
Cheng Zhao 2016-05-18 01:46:44 +00:00
commit 242508e22f
4 changed files with 75 additions and 1 deletions

View file

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

View file

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

View file

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

View file

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