4 https://bugzilla.mozilla.org/show_bug.cgi?id=548523
7 <title>Test for Bug
548523</title>
8 <script type=
"application/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
10 <script type=
"text/javascript" src=
"manifest.js"></script>
11 <script type=
"text/javascript" src=
"use_large_cache.js"></script>
14 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=548523">Mozilla Bug
548523</a>
16 <div id=
"content" style=
"display: none">
19 <!-- <button onClick="SimpleTest.finish();">Finish</button> -->
20 <div>Tests complete:
<span id=
"log" style=
"font-size: small;"></span></div>
22 <script type=
"application/javascript">
24 /** Test for Bug
548523 **/
26 var manager = new MediaTestManager;
28 manager.onFinished = function() {
29 is(gotLoadEvent, true,
"Should not have delayed the load event indefinitely");
32 var test = getPlayableVideo(gSeekTests);
33 var baseName = test.name;
35 var bogusSrc =
"bogus.duh";
36 var bogusType =
"video/bogus";
37 var gotLoadEvent = false;
40 addLoadEvent(function() {gotLoadEvent=true;});
43 var l = document.getElementById(
"log");
47 function maybeFinish(v, n) {
54 v.parentNode.removeChild(v);
56 manager.finished(v.token);
59 function filename(uri) {
60 return uri.substr(uri.lastIndexOf(
"/")+
1);
63 // Every test must have a setup(v) function, and must call maybeFinish() when test is complete.
66 //
1. Add preload:none video with src to document. Load should halt at NETWORK_IDLE and HAVE_NOTHING,
67 // after receiving a suspend event. Should not receive loaded events until after we call load().
68 // Note the suspend event is explictly sent by our
"stop the load" code, but other tests can't rely
69 // on it for the preload:metadata case, as there can be multiple suspend events when loading metadata.
73 is(v._gotLoadStart, true,
"(1) Must get loadstart.");
74 is(v._gotLoadedMetaData, false,
"(1) Must not get loadedmetadata.");
75 is(v.readyState, v.HAVE_NOTHING,
"(1) ReadyState must be HAVE_NOTHING");
76 is(v.networkState, v.NETWORK_IDLE,
"(1) NetworkState must be NETWORK_IDLE");
82 v._gotLoadStart = false;
83 v._gotLoadedMetaData = false;
85 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
86 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
87 v.addEventListener(
"suspend", this.suspend, false);
89 document.body.appendChild(v); // Causes implicit load, which will be halted due to preload:none.
93 //
2. Add preload:metadata video with src to document. Should halt with NETWORK_IDLE, HAVE_CURRENT_DATA
94 // after suspend event and after loadedmetadata.
98 is(v._gotLoadStart, true,
"(2) Must get loadstart.");
99 is(v._gotLoadedMetaData, true,
"(2) Must get loadedmetadata.");
100 ok(v.readyState
>= v.HAVE_CURRENT_DATA,
"(2) ReadyState must be >= HAVE_CURRENT_DATA");
101 is(v.networkState, v.NETWORK_IDLE,
"(2) NetworkState must be NETWORK_IDLE");
107 v._gotLoadStart = false;
108 v._gotLoadedMetaData = false;
109 v.preload =
"metadata";
110 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
111 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
112 v.addEventListener(
"loadeddata", this.loadeddata, false);
114 document.body.appendChild(v); // Causes implicit load, which will be halted after
115 // metadata due to preload:metadata.
119 //
3. Add preload:auto to document. Should receive canplaythrough eventually.
123 is(v._gotLoadStart, true,
"(3) Must get loadstart.");
124 is(v._gotLoadedMetaData, true,
"(3) Must get loadedmetadata.");
130 v._gotLoadStart = false;
131 v._gotLoadedMetaData = false;
133 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
134 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
135 v.addEventListener(
"canplaythrough", this.canplaythrough, false);
136 v.src = test.name; // Causes implicit load.
137 document.body.appendChild(v);
141 //
4. Add preload:none video to document. Call play(), should load then play through.
146 return; // We can receive multiple suspend events, like the one after download completes.
148 v._gotSuspend = true;
149 is(v._gotLoadStart, true,
"(4) Must get loadstart.");
150 is(v._gotLoadedMetaData, false,
"(4) Must not get loadedmetadata.");
151 is(v.readyState, v.HAVE_NOTHING,
"(4) ReadyState must be HAVE_NOTHING");
152 is(v.networkState, v.NETWORK_IDLE,
"(4) NetworkState must be NETWORK_IDLE");
153 v.play(); // Should load and play through.
158 ok(true,
"(4) Got playback ended");
159 maybeFinish(e.target,
4);
164 v._gotLoadStart = false;
165 v._gotLoadedMetaData = false;
166 v._gotSuspend = false;
168 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
169 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
170 v.addEventListener(
"suspend", this.suspend, false);
171 v.addEventListener(
"ended", this.ended, false);
173 document.body.appendChild(v);
177 //
5. preload:none video without resource, add to document, will implicitly start a
178 // preload:none load. Add a src, it shouldn't load.
182 is(v._gotLoadStart, true,
"(5) Must get loadstart.");
183 is(v._gotLoadedMetaData, false,
"(5) Must not get loadedmetadata.");
184 is(v.readyState, v.HAVE_NOTHING,
"(5) ReadyState must be HAVE_NOTHING");
185 is(v.networkState, v.NETWORK_IDLE,
"(5) NetworkState must be NETWORK_IDLE");
191 v._gotLoadStart = false;
192 v._gotLoadedMetaData = false;
194 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
195 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
196 v.addEventListener(
"suspend", this.suspend, false);
197 document.body.appendChild(v); // Causes implicit load, which will be halted due to no resource.
198 v.src = test.name; // Load should start, and halt at preload:none.
202 //
6. preload:none video without resource, add to document, will implicitly start a
203 // preload:none load. Add a source, it shouldn't load.
207 is(v._gotLoadStart, true,
"(6) Must get loadstart.");
208 is(v._gotLoadedMetaData, false,
"(6) Must not get loadedmetadata.");
209 is(v.readyState, v.HAVE_NOTHING,
"(6) ReadyState must be HAVE_NOTHING");
210 is(v.networkState, v.NETWORK_IDLE,
"(6) NetworkState must be NETWORK_IDLE");
216 v._gotLoadStart = false;
217 v._gotLoadedMetaData = false;
219 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
220 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
221 v.addEventListener(
"suspend", this.suspend, false);
222 document.body.appendChild(v); // Causes implicit load, which will be halted due to no resource.
223 var s = document.createElement(
"source");
226 v.appendChild(s); // Load should start, and halt at preload:none.
230 //
7. create a preload:none document with multiple sources, the first of which is invalid.
231 // Add to document, then play. It should load and play through the second source.
236 return; // We can receive multiple suspend events, like the one after download completes.
237 v._gotSuspend = true;
238 is(v._gotLoadStart, true,
"(7) Must get loadstart.");
239 is(v._gotLoadedMetaData, false,
"(7) Must not get loadedmetadata.");
240 is(v.readyState, v.HAVE_NOTHING,
"(7) ReadyState must be HAVE_NOTHING");
241 is(v.networkState, v.NETWORK_IDLE,
"(7) NetworkState must be NETWORK_IDLE");
242 v.play(); // Should load and play through.
247 ok(true,
"(7) Got playback ended");
249 is(v._gotErrorEvent, true,
"(7) Should get error event from first source load failure");
255 v._gotLoadStart = false;
256 v._gotLoadedMetaData = false;
258 v._gotErrorEvent = false;
259 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
260 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
261 v.addEventListener(
"suspend", this.suspend, false);
262 v.addEventListener(
"ended", this.ended, false);
263 var s1 = document.createElement(
"source");
264 s1.src =
"not-a-real-file.404"
266 s1.addEventListener(
"error", function(e){v._gotErrorEvent = true;}, false);
268 var s2 = document.createElement(
"source");
272 document.body.appendChild(v); // Causes implicit load, which will be halt at preload:none on the second resource.
276 //
8. Change preload value from none to metadata should cause metadata to be loaded.
280 is(v._gotLoadedMetaData, true,
"(8) Must get loadedmetadata.");
281 ok(v.readyState
>= v.HAVE_CURRENT_DATA,
"(8) ReadyState must be >= HAVE_CURRENT_DATA on suspend.");
282 is(v.networkState, v.NETWORK_IDLE,
"(8) NetworkState must be NETWORK_IDLE when load is halted");
288 v._gotLoadedMetaData = false;
290 v.addEventListener(
"loadstart", function(e){v.preload =
"metadata";}, false);
291 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
292 v.addEventListener(
"loadeddata", this.loadeddata, false);
293 v.src = test.name; // Causes implicit load.
294 document.body.appendChild(v);
298 //
9. Change preload value from metadata to auto should cause entire media to be loaded.
299 // For some reason we don't always receive the canplaythrough event, particuarly on this test.
300 // We've disabled this test until bug
568402 is fixed.
304 is(v._gotLoadStart, true,
"(9) Must get loadstart.");
305 is(v._gotLoadedMetaData, true,
"(9) Must get loadedmetadata.");
311 v._gotLoadStart = false;
312 v._gotLoadedMetaData = false;
313 v.preload =
"metadata";
314 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
315 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
316 v.addEventListener(
"loadeddata", function(){v.preload =
"auto"}, false);
317 v.addEventListener(
"canplaythrough", this.canplaythrough, false);
318 v.src = test.name; // Causes implicit load.
319 document.body.appendChild(v);
323 //
10. Change preload value from none to auto should cause entire media to be loaded.
327 is(v._gotLoadedMetaData, true,
"(10) Must get loadedmetadata.");
333 v._gotLoadedMetaData = false;
335 v.addEventListener(
"loadstart", function(e){v.preload =
"auto";}, false);
336 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
337 v.addEventListener(
"canplaythrough", this.canplaythrough, false);
338 v.src = test.name; // Causes implicit load.
339 document.body.appendChild(v);
343 //
11. Change preload value from none to metadata should cause metadata to load.
347 is(v._gotLoadedMetaData, true,
"(11) Must get loadedmetadata.");
348 ok(v.readyState
>= v.HAVE_CURRENT_DATA,
"(11) ReadyState must be >= HAVE_CURRENT_DATA.");
349 is(v.networkState, v.NETWORK_IDLE,
"(11) NetworkState must be NETWORK_IDLE.");
355 v._gotLoadedMetaData = false;
357 v.addEventListener(
"loadstart", function(e){v.preload =
"metadata";}, false);
358 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
359 v.addEventListener(
"loadeddata", this.loadeddata, false);
360 v.src = test.name; // Causes implicit load.
361 document.body.appendChild(v);
365 //
12. Change preload value from auto to metadata after load started,
366 // should still do full load, should not halt after metadata only.
370 is(v._gotLoadedMetaData, true,
"(12) Must get loadedmetadata.");
371 is(v._gotLoadStart, true,
"(12) Must get loadstart.");
377 v._gotLoadStart = false;
378 v._gotLoadedMetaData = false;
380 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
381 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
382 v.addEventListener(
"canplaythrough", this.canplaythrough, false);
383 v.src = test.name; // Causes implicit load.
384 document.body.appendChild(v);
385 v.preload =
"metadata";
389 //
13. Change preload value from auto to none after specifying a src
390 // should load according to preload none, no buffering should have taken place
394 is(v._gotLoadStart, true,
"(13) Must get loadstart.");
395 is(v._gotLoadedMetaData, false,
"(13) Must not get loadedmetadata.");
396 is(v.readyState, v.HAVE_NOTHING,
"(13) ReadyState must be HAVE_NOTHING");
397 is(v.networkState, v.NETWORK_IDLE,
"(13) NetworkState must be NETWORK_IDLE");
403 v._gotLoadStart = false;
404 v._gotLoadedMetaData = false;
408 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
409 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
410 v.addEventListener(
"suspend", this.suspend, false);
411 document.body.appendChild(v); // Causes implicit load, should load according to preload none
412 var s = document.createElement(
"source");
416 //
14. Add preload:metadata video with src to document. Play(), should play through.
420 is(v._gotLoadStart, true,
"(14) Must get loadstart.");
421 is(v._gotLoadedMetaData, true,
"(14) Must get loadedmetadata.");
422 ok(v.readyState
>= v.HAVE_CURRENT_DATA,
"(14) ReadyState must be >= HAVE_CURRENT_DATA");
423 is(v.networkState, v.NETWORK_IDLE,
"(14) NetworkState must be NETWORK_IDLE");
429 ok(true,
"(14) Got playback ended");
436 v._gotLoadStart = false;
437 v._gotLoadedMetaData = false;
438 v.preload =
"metadata";
439 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
440 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
441 v.addEventListener(
"ended", this.ended, false);
442 v.addEventListener(
"loadeddata", this.loadeddata, false);
444 document.body.appendChild(v); // Causes implicit load, which will be halted after
445 // metadata due to preload:metadata.
449 //
15. Autoplay should override preload:none.
452 ok(true,
"(15) Got playback ended.");
459 v._gotLoadStart = false;
460 v._gotLoadedMetaData = false;
463 v.addEventListener(
"loadstart", function(e){v._gotLoadStart = true;}, false);
464 v.addEventListener(
"loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
465 v.addEventListener(
"ended", this.ended, false);
466 v.src = test.name; // Causes implicit load.
467 document.body.appendChild(v);
471 //
16. Autoplay should override preload:metadata.
474 ok(true,
"(16) Got playback ended.");
481 v.preload =
"metadata";
483 v.addEventListener(
"ended", this.ended, false);
484 v.src = test.name; // Causes implicit load.
485 document.body.appendChild(v);
489 //
17. On a preload:none video, adding autoplay should disable preload none, i.e. don't break autoplay!
492 ok(true,
"(17) Got playback ended.");
499 v.addEventListener(
"ended", this.ended, false);
501 document.body.appendChild(v); // Causes implicit load, which will be halted due to preload:none.
507 //
18. On a preload='none' video, call play() before load algorithms's sync
508 // has run, the play() call should override preload='none'.
511 ok(true,
"(18) Got playback ended.");
518 v.addEventListener(
"ended", this.ended, false);
520 v.src = test.name; // Schedules async section to continue load algorithm.
521 document.body.appendChild(v);
522 v.play(); // Should cause preload:none to be overridden.
526 //
19. Set preload='auto' on first video source then switching preload='none' and swapping the video source to another.
527 // The second video should not start playing as it's preload state has been changed to 'none' from 'auto'
528 loadedmetadata: function(e) {
530 is(v.preload ===
"auto", true,
"(19) preload is initially auto");
531 setTimeout(function() {
532 // set preload state to none and switch video sources
534 v.src = test.name +
"?asdf";
535 setTimeout(function() {
536 is(v.readyState ===
0, true,
"(19) no buffering has taken place");
548 // add a listener for when the video has loaded, so we know preload auto has worked
549 v.addEventListener(
"loadedmetadata", this.loadedmetadata, false);
550 document.body.appendChild(v);
555 var iterationCount =
0;
556 function startTest(test, token) {
557 if (test == tests[
0]) {
560 if (iterationCount ==
2) {
561 // Do this series of tests on logically different resources
562 test.name = baseName +
"?" + Math.floor(Math.random()*
100000);
564 var v = document.createElement(
"video");
567 manager.started(token);
570 var twiceTests = tests.concat(tests);
571 manager.runTests(twiceTests, startTest);