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

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: removed WebRuntimeFeatures.h whitespace-only change. 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 checkVideoStatus(video, spec)
84 {
85 // Now that we can play, if we're supposed to play / mute via js do so.
86 if (spec.mutedType == "js")
87 video.muted = true;
88 if(spec.autoplayType == "js")
89 video.play();
90
91 // Update the spec with the results.
92 var didStart = didPlaybackStart(video);
93 video.spec.played = didStart ? "played" : "no";
94 video.spec.muted = didStart ? (video.muted ? "muted" : "unmuted") : "-";
95
96 addResultsRow(video.spec);
97 video.parentElement.removeChild(video);
98
99 // Scroll back to the top, in case this was a scrolling test.
100 onscreenParent.scrollIntoView();
101
102 // Start the next config, but let the event queue drain.
103 setTimeout(runNextConfig, 0);
104 }
105
106 function runOneConfig(spec)
107 {
108 internals.settings.setAutoplayExperimentMode(spec.experimentType);
109
110 // Create, configure, and attach a media element.
111 var video = document.createElement("video");
112
113 // Pick whether the element will be visible when canPlayThrough.
114 if (spec.visType == "onscreen")
115 onscreenParent.appendChild(video);
116 else
117 offscreenParent.appendChild(video);
118
119 // Set any attributes before canPlayThrough.
120 if (spec.mutedType == "attr")
121 video.setAttribute("muted", "true");
122 if (spec.autoplayType == "attr")
123 video.setAttribute("autoplay", "true");
124
125 spec.playedEarly = "-";
126
127 // Record the spec in the video element, so that we can display the
128 // results later.
129 video.spec = spec;
130
131 // Wait for canplaythrough before continuing, so that the media
132 // might actually be playing.
133 video.addEventListener("canplaythrough", function()
134 {
135 // If we're supposed to scroll the item onscreen after it is ready to
136 // play, then do so now.
137 if(spec.visType == "scroll") {
138 // Record the play state here, too, before we scroll.
139 spec.playedEarly = didPlaybackStart(video) ? "yes" : "no";
140
141 // We are supposed to scroll the player into view. Doing so
142 // earlier would work, but might not test the scroll listener.
143 video.scrollIntoView(true);
144 // Wait for HTMLMediaElement to get the scroll event before
145 // recording the results.
146 setTimeout(function() { checkVideoStatus(video, spec); }, 0);
147 } else {
148 // Record the results immediately.
149 checkVideoStatus(video, spec);
150 }
151 });
152
153 // Set the source, which will eventually lead to canPlayThrough.
154 video.src=mediaFile;
155 }
156
157 var experimentTypes = ["none", "always", "if-muted", "play-muted"];
158 var autoplayTypes = ["none", "attr", "js"];
159 var mutedTypes = ["none", "attr", "js"];
160 var visTypes = ["onscreen", "scroll", "offscreen"];
161
162 function runNextConfig()
163 {
164 // Convert configNumber into a spec, and run it.
165 var exp = configNumber;
166
167 // Convert this experiment number into settings.
168 var spec = {};
169 spec.experimentType = experimentTypes[exp % experimentTypes.length];
170 exp = Math.floor(exp / experimentTypes.length);
171 spec.autoplayType = autoplayTypes[exp % autoplayTypes.length];
172 exp = Math.floor(exp / autoplayTypes.length);
173 spec.mutedType = mutedTypes[exp % mutedTypes.length];
174 exp = Math.floor(exp / mutedTypes.length);
175 spec.visType = visTypes[exp % visTypes.length];
176 exp = Math.floor(exp / visTypes.length);
177 spec.experimentNumber = configNumber;
178
179 // exp>0 here indicates that we've wrapped around.
180 if (exp > 0) {
181 endTest();
182 }
183
184 configNumber++;
185 runOneConfig(spec);
186 }
187
188 window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
189 window.internals.settings.setOverrideOptimizedForMobileCheck(true);
190 runNextConfig();
191
192 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/media/video-autoplay-experiment-expected.txt » ('j') | Source/core/html/HTMLMediaElement.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698