Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: third_party/WebKit/LayoutTests/media/autoplay-when-visible-multiple-times.html

Issue 2654123002: Autoplay muted video when visible and pause when invisible (Closed)
Patch Set: finalizing implementation and tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/HTMLMediaElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/HTMLMediaElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698