resource-selection-currentSrc.html (2920B)
1 <!doctype html> 2 <title>currentSrc should not be reset when changing source</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <div id=log></div> 6 <audio src="/media/sine440.mp3"></audio> 7 <script> 8 let v; 9 let t = async_test("Test currentSrc behaviour in various playback scenarios"); 10 v = document.querySelector('audio'); 11 function queueTaskAndStep(f) { 12 step_timeout(function() { 13 t.step(f); 14 }, 0); 15 } 16 17 function next() { 18 let testcase = tests.shift(); 19 if (!testcase) { 20 t.done(); 21 return; 22 } 23 step_timeout(testcase, 0); 24 } 25 26 let tests = [ 27 function() { 28 v.src = "/media/sound_0.mp3"; 29 queueTaskAndStep(function() { 30 assert_true(v.currentSrc.indexOf("sound_0.mp3") != -1, "currentSrc must be equal to the source after load if present"); 31 next(); 32 }); 33 }, 34 function() { 35 v.src = URL.createObjectURL(new MediaSource()); 36 queueTaskAndStep(function() { 37 assert_not_equals(v.currentSrc, "", "currentSrc must not be equal to the empty string after load if playing a MediaSource from the src attribute"); 38 next(); 39 }); 40 }, 41 function() { 42 fetch('/media/sound_0.mp3') 43 .then(function(response) { 44 return response.arrayBuffer(); 45 }).then((b) => { 46 v.src = URL.createObjectURL(new Blob([new Uint8Array(b)], ["audio/mpeg"])); 47 queueTaskAndStep(function() { 48 assert_not_equals(v.currentSrc, "", "currentSrc must be not equal to the empty string after load if playing a Blob from the src attribute"); 49 next(); 50 }); 51 }); 52 }, 53 function() { 54 v.src = "/media/sound_0.mp3"; 55 // Source should be ignored when there is an `src` 56 let sourceNode = document.createElement("source"); 57 sourceNode.setAttribute("src", "/media/sine440.mp3"); 58 sourceNode.setAttribute("type", "audio/mpeg"); 59 v.appendChild(sourceNode); 60 queueTaskAndStep(function() { 61 assert_true(v.currentSrc.indexOf("sine440.mp3") == -1, "The src attribute takes precedence over any source child element when both are preset"); 62 next(); 63 }) 64 }, 65 function() { 66 // But taken into account when there is no `src` attribute; 67 v.src = ""; 68 v.removeAttribute("src"); 69 queueTaskAndStep(function() { 70 assert_true(v.currentSrc.indexOf("sine440.mp3") != -1, "The child source element is the current source when no src attribute is present"); 71 next(); 72 }); 73 }, 74 function() { 75 v.firstChild.remove(); 76 v.src = "https://test:test/"; 77 queueTaskAndStep(function() { 78 assert_true(v.currentSrc.indexOf("sine440.mp3") != -1, "Not reset when a new load errors"); 79 next(); 80 }); 81 }, 82 function() { 83 v.srcObject = new MediaStream(); 84 queueTaskAndStep(function() { 85 assert_equals(v.currentSrc, "", "When playing a MediaStream, currentSrc should also be reset to an empty string"); 86 next(); 87 }); 88 } 89 ]; 90 91 next(); 92 93 </script>