| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Test behaviour of autoplay muted videos with regards to visibility</title
> |
| 5 </head> |
| 6 <body> |
| 7 <script src="../resources/testharness.js"></script> |
| 8 <script src="../resources/testharnessreport.js"></script> |
| 9 <script src="media-file.js"></script> |
| 10 <script> |
| 11 window.internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| 12 window.internals.runtimeFlags.autoplayMutedVideosEnabled = true; |
| 13 |
| 14 async_test(function(t) { |
| 15 // Create a video off screen. |
| 16 { |
| 17 var video = document.createElement('video'); |
| 18 video.id = 'offscreen'; |
| 19 video.src = findMediaFile('video', 'content/test'); |
| 20 video.muted = true; |
| 21 video.autoplay = true; |
| 22 video.loop = true; |
| 23 video.style.position = 'absolute'; |
| 24 video.style.top = '-10000px'; |
| 25 document.body.appendChild(video); |
| 26 } |
| 27 |
| 28 // Create a video in screen. |
| 29 { |
| 30 var video = document.createElement('video'); |
| 31 video.id = 'inscreen'; |
| 32 video.src = findMediaFile('video', 'content/test'); |
| 33 video.muted = true; |
| 34 video.autoplay = true; |
| 35 video.loop = true; |
| 36 document.body.appendChild(video); |
| 37 } |
| 38 |
| 39 // Create offscreen video without autoplay. |
| 40 { |
| 41 var video = document.createElement('video'); |
| 42 video.id = 'offscreen-no-autoplay'; |
| 43 video.src = findMediaFile('video', 'content/test'); |
| 44 video.muted = true; |
| 45 video.loop = true; |
| 46 video.style.position = 'absolute'; |
| 47 video.style.top = '-10000px'; |
| 48 document.body.appendChild(video); |
| 49 } |
| 50 |
| 51 var inscreen = document.querySelector('#inscreen'); |
| 52 var offscreen = document.querySelector('#offscreen'); |
| 53 var offscreenNoAutoplay = document.querySelector('#offscreen-no-autoplay'); |
| 54 |
| 55 inscreen.addEventListener('playing', t.step_func(function() { |
| 56 // The offscreen videos shouldn't play. |
| 57 assert_true(offscreen.paused); |
| 58 assert_true(offscreenNoAutoplay.paused); |
| 59 assert_false(inscreen.paused); |
| 60 |
| 61 // Both autoplay videos should have loaded. |
| 62 assert_greater_than_equal(inscreen.readyState, HTMLMediaElement.HAVE_ENOUG
H_DATA); |
| 63 assert_greater_than_equal(offscreen.readyState, HTMLMediaElement.HAVE_ENOU
GH_DATA); |
| 64 |
| 65 // Move video in screen. |
| 66 offscreen.style.top = '0px'; |
| 67 |
| 68 offscreen.addEventListener('playing', t.step_func(function() { |
| 69 // Both autoplay videos should now play. |
| 70 assert_false(inscreen.paused); |
| 71 assert_false(offscreen.paused); |
| 72 assert_true(offscreenNoAutoplay.paused); |
| 73 |
| 74 // Call to play() should succeed regardless of visibility. |
| 75 offscreenNoAutoplay.play(); |
| 76 offscreenNoAutoplay.addEventListener('playing', t.step_func_done(functio
n() { |
| 77 assert_false(inscreen.paused); |
| 78 assert_false(offscreen.paused); |
| 79 assert_false(offscreenNoAutoplay.paused); |
| 80 })); |
| 81 })); |
| 82 })); |
| 83 }); |
| 84 |
| 85 </script> |
| 86 </body> |
| 87 </html> |
| OLD | NEW |