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

Side by Side 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: improved 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 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 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.
12 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.
13
14 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.
15 assert_unreached(description);
16 }
17
18 var video;
19
20 function runStepsWhenInvisible() {
21 assert_true(video.paused);
22 video.style.top = '0px';
23
24 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.
25 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.
26 video.addEventListener('pause', neverHappens);
27 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.
28 }
29
30 function runStepsWhenVisible() {
31 assert_false(video.paused);
32
33 if (cycleCount++ >= 3)
34 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.
35
36 video.style.top = '-10000px';
37
38 video.removeEventListener('pause', neverHappens);
39 video.removeEventListener('play', runStepsWhenVisible);
40 video.addEventListener('pause', runStepsWhenInvisible);
41 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.
42 }
43
44 async_test(function(t) {
45 testInstance = t;
46 // Create a video off screen.
47 {
48 video = document.createElement('video');
49 video.src = findMediaFile('video', 'content/test');
50 video.muted = true;
51 video.autoplay = true;
52 video.loop = true;
53 video.style.position = 'absolute';
54 video.style.top = '-10000px';
55 document.body.appendChild(video);
56 }
57
58 var canplayListener = t.step_func(_ => {
59 runStepsWhenInvisible(t);
60 video.removeEventListener('canplay', canplayListener);
61 });
62 video.addEventListener('canplay', canplayListener);
63 });
64 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698