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..22af2da8011fd2a87f3bb97355e349f55fd913ce |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/media/autoplay-when-visible-multiple-times.html |
| @@ -0,0 +1,64 @@ |
| +<!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 cycleCount = 0; |
|
mlamouri (slow - plz ping)
2017/02/14 20:59:02
gCyclecount to make it clear it's global maybe?
Zhiqiang Zhang (Slow)
2017/02/14 21:47:31
Done.
|
| + var testInstance; |
|
mlamouri (slow - plz ping)
2017/02/14 20:59:01
I don't think you need this.
Zhiqiang Zhang (Slow)
2017/02/14 21:47:31
Done.
|
| + |
| + function neverHappens(description) { |
|
mlamouri (slow - plz ping)
2017/02/14 20:59:02
Usage of neverHappens should be: `t.unreached_func
Zhiqiang Zhang (Slow)
2017/02/14 21:47:31
Done.
|
| + assert_unreached(description); |
| + } |
| + |
| + var video; |
| + |
| + function runStepsWhenInvisible() { |
| + assert_true(video.paused); |
| + video.style.top = '0px'; |
| + |
| + video.removeEventListener('pause', runStepsWhenInvisible); |
|
mlamouri (slow - plz ping)
2017/02/14 20:59:02
To avoid the `removeEventListener`, you can add `{
Zhiqiang Zhang (Slow)
2017/02/14 21:47:31
Done.
|
| + video.removeEventListener('play', neverHappens); |
|
mlamouri (slow - plz ping)
2017/02/14 20:59:02
Maybe use `onplay` here and below to be able to re
Zhiqiang Zhang (Slow)
2017/02/14 21:47:31
Done.
|
| + video.addEventListener('pause', neverHappens); |
| + video.addEventListener('play', runStepsWhenVisible); |
|
mlamouri (slow - plz ping)
2017/02/14 20:59:02
You should pass `t` to `runStepsWhenINvisible` the
Zhiqiang Zhang (Slow)
2017/02/14 21:47:31
Done.
|
| + } |
| + |
| + function runStepsWhenVisible() { |
| + assert_false(video.paused); |
| + |
| + if (cycleCount++ >= 3) |
| + testInstance.done(); |
|
mlamouri (slow - plz ping)
2017/02/14 20:59:02
If `t` is passed, you should be able to do `t.done
Zhiqiang Zhang (Slow)
2017/02/14 21:47:31
Done.
|
| + |
| + video.style.top = '-10000px'; |
| + |
| + video.removeEventListener('pause', neverHappens); |
| + video.removeEventListener('play', runStepsWhenVisible); |
| + video.addEventListener('pause', runStepsWhenInvisible); |
| + video.addEventListener('play', neverHappens); |
|
mlamouri (slow - plz ping)
2017/02/14 20:59:02
See comments above.
Zhiqiang Zhang (Slow)
2017/02/14 21:47:31
Done.
|
| + } |
| + |
| + async_test(function(t) { |
| + testInstance = 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); |
| + } |
| + |
| + var canplayListener = t.step_func(_ => { |
| + runStepsWhenInvisible(t); |
| + video.removeEventListener('canplay', canplayListener); |
| + }); |
| + video.addEventListener('canplay', canplayListener); |
| + }); |
| +</script> |