1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/test/test_load_same_resource.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test loading of the same resource in multiple elements</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.10 + <script type="text/javascript" src="manifest.js"></script> 1.11 +</head> 1.12 +<body> 1.13 + 1.14 +<pre id="test"> 1.15 +<script class="testbody" type="text/javascript"> 1.16 + 1.17 +var manager = new MediaTestManager; 1.18 + 1.19 +function cloneLoaded(event) { 1.20 + ok(true, "Clone loaded OK"); 1.21 + var e = event.target; 1.22 + 1.23 + if (e._expectedDuration) { 1.24 + ok(Math.abs(e.duration - e._expectedDuration) < 0.1, 1.25 + "Clone " + e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration); 1.26 + } 1.27 + 1.28 + e.removeEventListener("loadeddata", cloneLoaded, false); 1.29 + removeNodeAndSource(e); 1.30 + manager.finished(e.token); 1.31 +} 1.32 + 1.33 +function tryClone(event) { 1.34 + var e = event.target; 1.35 + var clone = e.cloneNode(false); 1.36 + clone.token = e.token; 1.37 + 1.38 + if (e._expectedDuration) { 1.39 + ok(Math.abs(e.duration - e._expectedDuration) < 0.1, 1.40 + e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration); 1.41 + clone._expectedDuration = e._expectedDuration; 1.42 + } 1.43 + 1.44 + clone.addEventListener("loadeddata", cloneLoaded, false); 1.45 + clone.onloadstart = function(evt) { 1.46 + info("cloned " + evt.target.token + " start loading."); 1.47 + evt.target.onloadstart = null; 1.48 + // Since there is only one H264 decoder instance, we have to delete the 1.49 + // decoder of the original element for the cloned element to load. However, 1.50 + // we can't delete the decoder too early otherwise cloning decoder will 1.51 + // fail to kick in. We wait for 'loadstart' event of the cloned element to 1.52 + // know when the decoder is already cloned and we can delete the decoder of 1.53 + // the original element. 1.54 + removeNodeAndSource(e); 1.55 + } 1.56 + 1.57 + e.removeEventListener("loadeddata", tryClone, false); 1.58 +} 1.59 + 1.60 +// This test checks that loading the same URI twice in different elements at the same time 1.61 +// uses the same resource without doing another network fetch. One of the gCloneTests 1.62 +// uses dynamic_resource.sjs to return one resource on the first fetch and a different resource 1.63 +// on the second fetch. These resources have different lengths, so if the cloned element 1.64 +// does a network fetch it will get a resource with the wrong length and we get a test 1.65 +// failure. 1.66 + 1.67 +function initTest(test, token) { 1.68 + var elemType = /^audio/.test(test.type) ? "audio" : "video"; 1.69 + var e = document.createElement(elemType); 1.70 + e.preload = "auto"; 1.71 + if (e.canPlayType(test.type)) { 1.72 + e.src = test.name; 1.73 + if (test.duration) { 1.74 + e._expectedDuration = test.duration; 1.75 + } 1.76 + ok(true, "Trying to load " + test.name); 1.77 + e.addEventListener("loadeddata", tryClone, false); 1.78 + e.load(); 1.79 + e.token = token; 1.80 + manager.started(token); 1.81 + } 1.82 +} 1.83 + 1.84 +manager.runTests(gCloneTests, initTest); 1.85 + 1.86 +</script> 1.87 +</pre> 1.88 +</body> 1.89 +</html>