| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="/w3c/resources/testharness.js"></script> | 4 <script src="/w3c/resources/testharness.js"></script> |
| 5 <script src="/w3c/resources/testharnessreport.js"></script> | 5 <script src="/w3c/resources/testharnessreport.js"></script> |
| 6 <script src="mediasource-util.js"></script> | 6 <script src="mediasource-util.js"></script> |
| 7 <link rel='stylesheet' href='/w3c/resources/testharness.css'> | 7 <link rel='stylesheet' href='/w3c/resources/testharness.css'> |
| 8 </head> | 8 </head> |
| 9 <body> | 9 <body> |
| 10 <div id="log"></div> | 10 <div id="log"></div> |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 }); | 136 }); |
| 137 }, 'Test endOfStream completes previous seek to truncated duration'); | 137 }, 'Test endOfStream completes previous seek to truncated duration'); |
| 138 | 138 |
| 139 mediasource_testafterdataloaded(function(test, mediaElement, mediaSour
ce, segmentInfo, sourceBuffer, mediaData) | 139 mediasource_testafterdataloaded(function(test, mediaElement, mediaSour
ce, segmentInfo, sourceBuffer, mediaData) |
| 140 { | 140 { |
| 141 assert_greater_than(segmentInfo.duration, 2, 'Sufficient test medi
a duration'); | 141 assert_greater_than(segmentInfo.duration, 2, 'Sufficient test medi
a duration'); |
| 142 | 142 |
| 143 var fullDuration = segmentInfo.duration; | 143 var fullDuration = segmentInfo.duration; |
| 144 var newDuration = 0.5; | 144 var newDuration = 0.5; |
| 145 | 145 |
| 146 var durationchangeEventCounter = 0; |
| 147 var expectedDurationChangeEventCount = 1; |
| 148 var durationchangeEventHandler = test.step_func(function(event) |
| 149 { |
| 150 assert_equals(mediaElement.duration, newDuration, 'mediaElemen
t newDuration'); |
| 151 assert_equals(mediaSource.duration, newDuration, 'mediaSource
newDuration'); |
| 152 durationchangeEventCounter++; |
| 153 }); |
| 154 |
| 146 mediaElement.play(); | 155 mediaElement.play(); |
| 147 | 156 |
| 148 // Append all the segments | 157 // Append all the segments |
| 149 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); | 158 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); |
| 150 test.expectEvent(mediaElement, 'playing', 'Playing triggered'); | 159 test.expectEvent(mediaElement, 'playing', 'Playing triggered'); |
| 151 sourceBuffer.appendBuffer(mediaData); | 160 sourceBuffer.appendBuffer(mediaData); |
| 152 | 161 |
| 153 test.waitForExpectedEvents(function() | 162 test.waitForExpectedEvents(function() |
| 154 { | 163 { |
| 155 assert_equals(mediaElement.duration, fullDuration, 'mediaEleme
nt fullDuration'); | 164 assert_equals(mediaElement.duration, fullDuration, 'mediaEleme
nt fullDuration'); |
| 156 assert_equals(mediaSource.duration, fullDuration, 'mediaSource
fullDuration'); | 165 assert_equals(mediaSource.duration, fullDuration, 'mediaSource
fullDuration'); |
| 157 assert_less_than(mediaElement.currentTime, newDuration / 2, 'm
ediaElement currentTime'); | 166 assert_less_than(mediaElement.currentTime, newDuration / 2, 'm
ediaElement currentTime'); |
| 158 | 167 |
| 159 var durationchangeEventCounter = 0; | |
| 160 var expectedDurationChangeEventCount = 1; | |
| 161 var durationchangeEventHandler = test.step_func(function(event
) | |
| 162 { | |
| 163 assert_equals(mediaSource.readyState, 'ended', 'mediaSourc
e ended'); | |
| 164 assert_equals(mediaElement.duration, newDuration, 'mediaEl
ement newDuration'); | |
| 165 assert_equals(mediaSource.duration, newDuration, 'mediaSou
rce newDuration'); | |
| 166 durationchangeEventCounter++; | |
| 167 }); | |
| 168 | |
| 169 // Media load also fires 'durationchange' event, so only start
counting them now. | 168 // Media load also fires 'durationchange' event, so only start
counting them now. |
| 170 mediaElement.addEventListener('durationchange', durationchange
EventHandler); | 169 mediaElement.addEventListener('durationchange', durationchange
EventHandler); |
| 171 | 170 |
| 172 // Truncate duration. This should result in one 'durationchang
e' fired. | 171 // Truncate duration. This should result in one 'durationchang
e' fired. |
| 173 mediaSource.duration = newDuration; | 172 mediaSource.duration = newDuration; |
| 174 | 173 |
| 174 assert_true(sourceBuffer.updating, "sourceBuffer.updating"); |
| 175 test.expectEvent(sourceBuffer, "updateend"); |
| 176 }); |
| 177 |
| 178 test.waitForExpectedEvents(function() |
| 179 { |
| 175 // Set duration again to make sure it does not trigger another
'durationchange' event. | 180 // Set duration again to make sure it does not trigger another
'durationchange' event. |
| 176 mediaSource.duration = newDuration; | 181 mediaSource.duration = newDuration; |
| 177 | 182 |
| 183 assert_false(sourceBuffer.updating, "sourceBuffer.updating"); |
| 184 |
| 178 // Mark endOfStream so that playback can reach 'ended' at the
new duration. | 185 // Mark endOfStream so that playback can reach 'ended' at the
new duration. |
| 179 test.expectEvent(mediaSource, 'sourceended', 'endOfStream ackn
owledged'); | 186 test.expectEvent(mediaSource, 'sourceended', 'endOfStream ackn
owledged'); |
| 180 mediaSource.endOfStream(); | 187 mediaSource.endOfStream(); |
| 181 | 188 |
| 182 // endOfStream can change duration downwards slightly. | 189 // endOfStream can change duration downwards slightly. |
| 183 // Allow for one more 'durationchange' event only in this case
. | 190 // Allow for one more 'durationchange' event only in this case
. |
| 184 var currentDuration = mediaSource.duration; | 191 var currentDuration = mediaSource.duration; |
| 185 if (currentDuration != newDuration) { | 192 if (currentDuration != newDuration) { |
| 186 assert_true(currentDuration > 0 && currentDuration < newDu
ration, 'adjusted duration'); | 193 assert_true(currentDuration > 0 && currentDuration < newDu
ration, 'adjusted duration'); |
| 187 newDuration = currentDuration; | 194 newDuration = currentDuration; |
| 188 ++expectedDurationChangeEventCount; | 195 ++expectedDurationChangeEventCount; |
| 189 } | 196 } |
| 190 | 197 |
| 191 // Allow media to play to end while counting 'durationchange'
events. | 198 // Allow media to play to end while counting 'durationchange'
events. |
| 192 test.expectEvent(mediaElement, 'ended', 'Playback ended'); | 199 test.expectEvent(mediaElement, 'ended', 'Playback ended'); |
| 193 test.waitForExpectedEvents(function() | 200 test.waitForExpectedEvents(function() |
| 194 { | 201 { |
| 195 mediaElement.removeEventListener('durationchange', duratio
nchangeEventHandler); | 202 mediaElement.removeEventListener('durationchange', duratio
nchangeEventHandler); |
| 196 assert_equals(durationchangeEventCounter, expectedDuration
ChangeEventCount, 'durationchanges'); | 203 assert_equals(durationchangeEventCounter, expectedDuration
ChangeEventCount, 'durationchanges'); |
| 197 test.done(); | 204 test.done(); |
| 198 }); | 205 }); |
| 199 }); | 206 }); |
| 200 }, 'Test setting same duration multiple times does not fire duplicate
durationchange', {timeout: 2500}); | 207 }, 'Test setting same duration multiple times does not fire duplicate
durationchange', {timeout: 2500}); |
| 201 | 208 |
| 202 </script> | 209 </script> |
| 203 </body> | 210 </body> |
| 204 </html> | 211 </html> |
| OLD | NEW |