AutoplayTestUtils.js (1071B)
1 /* import-globals-from ../../../test/manifest.js */ 2 3 function playAndPostResult(muted, parent_window) { 4 let element = document.createElement("video"); 5 element.preload = "auto"; 6 element.muted = muted; 7 element.src = "short.mp4"; 8 element.id = "video"; 9 document.body.appendChild(element); 10 element.play().then( 11 () => { 12 parent_window.postMessage( 13 { played: true, allowedToPlay: element.allowedToPlay }, 14 "*" 15 ); 16 }, 17 () => { 18 parent_window.postMessage( 19 { played: false, allowedToPlay: element.allowedToPlay }, 20 "*" 21 ); 22 } 23 ); 24 } 25 26 function nextWindowMessage() { 27 return nextEvent(window, "message"); 28 } 29 30 function log(msg) { 31 var log_pane = document.body; 32 log_pane.appendChild(document.createTextNode(msg)); 33 log_pane.appendChild(document.createElement("br")); 34 } 35 36 const autoplayPermission = "autoplay-media"; 37 38 async function pushAutoplayAllowedPermission() { 39 return SpecialPowers.pushPermissions([ 40 { 41 type: autoplayPermission, 42 allow: true, 43 context: document, 44 }, 45 ]); 46 }