| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| Aaron Colwell | aa3c90b | 2014-08-04 17:58:37 | [diff] [blame^] | 4 | <title>Test MediaSource behavior when a seek is requested while another seek is pending.</title> |
| Aaron Colwell | 06f8ec2 | 2014-03-07 18:09:47 | [diff] [blame] | 5 | <script src="/resources/testharness.js"></script> |
| 6 | <script src="/resources/testharnessreport.js"></script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 7 | <script src="mediasource-util.js"></script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 8 | </head> |
| 9 | <body> |
| 10 | <div id="log"></div> |
| 11 | <script> |
| 12 | |
| 13 | mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
| 14 | { |
| 15 | mediaElement.play(); |
| 16 | |
| 17 | var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init); |
| 18 | var firstSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]); |
| 19 | var secondSegmentInfo = segmentInfo.media[2]; |
| 20 | var secondSegment = MediaSourceUtil.extractSegmentData(mediaData, secondSegmentInfo); |
| 21 | |
| 22 | // Append the initialization segment to trigger a transition to HAVE_METADATA. |
| 23 | test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); |
| 24 | test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA'); |
| 25 | sourceBuffer.appendBuffer(initSegment); |
| 26 | |
| 27 | test.waitForExpectedEvents(function() |
| 28 | { |
| 29 | assert_false(mediaElement.seeking, 'mediaElement is not seeking'); |
| 30 | assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA, 'Still in HAVE_METADATA'); |
| 31 | |
| 32 | // Seek to a new position before letting the initial seek to 0 completes. |
| 33 | test.expectEvent(mediaElement, 'seeking', 'mediaElement'); |
| 34 | mediaElement.currentTime = secondSegmentInfo.timecode; |
| 35 | assert_true(mediaElement.seeking, 'mediaElement is seeking'); |
| 36 | |
| 37 | // Append media data for time 0. |
| 38 | test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); |
| 39 | sourceBuffer.appendBuffer(firstSegment); |
| 40 | }); |
| 41 | |
| 42 | test.waitForExpectedEvents(function() |
| 43 | { |
| 44 | // Verify that the media data didn't trigger a 'seeking' event or a transition beyond HAVE_METADATA. |
| 45 | assert_true(mediaElement.seeking, 'mediaElement is still seeking'); |
| 46 | assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA, 'Still in HAVE_METADATA'); |
| 47 | |
| 48 | // Append media data for the current position. |
| 49 | test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); |
| 50 | test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek'); |
| 51 | test.expectEvent(mediaElement, 'playing', 'mediaElement playing'); |
| 52 | sourceBuffer.appendBuffer(secondSegment); |
| 53 | }); |
| 54 | |
| 55 | test.waitForExpectedEvents(function() |
| 56 | { |
| 57 | test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended'); |
| 58 | mediaSource.endOfStream(); |
| 59 | }); |
| 60 | |
| 61 | test.waitForExpectedEvents(function() |
| 62 | { |
| 63 | assert_greater_than(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater than HAVE_CURRENT_DATA'); |
| 64 | test.done(); |
| 65 | }); |
| 66 | |
| 67 | }, 'Test seeking to a new location before transitioning beyond HAVE_METADATA.', {timeout: 10000} ); |
| 68 | |
| 69 | mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
| 70 | { |
| 71 | mediaElement.play(); |
| 72 | |
| 73 | var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init); |
| 74 | var firstSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]); |
| 75 | var secondSegmentInfo = segmentInfo.media[2]; |
| 76 | var secondSegment = MediaSourceUtil.extractSegmentData(mediaData, secondSegmentInfo); |
| 77 | var thirdSegmentInfo = segmentInfo.media[4]; |
| 78 | var thirdSegment = MediaSourceUtil.extractSegmentData(mediaData, thirdSegmentInfo); |
| 79 | |
| 80 | // Append the initialization segment to trigger a transition to HAVE_METADATA. |
| 81 | test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); |
| 82 | test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA'); |
| 83 | sourceBuffer.appendBuffer(initSegment); |
| 84 | |
| 85 | test.waitForExpectedEvents(function() |
| 86 | { |
| 87 | test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); |
| 88 | test.expectEvent(mediaElement, 'playing', 'mediaElement playing'); |
| 89 | sourceBuffer.appendBuffer(firstSegment); |
| 90 | }); |
| 91 | |
| 92 | test.waitForExpectedEvents(function() |
| 93 | { |
| 94 | assert_greater_than(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater than HAVE_CURRENT_DATA'); |
| 95 | |
| 96 | // Seek to a new position. |
| 97 | test.expectEvent(mediaElement, 'seeking', 'mediaElement'); |
| 98 | mediaElement.currentTime = secondSegmentInfo.timecode; |
| 99 | assert_true(mediaElement.seeking, 'mediaElement is seeking'); |
| 100 | |
| 101 | }); |
| 102 | |
| 103 | test.waitForExpectedEvents(function() |
| 104 | { |
| 105 | assert_true(mediaElement.seeking, 'mediaElement is still seeking'); |
| 106 | |
| 107 | // Seek to a second position while the first seek is still pending. |
| 108 | test.expectEvent(mediaElement, 'seeking', 'mediaElement'); |
| 109 | mediaElement.currentTime = thirdSegmentInfo.timecode; |
| 110 | assert_true(mediaElement.seeking, 'mediaElement is seeking'); |
| 111 | |
| 112 | // Append media data for the first seek position. |
| 113 | test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); |
| 114 | sourceBuffer.appendBuffer(secondSegment); |
| 115 | }); |
| 116 | |
| 117 | test.waitForExpectedEvents(function() |
| 118 | { |
| 119 | assert_true(mediaElement.seeking, 'mediaElement is still seeking'); |
| 120 | |
| 121 | // Append media data for the second seek position. |
| 122 | test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); |
| 123 | test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek'); |
| 124 | sourceBuffer.appendBuffer(thirdSegment); |
| 125 | }); |
| 126 | |
| 127 | test.waitForExpectedEvents(function() |
| 128 | { |
| 129 | assert_false(mediaElement.seeking, 'mediaElement is no longer seeking'); |
| 130 | |
| 131 | test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended'); |
| 132 | mediaSource.endOfStream(); |
| 133 | }); |
| 134 | |
| 135 | test.waitForExpectedEvents(function() |
| 136 | { |
| 137 | assert_greater_than(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater than HAVE_CURRENT_DATA'); |
| 138 | test.done(); |
| 139 | }); |
| 140 | }, 'Test seeking to a new location during a pending seek.', {timeout: 10000} ); |
| 141 | </script> |
| 142 | </body> |
| 143 | </html> |