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

Side by Side Diff: third_party/WebKit/LayoutTests/media/autoplay-experiment-helper.js

Issue 2133383002: Remove video-test.js dependency from [audio, video]-autoplay-* tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
1 // Starting configuration number. This should be zero normally. 1 // Starting configuration number. This should be zero normally.
2 var configNumber = 0; 2 var configNumber = 0;
3 3
4 var mediaFile = findMediaFile("video", "content/test"); 4 var mediaFile = findMediaFile("video", "content/test");
5 var onscreenParent = document.createElement("div"); 5 var onscreenParent = document.createElement("div");
6 // The onscreen parent's height is also used to make sure that the off-screen 6 // The onscreen parent's height is also used to make sure that the off-screen
7 // parent is, in fact, off-screen. 7 // parent is, in fact, off-screen.
8 onscreenParent.style.height = "1000px"; 8 onscreenParent.style.height = "1000px";
9 document.body.insertBefore(onscreenParent, document.body.firstChild); 9 document.body.insertBefore(onscreenParent, document.body.firstChild);
10 // Is the page optimized for mobile? We can't un-optimize it. 10 // Is the page optimized for mobile? We can't un-optimize it.
11 var isOptimizedForMobile = false; 11 var isOptimizedForMobile = false;
12 // Also create another root that's off the bottom of the window. 12 // Also create another root that's off the bottom of the window.
13 var offscreenParent = document.createElement("div"); 13 var offscreenParent = document.createElement("div");
14 document.body.appendChild(offscreenParent); 14 document.body.appendChild(offscreenParent);
15 15
16 function didPlaybackStart(element) 16 function didPlaybackStart(element)
17 { 17 {
18 return !element.paused || element.ended; 18 return !element.paused || element.ended;
19 } 19 }
20 20
21 function becomeOptimizedForMobile(enable) 21 function becomeOptimizedForMobile(enable)
22 { 22 {
23 // If we're in the right state already, then return; 23 // If we're in the right state already, then return;
24 if (enable == isOptimizedForMobile) 24 if (enable == isOptimizedForMobile)
25 return; 25 return;
26 26
27 if (!enable) { 27 if (!enable) {
28 // We can't transition out of optimized for mobile. 28 // We can't transition out of optimized for mobile.
29 endTest(); 29 testRunner.notifyDone();
30 } else { 30 } else {
31 // This only works once. 31 // This only works once.
32 mobileMetaTag = document.createElement('meta'); 32 mobileMetaTag = document.createElement('meta');
33 mobileMetaTag.name = "viewport"; 33 mobileMetaTag.name = "viewport";
34 mobileMetaTag.content = "width=device-width"; 34 mobileMetaTag.content = "width=device-width";
35 document.head.appendChild(mobileMetaTag); 35 document.head.appendChild(mobileMetaTag);
36 isOptimizedForMobile = true; 36 isOptimizedForMobile = true;
37 } 37 }
38 } 38 }
39 39
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (spec.autoplayType == "attr") 123 if (spec.autoplayType == "attr")
124 element.autoplay = true; 124 element.autoplay = true;
125 125
126 becomeOptimizedForMobile(spec.mobileType == "yes"); 126 becomeOptimizedForMobile(spec.mobileType == "yes");
127 127
128 spec.playedEarly = "-"; 128 spec.playedEarly = "-";
129 129
130 // Record the spec in the element, so that we can display the 130 // Record the spec in the element, so that we can display the
131 // results later. 131 // results later.
132 element.spec = spec; 132 element.spec = spec;
133 window.internals.triggerAutoplayViewportCheck(element); 133 internals.triggerAutoplayViewportCheck(element);
134 134
135 // Wait for canplaythrough before continuing, so that the media 135 // Wait for canplaythrough before continuing, so that the media
136 // might actually be playing. 136 // might actually be playing.
137 element.addEventListener("canplaythrough", function() 137 element.addEventListener("canplaythrough", function()
138 { 138 {
139 // Now that we can play, if we're supposed to play / mute via js do so. 139 // Now that we can play, if we're supposed to play / mute via js do so.
140 configureElementViaScript(element, spec); 140 configureElementViaScript(element, spec);
141 141
142 // If we're supposed to scroll the item onscreen after it is ready to 142 // If we're supposed to scroll the item onscreen after it is ready to
143 // play, then do so now. 143 // play, then do so now.
144 if(spec.visType == "scroll") { 144 if(spec.visType == "scroll") {
145 // Record the play state here, too, before we scroll. 145 // Record the play state here, too, before we scroll.
146 spec.playedEarly = didPlaybackStart(element) ? "yes" : "no"; 146 spec.playedEarly = didPlaybackStart(element) ? "yes" : "no";
147 147
148 // We are supposed to scroll the player into view. 148 // We are supposed to scroll the player into view.
149 element.scrollIntoView(true); 149 element.scrollIntoView(true);
150 // TODO(liberato): remove once autoplay gesture override experiment concludes. 150 // TODO(liberato): remove once autoplay gesture override experiment concludes.
151 window.internals.triggerAutoplayViewportCheck(element); 151 internals.triggerAutoplayViewportCheck(element);
152 // Once these two methods return, changes to the element state due 152 // Once these two methods return, changes to the element state due
153 // to the autoplay experiment should be observable synchronously. 153 // to the autoplay experiment should be observable synchronously.
154 checkElementStatus(element, spec); 154 checkElementStatus(element, spec);
155 } else { 155 } else {
156 // Record the results immediately. 156 // Record the results immediately.
157 checkElementStatus(element, spec); 157 checkElementStatus(element, spec);
158 } 158 }
159 }); 159 });
160 160
161 // Set the source, which will eventually lead to canPlayThrough. 161 // Set the source, which will eventually lead to canPlayThrough.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Mobile must always change last, so that all the "no" cases precede 193 // Mobile must always change last, so that all the "no" cases precede
194 // all the "yes" cases, since we can't switch the doc back to "not 194 // all the "yes" cases, since we can't switch the doc back to "not
195 // optimized for mobile". 195 // optimized for mobile".
196 spec.mobileType = mobileTypes[exp % mobileTypes.length]; 196 spec.mobileType = mobileTypes[exp % mobileTypes.length];
197 exp = Math.floor(exp / mobileTypes.length); 197 exp = Math.floor(exp / mobileTypes.length);
198 198
199 spec.experimentNumber = configNumber; 199 spec.experimentNumber = configNumber;
200 200
201 // Return null if configNumber was larger than the highest experiment. 201 // Return null if configNumber was larger than the highest experiment.
202 if (exp > 0) 202 if (exp > 0)
203 endTest(); 203 testRunner.notifyDone();
204 204
205 configNumber++; 205 configNumber++;
206 206
207 // To keep the test fast, skip a few combinations. 207 // To keep the test fast, skip a few combinations.
208 var skip = false; 208 var skip = false;
209 if (!spec.experimentType.includes("-ifmuted") && spec.mutedType != "no") 209 if (!spec.experimentType.includes("-ifmuted") && spec.mutedType != "no")
210 skip = true; 210 skip = true;
211 211
212 // Only allow basic combinations for the mobile case. We just want to 212 // Only allow basic combinations for the mobile case. We just want to
213 // test video with autoplay, no mute options when testing -ifmobile. 213 // test video with autoplay, no mute options when testing -ifmobile.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 && ((spec.visType != "onscreen") || (spec.autoplayType != "play()"))) 256 && ((spec.visType != "onscreen") || (spec.autoplayType != "play()")))
257 skip = true; 257 skip = true;
258 258
259 if (skip) 259 if (skip)
260 queueNextExperiment(); 260 queueNextExperiment();
261 else 261 else
262 runOneConfig(spec); 262 runOneConfig(spec);
263 } 263 }
264 264
265 function start(mediaType, experiments) { 265 function start(mediaType, experiments) {
266 elementTypes = [ mediaType ]; 266 testRunner.waitUntilDone();
267 experimentTypes = experiments; 267 testRunner.dumpAsText();
268 elementTypes = [ mediaType ];
269 experimentTypes = experiments;
268 270
269 window.internals.settings.setMediaPlaybackRequiresUserGesture(true); 271 internals.settings.setMediaPlaybackRequiresUserGesture(true);
270 runNextConfig(); 272 runNextConfig();
271 } 273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698