Bug 1362793 - part2 : add test.
If video gets error after loaded metadata, its duration should still be available.
MozReview-Commit-ID: GvwqX28I04o
--- a/dom/media/test/manifest.js
+++ b/dom/media/test/manifest.js
@@ -540,16 +540,23 @@ var gErrorTests = [
// Windows' H.264 decoder cannot handle H.264 streams with resolution
// less than 48x48 pixels. We refuse to play and error on such streams.
if (manifestNavigator().userAgent.includes("Windows") &&
manifestVideo().canPlayType('video/mp4; codecs="avc1.42E01E"')) {
gErrorTests = gErrorTests.concat({name: "red-46x48.mp4", type:"video/mp4"},
{name: "red-48x46.mp4", type:"video/mp4"});
}
+// These files would get error after receiving "loadedmetadata", we would like
+// to check duration in "onerror" and make sure the duration is still available.
+var gDurationTests = [
+ { name:"bug603918.webm", duration:6.076 },
+ { name:"bug604067.webm", duration:6.076 }
+]
+
// These are files that have nontrivial duration and are useful for seeking within.
var gSeekTests = [
{ name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 },
{ name:"audio.wav", type:"audio/x-wav", duration:0.031247 },
{ name:"seek.ogv", type:"video/ogg", duration:3.966 },
{ name:"320x240.ogv", type:"video/ogg", duration:0.266 },
{ name:"seek.webm", type:"video/webm", duration:3.966 },
{ name:"sine.webm", type:"audio/webm", duration:4.001 },
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -719,16 +719,17 @@ skip-if = toolkit == 'android' # bug 133
[test_cueless_webm_seek-3.html]
skip-if = toolkit == 'android' # bug 1336166
[test_currentTime.html]
[test_decode_error.html]
[test_decoder_disable.html]
[test_defaultMuted.html]
[test_delay_load.html]
skip-if = android_version == '17' # android(bug 1232305)
+[test_duration_after_error.html]
[test_eme_session_callable_value.html]
[test_eme_canvas_blocked.html]
skip-if = toolkit == 'android' # bug 1149374
[test_eme_detach_media_keys.html]
skip-if = toolkit == 'android' # bug 1149374
[test_eme_initDataTypes.html]
skip-if = toolkit == 'android' # bug 1149374
[test_eme_missing_pssh.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_duration_after_error.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test playback of media files that should have errors</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">
+
+var manager = new MediaTestManager;
+
+function checkDuration(name, e, test) {
+ if (test.duration) {
+ ok(Math.abs(e.duration - test.duration) < 0.1,
+ name + " duration (" + e.duration + ") should be around " + test.duration);
+ } else {
+ ok(false, "Test doesn't include the duration field!")
+ }
+}
+
+function startTest(test, token) {
+ manager.started(token);
+
+ let v = document.createElement('video');
+ v._loadedMetadata = false;
+ let name = test.name;
+
+ v.onloadedmetadata = function() {
+ v.onloadedmetadata = null;
+ v._loadedMetadata = true;
+ ok(v._loadedMetadata , name + " has loaded metadata.");
+ }
+
+ v.onerror = function() {
+ v.onerror = null;
+ ok(v._loadedMetadata , name + " should load metadata before getting error.");
+ checkDuration(name, v, test);
+ manager.finished(token);
+ }
+
+ v.src = name;
+ document.body.appendChild(v);
+ v.play();
+}
+
+manager.runTests(gDurationTests, startTest);
+
+</script>
+</pre>
+</body>
+</html>