Bug 1362165: Add web platform test. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 11 May 2017 10:43:25 +0200
changeset 361285 3329385fcf2d39197bb9aae5794c5429d1ccfde4
parent 361284 2ba56b296e40a529b1b58f27b36e68248cf9500a
child 361286 138425350cc671dc20e26b2b2ba019bb2ae85c1f
push id31924
push userryanvm@gmail.com
push dateTue, 30 May 2017 20:08:50 +0000
treeherdermozilla-central@692e277e2b9f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1362165
milestone55.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 1362165: Add web platform test. r=gerald readyState is supposed to be updated during MSE's Initialization Segment Received and Coded Frame Processing algorithm. Only then would the appendBuffer operation terminates by queueing the update/updateend events. These tests ensure that loadedmetadata and loadeddata are fired first. MozReview-Commit-ID: BJ5gISQRA7B
testing/web-platform/tests/media-source/mediasource-append-buffer.html
--- a/testing/web-platform/tests/media-source/mediasource-append-buffer.html
+++ b/testing/web-platform/tests/media-source/mediasource-append-buffer.html
@@ -409,16 +409,68 @@
                   assert_equals(sourceBuffer.updating, false);
                   test.done();
               });
           }, "Test appendBuffer with partial media segments.");
 
           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
           {
               var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
+              var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
+
+              assert_equals(mediaElement.readyState, mediaElement.HAVE_NOTHING);
+              assert_equals(mediaSource.duration, Number.NaN);
+
+              // readyState is changing as per the Initialization Segment Received algorithm.
+              var loadedmetadataCalled = false;
+              mediaElement.addEventListener("loadedmetadata", function metadata(e) {
+                 loadedmetadataCalled = true;
+                 e.target.removeEventListener(e.type, metadata);
+              });
+              sourceBuffer.addEventListener("updateend", function updateend(e) {
+                 assert_true(loadedmetadataCalled);
+                 assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA);
+                 e.target.removeEventListener(e.type, updateend);
+              });
+              test.expectEvent(sourceBuffer, "updateend", "remainingInitSegment append ended.");
+              test.expectEvent(mediaElement, "loadedmetadata", "loadedmetadata event received.");
+              sourceBuffer.appendBuffer(initSegment);
+
+              test.waitForExpectedEvents(function()
+              {
+                  assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA);
+                  assert_equals(mediaSource.duration, segmentInfo.duration);
+                  // readyState is changing as per the Coded Frame Processing algorithm.
+                  var loadeddataCalled = false;
+                  mediaElement.addEventListener("loadeddata", function loadeddata(e) {
+                      loadeddataCalled = true;
+                      e.target.removeEventListener(e.type, loadeddata);
+                  });
+                  sourceBuffer.addEventListener("updateend", function updateend(e) {
+                      assert_true(loadeddataCalled);
+                      assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA);
+                      e.target.removeEventListener(e.type, updateend);
+                  });
+                  test.expectEvent(sourceBuffer, "updateend", "mediaSegment append ended.");
+                  test.expectEvent(mediaElement, "loadeddata", "loadeddata fired.");
+                  sourceBuffer.appendBuffer(mediaSegment);
+              });
+
+              test.waitForExpectedEvents(function()
+              {
+                  assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA);
+                  assert_equals(sourceBuffer.updating, false);
+                  assert_equals(mediaSource.readyState, "open");
+                  test.done();
+              });
+          }, "Test appendBuffer events order.");
+
+          mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
+          {
+              var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
               var partialInitSegment = initSegment.subarray(0, initSegment.length / 2);
               var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
 
               test.expectEvent(sourceBuffer, "updateend", "partialInitSegment append ended.");
               sourceBuffer.appendBuffer(partialInitSegment);
 
               test.waitForExpectedEvents(function()
               {