From 8f7b86117b6fb44bee751b6bbd98b7daee8b83e1 Mon Sep 17 00:00:00 2001 From: alwu Date: Tue, 18 Sep 2018 14:59:48 +0000 Subject: [PATCH] Bug 1489375 - part2 : add test. r=padenot add test. Differential Revision: https://phabricator.services.mozilla.com/D5800 --HG-- extra : moz-landing-system : lando --- toolkit/content/tests/browser/browser.ini | 2 + .../browser_webAudio_hideSoundPlayingIcon.js | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 toolkit/content/tests/browser/browser_webAudio_hideSoundPlayingIcon.js diff --git a/toolkit/content/tests/browser/browser.ini b/toolkit/content/tests/browser/browser.ini index 0c44fefedd12..deadd77a015d 100644 --- a/toolkit/content/tests/browser/browser.ini +++ b/toolkit/content/tests/browser/browser.ini @@ -127,3 +127,5 @@ uses-unsafe-cpows = true [browser_sound_indicator_silent_video.js] tags = audiochannel [browser_resume_bkg_video_on_tab_hover.js] +[browser_webAudio_hideSoundPlayingIcon.js] +tags = audiochannel diff --git a/toolkit/content/tests/browser/browser_webAudio_hideSoundPlayingIcon.js b/toolkit/content/tests/browser/browser_webAudio_hideSoundPlayingIcon.js new file mode 100644 index 000000000000..b6943fa769e3 --- /dev/null +++ b/toolkit/content/tests/browser/browser_webAudio_hideSoundPlayingIcon.js @@ -0,0 +1,61 @@ +/** + * This test is used to ensure the 'sound-playing' icon would not disappear after + * sites call AudioContext.resume(). + */ +"use strict"; + +function setup_test_preference() { + return SpecialPowers.pushPrefEnv({"set": [ + ["media.useAudioChannelService.testing", true], + ["browser.tabs.delayHidingAudioPlayingIconMS", 0], + ]}); +} + +function createAudioContext() { + content.ac = new content.AudioContext(); + const ac = content.ac; + const dest = ac.destination; + const osc = ac.createOscillator(); + osc.connect(dest); + osc.start(); +} + +async function resumeAudioContext() { + const ac = content.ac; + await ac.resume(); + ok(true, "AudioContext is resumed."); +} + +async function testResumeRunningAudioContext() { + info(`- create new tab -`); + const tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, + "about:blank"); + const browser = tab.linkedBrowser; + + info(`- create audio context -`); + // We want the same audio context to be used across different content + // tasks, so it needs to be loaded by a frame script. + const mm = tab.linkedBrowser.messageManager; + mm.loadFrameScript("data:,(" + createAudioContext.toString() + ")();", false); + + info(`- wait for 'sound-playing' icon showing -`); + await waitForTabPlayingEvent(tab, true); + + info(`- resume AudioContext -`); + await ContentTask.spawn(browser, null, + resumeAudioContext); + + info(`- 'sound-playing' icon should still exist -`); + await waitForTabPlayingEvent(tab, true); + + info(`- remove tab -`); + await BrowserTestUtils.removeTab(tab); +} + +add_task(async function start_test() { + info("- setup test preference -"); + await setup_test_preference(); + + info("- start testing -"); + await testResumeRunningAudioContext(); +});