autoplay-hidden.optional.html (1404B)
1 <!doctype html> 2 <title>autoplay hidden</title> 3 <link rel="author" title="Intel" href="http://www.intel.com"> 4 <link rel="help" href="https://html.spec.whatwg.org/multipage/media.html#ready-states"/> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/common/media.js"></script> 8 <div id="log"></div> 9 <script> 10 11 // https://html.spec.whatwg.org/multipage/media.html#ready-states:eligible-for-autoplay-2 12 13 promise_test(async t => { 14 let video = document.createElement("video"); 15 video.src = getVideoURI("/media/movie_5"); 16 video.autoplay = true; 17 // In Safari, Chrome and Firefox, the video needs to be muted in order to be 18 // paused when hidden. They decided to do this in order to save resources when 19 // a video goes out of view and isn't expected to make any sound. 20 video.muted = true; 21 video.loop = true; 22 let watcher = new EventWatcher(t, video, ["playing", "pause"]); 23 document.body.appendChild(video); 24 25 await watcher.wait_for("playing"); 26 assert_false(video.paused, "paused when video is display"); 27 video.hidden = true; 28 29 await watcher.wait_for("pause"); 30 assert_true(video.paused, "paused when video is hidden"); 31 video.hidden = false; 32 33 await watcher.wait_for("playing"); 34 assert_false(video.paused, "paused when video is display"); 35 }, "Allow delaying autoplay until video elements become visible"); 36 37 </script>