Bug 1118123: Mochitest to verify proper sourcebuffer behavior. r=cajbir a=sledru
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 09 Jan 2015 12:34:45 +1100
changeset 242907 61e917f920c9
parent 242906 9a4a8602e6f4
child 242908 7cd63f89473b
push id4338
push userrgiles@mozilla.com
push date2015-01-20 00:26 +0000
treeherdermozilla-beta@7dd701f60492 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir, sledru
bugs1118123
milestone36.0
Bug 1118123: Mochitest to verify proper sourcebuffer behavior. r=cajbir a=sledru
dom/media/mediasource/test/mochitest.ini
dom/media/mediasource/test/test_DurationUpdated.html
--- a/dom/media/mediasource/test/mochitest.ini
+++ b/dom/media/mediasource/test/mochitest.ini
@@ -1,25 +1,26 @@
 [DEFAULT]
 skip-if = e10s || buildapp == 'b2g' # b2g( ReferenceError: MediaSource is not defined)
 support-files =
   mediasource.js
   seek.webm seek.webm^headers^
   seek_lowres.webm seek_lowres.webm^headers^
 
-[test_MediaSource.html]
-[test_MediaSource_disabled.html]
 [test_BufferedSeek.html]
 [test_BufferingWait.html]
 skip-if = true # bug 1093133
 [test_EndOfStream.html]
 skip-if = (toolkit == 'android' || buildapp == 'mulet') #timeout android/mulet only bug 1101187
+[test_DurationUpdated.html]
 [test_FrameSelection.html]
 [test_HaveMetadataUnbufferedSeek.html]
 [test_LoadedMetadataFired.html]
+[test_MediaSource.html]
+[test_MediaSource_disabled.html]
 [test_SeekableAfterEndOfStream.html]
 [test_SeekableAfterEndOfStreamSplit.html]
 [test_SeekableBeforeEndOfStream.html]
 [test_SeekableBeforeEndOfStreamSplit.html]
 [test_SetModeThrows.html]
 [test_SplitAppendDelay.html]
 [test_SplitAppend.html]
 [test_WaitingOnMissingData.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/mediasource/test/test_DurationUpdated.html
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>MSE: append data and check that mediasource duration got updated</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="mediasource.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+var updateCount = 0;
+var durationChangeCount = 0;
+
+runWithMSE(function (ms, v) {
+  ms.addEventListener("sourceopen", function () {
+    var sb = ms.addSourceBuffer("video/webm");
+
+    fetchWithXHR("seek.webm", function (arrayBuffer) {
+      sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
+      sb.addEventListener("updateend", function () {
+        updateCount++;
+        if (updateCount == 1) {
+          v.addEventListener("loadedmetadata", function () {
+            v.addEventListener("durationchange", function () {
+              durationChangeCount++;
+              if (durationChangeCount == 1) {
+                sb.addEventListener('updateend', function(e) {
+                  sb.removeEventListener('updateend', arguments.callee);
+                  sb.appendBuffer(new Uint8Array(arrayBuffer, 318));
+                });
+              }
+            });
+            // Set mediasource duration to 0, so future appendBuffer
+            // will update the mediasource duration
+            // setting ms.duration will fire updatestart/update/updateend
+            //  event as per w3c spec
+            ms.duration = 0;
+          });
+        }
+      });
+    });
+  });
+
+  v.addEventListener("loadeddata", function () {
+    // XXX: Duration should be exactly 4.0, see bug 1065207.
+    is(durationChangeCount, 2, "durationchange not fired as many times as expected");
+    ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
+    SimpleTest.finish();
+  });
+});
+
+</script>
+</pre>
+</body>
+</html>