File's structured serialization should serialize lastModified attribute
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / media-source / mediasource-sourcebuffer-mode.html
1 <!DOCTYPE html>
2 <!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
3 <html>
4     <head>
5         <meta charset="utf-8">
6         <title>SourceBuffer.mode test cases.</title>
7         <script src="/resources/testharness.js"></script>
8         <script src="/resources/testharnessreport.js"></script>
9         <script src="mediasource-util.js"></script>
10     </head>
11     <body>
12         <div id="log"></div>
13         <script>
14           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
15           {
16               assert_equals(sourceBuffer.mode, 'segments', 'default append mode should be \'segments\'');
17               test.done();
18           }, 'Test initial value of SourceBuffer.mode is "segments"');
19
20           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
21           {
22               sourceBuffer.mode = 'sequence';
23               assert_equals(sourceBuffer.mode, 'sequence', 'mode after setting it to \'sequence\'');
24
25               // Setting a mode that is not in AppendMode IDL enum should be ignored and not cause exception.
26               sourceBuffer.mode = 'invalidmode';
27               sourceBuffer.mode = null;
28               sourceBuffer.mode = '';
29               sourceBuffer.mode = 'Segments';
30               assert_equals(sourceBuffer.mode, 'sequence', 'mode unchanged by attempts to set invalid modes');
31
32               sourceBuffer.mode = 'segments';
33               assert_equals(sourceBuffer.mode, 'segments', 'mode after setting it to \'segments\'');
34               test.done();
35           }, 'Test setting SourceBuffer.mode');
36
37           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
38           {
39               mediaSource.removeSourceBuffer(sourceBuffer);
40               assert_throws('InvalidStateError',
41                   function() { sourceBuffer.mode = 'segments'; },
42                   'Setting valid sourceBuffer.mode on removed SourceBuffer should throw InvalidStateError.');
43               test.done();
44           }, 'Test setting a removed SourceBuffer\'s mode');
45
46           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
47           {
48               sourceBuffer.appendBuffer(mediaData);
49               assert_true(sourceBuffer.updating, 'updating attribute is true');
50               assert_throws('InvalidStateError',
51                   function() { sourceBuffer.mode = 'segments'; },
52                   'Setting valid sourceBuffer.mode on updating SourceBuffer threw InvalidStateError.');
53               test.done();
54           }, 'Test setting SourceBuffer.mode while still updating');
55
56           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
57           {
58               test.expectEvent(sourceBuffer, 'updateend', 'Append ended.');
59               sourceBuffer.appendBuffer(mediaData);
60
61               test.waitForExpectedEvents(function()
62               {
63                   assert_false(sourceBuffer.updating, 'updating attribute is false');
64
65                   test.expectEvent(mediaSource, 'sourceended', 'MediaSource sourceended event');
66                   mediaSource.endOfStream();
67                   assert_equals(mediaSource.readyState, 'ended', 'MediaSource readyState is \'ended\'');
68               });
69
70               test.waitForExpectedEvents(function()
71               {
72                   assert_equals(mediaSource.readyState, 'ended', 'MediaSource readyState is \'ended\'');
73
74                   test.expectEvent(mediaSource, 'sourceopen', 'MediaSource sourceopen event');
75                   sourceBuffer.mode = 'segments';
76
77                   assert_equals(mediaSource.readyState, 'open', 'MediaSource readyState is \'open\'');
78               });
79
80               test.waitForExpectedEvents(function()
81               {
82                   assert_equals(mediaSource.readyState, 'open', 'MediaSource readyState is \'open\'');
83                   test.done();
84               });
85           }, 'Test setting SourceBuffer.mode triggers parent MediaSource \'ended\' to \'open\' transition.');
86
87           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
88           {
89               var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
90               var fullMediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
91               var truncateAt = Math.floor(segmentInfo.media[0].size * 0.5);  // Pick first 50% of segment bytes.
92               var partialMediaSegment = fullMediaSegment.subarray(0, truncateAt);
93               var mediaSegmentRemainder = fullMediaSegment.subarray(truncateAt);
94
95               // Append init segment.
96               test.expectEvent(sourceBuffer, 'updateend', 'Init segment append ended.');
97               sourceBuffer.appendBuffer(initSegment);
98
99               test.waitForExpectedEvents(function()
100               {
101                   assert_false(sourceBuffer.updating, 'updating attribute is false');
102                   assert_equals(sourceBuffer.mode, 'segments');
103                   sourceBuffer.mode = 'segments';  // No exception should occur.
104                   assert_equals(sourceBuffer.timestampOffset, 0.0);
105                   sourceBuffer.timestampOffset = 10.123456789;  // No exception should occur.
106                   assert_equals(sourceBuffer.timestampOffset, 10.123456789);  // Super-precise offsets should round-trip.
107
108                   // Append first part of media segment.
109                   test.expectEvent(sourceBuffer, 'updateend', 'Partial media segment append ended.');
110                   sourceBuffer.appendBuffer(partialMediaSegment);
111               });
112
113               test.waitForExpectedEvents(function()
114               {
115                   assert_false(sourceBuffer.updating, 'updating attribute is false');
116                   assert_equals(sourceBuffer.mode, 'segments');
117                   assert_throws('InvalidStateError',
118                       function() { sourceBuffer.mode = 'segments'; },
119                       'Setting valid sourceBuffer.mode while still parsing media segment threw InvalidStateError.');
120                   assert_equals(sourceBuffer.timestampOffset, 10.123456789);
121                   assert_throws('InvalidStateError',
122                       function() { sourceBuffer.timestampOffset = 20.0; },
123                       'Setting valid sourceBuffer.timestampOffset while still parsing media segment threw InvalidStateError.');
124
125                   // Append remainder of media segment.
126                   test.expectEvent(sourceBuffer, 'updateend', 'Append ended of remainder of media segment.');
127                   sourceBuffer.appendBuffer(mediaSegmentRemainder);
128               });
129
130               test.waitForExpectedEvents(function()
131               {
132                   assert_false(sourceBuffer.updating, 'updating attribute is false');
133                   assert_equals(sourceBuffer.mode, 'segments');
134                   sourceBuffer.mode = 'segments';  // No exception should occur.
135                   assert_equals(sourceBuffer.timestampOffset, 10.123456789);
136                   sourceBuffer.timestampOffset = 20.0;  // No exception should occur.
137                   test.done();
138               });
139           }, 'Test setting SourceBuffer.mode and SourceBuffer.timestampOffset while parsing media segment.');
140         </script>
141     </body>
142 </html>