Merge branch 'master' into chrome-storage-sync

This commit is contained in:
Jessica Lord 2016-06-09 16:35:00 -07:00
commit f121f46a24
50 changed files with 605 additions and 192 deletions

View file

@ -859,11 +859,13 @@ describe('browser-window module', function () {
})
describe('when the devtools is docked', function () {
it('creates the extension', function (done) {
it.only('creates the extension', function (done) {
w.webContents.openDevTools({mode: 'bottom'})
ipcMain.once('answer', function (event, message) {
assert.equal(message.runtimeId, 'foo')
assert.equal(message.tabId, w.webContents.id)
assert.equal(message.i18nString, 'foo - bar (baz)')
assert.deepEqual(message.storageItems, {foo: 'bar'})
done()
})
@ -876,12 +878,52 @@ describe('browser-window module', function () {
ipcMain.once('answer', function (event, message, extensionId) {
assert.equal(message.runtimeId, 'foo')
assert.equal(message.tabId, w.webContents.id)
done()
})
})
})
})
it('works when used with partitions', function (done) {
this.timeout(10000)
if (w != null) {
w.destroy()
}
w = new BrowserWindow({
show: false,
webPreferences: {
partition: 'temp'
}
})
var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
BrowserWindow.removeDevToolsExtension('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')
w.webContents.openDevTools({mode: 'bottom'})
ipcMain.once('answer', function (event, message) {
assert.equal(message.runtimeId, 'foo')
done()
})
})
it('serializes the registered extensions on quit', function () {
var extensionName = 'foo'
var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName)

View file

@ -16,8 +16,15 @@ describe('session module', function () {
var fixtures = path.resolve(__dirname, 'fixtures')
var w = null
var url = 'http://127.0.0.1'
var partitionName = 'temp'
var protocolName = 'sp'
const tempProtocol = session.fromPartition(partitionName).protocol
const protocol = session.defaultSession.protocol
beforeEach(function () {
if (w != null) {
w.destroy()
}
w = new BrowserWindow({
show: false,
width: 400,
@ -26,7 +33,10 @@ describe('session module', function () {
})
afterEach(function () {
w.destroy()
if (w != null) {
w.destroy()
}
w = null
})
describe('session.cookies', function () {
@ -262,4 +272,43 @@ describe('session module', function () {
})
})
})
describe('session.protocol', function () {
beforeEach(function () {
if (w != null) {
w.destroy()
}
w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
partition: partitionName
}
})
})
it('handles requests from a partition', function (done) {
var handler = function (error, callback) {
callback({
data: 'test'
})
}
tempProtocol.registerStringProtocol(protocolName, handler, function (error) {
if (error) {
return done(error)
}
protocol.isProtocolHandled(protocolName, function (result) {
assert.equal(result, false)
tempProtocol.isProtocolHandled(protocolName, function (result) {
assert.equal(result, true)
w.webContents.on('did-finish-load', function () {
done()
})
w.loadURL(protocolName + "://fake-host")
})
})
})
})
})
})

View file

@ -0,0 +1,10 @@
{
"foo": {
"message": "foo - $BAZ$ ($2)",
"placeholders": {
"baz": {
"content": "$1"
}
}
}
}

View file

@ -13,6 +13,8 @@
testStorage(function (items) {
var message = JSON.stringify({
runtimeId: chrome.runtime.id,
tabId: chrome.devtools.inspectedWindow.tabId,
i18nString: chrome.i18n.getMessage('foo', ['bar', 'baz']),
storageItems: items
})
var sendMessage = `require('electron').ipcRenderer.send('answer', ${message})`

View file

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

View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<webview nodeintegration src="./a.html"></webview>
<script>
var wv = document.querySelector('webview')
wv.addEventListener('dom-ready', () => {
const webContents = wv.getWebContents()
webContents.on('devtools-opened', function () {
var showPanelIntevalId = setInterval(function () {
if (webContents.devToolsWebContents) {
webContents.devToolsWebContents.executeJavaScript('(' + (function () {
var lastPanelId = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id
WebInspector.inspectorView.showPanel(lastPanelId)
}).toString() + ')()')
} else {
clearInterval(showPanelIntevalId)
}
}, 100)
})
wv.openDevTools()
})
</script>
</script>
</body>
</html>

View file

@ -912,4 +912,25 @@ describe('<webview> tag', function () {
w.loadURL('file://' + fixtures + '/pages/webview-visibilitychange.html')
})
it('loads devtools extensions registered on the parent window', function (done) {
this.timeout(10000)
w = new BrowserWindow({
show: false
})
BrowserWindow.removeDevToolsExtension('foo')
var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
BrowserWindow.addDevToolsExtension(extensionPath)
w.loadURL('file://' + fixtures + '/pages/webview-devtools.html')
ipcMain.once('answer', function (event, message) {
assert.equal(message.runtimeId, 'foo')
assert.notEqual(message.tabId, w.webContents.id)
done()
})
})
})