Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / media-source / mediasource-sourcebuffer-mode.html
blobbaac70ca1d6bef6f6e2f5d248080852fd420b33c
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/w3c/resources/testharness.js"></script>
5 <script src="/w3c/resources/testharnessreport.js"></script>
6 <script src="mediasource-util.js"></script>
8 <link rel='stylesheet' href='/w3c/resources/testharness.css'>
9 </head>
10 <body>
11 <div id="log"></div>
12 <script>
13 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
15 assert_equals(sourceBuffer.mode, 'segments', 'default append mode should be \'segments\'');
16 test.done();
17 }, 'Test initial value of SourceBuffer.mode is "segments"');
19 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
21 sourceBuffer.mode = 'sequence';
22 assert_equals(sourceBuffer.mode, 'sequence', 'mode after setting it to \'sequence\'');
24 // Setting a mode that is not in AppendMode IDL enum should be ignored and not cause exception.
25 sourceBuffer.mode = 'invalidmode';
26 sourceBuffer.mode = null;
27 sourceBuffer.mode = '';
28 sourceBuffer.mode = 'Segments';
29 assert_equals(sourceBuffer.mode, 'sequence', 'mode unchanged by attempts to set invalid modes');
31 sourceBuffer.mode = 'segments';
32 assert_equals(sourceBuffer.mode, 'segments', 'mode after setting it to \'segments\'');
33 test.done();
34 }, 'Test setting SourceBuffer.mode');
36 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
38 mediaSource.removeSourceBuffer(sourceBuffer);
39 assert_throws('InvalidStateError',
40 function() { sourceBuffer.mode = 'segments'; },
41 'Setting valid sourceBuffer.mode on removed SourceBuffer should throw InvalidStateError.');
42 test.done();
43 }, 'Test setting a removed SourceBuffer\'s mode');
45 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
47 sourceBuffer.appendBuffer(mediaData);
48 assert_true(sourceBuffer.updating, 'updating attribute is true');
49 assert_throws('InvalidStateError',
50 function() { sourceBuffer.mode = 'segments'; },
51 'Setting valid sourceBuffer.mode on updating SourceBuffer threw InvalidStateError.');
52 test.done();
53 }, 'Test setting SourceBuffer.mode while still updating');
55 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
57 test.expectEvent(sourceBuffer, 'updateend', 'Append ended.');
58 sourceBuffer.appendBuffer(mediaData);
60 test.waitForExpectedEvents(function()
62 assert_false(sourceBuffer.updating, 'updating attribute is false');
64 test.expectEvent(mediaSource, 'sourceended', 'MediaSource sourceended event');
65 mediaSource.endOfStream();
66 assert_equals(mediaSource.readyState, 'ended', 'MediaSource readyState is \'ended\'');
67 });
69 test.waitForExpectedEvents(function()
71 assert_equals(mediaSource.readyState, 'ended', 'MediaSource readyState is \'ended\'');
73 test.expectEvent(mediaSource, 'sourceopen', 'MediaSource sourceopen event');
74 sourceBuffer.mode = 'segments';
76 assert_equals(mediaSource.readyState, 'open', 'MediaSource readyState is \'open\'');
77 });
79 test.waitForExpectedEvents(function()
81 assert_equals(mediaSource.readyState, 'open', 'MediaSource readyState is \'open\'');
82 test.done();
83 });
84 }, 'Test setting SourceBuffer.mode triggers parent MediaSource \'ended\' to \'open\' transition.');
86 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
88 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
89 var fullMediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
90 var truncateAt = Math.floor(segmentInfo.media[0].size * 0.5); // Pick first 50% of segment bytes.
91 var partialMediaSegment = fullMediaSegment.subarray(0, truncateAt);
92 var mediaSegmentRemainder = fullMediaSegment.subarray(truncateAt);
94 // Append init segment.
95 test.expectEvent(sourceBuffer, 'updateend', 'Init segment append ended.');
96 sourceBuffer.appendBuffer(initSegment);
98 test.waitForExpectedEvents(function()
100 assert_false(sourceBuffer.updating, 'updating attribute is false');
101 assert_equals(sourceBuffer.mode, 'segments');
102 sourceBuffer.mode = 'segments'; // No exception should occur.
103 assert_equals(sourceBuffer.timestampOffset, 0.0);
104 sourceBuffer.timestampOffset = 10.123456789; // No exception should occur.
105 assert_equals(sourceBuffer.timestampOffset, 10.123456789); // Super-precise offsets should round-trip.
107 // Append first part of media segment.
108 test.expectEvent(sourceBuffer, 'updateend', 'Partial media segment append ended.');
109 sourceBuffer.appendBuffer(partialMediaSegment);
112 test.waitForExpectedEvents(function()
114 assert_false(sourceBuffer.updating, 'updating attribute is false');
115 assert_equals(sourceBuffer.mode, 'segments');
116 assert_throws('InvalidStateError',
117 function() { sourceBuffer.mode = 'segments'; },
118 'Setting valid sourceBuffer.mode while still parsing media segment threw InvalidStateError.');
119 assert_equals(sourceBuffer.timestampOffset, 10.123456789);
120 assert_throws('InvalidStateError',
121 function() { sourceBuffer.timestampOffset = 20.0; },
122 'Setting valid sourceBuffer.timestampOffset while still parsing media segment threw InvalidStateError.');
124 // Append remainder of media segment.
125 test.expectEvent(sourceBuffer, 'updateend', 'Append ended of remainder of media segment.');
126 sourceBuffer.appendBuffer(mediaSegmentRemainder);
129 test.waitForExpectedEvents(function()
131 assert_false(sourceBuffer.updating, 'updating attribute is false');
132 assert_equals(sourceBuffer.mode, 'segments');
133 sourceBuffer.mode = 'segments'; // No exception should occur.
134 assert_equals(sourceBuffer.timestampOffset, 10.123456789);
135 sourceBuffer.timestampOffset = 20.0; // No exception should occur.
136 test.done();
138 }, 'Test setting SourceBuffer.mode and SourceBuffer.timestampOffset while parsing media segment.');
140 // FIXME: Once 'sequence' mode implemented, add verification. See http://crbug.com/249422.
141 </script>
142 </body>
143 </html>