Send coverage from chrome extension iframe

This commit is contained in:
Kevin Sawicki 2016-08-02 17:59:31 -07:00
parent 9aec425ea8
commit 60e60d86d1
2 changed files with 15 additions and 0 deletions

View file

@ -117,6 +117,10 @@ const saveCoverageOnBeforeUnload = () => {
saveCoverageData(event.sender, coverage, pid) saveCoverageData(event.sender, coverage, pid)
}) })
ipcMain.on('report-coverage', function (event, message) {
saveCoverageData(event.sender, message.coverage, `${message.pid}-extension`)
})
app.on('web-contents-created', function (event, webContents) { app.on('web-contents-created', function (event, webContents) {
webContents.executeJavaScript(` webContents.executeJavaScript(`
window.addEventListener('beforeunload', function () { window.addEventListener('beforeunload', function () {

View file

@ -16,6 +16,15 @@
}) })
} }
function reportCoverage () {
var message = JSON.stringify({
pid: chrome.runtime.id,
coverage: window.__coverage__
})
var coverageMessage = `require('electron').ipcRenderer.send('report-coverage', ${message})`
window.chrome.devtools.inspectedWindow.eval(coverageMessage, function () {})
}
testStorage(function (syncItems, localItems) { testStorage(function (syncItems, localItems) {
var message = JSON.stringify({ var message = JSON.stringify({
runtimeId: chrome.runtime.id, runtimeId: chrome.runtime.id,
@ -26,6 +35,8 @@
sync: syncItems sync: syncItems
} }
}) })
reportCoverage()
var sendMessage = `require('electron').ipcRenderer.send('answer', ${message})` var sendMessage = `require('electron').ipcRenderer.send('answer', ${message})`
window.chrome.devtools.inspectedWindow.eval(sendMessage, function () {}) window.chrome.devtools.inspectedWindow.eval(sendMessage, function () {})
}) })