test_source.html (2369B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Media test: append source child</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 <script type="text/javascript" src="manifest.js"></script> 8 </head> 9 <body> 10 <video id="v1"></video> 11 <audio id="a1"></audio> 12 <pre id="test"> 13 <script class="testbody" type="text/javascript"> 14 var v1 = document.getElementById("v1"); 15 var a1 = document.getElementById("a1"); 16 v1.preload = "auto"; 17 a1.preload = "auto"; 18 19 is(v1.src, "", "src should be null"); 20 is(a1.src, "", "src should be null"); 21 is(v1.currentSrc, "", "currentSrc should be null"); 22 is(a1.currentSrc, "", "currentSrc should be null"); 23 is(v1.childNodes.length, 0, "should have no children"); 24 is(a1.childNodes.length, 0, "should have no children"); 25 26 function newSource(filter) { 27 var candidates = gSmallTests.filter(function(x){return filter.test(x.type);}); 28 if (candidates.length) { 29 var e = document.createElement("source"); 30 e.type = candidates[0].type; 31 e.src = candidates[0].name; 32 return e; 33 } 34 return null 35 36 } 37 38 var audioLoaded = false; 39 var videoLoaded = false; 40 41 function loaded(e) { 42 var media = e.target; 43 ok(media.networkState > 0, "networkState should be > 0"); 44 is(media.childNodes.length, 1, "should have 1 child"); 45 var sourceFile = media.currentSrc.substring(media.currentSrc.lastIndexOf('/')+1); 46 var resource = media.firstChild.src.substring(media.firstChild.src.lastIndexOf('/')+1); 47 is(sourceFile, resource, "loaded wrong resource!"); 48 if (media == a1) 49 audioLoaded = true; 50 else if (media == v1) 51 videoLoaded = true; 52 if (audioLoaded && videoLoaded) { 53 SimpleTest.finish(); 54 } 55 } 56 57 v1.addEventListener('loadeddata', loaded); 58 a1.addEventListener('loadeddata', loaded); 59 60 var videoSource = newSource(/^video/); 61 if (videoSource) { 62 v1.appendChild(videoSource); 63 v1.load(); 64 } else { 65 // No video backends? Don't test anything. 66 videoLoaded = true; 67 } 68 69 var audioSource = newSource(/^audio/); 70 if (audioSource) { 71 a1.appendChild(audioSource); 72 a1.load(); 73 } else { 74 audioLoaded = true; 75 } 76 77 if (!audioLoaded && !videoLoaded) { 78 SimpleTest.waitForExplicitFinish(); 79 } else { 80 if (audioLoaded) { 81 todo(false, "No audio types supported"); 82 } 83 if (videoLoaded) { 84 todo(false, "No video types supported"); 85 } 86 } 87 88 </script> 89 </pre> 90 </body> 91 </html>