summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/media-source/mediasource-config-changes.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/media-source/mediasource-config-changes.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/media-source/mediasource-config-changes.js')
-rw-r--r--testing/web-platform/tests/media-source/mediasource-config-changes.js113
1 files changed, 113 insertions, 0 deletions
diff --git a/testing/web-platform/tests/media-source/mediasource-config-changes.js b/testing/web-platform/tests/media-source/mediasource-config-changes.js
new file mode 100644
index 000000000..ea99b8ba5
--- /dev/null
+++ b/testing/web-platform/tests/media-source/mediasource-config-changes.js
@@ -0,0 +1,113 @@
+// Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang).
+
+// Extract & return the resolution string from a filename, if any.
+function resolutionFromFilename(filename)
+{
+ resolution = filename.replace(/^.*[^0-9]([0-9]+x[0-9]+)[^0-9].*$/, "$1");
+ if (resolution != filename) {
+ return resolution;
+ }
+ return "";
+}
+
+function appendBuffer(test, sourceBuffer, data)
+{
+ test.expectEvent(sourceBuffer, "update");
+ test.expectEvent(sourceBuffer, "updateend");
+ sourceBuffer.appendBuffer(data);
+}
+
+function mediaSourceConfigChangeTest(directory, idA, idB, description)
+{
+ var manifestFilenameA = directory + "/test-" + idA + "-manifest.json";
+ var manifestFilenameB = directory + "/test-" + idB + "-manifest.json";
+ mediasource_test(function(test, mediaElement, mediaSource)
+ {
+ mediaElement.pause();
+ mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));
+ var expectResizeEvents = resolutionFromFilename(manifestFilenameA) != resolutionFromFilename(manifestFilenameB);
+ var expectedResizeEventCount = 0;
+
+ MediaSourceUtil.fetchManifestAndData(test, manifestFilenameA, function(typeA, dataA)
+ {
+ MediaSourceUtil.fetchManifestAndData(test, manifestFilenameB, function(typeB, dataB)
+ {
+ assert_equals(typeA, typeB, "Media format types match");
+
+ var sourceBuffer = mediaSource.addSourceBuffer(typeA);
+
+ appendBuffer(test, sourceBuffer, dataA);
+ ++expectedResizeEventCount;
+
+ test.waitForExpectedEvents(function()
+ {
+ // Add the second buffer starting at 0.5 second.
+ sourceBuffer.timestampOffset = 0.5;
+ appendBuffer(test, sourceBuffer, dataB);
+ ++expectedResizeEventCount;
+ });
+
+ test.waitForExpectedEvents(function()
+ {
+ // Add the first buffer starting at 1 second.
+ sourceBuffer.timestampOffset = 1;
+ appendBuffer(test, sourceBuffer, dataA);
+ ++expectedResizeEventCount;
+ });
+
+ test.waitForExpectedEvents(function()
+ {
+ // Add the second buffer starting at 1.5 second.
+ sourceBuffer.timestampOffset = 1.5;
+ appendBuffer(test, sourceBuffer, dataB);
+ ++expectedResizeEventCount;
+ });
+
+ test.waitForExpectedEvents(function()
+ {
+ assert_false(sourceBuffer.updating, "updating");
+
+ // Truncate the presentation to a duration of 2 seconds.
+ sourceBuffer.remove(2, Infinity);
+
+ assert_true(sourceBuffer.updating, "updating");
+ test.expectEvent(sourceBuffer, 'updatestart', 'sourceBuffer');
+ test.expectEvent(sourceBuffer, 'update', 'sourceBuffer');
+ test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
+ });
+
+ test.waitForExpectedEvents(function()
+ {
+ assert_false(sourceBuffer.updating, "updating");
+ assert_greater_than(mediaSource.duration, 2, "duration");
+
+ // Truncate the presentation to a duration of 2 seconds.
+ mediaSource.duration = 2;
+
+ test.expectEvent(mediaElement, "durationchange");
+ });
+
+ test.waitForExpectedEvents(function()
+ {
+ assert_false(sourceBuffer.updating, "updating");
+
+ mediaSource.endOfStream();
+
+ assert_false(sourceBuffer.updating, "updating");
+
+ if (expectResizeEvents) {
+ for (var i = 0; i < expectedResizeEventCount; ++i) {
+ test.expectEvent(mediaElement, "resize");
+ }
+ }
+ test.expectEvent(mediaElement, "ended");
+ mediaElement.play();
+ });
+
+ test.waitForExpectedEvents(function() {
+ test.done();
+ });
+ });
+ });
+ }, description);
+};