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

Side by Side 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: address comments Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE HTML> 1 <!DOCTYPE html>
2 <title>Test media loading behaviour with different "preload" values.</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="media-file.js"></script>
6 <script>
7 var movies = [
8 // should not buffer, "preload" is "none".
9 { preload: "none", shouldBuffer: false, autoPlay: false },
10 // should buffer because "autoplay" is set.
11 { preload: "none", shouldBuffer: true, autoPlay: true },
12 // should buffer, because load() is called.
13 { preload: "none", shouldBuffer: true, autoPlay: false, load: "" },
14 // should buffer, because play() is called.
15 { preload: "none", shouldBuffer: true, autoPlay: false, play: "" },
16 // should buffer because "preload" is "metadata".
17 { preload: "metadata", shouldBuffer: true, autoPlay: false },
18 // should buffer because "preload" is "auto".
19 { preload: "auto", shouldBuffer: true, autoPlay: false }
20 ];
2 21
3 <html> 22 for (var movie of movies) {
4 <head> 23 async_test(function(t) {
5 <script src=media-file.js></script> 24 var video = document.createElement("video");
6 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 25 video.onerror = t.step_func(function() {});
7 (Please avoid writing new tests using video-test.js) --> 26 video.onloadstart = t.step_func(function() {});
8 <script src=video-test.js></script> 27 video.onplay = t.step_func(function() {});
9 28
10 <script> 29 video.onloadedmetadata = t.step_func_done(function() {
11 var timer = null; 30 assert_true(movie.shouldBuffer);
12 var movieInfo = 31 });
13 {
14 current : -1,
15 movies :
16 [
17 {
18 // should not buffer, 'preload' is 'none'
19 preload : "none",
20 shouldBuffer : false,
21 autoPlay : false,
22 playInsteadOfLoad : false,
23 description : "until 'play()' is called",
24 },
25 {
26 // should buffer, because load() is called.
27 preload : "none",
28 shouldBuffer : true,
29 autoPlay : false,
30 playInsteadOfLoad : false,
31 description : "because 'load()' is called",
32 },
33 {
34 // should buffer, because play() is called.
35 preload : "none",
36 shouldBuffer : true,
37 autoPlay : false,
38 playInsteadOfLoad : true,
39 description : "because 'play()' is called",
40 },
41 {
42 preload : "metadata",
43 shouldBuffer : true,
44 autoPlay : false,
45 playInsteadOfLoad : false,
46 description : "",
47 },
48 {
49 preload : "auto",
50 shouldBuffer : true,
51 autoPlay : false,
52 playInsteadOfLoad : false,
53 description : "",
54 },
55 {
56 // should buffer because 'autoplay' is set
57 preload : "none",
58 shouldBuffer : true,
59 autoPlay : true,
60 playInsteadOfLoad : false,
61 description : " because of 'autoplay'",
62 },
63 ]
64 };
65 var timer = null;
66 32
67 function checkLoad() 33 setupAttribute("preload", movie.preload);
68 { 34 setupAttribute("autoplay", movie.autoPlay);
69 var movie = movieInfo.movies[movieInfo.current]; 35 video.src = findMediaFile("video", "content/test");
70 36
71 logResult(true, "did not buffer automatically"); 37 if (movie.hasOwnProperty("play"))
38 video.play();
39 else if (movie.hasOwnProperty("load"))
40 video.load();
72 41
73 // start playback, which should force data to load 42 if (!movie.shouldBuffer) {
43 setTimeout(function() {
44 // start playback, which should force data to load.
74 movie.shouldBuffer = true; 45 movie.shouldBuffer = true;
75 run("video.play()"); 46 video.play();
76 } 47 }, 200);
48 }
77 49
78 function loadedmetadata() 50 function setupAttribute(attr, value) {
79 { 51 if (value)
80 var movie = movieInfo.movies[movieInfo.current]; 52 video.setAttribute(attr, value);
81 53 else
82 clearTimeout(timer); 54 video.removeAttribute(attr);
83 logResult(movie.shouldBuffer, "buffered automatically"); 55 }
84 openNextMovie(); 56 });
85 } 57 }
86 58 </script>
87 function setupAttribute(attr, value)
88 {
89 if (value)
90 run("video.setAttribute('" + attr + "', '" + value + "')");
91 else
92 run("video.removeAttribute('" + attr + "')");
93 }
94
95 function openNextMovie()
96 {
97 consoleWrite("");
98
99 movieInfo.current++;
100 if (movieInfo.current >= movieInfo.movies.length)
101 {
102 endTest();
103 return;
104 }
105
106 var movie = movieInfo.movies[movieInfo.current];
107 var url = findMediaFile("video", "content/test");
108 var desc = "Will load with <em>'preload=" + movie.preload + "'</ em>"
109 + ", <b>should" + (movie.shouldBuffer ? "" : " not") + " </b> buffer automatically "
110 + movie.description;
111 consoleWrite(desc);
112
113 setupAttribute('preload', movie.preload);
114 setupAttribute('autoplay', movie.autoPlay);
115
116 video.src = url;
117 if (movieInfo.current > 0) {
118 if (movie.playInsteadOfLoad) {
119 run("video.play()");
120 } else {
121 run("video.load()");
122 }
123 }
124 if (!movie.shouldBuffer)
125 timer = setTimeout(checkLoad, 200);
126 }
127
128 function start()
129 {
130 findMediaElement();
131
132 waitForEvent("error");
133 waitForEvent("loadstart");
134 waitForEvent("play");
135 waitForEvent('loadedmetadata', loadedmetadata);
136
137 openNextMovie();
138 }
139
140 </script>
141 </head>
142
143 <body onload="start()">
144 <p>Test to see if media loads automatically when 'preload' is specified. </p>
145 <video controls ></video>
146 </body>
147 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698