OLD | NEW |
---|---|
(Empty) | |
1 <script src=media-file.js></script> | |
2 <script src=video-test.js></script> | |
3 <script> | |
4 | |
5 var mediaFile; | |
philipj_slow
2015/09/04 09:24:26
It looks like none of these need to be global, if
liberato (no reviews please)
2015/09/08 21:58:01
Done.
philipj_slow
2015/09/10 09:58:59
It doesn't matter much, but mediaFile is still glo
liberato (no reviews please)
2015/09/10 14:52:27
Done.
| |
6 var parent; | |
7 | |
8 function didPlaybackStart(video) | |
9 { | |
10 // We say that the video started if it's not paused or if it played and | |
11 // already ended. | |
12 return !video.paused || video.ended; | |
philipj_slow
2015/09/04 09:24:26
A more direct way is to check if video.played.leng
liberato (no reviews please)
2015/09/08 21:58:01
This didn't seem to work -- it always returned fal
philipj_slow
2015/09/10 09:58:59
That's surprising, but figuring out why isn't in s
liberato (no reviews please)
2015/09/10 14:52:27
Acknowledged.
| |
13 } | |
14 | |
15 function prepareVideo() | |
16 { | |
17 var video = document.createElement("video"); | |
18 video.src=mediaFile; | |
philipj_slow
2015/09/04 09:24:26
Missing whitespace
liberato (no reviews please)
2015/09/08 21:58:01
Done.
| |
19 video.setAttribute("autoplay", "true"); | |
philipj_slow
2015/09/04 09:24:26
video.autoplay = true works as it's a reflected at
liberato (no reviews please)
2015/09/08 21:58:01
Done.
| |
20 parent.appendChild(video); | |
21 | |
22 return video; | |
23 } | |
24 | |
25 function runTest() | |
26 { | |
27 mediaFile = findMediaFile("video", "content/test"); | |
28 parent = document.createElement("div"); | |
29 document.body.insertBefore(parent, document.body.firstChild); | |
philipj_slow
2015/09/04 09:24:26
Since body has no other children (except a text no
liberato (no reviews please)
2015/09/08 21:58:01
Done.
| |
30 | |
31 // Require a user gesture, but override it for muted videos. | |
32 window.internals.settings.setMediaPlaybackRequiresUserGesture(true); | |
philipj_slow
2015/09/04 09:24:26
Use just internals or window.internals on both lin
liberato (no reviews please)
2015/09/08 21:58:01
no idea. done.
| |
33 internals.settings.setAutoplayExperimentMode("enabled-forvideo-ifmuted"); | |
34 | |
35 var videoShouldPlay = prepareVideo(); | |
36 var videoShouldNotPlay = prepareVideo(); | |
37 | |
38 // Pause() will clear the autoplaying flag, which should also prevent the | |
39 // gesture override experiment from autoplaying. | |
40 videoShouldNotPlay.pause(); | |
41 | |
42 // Mute them both, and see if only one starts. | |
43 videoShouldPlay.muted = true; | |
44 videoShouldNotPlay.muted = true; | |
45 logResult(didPlaybackStart(videoShouldPlay), "First video should play"); | |
46 logResult(!didPlaybackStart(videoShouldNotPlay), "Second video should not pl ay"); | |
47 testRunner.notifyDone(); | |
48 } | |
49 | |
50 </script> | |
51 <p>Test that the autoplay experiment doesn't play media once the media | |
52 is no longer eligible for autoplay.</p> | |
53 <body onLoad="runTest()"> | |
54 </body> | |
OLD | NEW |