feat: Add isCurrentlyAudible() to WebContents (#13614)
* 🔧 Add isCurrentlyAudible() to WebContents * ❤️ Implement feedback, use await to wait for event * 👷 Add missing imports
This commit is contained in:
parent
e90c4abc0d
commit
deedf6c3f4
7 changed files with 57 additions and 0 deletions
|
@ -4,12 +4,18 @@ const assert = require('assert')
|
|||
const http = require('http')
|
||||
const path = require('path')
|
||||
const {closeWindow} = require('./window-helpers')
|
||||
const {emittedOnce} = require('./events-helpers')
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
const {BrowserWindow, webContents, ipcMain, session} = remote
|
||||
const {expect} = chai
|
||||
|
||||
const isCi = remote.getGlobal('isCi')
|
||||
|
||||
chai.use(dirtyChai)
|
||||
|
||||
/* The whole webContents API doesn't use standard callbacks */
|
||||
/* eslint-disable standard/no-callback-literal */
|
||||
|
||||
|
@ -116,6 +122,21 @@ describe('webContents module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('isCurrentlyAudible() API', () => {
|
||||
it('returns whether audio is playing', async () => {
|
||||
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'api', 'is-currently-audible.html')}`)
|
||||
w.show()
|
||||
await emittedOnce(w.webContents, 'did-finish-load')
|
||||
|
||||
expect(w.webContents.isCurrentlyAudible()).to.be.false()
|
||||
|
||||
w.webContents.send('play')
|
||||
await emittedOnce(ipcMain, 'playing')
|
||||
|
||||
expect(w.webContents.isCurrentlyAudible()).to.be.true()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getWebPreferences() API', () => {
|
||||
it('should not crash when called for devTools webContents', (done) => {
|
||||
w.webContents.openDevTools()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue