file_autoplay_policy_activation_window.html (3085B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Autoplay policy window</title> 5 <style> 6 video { 7 width: 50%; 8 height: 50%; 9 } 10 </style> 11 <script src="/tests/SimpleTest/SimpleTest.js"></script> 12 <script src="/tests/SimpleTest/EventUtils.js"></script> 13 <script type="text/javascript" src="manifest.js"></script> 14 <script type="text/javascript" src="AutoplayTestUtils.js"></script> 15 </head> 16 <body> 17 <pre id="test"> 18 <script> 19 20 async function createChildFrame(testInfo) { 21 let frame = document.createElement("iframe"); 22 let origin = testInfo.same_origin_child 23 ? "http://mochi.test:8888" : "http://example.org"; 24 frame.src = origin + "/tests/dom/media/autoplay/test/mochitest/file_autoplay_policy_activation_frame.html"; 25 // Wait for it to load... 26 document.body.appendChild(frame); 27 is((await nextWindowMessage()).data, "ready", "Expected a 'ready' message"); 28 return frame; 29 } 30 31 async function activateDocument(testInfo) { 32 // Click the window to activate if appropriate. 33 if (testInfo.activated_from == "parent") { 34 info(`activate parent's document`); 35 SpecialPowers.wrap(document).notifyUserGestureActivation(); 36 } else if (testInfo.activated_from == "child") { 37 info(`activate child's document`); 38 testInfo.childFrame.contentWindow.postMessage("click", "*"); 39 is((await nextWindowMessage()).data, "activated", "has activated child frame."); 40 } 41 } 42 43 function testAutoplayInWindow(testInfo) { 44 info(`start autoplay from parent frame`); 45 playAndPostResult(testInfo.muted, testInfo.parentWindow); 46 } 47 48 async function testAutoplayInChildFrame(testInfo) { 49 info("start autoplay from " + (testInfo.same_origin_child ? "same" : "cross") + " origin child frame"); 50 // Ask the child iframe to try to play video. 51 let play_message = testInfo.muted ? "play-muted" : "play-audible"; 52 testInfo.childFrame.contentWindow.postMessage(play_message, "*"); 53 // Wait for the iframe to tell us whether it could play video. 54 let result = await nextWindowMessage(); 55 // Report whether the iframe could play to the parent. 56 testInfo.parentWindow.postMessage(result.data, "*"); 57 } 58 59 nextWindowMessage().then( 60 async (event) => { 61 let testInfo = event.data; 62 testInfo.parentWindow = event.source; 63 testInfo.childFrame = await createChildFrame(testInfo); 64 65 await activateDocument(testInfo); 66 switch (testInfo.play_from) { 67 case "parent": 68 testAutoplayInWindow(testInfo); 69 break; 70 case "child": 71 testAutoplayInChildFrame(testInfo); 72 break; 73 default: 74 ok(false, "Incorrect 'play_from' value!") 75 } 76 }); 77 </script> 78 </pre> 79 </body> 80 </html>