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

Side by Side Diff: third_party/WebKit/LayoutTests/media/autoplay-when-visible.html

Issue 2051253002: Start autoplay muted videos with autoplay attribute when they are visible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
esprehn 2016/06/21 21:28:41 ditto
4 <title>Test behaviour of autoplay muted videos with regards to visibility</title >
5 </head>
6 <body>
esprehn 2016/06/21 21:28:41 put the body after the media-file.js, right before
mlamouri (slow - plz ping) 2016/06/21 21:32:11 What's the intent?
esprehn 2016/06/21 21:36:40 It's the most minimal thing needed to make your te
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 an audio in screen.
40 {
41 var audio = document.createElement('audio');
42 audio.src = findMediaFile('audio', 'content/test');
43 audio.muted = true;
44 audio.autoplay = true;
45 audio.loop = true;
46 audio.controls = true;
47 document.body.appendChild(audio);
48 }
49
50 // Create offscreen video without autoplay.
51 {
52 var video = document.createElement('video');
53 video.id = 'offscreen-no-autoplay';
54 video.src = findMediaFile('video', 'content/test');
55 video.muted = true;
56 video.loop = true;
57 video.style.position = 'absolute';
58 video.style.top = '-10000px';
59 document.body.appendChild(video);
60 }
61
62 var inscreen = document.querySelector('#inscreen');
63 var offscreen = document.querySelector('#offscreen');
64 var offscreenNoAutoplay = document.querySelector('#offscreen-no-autoplay');
65 var audio = document.querySelector('audio');
66
67 inscreen.addEventListener('playing', t.step_func(function() {
68 // The offscreen videos shouldn't play.
69 assert_true(offscreen.paused);
70 assert_true(offscreenNoAutoplay.paused);
71 assert_false(inscreen.paused);
72 assert_true(audio.paused, 'audio should not play');
73
74 // Both autoplay videos should have loaded.
75 assert_greater_than_equal(inscreen.readyState, HTMLMediaElement.HAVE_ENOUG H_DATA);
76 assert_greater_than_equal(offscreen.readyState, HTMLMediaElement.HAVE_ENOU GH_DATA);
77
78 // Move video in screen.
79 offscreen.style.top = '0px';
80
81 offscreen.addEventListener('playing', t.step_func(function() {
82 // Both autoplay videos should now play.
83 assert_false(inscreen.paused);
84 assert_false(offscreen.paused);
85 assert_true(offscreenNoAutoplay.paused);
86 assert_true(audio.paused, 'audio should not play');
87
88 // Call to play() should succeed regardless of visibility.
89 offscreenNoAutoplay.play();
90 offscreenNoAutoplay.addEventListener('playing', t.step_func_done(functio n() {
91 assert_false(inscreen.paused);
92 assert_false(offscreen.paused);
93 assert_false(offscreenNoAutoplay.paused);
94 assert_true(audio.paused, 'audio should not play');
95 }));
96 }));
97 }));
98 });
99
100 </script>
101 </body>
102 </html>
esprehn 2016/06/21 21:28:41 no need for these
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698