diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/base/test/browser_timeout_throttling_with_audio_playback.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/base/test/browser_timeout_throttling_with_audio_playback.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/dom/base/test/browser_timeout_throttling_with_audio_playback.js b/dom/base/test/browser_timeout_throttling_with_audio_playback.js new file mode 100644 index 0000000000..078b3c01a5 --- /dev/null +++ b/dom/base/test/browser_timeout_throttling_with_audio_playback.js @@ -0,0 +1,73 @@ +// The tab closing code leaves an uncaught rejection. This test has been +// whitelisted until the issue is fixed. +if (!gMultiProcessBrowser) { + const { PromiseTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PromiseTestUtils.sys.mjs" + ); + PromiseTestUtils.expectUncaughtRejection(/is no longer, usable/); +} + +const kBaseURI = "http://mochi.test:8888/browser/dom/base/test/empty.html"; +var testURLs = [ + "http://mochi.test:8888/browser/dom/base/test/file_audioLoop.html", + "http://mochi.test:8888/browser/dom/base/test/file_audioLoopInIframe.html", + "http://mochi.test:8888/browser/dom/base/test/file_webaudio_startstop.html", +]; + +// We want to ensure that while audio is being played back, a background tab is +// treated the same as a foreground tab as far as timeout throttling is concerned. +// So we use a 100,000 second minimum timeout value for background tabs. This +// means that in case the test fails, it will time out in practice, but just for +// sanity the test condition ensures that the observed timeout delay falls in +// this range. +const kMinTimeoutBackground = 100 * 1000 * 1000; + +const kDelay = 10; + +async function runTest(url) { + let currentTab = gBrowser.selectedTab; + let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kBaseURI); + let newBrowser = gBrowser.getBrowserForTab(newTab); + + // Wait for the UI to indicate that audio is being played back. + let promise = BrowserTestUtils.waitForAttribute("soundplaying", newTab); + BrowserTestUtils.startLoadingURIString(newBrowser, url); + await promise; + + // Put the tab in the background. + await BrowserTestUtils.switchTab(gBrowser, currentTab); + + let timeout = await SpecialPowers.spawn( + newBrowser, + [kDelay], + function (delay) { + return new Promise(resolve => { + let before = new Date(); + content.window.setTimeout(function () { + let after = new Date(); + resolve(after - before); + }, delay); + }); + } + ); + Assert.lessOrEqual( + timeout, + kMinTimeoutBackground, + `Got the correct timeout (${timeout})` + ); + + // All done. + BrowserTestUtils.removeTab(newTab); +} + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [["dom.min_background_timeout_value", kMinTimeoutBackground]], + }); +}); + +add_task(async function test() { + for (var url of testURLs) { + await runTest(url); + } +}); |