| <head> |
| <style> |
| iframe { |
| width: 320px; |
| height: 240px; |
| } |
| </style> |
| <script src="media-file.js"></script> |
| <script src="video-test.js"></script> |
| <script> |
| if (window.testRunner) { |
| testRunner.waitUntilDone(); |
| testRunner.dumpAsText(); |
| } |
| |
| async function checkAutoPlay(allowed) |
| { |
| let message = allowed ? "Video auto-played" : "Video did not auto-play"; |
| let video = iframe.contentDocument.querySelector("video"); |
| |
| let played; |
| let counter = 0; |
| while (++counter < 20) { |
| played = video.ended || video.currentTime != 0; |
| if (allowed === played) |
| break; |
| await new Promise(resolve => setTimeout(resolve, 50)); |
| } |
| |
| if (allowed == played) |
| consoleWrite(`PASS: ${allowed ? "Video auto-played" : "Video did not auto-play"}`); |
| else |
| consoleWrite(`FAIL: ${allowed ? "Video did not auto-play" : "Video auto-played"}`); |
| } |
| |
| async function loadVideo(policy, allow) |
| { |
| consoleWrite(`<br>*** Test with auto-play policy set to '${policy}'`); |
| |
| if (window.internals) |
| internals.setDocumentAutoplayPolicy(document, policy) |
| |
| iframe.src = 'about:blank'; |
| await waitForEventWithTimeout(iframe, 'load', 4000, '"about:blank" iframe failed to load!'); |
| |
| let script = iframe.contentDocument.head.appendChild(iframe.contentDocument.createElement('script')); |
| let code = ` |
| let video=document.createElement('video'); |
| document.body.appendChild(video); |
| video.controls = 1; |
| video.playsinline = 1; |
| video.autoplay = 1; |
| video.src = 'content/test.wav'; |
| let postedMessage = false; |
| let postMessage = () => { |
| if (!postedMessage) |
| window.parent.postMessage('loaded', '*'); |
| postedMessage = true; |
| }; |
| setTimeout(postMessage, 1000); |
| video.oncanplaythrough = postMessage; |
| `; |
| script.appendChild(iframe.contentDocument.createTextNode(code)); |
| |
| await waitForEventWithTimeout(window, 'message', 4000, 'iframe failed to send message!'); |
| await new Promise(resolve => setTimeout(resolve, 250)); |
| await checkAutoPlay(allow); |
| } |
| |
| window.addEventListener('load', async () => { |
| iframe = document.querySelector('iframe'); |
| |
| await loadVideo('Allow', true); |
| |
| await loadVideo('AllowWithoutSound', false); |
| |
| await loadVideo('Deny', false); |
| |
| consoleWrite(''); |
| endTest(); |
| }, false); |
| |
| </script> |
| </head> |
| <body> |
| <iframe ></iframe> |
| </body> |