OLD | NEW |
1 <!doctype html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Test that the resource selection algorithm is restarted when load() is ca
lled, and that all "source" elements are reconsidered.</title> |
3 <head> | 3 <script src="../resources/testharness.js"></script> |
4 <title>load() and the <source> element</title> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 5 <script src="media-file.js"></script> |
6 (Please avoid writing new tests using video-test.js) --> | 6 <video></video> |
7 <script src=video-test.js></script> | 7 <script> |
8 <script src=media-file.js></script> | 8 async_test(function(t) { |
9 <script> | 9 var sourceUrls = []; |
10 var sources = []; | 10 var errorCount = 0; |
11 var count = 0; | 11 var video = document.querySelector("video"); |
12 | 12 |
13 function canplaythrough() | 13 // Test initial networkState. |
14 { | 14 assert_equals(video.networkState, HTMLMediaElement.NETWORK_EMPTY); |
15 testExpected("stripExtension(relativeURL(video.currentSrc))", re
lativeURL(stripExtension(sources[1]))); | |
16 ++count; | |
17 switch (count) | |
18 { | |
19 case 1: | |
20 consoleWrite("<br>+++ Calling load()."); | |
21 video.load(); | |
22 break; | |
23 case 2: | |
24 endTest(); | |
25 return; | |
26 } | |
27 } | |
28 | 15 |
29 function addSource(type, name) | 16 video.oncanplaythrough = t.step_func(function() { |
30 { | 17 var url = video.currentSrc; |
31 var source = document.createElement('source'); | 18 assert_equals(url.substr(url.lastIndexOf("/media/") + 7), |
32 source.src = findMediaFile(type, name); | 19 sourceUrls[1].substr(sourceUrls[1].lastIndexOf("/media/") + 7)); |
33 sources.push(source.src); | 20 switch (errorCount) { |
34 source.type = mimeTypeForExtension(source.src.split('.').pop()); | 21 case 1: |
35 video.appendChild(source); | 22 // Calling load() to invoke resource selection again. |
36 } | 23 video.load(); |
| 24 break; |
| 25 case 2: |
| 26 t.done(); |
| 27 } |
| 28 }); |
37 | 29 |
38 function setup() | 30 video.addEventListener("error", function() { |
39 { | 31 errorCount++; |
40 video = mediaElement = document.getElementsByTagName('video')[0]
; | 32 }, true); |
41 | 33 |
42 consoleWrite("+++ Test initial networkState."); | 34 // Add an invalid url to the first source so we test getting |
43 testExpected("video.networkState", HTMLMediaElement.prototype.NE
TWORK_EMPTY, "=="); | 35 // an error event each time resource selection runs. |
| 36 addSource("video", "content/bogus"); |
| 37 addSource("video", "content/test"); |
| 38 addSource("audio", "content/test"); |
44 | 39 |
45 // Add an invalid url to the first source so we test getting an
error event | 40 // test networkState. |
46 // each time resource selection runs. | 41 assert_equals(video.networkState, HTMLMediaElement.NETWORK_NO_SOURCE); |
47 addSource("video", "content/bogus"); | |
48 addSource("video", "content/test"); | |
49 addSource("audio", "content/test"); | |
50 | 42 |
51 consoleWrite("<br>+++ Add <source> elements to trigger loa
ding, test networkState."); | 43 function addSource(type, name) { |
52 testExpected("video.networkState", HTMLMediaElement.prototype.NE
TWORK_NO_SOURCE, "=="); | 44 var source = document.createElement("source"); |
53 | 45 source.src = findMediaFile(type, name); |
54 waitForEvent("canplaythrough", canplaythrough); | 46 sourceUrls.push(source.src); |
55 waitForEvent("error"); | 47 source.type = mimeTypeForExtension(source.src.split(".").pop()); |
56 } | 48 video.appendChild(source); |
57 </script> | 49 } |
58 </head> | 50 }); |
59 <body onload="setup()"> | 51 </script> |
60 <video controls width=300 ></video> | |
61 <p>Test that the resource selection algorithm is restarted when load() i
s called, and that all <source> elements are reconsidered.</p> | |
62 </body> | |
63 </html> | |
OLD | NEW |