feat(extensions): add chrome.tabs.connect API (#22457)

* feat(extensions): add chrome.tabs.connect API

* test(extensions): verify that chrome.tabs.connect port communication works
This commit is contained in:
John Kleinschmidt 2020-03-05 09:59:32 -05:00 committed by GitHub
parent d6701ff435
commit 0201b3e571
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 0 deletions

View file

@ -186,6 +186,22 @@ ifdescribe(process.electronBinding('features').isExtensionsEnabled())('chrome ex
expect(response).to.equal(3)
})
it('connect', async () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-api'))
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true } })
await w.loadURL(url)
const portName = require('uuid').v4()
const message = { method: 'connectTab', args: [portName] }
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`)
const [,, responseString] = await emittedOnce(w.webContents, 'console-message')
const response = responseString.split(',')
expect(response[0]).to.equal(portName)
expect(response[1]).to.equal('howdy')
})
it('sendMessage receives the response', async function () {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-api'))