Bug 1297580: [MSE] P4. Add mochitest. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 25 Aug 2016 10:59:42 +1200
changeset 405247 a8af1ddd57ba1c8e69c6e463ff6fcf6f12877464
parent 405246 696d461f777f24895815351c7bb61c845f3f7ced
child 405922 05242f1aca3f657abccbd398a8005e5ee7dd11b8
push id27443
push userbmo:jyavenard@mozilla.com
push dateThu, 25 Aug 2016 04:44:40 +0000
reviewersgerald
bugs1297580
milestone51.0a1
Bug 1297580: [MSE] P4. Add mochitest. r?gerald MozReview-Commit-ID: IulzS2GSHa2
dom/media/mediasource/test/mochitest.ini
dom/media/mediasource/test/test_Threshold_mp4.html
--- a/dom/media/mediasource/test/mochitest.ini
+++ b/dom/media/mediasource/test/mochitest.ini
@@ -110,16 +110,18 @@ skip-if = ((os == "win" && os_version ==
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_SetModeThrows.html]
 [test_SplitAppendDelay.html]
 [test_SplitAppendDelay_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_SplitAppend.html]
 [test_SplitAppend_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
+[test_Threshold_mp4.html]
+skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_TimestampOffset_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_TruncatedDuration.html]
 [test_TruncatedDuration_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_WaitingOnMissingData.html]
 skip-if = true # Disabled due to bug 1124493 and friends. WebM MSE is deprioritized.
 [test_WaitingOnMissingData_mp4.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/mediasource/test/test_Threshold_mp4.html
@@ -0,0 +1,81 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>MSE: data gap detection</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();
+
+runWithMSE(function(ms, el) {
+
+var threshold = 0.5; // gap threshold in seconds.
+// duration of a frame. The FFmpeg decoder can't calculate properly calculate the duration of the last frame.
+var fuzz = 33322 / 1000000;
+
+  once(ms, 'sourceopen').then(function() {
+    ok(true, "Receive a sourceopen event");
+    var videosb = ms.addSourceBuffer("video/mp4");
+    var vchunks = [ {start: 0, end: 3.2033}, { start: 3.2033, end: 6.4066}];
+
+    fetchAndLoad(videosb, 'bipbop/bipbop_video', ['init'], '.mp4')
+    .then(fetchAndLoad.bind(null, videosb, 'bipbop/bipbop_video', range(1, 5), '.m4s'))
+    .then(function() {
+      // We will insert a gap of threshold
+      videosb.timestampOffset = threshold;
+      return fetchAndLoad(videosb, 'bipbop/bipbop_video', range(5, 9), '.m4s');
+    }).then(function() {
+      // HTMLMediaElement fires 'waiting' if somebody invokes |play()| before the MDSM
+      // has notified it of available data. Make sure that we get 'playing' before
+      // we starting waiting for 'waiting'.
+      info("Invoking play()");
+      var p = once(el, 'playing');
+      el.play();
+      return p;
+    }).then(function() {
+      return once(el, 'waiting');
+    }).then(function() {
+      // We're waiting for data at the end of the last segment.
+      isfuzzy(el.currentTime, vchunks[1].end + threshold, fuzz, "skipped the gap properly");
+      is(el.buffered.length, 2, "buffered range has right length");
+      // Now we test that seeking will succeed despite the gap.
+      el.currentTime = el.buffered.end(0) + (threshold / 2);
+      return once(el, 'seeked');
+    }).then(function() {
+      // Now we test that we don't pass the gap.
+      // Clean up our sourcebuffer by removing all data.
+      videosb.timestampOffset = 0;
+      videosb.remove(0, Infinity);
+      el.currentTime = 0;
+      el.pause();
+      return once(videosb, "updateend");
+    }).then(function() {
+      return fetchAndLoad(videosb, 'bipbop/bipbop_video', range(1, 5), '.m4s');
+    }).then(function() {
+      // We will insert a gap of threshold + 1ms
+      videosb.timestampOffset = threshold + 1/1000;
+      return fetchAndLoad(videosb, 'bipbop/bipbop_video', range(5, 9), '.m4s');
+    }).then(function() {
+      info("Invoking play()");
+      var p = once(el, 'playing');
+      el.play();
+      return p;
+    }).then(function() {
+      return once(el, 'waiting');
+    }).then(function() {
+      // We're waiting for data at the end of the first segment as the gap is too big.
+      isfuzzy(el.currentTime, vchunks[0].end, fuzz, "stopped at the gap properly");
+      SimpleTest.finish();
+    });
+  });
+});
+
+</script>
+</pre>
+</body>
+</html>