diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /browser/components/extensions/test/browser/browser_ext_autoplayInBackground.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/extensions/test/browser/browser_ext_autoplayInBackground.js')
-rw-r--r-- | browser/components/extensions/test/browser/browser_ext_autoplayInBackground.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/browser/components/extensions/test/browser/browser_ext_autoplayInBackground.js b/browser/components/extensions/test/browser/browser_ext_autoplayInBackground.js new file mode 100644 index 0000000000..e082b1e9bf --- /dev/null +++ b/browser/components/extensions/test/browser/browser_ext_autoplayInBackground.js @@ -0,0 +1,52 @@ +"use strict"; + +function setup_test_preference(enableScript) { + return SpecialPowers.pushPrefEnv({ + set: [ + ["media.autoplay.default", 1], + ["media.autoplay.blocking_policy", 0], + ["media.autoplay.allow-extension-background-pages", enableScript], + ], + }); +} + +async function testAutoplayInBackgroundScript(enableScript) { + info(`- setup test preference, enableScript=${enableScript} -`); + await setup_test_preference(enableScript); + + let extension = ExtensionTestUtils.loadExtension({ + background() { + browser.test.log("- create audio in background page -"); + let audio = new Audio(); + audio.src = + "https://example.com/browser/browser/components/extensions/test/browser/silence.ogg"; + audio.play().then( + function () { + browser.test.log("play succeed!"); + browser.test.sendMessage("play-succeed"); + }, + function () { + browser.test.log("play promise was rejected!"); + browser.test.sendMessage("play-failed"); + } + ); + }, + }); + + await extension.startup(); + + if (enableScript) { + await extension.awaitMessage("play-succeed"); + ok(true, "play promise was resolved!"); + } else { + await extension.awaitMessage("play-failed"); + ok(true, "play promise was rejected!"); + } + + await extension.unload(); +} + +add_task(async function testMain() { + await testAutoplayInBackgroundScript(true /* enable autoplay */); + await testAutoplayInBackgroundScript(false /* enable autoplay */); +}); |