Skip to content

Commit

Permalink
👷 Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed Jul 10, 2018
1 parent 555d883 commit fe01734
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/api-web-contents-spec.js
Expand Up @@ -116,6 +116,23 @@ describe('webContents module', () => {
})
})

describe('isCurrentlyAudible() API', () => {
it('returns whether audio is playing', (done) => {
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'api', 'is-currently-audible.html')}`)
w.show()
w.webContents.once('did-finish-load', () => {
assert.equal(w.webContents.isCurrentlyAudible(), false)

ipcMain.once('playing', () => {
assert.equal(w.webContents.isCurrentlyAudible(), true)
done()
})

w.webContents.send('play')
})
});
})

describe('getWebPreferences() API', () => {
it('should not crash when called for devTools webContents', (done) => {
w.webContents.openDevTools()
Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures/api/is-currently-audible.html
@@ -0,0 +1,21 @@
<html>
<body>
<div id="video"></div>
<script type="text/javascript" charset="utf-8">
const {ipcRenderer} = window.top != null ? window.top.require('electron') : require('electron')
ipcRenderer.on('play', (event) => {
const context = new window.AudioContext();
const oscillator = context.createOscillator();

// A beep
oscillator.type = 'sine';
oscillator.frequency.value = 440
oscillator.connect(context.destination)
oscillator.start()

// It'll take a few ms before the beep shows up
setTimeout(() => event.sender.send('playing'), 100)
})
</script>
</body>
</html>

0 comments on commit fe01734

Please sign in to comment.