Index: LayoutTests/media/video-autoplay-experiment-just-once.html |
diff --git a/LayoutTests/media/video-autoplay-experiment-just-once.html b/LayoutTests/media/video-autoplay-experiment-just-once.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4d9e72072de2ae023f04c83287d99aac73ffd8ac |
--- /dev/null |
+++ b/LayoutTests/media/video-autoplay-experiment-just-once.html |
@@ -0,0 +1,54 @@ |
+<script src=media-file.js></script> |
+<script src=video-test.js></script> |
+<script> |
+ |
+var mediaFile; |
philipj_slow
2015/09/04 09:24:26
It looks like none of these need to be global, if
liberato (no reviews please)
2015/09/08 21:58:01
Done.
philipj_slow
2015/09/10 09:58:59
It doesn't matter much, but mediaFile is still glo
liberato (no reviews please)
2015/09/10 14:52:27
Done.
|
+var parent; |
+ |
+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
A more direct way is to check if video.played.leng
liberato (no reviews please)
2015/09/08 21:58:01
This didn't seem to work -- it always returned fal
philipj_slow
2015/09/10 09:58:59
That's surprising, but figuring out why isn't in s
liberato (no reviews please)
2015/09/10 14:52:27
Acknowledged.
|
+} |
+ |
+function prepareVideo() |
+{ |
+ var video = document.createElement("video"); |
+ video.src=mediaFile; |
philipj_slow
2015/09/04 09:24:26
Missing whitespace
liberato (no reviews please)
2015/09/08 21:58:01
Done.
|
+ video.setAttribute("autoplay", "true"); |
philipj_slow
2015/09/04 09:24:26
video.autoplay = true works as it's a reflected at
liberato (no reviews please)
2015/09/08 21:58:01
Done.
|
+ parent.appendChild(video); |
+ |
+ return video; |
+} |
+ |
+function runTest() |
+{ |
+ mediaFile = findMediaFile("video", "content/test"); |
+ parent = document.createElement("div"); |
+ document.body.insertBefore(parent, document.body.firstChild); |
philipj_slow
2015/09/04 09:24:26
Since body has no other children (except a text no
liberato (no reviews please)
2015/09/08 21:58:01
Done.
|
+ |
+ // Require a user gesture, but override it for muted videos. |
+ window.internals.settings.setMediaPlaybackRequiresUserGesture(true); |
philipj_slow
2015/09/04 09:24:26
Use just internals or window.internals on both lin
liberato (no reviews please)
2015/09/08 21:58:01
no idea. done.
|
+ internals.settings.setAutoplayExperimentMode("enabled-forvideo-ifmuted"); |
+ |
+ var videoShouldPlay = prepareVideo(); |
+ var videoShouldNotPlay = prepareVideo(); |
+ |
+ // Pause() will clear the autoplaying flag, which should also prevent the |
+ // gesture override experiment from autoplaying. |
+ videoShouldNotPlay.pause(); |
+ |
+ // Mute them both, and see if only one starts. |
+ videoShouldPlay.muted = true; |
+ videoShouldNotPlay.muted = true; |
+ logResult(didPlaybackStart(videoShouldPlay), "First video should play"); |
+ logResult(!didPlaybackStart(videoShouldNotPlay), "Second video should not play"); |
+ testRunner.notifyDone(); |
+} |
+ |
+</script> |
+<p>Test that the autoplay experiment doesn't play media once the media |
+is no longer eligible for autoplay.</p> |
+<body onLoad="runTest()"> |
+</body> |