feat: [extensions] implement a couple of tabs APIs (#21779)
This commit is contained in:
parent
8278a64e00
commit
b9eb68c0b4
21 changed files with 568 additions and 17 deletions
|
@ -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()}`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue