eric.carlson@apple.com | d968500 | 2011-09-06 18:49:56 +0000 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>load() and the <source> element</title> |
| 5 | <script src=video-test.js></script> |
| 6 | <script src=media-file.js></script> |
| 7 | <script> |
| 8 | var sources = []; |
| 9 | var count = 0; |
| 10 | |
| 11 | function canplaythrough() |
| 12 | { |
| 13 | testExpected("stripExtension(relativeURL(video.currentSrc))", relativeURL(stripExtension(sources[1]))); |
| 14 | ++count; |
| 15 | switch (count) |
| 16 | { |
| 17 | case 1: |
| 18 | consoleWrite("<br>+++ Calling load()."); |
| 19 | video.load(); |
| 20 | break; |
| 21 | case 2: |
| 22 | endTest(); |
| 23 | return; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | function addSource(type, name) |
| 28 | { |
| 29 | var source = document.createElement('source'); |
| 30 | source.src = findMediaFile(type, name); |
| 31 | sources.push(source.src); |
jer.noble@apple.com | 68b5ac7 | 2011-10-07 02:33:23 +0000 | [diff] [blame] | 32 | source.type = mimeTypeForExtension(source.src.split('.').pop()); |
eric.carlson@apple.com | d968500 | 2011-09-06 18:49:56 +0000 | [diff] [blame] | 33 | video.appendChild(source); |
| 34 | } |
| 35 | |
| 36 | function setup() |
| 37 | { |
| 38 | video = mediaElement = document.getElementsByTagName('video')[0]; |
| 39 | |
| 40 | consoleWrite("+++ Test initial networkState."); |
| 41 | testExpected("video.networkState", HTMLMediaElement.prototype.NETWORK_EMPTY, "=="); |
| 42 | |
| 43 | // Add an invalid url to the first source so we test getting an error event |
| 44 | // each time resource selection runs. |
| 45 | addSource("video", "content/bogus"); |
| 46 | addSource("video", "content/test"); |
| 47 | addSource("audio", "content/test"); |
| 48 | |
| 49 | consoleWrite("<br>+++ Add <source> elements to trigger loading, test networkState."); |
| 50 | testExpected("video.networkState", HTMLMediaElement.prototype.NETWORK_NO_SOURCE, "=="); |
| 51 | |
| 52 | waitForEvent("canplaythrough", canplaythrough); |
| 53 | waitForEvent("error"); |
| 54 | } |
| 55 | </script> |
| 56 | </head> |
| 57 | <body onload="setup()"> |
| 58 | <video controls width=300 ></video> |
| 59 | <p>Test that the resource selection algorithm is restarted when load() is called, and that all <source> elements are reconsidered.</p> |
| 60 | </body> |
| 61 | </html> |