chore: refactor webContents module isCurrentlyAudible api spec (#14410)
This commit is contained in:
parent
4d23e200f0
commit
8441d09a18
4 changed files with 25 additions and 33 deletions
|
@ -754,6 +754,11 @@ content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
|
||||||
return dialog_manager_.get();
|
return dialog_manager_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::OnAudioStateChanged(content::WebContents* web_contents,
|
||||||
|
bool audible) {
|
||||||
|
Emit("-audio-state-changed", audible);
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
||||||
// Do nothing, we override this method just to avoid compilation error since
|
// Do nothing, we override this method just to avoid compilation error since
|
||||||
// there are two virtual functions named BeforeUnloadFired.
|
// there are two virtual functions named BeforeUnloadFired.
|
||||||
|
|
|
@ -345,6 +345,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
const content::BluetoothChooser::EventHandler& handler) override;
|
const content::BluetoothChooser::EventHandler& handler) override;
|
||||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
||||||
content::WebContents* source) override;
|
content::WebContents* source) override;
|
||||||
|
void OnAudioStateChanged(content::WebContents* web_contents,
|
||||||
|
bool audible) override;
|
||||||
|
|
||||||
// content::WebContentsObserver:
|
// content::WebContentsObserver:
|
||||||
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
||||||
|
|
|
@ -122,19 +122,25 @@ describe('webContents module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Disabled because flaky. See #13969
|
describe('isCurrentlyAudible() API', () => {
|
||||||
xdescribe('isCurrentlyAudible() API', () => {
|
|
||||||
it('returns whether audio is playing', async () => {
|
it('returns whether audio is playing', async () => {
|
||||||
w.loadFile(path.join(fixtures, 'api', 'is-currently-audible.html'))
|
const webContents = remote.getCurrentWebContents()
|
||||||
w.show()
|
const context = new window.AudioContext()
|
||||||
await emittedOnce(w.webContents, 'did-finish-load')
|
// Start in suspended state, because of the
|
||||||
|
// new web audio api policy.
|
||||||
expect(w.webContents.isCurrentlyAudible()).to.be.false()
|
context.suspend()
|
||||||
|
const oscillator = context.createOscillator()
|
||||||
w.webContents.send('play')
|
oscillator.connect(context.destination)
|
||||||
await emittedOnce(ipcMain, 'playing')
|
oscillator.start()
|
||||||
|
await context.resume()
|
||||||
expect(w.webContents.isCurrentlyAudible()).to.be.true()
|
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()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
21
spec/fixtures/api/is-currently-audible.html
vendored
21
spec/fixtures/api/is-currently-audible.html
vendored
|
@ -1,21 +0,0 @@
|
||||||
<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>
|
|
Loading…
Reference in a new issue