chore: refactor webContents module isCurrentlyAudible api spec (#14410)

This commit is contained in:
Robo 2018-09-06 02:30:05 +05:30 committed by Charles Kerr
parent 4d23e200f0
commit 8441d09a18
4 changed files with 25 additions and 33 deletions

View file

@ -122,19 +122,25 @@ describe('webContents module', () => {
})
})
// Disabled because flaky. See #13969
xdescribe('isCurrentlyAudible() API', () => {
describe('isCurrentlyAudible() API', () => {
it('returns whether audio is playing', async () => {
w.loadFile(path.join(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()
const webContents = remote.getCurrentWebContents()
const context = new window.AudioContext()
// Start in suspended state, because of the
// new web audio api policy.
context.suspend()
const oscillator = context.createOscillator()
oscillator.connect(context.destination)
oscillator.start()
await context.resume()
const [, audible] = await emittedOnce(webContents, '-audio-state-changed')
assert(webContents.isCurrentlyAudible() === audible)
expect(webContents.isCurrentlyAudible()).to.be.true()
oscillator.stop()
await emittedOnce(webContents, '-audio-state-changed')
expect(webContents.isCurrentlyAudible()).to.be.false()
oscillator.disconnect()
context.close()
})
})