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

Unified Diff: LayoutTests/media/video-autoplay-experiment-modes.html

Issue 1179223002: Implement autoplay gesture override experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed !autoplaying behavior + test. Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/media/video-autoplay-experiment-modes.html
diff --git a/LayoutTests/media/video-autoplay-experiment-modes.html b/LayoutTests/media/video-autoplay-experiment-modes.html
new file mode 100644
index 0000000000000000000000000000000000000000..41042561431443708c69e06abc316dfc2b988e5a
--- /dev/null
+++ b/LayoutTests/media/video-autoplay-experiment-modes.html
@@ -0,0 +1,202 @@
+<video autoplay controls></video>
+<script src=media-file.js></script>
+<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"
+ M - "ifmuted"
+ p - "playmuted"
+ For example, EM means "enabled-ifmuted".
+ This test does not check -ifmobile since that check always
+ fails outside of android.
+ 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?
philipj_slow 2015/09/04 09:24:27 This really amounts to testing for bugs in our mut
liberato (no reviews please) 2015/09/08 21:58:01 gladly removed, this test is too big. done. (exce
philipj_slow 2015/09/10 09:58:59 Yay :)
+ none - media is not muted.
+ attr - muted attribute is set on the element.
+ js - muted property is set after media is ready to play.
+
+ == Test Outputs ==
+ 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>Played?</td>
+<td>Muted?</td>
+</tr>
+</table>
+</body>
+
+<script>
+
+// Starting configuration number. This should be zero normally.
+var configNumber = 0;
+
+var mediaFile = findMediaFile("video", "content/test");
+var onscreenParent = document.createElement("div");
+document.body.insertBefore(onscreenParent, document.body.firstChild);
+
+function didPlaybackStart(video)
+{
+ // We say that the video started if it's not paused or if it played and
+ // already ended.
+ return !video.paused || video.ended;
philipj_slow 2015/09/04 09:24:26 Same video.played.length test can be used here.
liberato (no reviews please) 2015/09/08 21:58:01 Always returned false, so i kept it this way.
+}
+
+function addResultsRow(spec)
+{
+ // Add a row to the results table.
+ var row = document.getElementById("results").insertRow(-1);
philipj_slow 2015/09/04 09:24:27 Since you're always appending rows and cells and t
liberato (no reviews please) 2015/09/08 21:58:01 neat. i thought that chrome prepended by default.
+ var td = row.insertCell(0);
+
+ // Add experiment number
+ row.insertCell(-1).innerText = (""+spec["experimentNumber"]);
philipj_slow 2015/09/04 09:24:26 You can always replace spec["foo"] with spec.foo.
liberato (no reviews please) 2015/09/08 21:58:01 Done.
+
+ // Process experiment type specially.
+ var type = spec["experimentType"];
+ var smallType = "";
+ smallType += (type.indexOf("-forvideo")>-1)?"v":"";
+ smallType += (type.indexOf("-foraudio")>-1)?"a":"";
+ smallType += (type.indexOf("-ifmuted")>-1)?"M":"";
+ smallType += (type.indexOf("-playmuted")>-1)?"p":"";
+ row.insertCell(-1).innerText = smallType;
+
+ // Add remaining fields.
+ var fields = [ "elementType", "autoplayType", "mutedType", "played",
+ "muted"];
+ for(idx in fields)
+ row.insertCell(-1).innerText = spec[fields[idx]].substring(0,7);
+}
+
+function configureVideoViaScript(element, spec)
+{
+ if (spec.mutedType == "js")
+ element.muted = true;
+ if(spec.autoplayType == "play()")
+ element.play();
+}
+
+function queueNextExperiment()
+{
+ // Start the next config, but let the event queue drain.
+ setTimeout(runNextConfig, 0);
+}
+
+function checkElementStatus(element)
+{
+ // Update the spec with the results.
+ var didStart = didPlaybackStart(element);
+ element.spec.played = didStart ? "played" : "no";
+ element.spec.muted = didStart ? (element.muted ? "muted" : "unmuted") : "-";
+
+ addResultsRow(element.spec);
+ element.parentElement.removeChild(element);
philipj_slow 2015/09/04 09:24:26 Can use element.remove()
liberato (no reviews please) 2015/09/08 21:58:01 Done.
+
+ queueNextExperiment();
+}
+
+function runOneConfig(spec)
+{
+ internals.settings.setAutoplayExperimentMode(spec.experimentType);
+
+ // Create, configure, and attach a media element.
+ var element = document.createElement(spec.elementType);
+
+ onscreenParent.appendChild(element);
+
+ // Set any attributes before canPlayThrough.
+ if (spec.mutedType == "attr")
+ element.setAttribute("muted", "true");
philipj_slow 2015/09/04 09:24:27 element.muted = true and element.autoplay = true b
liberato (no reviews please) 2015/09/08 21:58:01 Done.
+ if (spec.autoplayType == "attr")
+ element.setAttribute("autoplay", "true");
+
+ // Record the spec in the element, so that we can display the
+ // results later.
+ element.spec = spec;
+
+ // Wait for canplaythrough before continuing, so that the media
+ // might actually be playing.
+ element.addEventListener("canplaythrough", function()
+ {
+ // Now that we can play, if we're supposed to play / mute via js do so.
+ configureVideoViaScript(element, spec);
+
+ // Record the results.
+ checkElementStatus(element);
+ });
+
+ // Set the source, which will eventually lead to canPlayThrough.
+ element.src=mediaFile;
philipj_slow 2015/09/04 09:24:26 Missing whitespace
liberato (no reviews please) 2015/09/08 21:58:01 this was the original, just-once was the copy...
+}
+
+var experimentTypes = [
+ "none",
+ "enabled-forvideo",
philipj_slow 2015/09/04 09:24:26 Is it possible to test -ifmobile?
liberato (no reviews please) 2015/09/08 21:58:01 that's cool. it seems that it now is possible. w
+ "enabled-forvideo-ifmuted",
+ "enabled-forvideo-playmuted",
+ "enabled-foraudio",
+];
+var elementTypes = ["video", "audio"];
+var autoplayTypes = ["none", "attr", "play()"];
+var mutedTypes = ["none", "attr", "js"];
+
+function runNextConfig()
+{
+ // Convert configNumber into a spec, and run it.
+ var exp = configNumber;
+
+ // Convert this experiment number into settings.
+ var spec = {};
+ spec.elementType = elementTypes[exp % elementTypes.length];
+ exp = Math.floor(exp / elementTypes.length);
+ spec.experimentType = experimentTypes[exp % experimentTypes.length];
+ exp = Math.floor(exp / experimentTypes.length);
+ spec.autoplayType = autoplayTypes[exp % autoplayTypes.length];
+ exp = Math.floor(exp / autoplayTypes.length);
+ spec.mutedType = mutedTypes[exp % mutedTypes.length];
+ exp = Math.floor(exp / mutedTypes.length);
+ spec.experimentNumber = configNumber;
+
+ // exp>0 here indicates that we've wrapped around.
+ if (exp > 0) {
+ endTest();
+ }
+
+ configNumber++;
+
+ // To keep the test fast, skip a few combinations.
+ var skip = false;
+ if (spec.experimentType.indexOf("-ifmuted") == -1 && spec.mutedType != "none")
+ skip = true;
+
+ if (skip)
+ queueNextExperiment();
+ else
+ runOneConfig(spec);
+}
+
+window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
+runNextConfig();
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698