OLD | NEW |
---|---|
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 <video></video> | |
7 <script> | |
8 async_test(function(t) { | |
9 var movies = [ | |
10 // should not buffer, "preload" is "none" (don't use "playInsteadOfLoad" ). | |
11 { preload : "none", shouldBuffer : false, autoPlay : false, playInsteadO fLoad : false }, | |
fs
2016/06/28 08:56:42
Suggest dropping the space before the ':' ("preloa
Srirama
2016/06/29 17:27:46
Done.
| |
12 // should buffer, because load() is called. | |
13 { preload : "none", shouldBuffer : true, autoPlay : false, playInsteadOf Load : false }, | |
14 // should buffer, because play() is called. | |
15 { preload : "none", shouldBuffer : true, autoPlay : false, playInsteadOf Load : true }, | |
16 { preload : "metadata", shouldBuffer : true, autoPlay : false, playInste adOfLoad : false }, | |
17 { preload : "auto", shouldBuffer : true, autoPlay : false, playInsteadOf Load : false }, | |
18 // should buffer because "autoplay" is set. | |
19 { preload : "none", shouldBuffer : true, autoPlay : true, playInsteadOfL oad : false } | |
20 ]; | |
21 var timer = null; | |
22 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.
| |
23 var movieIndex = -1; | |
24 var video = document.querySelector("video"); | |
25 video.onerror = t.step_func(function() {}); | |
26 video.onloadstart = t.step_func(function() {}); | |
27 video.onplay = t.step_func(function() {}); | |
2 | 28 |
3 <html> | 29 video.onloadedmetadata = t.step_func(function() { |
4 <head> | 30 movie = movies[movieIndex]; |
5 <script src=media-file.js></script> | 31 clearTimeout(timer); |
6 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 32 assert_true(movie.shouldBuffer); |
7 (Please avoid writing new tests using video-test.js) --> | 33 openNextMovie(); |
8 <script src=video-test.js></script> | 34 }); |
9 | 35 |
10 <script> | 36 openNextMovie(); |
11 var timer = null; | |
12 var movieInfo = | |
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 | 37 |
67 function checkLoad() | 38 function openNextMovie() { |
68 { | 39 movieIndex++; |
69 var movie = movieInfo.movies[movieInfo.current]; | 40 movie = movies[movieIndex]; |
41 if (!movie) { | |
42 t.done(); | |
43 return; | |
44 } | |
70 | 45 |
71 logResult(true, "did not buffer automatically"); | 46 video.setAttribute("preload", movie.preload); |
47 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.
| |
48 video.src = findMediaFile("video", "content/test");; | |
fs
2016/06/28 08:56:42
Nit: ;;
Srirama
2016/06/29 17:27:46
Done.
| |
49 if (movieIndex > 0) { | |
50 if (movie.playInsteadOfLoad) | |
51 video.play(); | |
52 else | |
53 video.load(); | |
54 } | |
72 | 55 |
73 // start playback, which should force data to load | 56 if (!movie.shouldBuffer) { |
57 timer = setTimeout(function() { | |
58 var movie = movies[movieIndex]; | |
59 // start playback, which should force data to load. | |
74 movie.shouldBuffer = true; | 60 movie.shouldBuffer = true; |
75 run("video.play()"); | 61 video.play(); |
76 } | 62 }, 200); |
77 | 63 } |
78 function loadedmetadata() | 64 } |
79 { | 65 }); |
80 var movie = movieInfo.movies[movieInfo.current]; | 66 </script> |
81 | |
82 clearTimeout(timer); | |
83 logResult(movie.shouldBuffer, "buffered automatically"); | |
84 openNextMovie(); | |
85 } | |
86 | |
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> | |
OLD | NEW |