Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / media-source / mediasource-config-changes.js
blob7e8ba725d4857201fa0d6437fcce84cd9d41138a
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) {
6         return resolution;
7     }
8     return "";
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)
23     {
24         mediaElement.pause();
25         test.failOnEvent(mediaElement, 'error');
26         var expectResizeEvents = resolutionFromFilename(manifestFilenameA) != resolutionFromFilename(manifestFilenameB);
27         var expectedResizeEventCount = 0;
29         MediaSourceUtil.fetchManifestAndData(test, manifestFilenameA, function(typeA, dataA)
30         {
31             MediaSourceUtil.fetchManifestAndData(test, manifestFilenameB, function(typeB, dataB)
32             {
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()
41                 {
42                     // Add the second buffer starting at 0.5 second.
43                     sourceBuffer.timestampOffset = 0.5;
44                     appendBuffer(test, sourceBuffer, dataB);
45                     ++expectedResizeEventCount;
46                 });
48                 test.waitForExpectedEvents(function()
49                 {
50                     // Add the first buffer starting at 1 second.
51                     sourceBuffer.timestampOffset = 1;
52                     appendBuffer(test, sourceBuffer, dataA);
53                     ++expectedResizeEventCount;
54                 });
56                 test.waitForExpectedEvents(function()
57                 {
58                     // Add the second buffer starting at 1.5 second.
59                     sourceBuffer.timestampOffset = 1.5;
60                     appendBuffer(test, sourceBuffer, dataB);
61                     ++expectedResizeEventCount;
62                 });
64                 test.waitForExpectedEvents(function()
65                 {
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");
75                 });
77                 test.waitForExpectedEvents(function()
78                 {
79                     mediaSource.endOfStream();
81                     if (expectResizeEvents) {
82                         for (var i = 0; i < expectedResizeEventCount; ++i) {
83                             test.expectEvent(mediaElement, "resize");
84                         }
85                     }
86                     test.expectEvent(mediaElement, "ended");
87                     mediaElement.play();
88                 });
90                 test.waitForExpectedEvents(function() {
91                     test.done();
92                 });
93             });
94         });
95     }, description, { timeout: 10000 } );