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

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: reduce 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 <title>Test behaviour of autoplay muted videos with regards to visibility</title >
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="media-file.js"></script>
6 <body>
7 <script>
8 window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
9 window.internals.runtimeFlags.autoplayMutedVideosEnabled = true;
10
11 async_test(function(t) {
12 // Create a video off screen.
13 {
14 var video = document.createElement('video');
15 video.id = 'offscreen';
16 video.src = findMediaFile('video', 'content/test');
17 video.muted = true;
18 video.autoplay = true;
19 video.loop = true;
20 video.style.position = 'absolute';
21 video.style.top = '-10000px';
22 document.body.appendChild(video);
23 }
24
25 // Create a video in screen.
26 {
27 var video = document.createElement('video');
28 video.id = 'inscreen';
29 video.src = findMediaFile('video', 'content/test');
30 video.muted = true;
31 video.autoplay = true;
32 video.loop = true;
33 document.body.appendChild(video);
34 }
35
36 // Create an audio in screen.
37 {
38 var audio = document.createElement('audio');
39 audio.src = findMediaFile('audio', 'content/test');
40 audio.muted = true;
41 audio.autoplay = true;
42 audio.loop = true;
43 audio.controls = true;
44 document.body.appendChild(audio);
45 }
46
47 // Create offscreen video without autoplay.
48 {
49 var video = document.createElement('video');
50 video.id = 'offscreen-no-autoplay';
51 video.src = findMediaFile('video', 'content/test');
52 video.muted = true;
53 video.loop = true;
54 video.style.position = 'absolute';
55 video.style.top = '-10000px';
56 document.body.appendChild(video);
57 }
58
59 var inscreen = document.querySelector('#inscreen');
60 var offscreen = document.querySelector('#offscreen');
61 var offscreenNoAutoplay = document.querySelector('#offscreen-no-autoplay');
62 var audio = document.querySelector('audio');
63
64 inscreen.addEventListener('playing', t.step_func(function() {
65 // The offscreen videos shouldn't play.
66 assert_true(offscreen.paused);
67 assert_true(offscreenNoAutoplay.paused);
68 assert_false(inscreen.paused);
69 assert_true(audio.paused, 'audio should not play');
70
71 // Both autoplay videos should have loaded.
72 assert_greater_than_equal(inscreen.readyState, HTMLMediaElement.HAVE_ENOUG H_DATA);
73 assert_greater_than_equal(offscreen.readyState, HTMLMediaElement.HAVE_ENOU GH_DATA);
74
75 // Move video in screen.
76 offscreen.style.top = '0px';
77
78 offscreen.addEventListener('playing', t.step_func(function() {
79 // Both autoplay videos should now play.
80 assert_false(inscreen.paused);
81 assert_false(offscreen.paused);
82 assert_true(offscreenNoAutoplay.paused);
83 assert_true(audio.paused, 'audio should not play');
84
85 // Call to play() should succeed regardless of visibility.
86 offscreenNoAutoplay.play();
87 offscreenNoAutoplay.addEventListener('playing', t.step_func_done(functio n() {
88 assert_false(inscreen.paused);
89 assert_false(offscreen.paused);
90 assert_false(offscreenNoAutoplay.paused);
91 assert_true(audio.paused, 'audio should not play');
92 }));
93 }));
94 }));
95 });
96 </script>
97 </body>
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/media/autoplay-muted.html ('k') | third_party/WebKit/Source/core/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698