browser_autoplay_policy_detection_global_sticky.js (3442B)
1 /** 2 * This test checks whether Autoplay Policy Detection API works correctly under 3 * different situations of having global permission set for block autoplay. 4 * This test only checks the sticky user gesture blocking model. 5 */ 6 "use strict"; 7 8 add_setup(async function setSharedPrefs() { 9 await SpecialPowers.pushPrefEnv({ 10 set: [ 11 ["dom.media.autoplay-policy-detection.enabled", true], 12 ["media.autoplay.blocking_policy", 0], 13 ], 14 }); 15 }); 16 17 add_task(async function testGlobalPermissionIsAllowed() { 18 await SpecialPowers.pushPrefEnv({ 19 set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.ALLOWED]], 20 }); 21 let tab = await createTabAndSetupPolicyAssertFunc("about:blank"); 22 await SpecialPowers.spawn(tab.linkedBrowser, [], _ => { 23 info("global setting allows any autoplay"); 24 content.assertAutoplayPolicy({ 25 resultForElementType: "allowed", 26 resultForElement: "allowed", 27 resultForContextType: "allowed", 28 resultForContext: "allowed", 29 }); 30 }); 31 BrowserTestUtils.removeTab(tab); 32 }); 33 34 add_task(async function testGlobalPermissionIsBlocked() { 35 await SpecialPowers.pushPrefEnv({ 36 set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED]], 37 }); 38 let tab = await createTabAndSetupPolicyAssertFunc("about:blank"); 39 await SpecialPowers.spawn(tab.linkedBrowser, [], _ => { 40 info( 41 "global setting allows inaudible autoplay but audible autoplay is still not allowed" 42 ); 43 content.assertAutoplayPolicy({ 44 resultForElementType: "allowed-muted", 45 resultForElement: "allowed-muted", 46 resultForContextType: "disallowed", 47 resultForContext: "disallowed", 48 }); 49 50 info("tweaking video's muted attribute won't change the result"); 51 content.video.muted = true; 52 is( 53 "allowed-muted", 54 content.navigator.getAutoplayPolicy(content.video), 55 "getAutoplayPolicy(video) returns correct value" 56 ); 57 content.video.muted = false; 58 is( 59 "allowed-muted", 60 content.navigator.getAutoplayPolicy(content.video), 61 "getAutoplayPolicy(video) returns correct value" 62 ); 63 64 info( 65 "activate document by using user gesture, all autoplay will be allowed" 66 ); 67 content.document.notifyUserGestureActivation(); 68 content.assertAutoplayPolicy({ 69 resultForElementType: "allowed", 70 resultForElement: "allowed", 71 resultForContextType: "allowed", 72 resultForContext: "allowed", 73 }); 74 }); 75 BrowserTestUtils.removeTab(tab); 76 }); 77 78 add_task(async function testGlobalPermissionIsBlockedAll() { 79 await SpecialPowers.pushPrefEnv({ 80 set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED_ALL]], 81 }); 82 let tab = await createTabAndSetupPolicyAssertFunc("about:blank"); 83 await SpecialPowers.spawn(tab.linkedBrowser, [], _ => { 84 info("global setting doesn't allow any autoplay"); 85 content.assertAutoplayPolicy({ 86 resultForElementType: "disallowed", 87 resultForElement: "disallowed", 88 resultForContextType: "disallowed", 89 resultForContext: "disallowed", 90 }); 91 92 info( 93 "activate document by using user gesture, all autoplay will be allowed" 94 ); 95 content.document.notifyUserGestureActivation(); 96 content.assertAutoplayPolicy({ 97 resultForElementType: "allowed", 98 resultForElement: "allowed", 99 resultForContextType: "allowed", 100 resultForContext: "allowed", 101 }); 102 }); 103 BrowserTestUtils.removeTab(tab); 104 });