diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/base/content/test/tabMediaIndicator/browser_sound_indicator_silent_video.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/tabMediaIndicator/browser_sound_indicator_silent_video.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/browser/base/content/test/tabMediaIndicator/browser_sound_indicator_silent_video.js b/browser/base/content/test/tabMediaIndicator/browser_sound_indicator_silent_video.js new file mode 100644 index 0000000000..8f0d6961ca --- /dev/null +++ b/browser/base/content/test/tabMediaIndicator/browser_sound_indicator_silent_video.js @@ -0,0 +1,88 @@ +const SILENT_PAGE = GetTestWebBasedURL("file_silentAudioTrack.html"); +const ALMOST_SILENT_PAGE = GetTestWebBasedURL( + "file_almostSilentAudioTrack.html" +); + +function check_audio_playing_state(isPlaying) { + let autoPlay = content.document.getElementById("autoplay"); + if (!autoPlay) { + ok(false, "Can't get the audio element!"); + } + + is( + autoPlay.paused, + !isPlaying, + "The playing state of autoplay audio is correct." + ); + + // wait for a while to make sure the video is playing and related event has + // been dispatched (if any). + let PLAYING_TIME_SEC = 0.5; + ok(PLAYING_TIME_SEC < autoPlay.duration, "The playing time is valid."); + + return new Promise(resolve => { + autoPlay.ontimeupdate = function () { + if (autoPlay.currentTime > PLAYING_TIME_SEC) { + resolve(); + } + }; + }); +} + +add_task(async function should_not_show_sound_indicator_for_silent_video() { + info("- open new foreground tab -"); + let tab = await BrowserTestUtils.openNewForegroundTab( + window.gBrowser, + "about:blank" + ); + + info("- tab should not have sound indicator before playing silent video -"); + await waitForTabSoundIndicatorDisappears(tab); + + info("- loading autoplay silent video -"); + BrowserTestUtils.loadURIString(tab.linkedBrowser, SILENT_PAGE); + await BrowserTestUtils.browserLoaded(tab.linkedBrowser); + await SpecialPowers.spawn( + tab.linkedBrowser, + [true], + check_audio_playing_state + ); + + info("- tab should not have sound indicator after playing silent video -"); + await waitForTabSoundIndicatorDisappears(tab); + + info("- remove tab -"); + BrowserTestUtils.removeTab(tab); +}); + +add_task( + async function should_not_show_sound_indicator_for_almost_silent_video() { + info("- open new foreground tab -"); + let tab = await BrowserTestUtils.openNewForegroundTab( + window.gBrowser, + "about:blank" + ); + + info( + "- tab should not have sound indicator before playing almost silent video -" + ); + await waitForTabSoundIndicatorDisappears(tab); + + info("- loading autoplay almost silent video -"); + BrowserTestUtils.loadURIString(tab.linkedBrowser, ALMOST_SILENT_PAGE); + await BrowserTestUtils.browserLoaded(tab.linkedBrowser); + await SpecialPowers.spawn( + tab.linkedBrowser, + [true], + check_audio_playing_state + ); + + info( + "- tab should not have sound indicator after playing almost silent video -" + ); + await waitForTabSoundIndicatorDisappears(tab); + + info("- remove tab -"); + BrowserTestUtils.removeTab(tab); + } +); |