| Index: third_party/WebKit/LayoutTests/media/autoplay-experiment-helper.js
|
| diff --git a/third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes.html b/third_party/WebKit/LayoutTests/media/autoplay-experiment-helper.js
|
| similarity index 75%
|
| copy from third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes.html
|
| copy to third_party/WebKit/LayoutTests/media/autoplay-experiment-helper.js
|
| index edf742f1954cd537edad87c611e0507fac722bf0..183e2f11ad54822906f51136d95e567c4b4322c3 100644
|
| --- a/third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes.html
|
| +++ b/third_party/WebKit/LayoutTests/media/autoplay-experiment-helper.js
|
| @@ -1,72 +1,3 @@
|
| -<html>
|
| -<video autoplay controls></video>
|
| -<script src=media-file.js></script>
|
| -<!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956
|
| - (Please avoid writing new tests using video-test.js) -->
|
| -<script src=video-test.js></script>
|
| -<body>
|
| -<pre>
|
| - Check if the autoplay gesture override experiment works. There are a lot
|
| - of config options, so this test just runs all of them.
|
| -
|
| - The "results" table contains one row per config tested.
|
| - == Test Inputs ==
|
| - # - config number, in case you'd like to run just one.
|
| - Flags - autoplay experiment setting being tested.
|
| - a - "foraudio"
|
| - v - "forvideo"
|
| - V - "ifviewport"
|
| - P - "ifpagevisible"
|
| - M - "ifmuted"
|
| - p - "playmuted"
|
| - m - "ifmobile"
|
| - For example, vM means '-forvideo-ifmuted".
|
| - Type - audio or video element?
|
| - audio - <audio>
|
| - video - <video>
|
| - Play w/- how is play requested?
|
| - none - play is not requested.
|
| - attr - autoplay attribute is set on the element.
|
| - play() - play() called after media is ready to play.
|
| - Mute - how is media muted?
|
| - no - media is not muted.
|
| - yes - muted attribute is set on the element.
|
| - Mobile - is page optimized for mobile?
|
| - no - page is not optimized for mobile.
|
| - yes - page is optimized for mobile.
|
| - View - is media in viewport?
|
| - onscreen - element starts out onscreen.
|
| - scroll - element starts offscreen, scrolled into view once
|
| - it is ready to play.
|
| - offscreen - element starts out offscreen and stays offscreen.
|
| - obscured - onscreen but page is not visible.
|
| -
|
| - == Test Outputs ==
|
| - Early? - did playback start before element was scrolled onscreen? For
|
| - tests in which View!=scroll, this is reported as "-".
|
| - Played? - did playback start by the conclusion of the test?
|
| - Muted? - was the media muted? If the media didn't play, then this is
|
| - reported as "-".
|
| -
|
| -</pre>
|
| -<table id="results">
|
| -<tr>
|
| -<td>#</td>
|
| -<td>Flags</td>
|
| -<td>Type</td>
|
| -<td>Play w/</td>
|
| -<td>Mute</td>
|
| -<td>Mobile</td>
|
| -<td>View</td>
|
| -<td>Early?</td>
|
| -<td>Played?</td>
|
| -<td>Muted?</td>
|
| -</tr>
|
| -</table>
|
| -</body>
|
| -
|
| -<script>
|
| -
|
| // Starting configuration number. This should be zero normally.
|
| var configNumber = 0;
|
|
|
| @@ -95,7 +26,6 @@ function becomeOptimizedForMobile(enable)
|
|
|
| if (!enable) {
|
| // We can't transition out of optimized for mobile.
|
| - console.log("becomeOptimizedForMobile: test is broken -- cannot un-enable mobile");
|
| endTest();
|
| } else {
|
| // This only works once.
|
| @@ -130,7 +60,7 @@ function addResultsRow(spec)
|
|
|
| // Add remaining fields.
|
| var fields = [ "elementType", "autoplayType", "mutedType", "mobileType",
|
| - "visType", "playedEarly", "played", "muted"];
|
| + "visType", "settingValue", "playedEarly", "played", "muted"];
|
| for(idx in fields)
|
| row.insertCell().innerText = spec[fields[idx]].substring(0,7);
|
| }
|
| @@ -171,6 +101,7 @@ function runOneConfig(spec)
|
| {
|
| internals.settings.setAutoplayExperimentMode(spec.experimentType);
|
| internals.settings.setViewportMetaEnabled(true);
|
| + testRunner.setAutoplayAllowed(spec.settingValue == "enabled");
|
|
|
| // Create, configure, and attach a media element.
|
| var element = document.createElement(spec.elementType);
|
| @@ -231,23 +162,14 @@ function runOneConfig(spec)
|
| element.src = mediaFile;
|
| }
|
|
|
| -var experimentTypes = [
|
| - "none",
|
| - "enabled-forvideo",
|
| - "enabled-forvideo-ifpagevisible",
|
| - "enabled-forvideo-ifviewport",
|
| - "enabled-forvideo-ifviewport-ifmuted",
|
| - "enabled-forvideo-ifviewport-playmuted",
|
| - "enabled-foraudio",
|
| - "enabled-forvideo-ifmobile",
|
| - "enabled-foraudio-ifviewport",
|
| -];
|
| -var elementTypes = ["video", "audio"];
|
| +var experimentTypes = []; // set in start().
|
| +var elementTypes = []; // set in start().
|
| var autoplayTypes = ["none", "attr", "play()"];
|
| var mutedTypes = ["no", "yes"];
|
| var visTypes = ["onscreen", "scroll", "offscreen", "obscured"];
|
| // mobileTypes must always start with no, since we cannot un-optimize the page.
|
| var mobileTypes = ["no", "yes"];
|
| +var autoplaySettings = ["enabled", "disabled"];
|
|
|
| function runNextConfig()
|
| {
|
| @@ -266,11 +188,14 @@ function runNextConfig()
|
| exp = Math.floor(exp / mutedTypes.length);
|
| spec.visType = visTypes[exp % visTypes.length];
|
| exp = Math.floor(exp / visTypes.length);
|
| + spec.settingValue = autoplaySettings[exp % autoplaySettings.length];
|
| + exp = Math.floor(exp / autoplaySettings.length);
|
| // Mobile must always change last, so that all the "no" cases precede
|
| // all the "yes" cases, since we can't switch the doc back to "not
|
| // optimized for mobile".
|
| spec.mobileType = mobileTypes[exp % mobileTypes.length];
|
| exp = Math.floor(exp / mobileTypes.length);
|
| +
|
| spec.experimentNumber = configNumber;
|
|
|
| // Return null if configNumber was larger than the highest experiment.
|
| @@ -327,6 +252,9 @@ function runNextConfig()
|
| || spec.autoplayType != "attr" || spec.elementType != "video")
|
| && spec.experimentType.includes("-ifpagevisible"))
|
| skip = true;
|
| + else if (spec.settingValue == "disabled"
|
| + && ((spec.visType != "onscreen") || (spec.autoplayType != "play()")))
|
| + skip = true;
|
|
|
| if (skip)
|
| queueNextExperiment();
|
| @@ -334,8 +262,10 @@ function runNextConfig()
|
| runOneConfig(spec);
|
| }
|
|
|
| -window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
|
| -runNextConfig();
|
| +function start(mediaType, experiments) {
|
| + elementTypes = [ mediaType ];
|
| + experimentTypes = experiments;
|
|
|
| -</script>
|
| -</html>
|
| + window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
|
| + runNextConfig();
|
| +}
|
|
|