feat: [extensions] implement a couple of tabs APIs (#21779)

This commit is contained in:
Jeremy Apthorp 2020-01-15 15:11:51 -08:00 committed by GitHub
parent 8278a64e00
commit b9eb68c0b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 568 additions and 17 deletions

View file

@ -121,6 +121,39 @@ ifdescribe(process.electronBinding('features').isExtensionsEnabled())('chrome ex
})
})
describe('chrome.tabs', () => {
it('executeScript', async () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
;(customSession as any).loadExtension(path.join(fixtures, 'extensions', 'chrome-api'))
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true } })
await w.loadURL(url)
const message = { method: 'executeScript', args: ['1 + 2'] }
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`)
const [,, responseString] = await emittedOnce(w.webContents, 'console-message')
const response = JSON.parse(responseString)
expect(response).to.equal(3)
})
it('sendMessage receives the response', async function () {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
;(customSession as any).loadExtension(path.join(fixtures, 'extensions', 'chrome-api'))
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true } })
await w.loadURL(url)
const message = { method: 'sendMessage', args: ['Hello World!'] }
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`)
const [,, responseString] = await emittedOnce(w.webContents, 'console-message')
const response = JSON.parse(responseString)
expect(response.message).to.equal('Hello World!')
expect(response.tabId).to.equal(w.webContents.id)
})
})
describe('background pages', () => {
it('loads a lazy background page when sending a message', async () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)