diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/media/test/test_load_same_resource.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/media/test/test_load_same_resource.html')
-rw-r--r-- | dom/media/test/test_load_same_resource.html | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/dom/media/test/test_load_same_resource.html b/dom/media/test/test_load_same_resource.html new file mode 100644 index 000000000..b87abda32 --- /dev/null +++ b/dom/media/test/test_load_same_resource.html @@ -0,0 +1,100 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test loading of the same resource in multiple elements</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + <script type="text/javascript" src="manifest.js"></script> +</head> +<body> + +<pre id="test"> +<script class="testbody" type="text/javascript"> + +SimpleTest.requestCompleteLog(); +var manager = new MediaTestManager; + +function cloneLoaded(event) { + ok(true, "Clone loaded OK"); + var e = event.target; + + if (e._expectedDuration) { + ok(Math.abs(e.duration - e._expectedDuration) < 0.1, + "Clone " + e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration); + } + + e.removeEventListener("loadeddata", cloneLoaded, false); + removeNodeAndSource(e); + manager.finished(e.token); +} + +function tryClone(event) { + var e = event.target; + var clone = e.cloneNode(false); + clone.token = e.token; + + // Log events for debugging. + var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata", + "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort", + "waiting", "pause"]; + function logEvent(evt) { + var e = evt.target; + info(e.token + ": got " + evt.type); + } + events.forEach(function(e) { + clone.addEventListener(e, logEvent, false); + }); + + + if (e._expectedDuration) { + ok(Math.abs(e.duration - e._expectedDuration) < 0.1, + e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration); + clone._expectedDuration = e._expectedDuration; + } + + clone.addEventListener("loadeddata", cloneLoaded, false); + clone.onloadstart = function(evt) { + info("cloned " + evt.target.token + " start loading."); + evt.target.onloadstart = null; + // Since there is only one H264 decoder instance, we have to delete the + // decoder of the original element for the cloned element to load. However, + // we can't delete the decoder too early otherwise cloning decoder will + // fail to kick in. We wait for 'loadstart' event of the cloned element to + // know when the decoder is already cloned and we can delete the decoder of + // the original element. + removeNodeAndSource(e); + } + + e.removeEventListener("loadeddata", tryClone, false); +} + +// This test checks that loading the same URI twice in different elements at the same time +// uses the same resource without doing another network fetch. One of the gCloneTests +// uses dynamic_resource.sjs to return one resource on the first fetch and a different resource +// on the second fetch. These resources have different lengths, so if the cloned element +// does a network fetch it will get a resource with the wrong length and we get a test +// failure. + +function initTest(test, token) { + var elemType = /^audio/.test(test.type) ? "audio" : "video"; + var e = document.createElement(elemType); + e.preload = "auto"; + if (e.canPlayType(test.type)) { + e.src = test.name; + if (test.duration) { + e._expectedDuration = test.duration; + } + ok(true, "Trying to load " + test.name); + e.addEventListener("loadeddata", tryClone, false); + e.load(); + e.token = token; + manager.started(token); + } +} + +manager.runTests(gCloneTests, initTest); + +</script> +</pre> +</body> +</html> |