1 // Extract & return the resolution string from a filename, if any.
2 function resolutionFromFilename(filename)
4 resolution = filename.replace(/^.*[^0-9]([0-9]+x[0-9]+)[^0-9].*$/, "$1");
5 if (resolution != filename) {
11 function appendBuffer(test, sourceBuffer, data)
13 test.expectEvent(sourceBuffer, "update");
14 test.expectEvent(sourceBuffer, "updateend");
15 sourceBuffer.appendBuffer(data);
18 function mediaSourceConfigChangeTest(directory, idA, idB, description)
20 var manifestFilenameA = directory + "/test-" + idA + "-manifest.json";
21 var manifestFilenameB = directory + "/test-" + idB + "-manifest.json";
22 mediasource_test(function(test, mediaElement, mediaSource)
25 test.failOnEvent(mediaElement, 'error');
26 var expectResizeEvents = resolutionFromFilename(manifestFilenameA) != resolutionFromFilename(manifestFilenameB);
27 var expectedResizeEventCount = 0;
29 MediaSourceUtil.fetchManifestAndData(test, manifestFilenameA, function(typeA, dataA)
31 MediaSourceUtil.fetchManifestAndData(test, manifestFilenameB, function(typeB, dataB)
33 assert_equals(typeA, typeB, "Media format types match");
35 var sourceBuffer = mediaSource.addSourceBuffer(typeA);
37 appendBuffer(test, sourceBuffer, dataA);
38 ++expectedResizeEventCount;
40 test.waitForExpectedEvents(function()
42 // Add the second buffer starting at 0.5 second.
43 sourceBuffer.timestampOffset = 0.5;
44 appendBuffer(test, sourceBuffer, dataB);
45 ++expectedResizeEventCount;
48 test.waitForExpectedEvents(function()
50 // Add the first buffer starting at 1 second.
51 sourceBuffer.timestampOffset = 1;
52 appendBuffer(test, sourceBuffer, dataA);
53 ++expectedResizeEventCount;
56 test.waitForExpectedEvents(function()
58 // Add the second buffer starting at 1.5 second.
59 sourceBuffer.timestampOffset = 1.5;
60 appendBuffer(test, sourceBuffer, dataB);
61 ++expectedResizeEventCount;
64 test.waitForExpectedEvents(function()
66 // Truncate the presentation to a duration of 2 seconds.
67 assert_false(sourceBuffer.updating, "sourceBuffer.updating");
69 mediaSource.duration = 2;
71 assert_true(sourceBuffer.updating, "sourceBuffer.updating");
72 test.expectEvent(sourceBuffer, "updatestart");
73 test.expectEvent(sourceBuffer, "update");
74 test.expectEvent(sourceBuffer, "updateend");
77 test.waitForExpectedEvents(function()
79 mediaSource.endOfStream();
81 if (expectResizeEvents) {
82 for (var i = 0; i < expectedResizeEventCount; ++i) {
83 test.expectEvent(mediaElement, "resize");
86 test.expectEvent(mediaElement, "ended");
90 test.waitForExpectedEvents(function() {
95 }, description, { timeout: 10000 } );