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

Unified Diff: third_party/WebKit/LayoutTests/media/video-preload.html

Issue 2104823002: Convert video-prefixed* and video-preload* tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 6 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: third_party/WebKit/LayoutTests/media/video-preload.html
diff --git a/third_party/WebKit/LayoutTests/media/video-preload.html b/third_party/WebKit/LayoutTests/media/video-preload.html
index c02767aa0a393508d90c49fff3259dbebe7ea557..11dbc8b097ef964a931f16342d95ea836a42e3bf 100644
--- a/third_party/WebKit/LayoutTests/media/video-preload.html
+++ b/third_party/WebKit/LayoutTests/media/video-preload.html
@@ -1,147 +1,66 @@
-<!DOCTYPE HTML>
-
-<html>
- <head>
- <script src=media-file.js></script>
- <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956
- (Please avoid writing new tests using video-test.js) -->
- <script src=video-test.js></script>
-
- <script>
- var timer = null;
- var movieInfo =
- {
- current : -1,
- movies :
- [
- {
- // should not buffer, 'preload' is 'none'
- preload : "none",
- shouldBuffer : false,
- autoPlay : false,
- playInsteadOfLoad : false,
- description : "until 'play()' is called",
- },
- {
- // should buffer, because load() is called.
- preload : "none",
- shouldBuffer : true,
- autoPlay : false,
- playInsteadOfLoad : false,
- description : "because 'load()' is called",
- },
- {
- // should buffer, because play() is called.
- preload : "none",
- shouldBuffer : true,
- autoPlay : false,
- playInsteadOfLoad : true,
- description : "because 'play()' is called",
- },
- {
- preload : "metadata",
- shouldBuffer : true,
- autoPlay : false,
- playInsteadOfLoad : false,
- description : "",
- },
- {
- preload : "auto",
- shouldBuffer : true,
- autoPlay : false,
- playInsteadOfLoad : false,
- description : "",
- },
- {
- // should buffer because 'autoplay' is set
- preload : "none",
- shouldBuffer : true,
- autoPlay : true,
- playInsteadOfLoad : false,
- description : " because of 'autoplay'",
- },
- ]
- };
- var timer = null;
-
- function checkLoad()
- {
- var movie = movieInfo.movies[movieInfo.current];
-
- logResult(true, "did not buffer automatically");
-
- // start playback, which should force data to load
+<!DOCTYPE html>
+<title>Test media loading behaviour with different "preload" values.</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="media-file.js"></script>
+<video></video>
+<script>
+async_test(function(t) {
+ var movies = [
+ // should not buffer, "preload" is "none" (don't use "playInsteadOfLoad").
+ { preload : "none", shouldBuffer : false, autoPlay : false, playInsteadOfLoad : false },
fs 2016/06/28 08:56:42 Suggest dropping the space before the ':' ("preloa
Srirama 2016/06/29 17:27:46 Done.
+ // should buffer, because load() is called.
+ { preload : "none", shouldBuffer : true, autoPlay : false, playInsteadOfLoad : false },
+ // should buffer, because play() is called.
+ { preload : "none", shouldBuffer : true, autoPlay : false, playInsteadOfLoad : true },
+ { preload : "metadata", shouldBuffer : true, autoPlay : false, playInsteadOfLoad : false },
+ { preload : "auto", shouldBuffer : true, autoPlay : false, playInsteadOfLoad : false },
+ // should buffer because "autoplay" is set.
+ { preload : "none", shouldBuffer : true, autoPlay : true, playInsteadOfLoad : false }
+ ];
+ var timer = null;
+ var movie = null;
fs 2016/06/28 08:56:42 Could make this local where it's used. Or maybe re
Srirama 2016/06/29 13:27:07 You mean write a function like "check_video_preloa
fs 2016/06/29 13:35:18 Yes, that would be one way to do it. Could also ju
Srirama 2016/06/29 17:27:46 Done.
+ var movieIndex = -1;
+ var video = document.querySelector("video");
+ video.onerror = t.step_func(function() {});
+ video.onloadstart = t.step_func(function() {});
+ video.onplay = t.step_func(function() {});
+
+ video.onloadedmetadata = t.step_func(function() {
+ movie = movies[movieIndex];
+ clearTimeout(timer);
+ assert_true(movie.shouldBuffer);
+ openNextMovie();
+ });
+
+ openNextMovie();
+
+ function openNextMovie() {
+ movieIndex++;
+ movie = movies[movieIndex];
+ if (!movie) {
+ t.done();
+ return;
+ }
+
+ video.setAttribute("preload", movie.preload);
+ video.setAttribute("autoplay", movie.autoPlay);
fs 2016/06/28 08:56:42 This is not equivalent, since 'autoplay' is a bool
Srirama 2016/06/29 17:27:46 Done.
+ video.src = findMediaFile("video", "content/test");;
fs 2016/06/28 08:56:42 Nit: ;;
Srirama 2016/06/29 17:27:46 Done.
+ if (movieIndex > 0) {
+ if (movie.playInsteadOfLoad)
+ video.play();
+ else
+ video.load();
+ }
+
+ if (!movie.shouldBuffer) {
+ timer = setTimeout(function() {
+ var movie = movies[movieIndex];
+ // start playback, which should force data to load.
movie.shouldBuffer = true;
- run("video.play()");
- }
-
- function loadedmetadata()
- {
- var movie = movieInfo.movies[movieInfo.current];
-
- clearTimeout(timer);
- logResult(movie.shouldBuffer, "buffered automatically");
- openNextMovie();
- }
-
- function setupAttribute(attr, value)
- {
- if (value)
- run("video.setAttribute('" + attr + "', '" + value + "')");
- else
- run("video.removeAttribute('" + attr + "')");
- }
-
- function openNextMovie()
- {
- consoleWrite("");
-
- movieInfo.current++;
- if (movieInfo.current >= movieInfo.movies.length)
- {
- endTest();
- return;
- }
-
- var movie = movieInfo.movies[movieInfo.current];
- var url = findMediaFile("video", "content/test");
- var desc = "Will load with <em>'preload=" + movie.preload + "'</em>"
- + ", <b>should" + (movie.shouldBuffer ? "" : " not") + " </b> buffer automatically "
- + movie.description;
- consoleWrite(desc);
-
- setupAttribute('preload', movie.preload);
- setupAttribute('autoplay', movie.autoPlay);
-
- video.src = url;
- if (movieInfo.current > 0) {
- if (movie.playInsteadOfLoad) {
- run("video.play()");
- } else {
- run("video.load()");
- }
- }
- if (!movie.shouldBuffer)
- timer = setTimeout(checkLoad, 200);
- }
-
- function start()
- {
- findMediaElement();
-
- waitForEvent("error");
- waitForEvent("loadstart");
- waitForEvent("play");
- waitForEvent('loadedmetadata', loadedmetadata);
-
- openNextMovie();
- }
-
- </script>
- </head>
-
- <body onload="start()">
- <p>Test to see if media loads automatically when 'preload' is specified.</p>
- <video controls ></video>
- </body>
-</html>
+ video.play();
+ }, 200);
+ }
+ }
+});
+</script>

Powered by Google App Engine
This is Rietveld 408576698