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

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

Issue 1370723002: Include viewport visibility checks for autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased. Created 5 years, 1 month 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes.html
diff --git a/third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes.html b/third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes.html
index 04c704db8ca303cfb73658ac1f48d573b03baccf..f6230f0dc7481ab431704e7326b114b97f83edba 100644
--- a/third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes.html
+++ b/third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes.html
@@ -13,10 +13,12 @@
Flags - autoplay experiment setting being tested.
a - "foraudio"
v - "forvideo"
+ V - "ifviewport"
+ P - "ifpagevisible"
M - "ifmuted"
p - "playmuted"
m - "ifmobile"
- For example, EM means "enabled-ifmuted".
+ For example, vM means '-forvideo-ifmuted".
Type - audio or video element?
audio - <audio>
video - <video>
@@ -30,8 +32,16 @@
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 "-".
@@ -45,6 +55,8 @@
<td>Play w/</td>
<td>Mute</td>
<td>Mobile</td>
+<td>View</td>
+<td>Early?</td>
<td>Played?</td>
<td>Muted?</td>
</tr>
@@ -58,15 +70,19 @@ var configNumber = 0;
var mediaFile = findMediaFile("video", "content/test");
var onscreenParent = document.createElement("div");
+// The onscreen parent's height is also used to make sure that the off-screen
+// parent is, in fact, off-screen.
+onscreenParent.style.height = "1000px";
document.body.insertBefore(onscreenParent, document.body.firstChild);
-// When we remove the meta tag from the document, we put it here.
+// Is the page optimized for mobile? We can't un-optimize it.
var isOptimizedForMobile = false;
+// Also create another root that's off the bottom of the window.
+var offscreenParent = document.createElement("div");
+document.body.appendChild(offscreenParent);
-function didPlaybackStart(video)
+function didPlaybackStart(element)
{
- // We say that the video started if it's not paused or if it played and
- // already ended.
- return !video.paused || video.ended;
+ return !element.paused || element.ended;
}
function becomeOptimizedForMobile(enable)
@@ -101,16 +117,18 @@ function addResultsRow(spec)
// 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":"";
- smallType += (type.indexOf("-ifmobile")>-1)?"m":"";
+ smallType += type.includes("-forvideo")?"v":"";
+ smallType += type.includes("-foraudio")?"a":"";
+ smallType += type.includes("-ifviewport")?"V":"";
+ smallType += type.includes("-ifpagevisible")?"P":"";
+ smallType += type.includes("-ifmuted")?"M":"";
+ smallType += type.includes("-playmuted")?"p":"";
+ smallType += type.includes("-ifmobile")?"m":"";
row.insertCell().innerText = smallType;
// Add remaining fields.
var fields = [ "elementType", "autoplayType", "mutedType", "mobileType",
- "played", "muted"];
+ "visType", "playedEarly", "played", "muted"];
for(idx in fields)
row.insertCell().innerText = spec[fields[idx]].substring(0,7);
}
@@ -137,6 +155,13 @@ function checkElementStatus(element)
addResultsRow(element.spec);
element.remove();
+ // Scroll back to the top, in case this was a scrolling test.
+ onscreenParent.scrollIntoView();
+
+ // Also make sure that the page is visible again. Hidden pages cause the
+ // test to proceed very slowly.
+ testRunner.setPageVisibility("visible");
+
queueNextExperiment();
}
@@ -148,18 +173,30 @@ function runOneConfig(spec)
var element = document.createElement(spec.elementType);
element.controls = true;
- onscreenParent.appendChild(element);
+ // Hide or show the page.
+ if (spec.visType == "obscured")
+ testRunner.setPageVisibility("hidden");
+
+ // Pick whether the element will be visible when canPlayThrough.
+ if (spec.visType == "offscreen" || spec.visType == "scroll")
+ offscreenParent.appendChild(element);
+ else
+ onscreenParent.appendChild(element);
// Set any attributes before canPlayThrough.
if (spec.mutedType == "yes")
element.muted = true;
if (spec.autoplayType == "attr")
element.autoplay = true;
+
becomeOptimizedForMobile(spec.mobileType == "yes");
+ spec.playedEarly = "-";
+
// Record the spec in the element, so that we can display the
// results later.
element.spec = spec;
+ window.internals.triggerAutoplayViewportCheck(element);
// Wait for canplaythrough before continuing, so that the media
// might actually be playing.
@@ -168,8 +205,23 @@ function runOneConfig(spec)
// Now that we can play, if we're supposed to play / mute via js do so.
configureElementViaScript(element, spec);
- // Record the results.
- checkElementStatus(element);
+ // If we're supposed to scroll the item onscreen after it is ready to
+ // play, then do so now.
+ if(spec.visType == "scroll") {
+ // Record the play state here, too, before we scroll.
+ spec.playedEarly = didPlaybackStart(element) ? "yes" : "no";
+
+ // We are supposed to scroll the player into view.
+ element.scrollIntoView(true);
+ // TODO(liberato): remove once autoplay gesture override experiment concludes.
+ window.internals.triggerAutoplayViewportCheck(element);
+ // Once these two methods return, changes to the element state due
+ // to the autoplay experiment should be observable synchronously.
+ checkElementStatus(element, spec);
+ } else {
+ // Record the results immediately.
+ checkElementStatus(element, spec);
+ }
});
// Set the source, which will eventually lead to canPlayThrough.
@@ -179,14 +231,18 @@ function runOneConfig(spec)
var experimentTypes = [
"none",
"enabled-forvideo",
- "enabled-forvideo-ifmuted",
- "enabled-forvideo-playmuted",
+ "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 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"];
@@ -205,6 +261,8 @@ function runNextConfig()
exp = Math.floor(exp / autoplayTypes.length);
spec.mutedType = mutedTypes[exp % mutedTypes.length];
exp = Math.floor(exp / mutedTypes.length);
+ spec.visType = visTypes[exp % visTypes.length];
+ exp = Math.floor(exp / visTypes.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".
@@ -220,20 +278,53 @@ function runNextConfig()
// To keep the test fast, skip a few combinations.
var skip = false;
- if (spec.experimentType.indexOf("-ifmuted") == -1 && spec.mutedType != "no")
+ if (!spec.experimentType.includes("-ifmuted") && spec.mutedType != "no")
skip = true;
// Only allow basic combinations for the mobile case. We just want to
// test video with autoplay, no mute options when testing -ifmobile.
// Similarly, if we're setting the page to be optimied for mobile, then
// require that we're one of those tests.
- if ((spec.mobileType == "yes" || spec.experimentType.indexOf("-ifmobile")>0)
+ if ((spec.mobileType == "yes" || spec.experimentType.includes("-ifmobile"))
&& (spec.elementType != "video" || spec.autoplayType != "attr"
|| spec.mutedType != "no"
+ || spec.visType != "onscreen"
|| (spec.experimentType != "enabled-forvideo"
&& spec.experimentType != "enabled-forvideo-ifmobile")))
skip = true;
+ var mismatched =(spec.elementType == "video"
+ && spec.experimentType.includes("-foraudio"))
+ || (spec.elementType == "audio"
+ && spec.experimentType.includes("-forvideo"));
+
+ if (spec.autoplayType == "none" && spec.visType != 'onscreen')
+ skip = true;
+ else if (spec.experimentType.includes("-ifmuted")
+ && spec.visType != "onscreen")
+ skip = true;
+ else if (spec.visType == "offscreen"
+ && spec.autoplayType != "attr")
+ skip = true;
+ else if (!spec.experimentType.includes("-ifmuted")
+ && spec.mutedType == "yes")
+ skip = true;
+ else if (spec.elementType == "audio" && spec.mutedType == "yes")
+ skip = true;
+ else if (spec.elementType == "audio" && spec.visType != "scroll")
+ skip = true;
+ else if (mismatched && spec.visType !="onscreen")
+ skip = true;
+ else if (mismatched && spec.autoplayType != "attr")
+ skip = true;
+ else if (spec.visType == "obscured"
+ && !spec.experimentType.includes("-ifpagevisible"))
+ skip = true;
+ else if ((spec.visType == "offscreen" || spec.visType == "scroll"
+ || spec.autoplayType != "attr" || spec.elementType != "video")
+ && spec.experimentType.includes("-ifpagevisible"))
+ skip = true;
+
if (skip)
queueNextExperiment();
else
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/video-autoplay-experiment-modes-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698