Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/media/autoplay-when-visible-multiple-times.html |
| diff --git a/third_party/WebKit/LayoutTests/media/autoplay-when-visible-multiple-times.html b/third_party/WebKit/LayoutTests/media/autoplay-when-visible-multiple-times.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23ee975abee007ec02ea25c34ddb5c2bf525f448 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/media/autoplay-when-visible-multiple-times.html |
| @@ -0,0 +1,51 @@ |
| +<!DOCTYPE html> |
| +<title>Test behaviour of autoplay muted videos with regards to visibility</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="media-file.js"></script> |
| +<body> |
| +<script> |
| + window.internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| + window.internals.runtimeFlags.autoplayMutedVideosEnabled = true; |
| + |
| + var expectations = [ 'paused', 'playing', 'paused', 'playing', 'paused', 'playing', 'paused' ]; |
|
whywhat
2017/02/13 16:50:15
I don't think this is needed at all:
- you know wh
Zhiqiang Zhang (Slow)
2017/02/13 17:48:05
Now add/remove event listeners to ensure the event
|
| + var expectationId = 0; |
| + |
| + function checkExpectations(t, observed) { |
| + assert_equals(expectations[expectationId++], observed); |
| + if (expectationId >= expectations.length) |
| + t.done(); |
| + } |
| + |
| + var video; |
| + |
| + function runStepsWhenInvisible(t) { |
| + assert_true(video.paused); |
| + checkExpectations(t, 'paused'); |
|
whywhat
2017/02/13 16:50:15
you could simplify these two lines (ditto below) b
Zhiqiang Zhang (Slow)
2017/02/13 17:48:05
This no longer applies as removed.
|
| + video.style.top = '0px'; |
| + } |
| + |
| + function runStepsWhenVisible(t) { |
| + assert_false(video.paused); |
| + checkExpectations(t, 'playing'); |
| + video.style.top = '-10000px'; |
| + } |
| + |
| + async_test(function(t) { |
| + // Create a video off screen. |
| + { |
| + video = document.createElement('video'); |
| + 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); |
| + } |
| + |
| + video.addEventListener('canplay', t.step_func(_ => runStepsWhenInvisible(t))); |
|
whywhat
2017/02/13 16:50:15
will this event fire only once during this test? m
Zhiqiang Zhang (Slow)
2017/02/13 17:48:05
Done.
|
| + video.addEventListener('play', t.step_func(_ => runStepsWhenVisible(t))); |
|
whywhat
2017/02/13 16:50:15
I'd rather have a visibility observer to check the
Zhiqiang Zhang (Slow)
2017/02/13 17:48:05
I prefer not to use visibility observer as the int
|
| + video.addEventListener('pause', t.step_func(_ => runStepsWhenInvisible(t))); |
| + }); |
| +</script> |