| Index: third_party/WebKit/LayoutTests/media/autoplay-when-visible.html
|
| diff --git a/third_party/WebKit/LayoutTests/media/autoplay-when-visible.html b/third_party/WebKit/LayoutTests/media/autoplay-when-visible.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..39a9fc56d286c27d2f88fe1e814e0693a53ff751
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/media/autoplay-when-visible.html
|
| @@ -0,0 +1,87 @@
|
| +<!DOCTYPE html>
|
| +<html>
|
| +<head>
|
| +<title>Test behaviour of autoplay muted videos with regards to visibility</title>
|
| +</head>
|
| +<body>
|
| +<script src="../resources/testharness.js"></script>
|
| +<script src="../resources/testharnessreport.js"></script>
|
| +<script src="media-file.js"></script>
|
| +<script>
|
| + window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
|
| + window.internals.runtimeFlags.autoplayMutedVideosEnabled = true;
|
| +
|
| + async_test(function(t) {
|
| + // Create a video off screen.
|
| + {
|
| + var video = document.createElement('video');
|
| + video.id = 'offscreen';
|
| + video.src = findMediaFile('video', 'content/test');
|
| + video.muted = true;
|
| + video.autoplay = true;
|
| + video.loop = true;
|
| + video.style.position = 'absolute';
|
| + video.style.top = '-10000px';
|
| + document.body.appendChild(video);
|
| + }
|
| +
|
| + // Create a video in screen.
|
| + {
|
| + var video = document.createElement('video');
|
| + video.id = 'inscreen';
|
| + video.src = findMediaFile('video', 'content/test');
|
| + video.muted = true;
|
| + video.autoplay = true;
|
| + video.loop = true;
|
| + document.body.appendChild(video);
|
| + }
|
| +
|
| + // Create offscreen video without autoplay.
|
| + {
|
| + var video = document.createElement('video');
|
| + video.id = 'offscreen-no-autoplay';
|
| + video.src = findMediaFile('video', 'content/test');
|
| + video.muted = true;
|
| + video.loop = true;
|
| + video.style.position = 'absolute';
|
| + video.style.top = '-10000px';
|
| + document.body.appendChild(video);
|
| + }
|
| +
|
| + var inscreen = document.querySelector('#inscreen');
|
| + var offscreen = document.querySelector('#offscreen');
|
| + var offscreenNoAutoplay = document.querySelector('#offscreen-no-autoplay');
|
| +
|
| + inscreen.addEventListener('playing', t.step_func(function() {
|
| + // The offscreen videos shouldn't play.
|
| + assert_true(offscreen.paused);
|
| + assert_true(offscreenNoAutoplay.paused);
|
| + assert_false(inscreen.paused);
|
| +
|
| + // Both autoplay videos should have loaded.
|
| + assert_greater_than_equal(inscreen.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA);
|
| + assert_greater_than_equal(offscreen.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA);
|
| +
|
| + // Move video in screen.
|
| + offscreen.style.top = '0px';
|
| +
|
| + offscreen.addEventListener('playing', t.step_func(function() {
|
| + // Both autoplay videos should now play.
|
| + assert_false(inscreen.paused);
|
| + assert_false(offscreen.paused);
|
| + assert_true(offscreenNoAutoplay.paused);
|
| +
|
| + // Call to play() should succeed regardless of visibility.
|
| + offscreenNoAutoplay.play();
|
| + offscreenNoAutoplay.addEventListener('playing', t.step_func_done(function() {
|
| + assert_false(inscreen.paused);
|
| + assert_false(offscreen.paused);
|
| + assert_false(offscreenNoAutoplay.paused);
|
| + }));
|
| + }));
|
| + }));
|
| + });
|
| +
|
| +</script>
|
| +</body>
|
| +</html>
|
|
|