Bug 1286810: [MSE] P4. Mochitest for new duration behavior. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 16 Jul 2016 01:14:02 +1000
changeset 305451 af10601ac03ffd7da6426faa56f7471f1fe63277
parent 305450 66c06c6fb41bfe924a3ee8395831f3bac1ab6e0a
child 305452 6cdbb75807feef48ccd71b841a79757e349f91ea
push id79579
push userjyavenard@mozilla.com
push dateTue, 19 Jul 2016 01:45:28 +0000
treeherdermozilla-inbound@9afc48ae820f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1286810
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1286810: [MSE] P4. Mochitest for new duration behavior. r=gerald MozReview-Commit-ID: LLMGoWDFwte
dom/media/mediasource/test/mochitest.ini
dom/media/mediasource/test/test_DurationChange.html
--- a/dom/media/mediasource/test/mochitest.ini
+++ b/dom/media/mediasource/test/mochitest.ini
@@ -54,16 +54,17 @@ skip-if = toolkit == 'android' #timeout 
 [test_BufferingWait_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_DrainOnMissingData_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_EndOfStream.html]
 skip-if = (true || toolkit == 'android' || buildapp == 'mulet') #timeout android/mulet only bug 1101187 and bug 1182946
 [test_EndOfStream_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android' || buildapp == 'mulet')) # Not supported on xp and android 2.3
+[test_DurationChange.html]
 [test_DurationUpdated.html]
 [test_DurationUpdated_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_FrameSelection.html]
 [test_FrameSelection_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_HaveMetadataUnbufferedSeek.html]
 [test_HaveMetadataUnbufferedSeek_mp4.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/mediasource/test/test_DurationChange.html
@@ -0,0 +1,111 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>MSE: check that duration change behaves properly</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, v) {
+  ms.addEventListener("sourceopen", function () {
+    var sb = ms.addSourceBuffer("video/webm");
+
+    fetchWithXHR("seek.webm", function (arrayBuffer) {
+      sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
+      once(v, "loadedmetadata")
+      .then(function() {
+        is(v.duration, ms.duration, "video duration is mediasource one");
+        try {
+          ms.duration = 0;
+        } catch (e) { ok(false, "must not throw as operation is valid"); }
+        is(v.duration, 0, "reducing duration with no data buffered is valid");
+        sb.appendBuffer(new Uint8Array(arrayBuffer, 318));
+        // Adding more data will fire durationchange.
+        once(sb, "updateend")
+        .then(function() {
+          ok(true, "got updateend");
+          // XXX: Duration should be exactly 4.0, see bug 1065207.
+          ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
+          var error = false;
+          try {
+            ms.duration = 0;
+          } catch (e) {
+            ok(true, "must use remove for range removal");
+            is(e.name, "InvalidStateError", "Error is InvalidStateError");
+            error = true;
+          }
+          ok(error, "got an error");
+          ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
+          try {
+            ms.duration = 10;
+          } catch (e) { ok(false, "must not throw as setting duration past data is valid"); }
+          is(v.duration, 10, "extending duration is always valid");
+          // The last sample has a start time of 3.967000s and a end time of 4.001 (see bug 1065207).
+          try {
+            ms.duration = 3.967000;
+          } catch (e) { ok(false, "setting duration with >= highest frame presentation time is valid"); }
+          is(v.duration, sb.buffered.end(0), "duration is the highest end time reported by the buffered attribute ");
+          try {
+            ms.duration = 3.97;
+          } catch (e) { ok(false, "setting duration with >= highest frame presentation time is valid"); }
+          is(v.duration, sb.buffered.end(0), "duration is the highest end time reported by the buffered attribute ");
+          error = false;
+          try {
+            ms.duration = 3.96;
+          } catch (e) {
+            ok(true, "setting duration with < highest frame presentation time is not valid");
+            is(e.name, "InvalidStateError", "Error is InvalidStateError");
+            error = true;
+          }
+          ok(error, "got an error");
+          is(v.duration, sb.buffered.end(0), "duration is the highest end time reported by the buffered attribute ");
+          error = false;
+          try {
+            ms.duration = -1;
+          } catch (e) {
+            ok(true, "can't set a negative duration");
+            is(e.name, "TypeError", "Error is TypeError");
+            error = true;
+          }
+          ok(error, "got an error");
+          sb.remove(sb.buffered.end(0), Infinity);
+          is(sb.updating, true, "updating is true")
+          error = false;
+          try {
+            ms.duration = Infinity;
+          } catch (e) {
+            ok(true, "setting the duration while updating is not allowed");
+            is(e.name, "InvalidStateError", "Error is InvalidStateError");
+            error = true;
+          }
+          ok(error, "got an error");
+          error = false;
+          try {
+            sb.abort();
+          } catch (e) {
+            ok(true, "Can't use abort while range removal is in progress");
+            is(e.name, "InvalidStateError", "Error is InvalidStateError");
+            error = true;
+          }
+          ok(error, "got an error");
+          is(v.duration, sb.buffered.end(0), "duration is the highest end time reported by the buffered attribute ");
+          once(sb, "updateend", () => ms.endOfStream());
+        });
+      });
+    });
+  });
+  ms.addEventListener("sourceended", function () {
+    SimpleTest.finish();
+  });
+});
+
+</script>
+</pre>
+</body>
+</html>