Bug 1302573: [MSE] P1. Add mochitest. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 22 Sep 2016 19:55:38 +1000
changeset 417544 c5021c1a2c7b6284e37356fb3d7c8b73c9c2f689
parent 417383 29beaebdfaccbdaeb4c1ee5a43a9795ab015ef49
child 417545 a67dd4b39bcdc16aea6aa4e8504932a6fc06c620
push id30418
push userbmo:jyavenard@mozilla.com
push dateMon, 26 Sep 2016 05:26:55 +0000
reviewersgerald
bugs1302573
milestone52.0a1
Bug 1302573: [MSE] P1. Add mochitest. r?gerald MozReview-Commit-ID: 9zAZ8x3kwQ7
dom/media/mediasource/test/mochitest.ini
dom/media/mediasource/test/test_Eviction_mp4.html
--- a/dom/media/mediasource/test/mochitest.ini
+++ b/dom/media/mediasource/test/mochitest.ini
@@ -50,24 +50,26 @@ skip-if = ((os == "win" && os_version ==
 [test_BufferedSeek_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_BufferingWait.html]
 skip-if = toolkit == 'android' #timeout android bug 1199531
 [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_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_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_Eviction_mp4.html]
+skip-if = (os == "win" && os_version == "5.1") # Not supported on xp.
 [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]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_LiveSeekable.html]
 [test_LoadedDataFired_mp4.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/mediasource/test/test_Eviction_mp4.html
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<html><head>
+<meta http-equiv="content-type" content="text/html; charset=windows-1252">
+  <title>MSE: QuotaExceededError when source buffer is full</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();
+// We fill up the source buffer with audio data until the buffer is full.
+// We ensure that QuotaExceededError is thrown once the buffer is full.
+// We then seek to half the content. By that time, another appendBuffer must succeed
+// as the auto-eviction would succeed (removing all data prior currentTime)
+
+// Fill up the SourceBuffer by appending data repeatedly via doAppendDataFunc until
+// an exception is thrown.
+function fillUpSourceBuffer(sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback) {
+  // We are appending data repeatedly in sequence mode, there should be no gaps.
+  ok(sourceBuffer.buffered.length <= 1, "there should be no gap in buffered ranges.");
+  try {
+    doAppendDataFunc();
+  } catch(ex) {
+    onCaughtExceptionCallback(ex);
+    return;
+  }
+  once(sourceBuffer, 'updateend', () => {
+    fillUpSourceBuffer(sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback);
+  });
+}
+
+runWithMSE(function(ms, el) {
+  el.controls = true;
+  once(ms, 'sourceopen').then(function() {
+    ok(true, "Receive a sourceopen event");
+    SpecialPowers.pushPrefEnv({
+      "set": [
+        ["media.mediasource.eviction_threshold.audio", 524288],
+      ]
+    }, function() {
+      let audiosb = ms.addSourceBuffer("audio/mp4");
+      audiosb.mode = "sequence";
+      fetchAndLoad(audiosb, 'bipbop/bipbop_audio', ['init'], '.mp4')
+      .then(function() {
+        fetchWithXHR('bipbop/bipbop_audio1.m4s', function(audioBuffer) {
+           fillUpSourceBuffer(audiosb,
+             function() { // doAppendDataFunc
+               audiosb.appendBuffer(audioBuffer);
+             },
+             function(ex) { // onCaughtExceptionCallback
+               is(ex.name, 'QuotaExceededError', "QuotaExceededError thrown");
+               is(audiosb.buffered.end(0), el.duration, "Duration is end of buffered range");
+               let seekTime = audiosb.buffered.end(0) / 2;
+               el.currentTime = seekTime;
+               once(el, 'seeked', () => {
+                 is(el.currentTime, seekTime, "correctly seeked to " + seekTime);
+                 try {
+                   audiosb.appendBuffer(audioBuffer);
+                 } catch(ex) {
+                   ok(false, "Shouldn't throw another time when data can be evicted");
+                   el.mozDumpDebugInfo();
+                   SimpleTest.finish();
+                   return;
+                 }
+                 once(audiosb, 'update', () => {
+                   ok(true, "appendBuffer succeeded");
+                   SimpleTest.finish();
+                 });
+               });
+            });
+        });
+      });
+    });
+  });
+});
+
+</script>
+</pre>
+</body>
+</html>