Bug 1289742. P5 - test.duration is mandatory to run the test. r?kaku
MozReview-Commit-ID: GSvVrCBTeQB
--- a/dom/media/test/test_load_same_resource.html
+++ b/dom/media/test/test_load_same_resource.html
@@ -9,25 +9,25 @@
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.requestCompleteLog();
var manager = new MediaTestManager;
+function checkDuration(actual, expected, name) {
+ ok(Math.abs(actual - expected) < 0.1,
+ `${name} duration: ${actual} expected: ${expected}`);
+}
+
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);
- }
-
+ checkDuration(e.duration, e._expectedDuration, e.token);
removeNodeAndSource(e);
manager.finished(e.token);
}
function tryClone(event) {
var e = event.target;
var clone = e.cloneNode(false);
clone.token = e.token;
@@ -40,21 +40,18 @@ function tryClone(event) {
var e = evt.target;
info(e.token + ": got " + evt.type);
}
events.forEach(function(e) {
clone.addEventListener(e, logEvent);
});
- if (e._expectedDuration) {
- ok(Math.abs(e.duration - e._expectedDuration) < 0.1,
- e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration);
- clone._expectedDuration = e._expectedDuration;
- }
+ checkDuration(e.duration, e._expectedDuration, e.token);
+ clone._expectedDuration = e._expectedDuration;
clone.addEventListener("loadeddata", cloneLoaded, {once: true});
clone.addEventListener("loadstart", function(evt) {
info("cloned " + evt.target.token + " start loading.");
// 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
@@ -71,20 +68,18 @@ function tryClone(event) {
// 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";
e.src = test.name;
- if (test.duration) {
- e._expectedDuration = test.duration;
- }
- ok(true, "Trying to load " + test.name);
+ e._expectedDuration = test.duration;
+ ok(true, `Trying to load ${test.name}, duration=${test.duration}`);
e.addEventListener("loadeddata", tryClone, {once: true});
e.token = token;
manager.started(token);
}
manager.runTests(gCloneTests, initTest);
</script>