| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Test behaviour of autoplay muted videos with regards to visibility</title
> |
| 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="media-file.js"></script> |
| 6 <body> |
| 7 <script> |
| 8 window.internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| 9 window.internals.runtimeFlags.autoplayMutedVideosEnabled = true; |
| 10 |
| 11 var gCycleCount = 0; |
| 12 |
| 13 var video; |
| 14 |
| 15 function runStepsWhenInvisible(t) { |
| 16 assert_true(video.paused); |
| 17 video.style.top = '0px'; |
| 18 |
| 19 video.onplay = null; |
| 20 video.onpause = t.unreached_func(); |
| 21 video.addEventListener('play', t.step_func(_ => runStepsWhenVisible(t)), { o
nce: true }); |
| 22 } |
| 23 |
| 24 function runStepsWhenVisible(t) { |
| 25 assert_false(video.paused); |
| 26 |
| 27 if (gCycleCount++ >= 3) { |
| 28 t.done(); |
| 29 return; |
| 30 } |
| 31 video.style.top = '-10000px'; |
| 32 |
| 33 video.onpause = null; |
| 34 video.onplay = t.unreached_func(); |
| 35 video.addEventListener('pause', t.step_func(_ => runStepsWhenInvisible(t)),
{ once: true }); |
| 36 } |
| 37 |
| 38 async_test(function(t) { |
| 39 // Create a video off screen. |
| 40 { |
| 41 video = document.createElement('video'); |
| 42 video.src = findMediaFile('video', 'content/test'); |
| 43 video.muted = true; |
| 44 video.autoplay = true; |
| 45 video.loop = true; |
| 46 video.style.position = 'absolute'; |
| 47 video.style.top = '-10000px'; |
| 48 document.body.appendChild(video); |
| 49 } |
| 50 |
| 51 video.addEventListener('canplay', t.step_func(_ => runStepsWhenInvisible(t))
, { once : true }); |
| 52 }); |
| 53 </script> |
| OLD | NEW |