browser_autoplay_policy_webRTC_permission.js (1691B)
1 /** 2 * This test is used to ensure site which has granted 'camera' or 'microphone' 3 * or 'screen' permission could be allowed to autoplay. 4 */ 5 "use strict"; 6 7 const { PermissionTestUtils } = ChromeUtils.importESModule( 8 "resource://testing-common/PermissionTestUtils.sys.mjs" 9 ); 10 11 const VIDEO_PAGE = GetTestWebBasedURL("file_empty.html"); 12 13 add_task(() => { 14 return SpecialPowers.pushPrefEnv({ 15 set: [ 16 ["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED], 17 ["media.autoplay.blocking_policy", 0], 18 ["media.autoplay.block-event.enabled", true], 19 ], 20 }); 21 }); 22 23 async function testAutoplayWebRTCPermission(args) { 24 info(`- Starting ${args.name} -`); 25 await BrowserTestUtils.withNewTab( 26 { 27 gBrowser, 28 url: VIDEO_PAGE, 29 }, 30 async browser => { 31 PermissionTestUtils.add( 32 browser.currentURI, 33 args.permission, 34 Services.perms.ALLOW_ACTION 35 ); 36 37 await loadAutoplayVideo(browser, args); 38 await checkVideoDidPlay(browser, args); 39 40 // Reset permission. 41 PermissionTestUtils.remove(browser.currentURI, args.permission); 42 43 info(`- Finished ${args.name} -`); 44 } 45 ); 46 } 47 48 add_task(async function start_test() { 49 await testAutoplayWebRTCPermission({ 50 name: "Site with camera permission", 51 permission: "camera", 52 shouldPlay: true, 53 mode: "call play", 54 }); 55 await testAutoplayWebRTCPermission({ 56 name: "Site with microphone permission", 57 permission: "microphone", 58 shouldPlay: true, 59 mode: "call play", 60 }); 61 await testAutoplayWebRTCPermission({ 62 name: "Site with screen permission", 63 permission: "screen", 64 shouldPlay: true, 65 mode: "call play", 66 }); 67 });