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

Side by Side Diff: LayoutTests/media/video-autoplay-experiment.html

Issue 1179223002: Implement autoplay gesture override experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased. Created 5 years, 5 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 <video autoplay controls></video>
2 <script src=media-file.js></script>
3 <script src=video-test.js></script>
4 <body>
5 <pre>
6 Check if the autoplay gesture override experiment works. There are a lot
7 of config options, so this test just runs all of them.
8
9 The "results" table contains one row per config tested.
10 == Test Inputs ==
11 # - config number, in case you'd like to run just one.
12 Exp - autoplay experiment setting being tested.
13 A-play - how is autoplay requested?
14 none - autoplay is not requested.
15 attr - autoplay attribute is set on the element.
16 js - play() called after media is ready to play.
17 Mute - how is media muted?
18 none - media is not muted.
19 attr - muted attribute is set on the element.
20 js - muted property is set after media is ready to play.
21 Vis - is media visible?
22 onscreen - element starts out onscreen.
23 scroll - element starts offscreen, scrolled into view once
24 it is ready to play.
25 offscreen - element starts out offscreen and stays offscreen.
26
27 == Test Outputs ==
28 Early? - did playback start before element was scrolled onscreen? For
29 tests in which Vis!=scroll, this is reported as "-".
30 Played? - did playback start by the conclusion of the test?
31 Muted? - was the media muted? If the media didn't play, then this is
32 reported as "-".
33
34 </pre>
35 <table id="results">
36 <tr>
37 <td>#</td>
38 <td>Exp</td>
39 <td>A-play</td>
40 <td>Mute</td>
41 <td>Vis</td>
42 <td>Early?</td>
43 <td>Played?</td>
44 <td>Muted?</td>
45 </tr>
46 </table>
47 </body>
48
49 <script>
50
51 // Starting configuration number. This should be zero normally.
52 var configNumber = 0;
53
54 var mediaFile = findMediaFile("video", "content/test");
55 var onscreenParent = document.createElement("div");
56 // The onscreen parent's height is also used to make sure that the off-screen
57 // parent is, in fact, off-screen.
58 onscreenParent.style.height="1000px";
59 document.body.insertBefore(onscreenParent, document.body.firstChild);
60 // Also create another root that's off the bottom of the window.
61 var offscreenParent = document.createElement("div");
62 document.body.appendChild(offscreenParent);
63
64 function didPlaybackStart(video)
65 {
66 // We say that the video started if it's not paused or if it played and
67 // already ended.
68 return !video.paused || video.ended;
69 }
70
71 function addResultsRow(spec)
72 {
73 // Add a row to the results table.
74 var row = document.getElementById("results").insertRow(-1);
75 var td = row.insertCell(0);
76
77 var fields = [ "experimentNumber", "experimentType", "autoplayType", "mutedT ype", "visType",
78 "playedEarly", "played", "muted"];
79 for(idx in fields)
80 row.insertCell(-1).innerText = (""+spec[fields[idx]]).substring(0,7);
81 }
82
83 function configureVideoViaScript(video, spec)
84 {
85 if (spec.mutedType == "js")
86 video.muted = true;
87 if(spec.autoplayType == "js")
88 video.play();
89 }
90
91 function queueNextExperiment()
92 {
93 // Start the next config, but let the event queue drain.
94 setTimeout(runNextConfig, 0);
95 }
96
97 function checkVideoStatus(video, spec)
98 {
99 // Update the spec with the results.
100 var didStart = didPlaybackStart(video);
101 video.spec.played = didStart ? "played" : "no";
102 video.spec.muted = didStart ? (video.muted ? "muted" : "unmuted") : "-";
103
104 addResultsRow(video.spec);
105 video.parentElement.removeChild(video);
106
107 // Scroll back to the top, in case this was a scrolling test.
108 onscreenParent.scrollIntoView();
109
110 queueNextExperiment();
111 }
112
113 function runOneConfig(spec)
114 {
115 internals.settings.setAutoplayExperimentMode(spec.experimentType);
116
117 // Create, configure, and attach a media element.
118 var video = document.createElement("video");
119
120 // Pick whether the element will be visible when canPlayThrough.
121 if (spec.visType == "onscreen")
122 onscreenParent.appendChild(video);
123 else
124 offscreenParent.appendChild(video);
125
126 // Set any attributes before canPlayThrough.
127 if (spec.mutedType == "attr")
128 video.setAttribute("muted", "true");
129 if (spec.autoplayType == "attr")
130 video.setAttribute("autoplay", "true");
131
132 spec.playedEarly = "-";
133
134 // Record the spec in the video element, so that we can display the
135 // results later.
136 video.spec = spec;
137
138 // Wait for canplaythrough before continuing, so that the media
139 // might actually be playing.
140 video.addEventListener("canplaythrough", function()
141 {
142 // Now that we can play, if we're supposed to play / mute via js do so.
143 configureVideoViaScript(video, spec);
144
145 // If we're supposed to scroll the item onscreen after it is ready to
146 // play, then do so now.
147 if(spec.visType == "scroll") {
148 // Record the play state here, too, before we scroll.
149 spec.playedEarly = didPlaybackStart(video) ? "yes" : "no";
150
151 // We are supposed to scroll the player into view.
152 video.scrollIntoView(true);
153 // We cause two visibility checks. The first notices the scroll,
154 // while the second notices that scrolling has stopped.
155 // It would be nicer to trigger location polling here, but that
156 // can take ~second to notice that scrolling is stopped.
157 window.internals.triggerAutoplayVisibilityCheck(video);
158 window.internals.triggerAutoplayVisibilityCheck(video);
159 // Once those are return, the state should be correct.
160 checkVideoStatus(video, spec);
161 } else {
162 // Record the results immediately.
163 checkVideoStatus(video, spec);
164 }
165 });
166
167 // Set the source, which will eventually lead to canPlayThrough.
168 video.src=mediaFile;
169 }
170
171 var experimentTypes = ["none", "always", "if-muted", "play-muted"];
172 var autoplayTypes = ["none", "attr", "js"];
173 var mutedTypes = ["none", "attr", "js"];
174 var visTypes = ["onscreen", "scroll", "offscreen"];
175
176 function runNextConfig()
177 {
178 // Convert configNumber into a spec, and run it.
179 var exp = configNumber;
180
181 // Convert this experiment number into settings.
182 var spec = {};
183 spec.experimentType = experimentTypes[exp % experimentTypes.length];
184 exp = Math.floor(exp / experimentTypes.length);
185 spec.autoplayType = autoplayTypes[exp % autoplayTypes.length];
186 exp = Math.floor(exp / autoplayTypes.length);
187 spec.mutedType = mutedTypes[exp % mutedTypes.length];
188 exp = Math.floor(exp / mutedTypes.length);
189 spec.visType = visTypes[exp % visTypes.length];
190 exp = Math.floor(exp / visTypes.length);
191 spec.experimentNumber = configNumber;
192
193 // exp>0 here indicates that we've wrapped around.
194 if (exp > 0) {
195 endTest();
196 }
197
198 configNumber++;
199
200 // To keep the test fast, skip a few combinations.
201 var skip = false;
202 if (spec.autoplayType == "none" && spec.visType != 'onscreen')
203 skip = true;
204 else if (spec.experimentType == "if-muted" && spec.visType != "onscreen")
205 skip = true;
206 else if (spec.visType == "offscreen" && spec.autoplayType != "attr")
207 skip = true;
208 else if (spec.experimentType != "if-muted" && spec.mutedType != "none")
209 skip = true;
210
211 if (skip)
212 queueNextExperiment();
213 else
214 runOneConfig(spec);
215 }
216
217 window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
218 window.internals.settings.setOverrideOptimizedForMobileCheck(true);
219 runNextConfig();
220
221 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/media/video-autoplay-experiment-expected.txt » ('j') | Source/core/html/HTMLMediaElement.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698