| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 1 | <!DOCTYPE html> |
| Matt Wolenetz | 74803c6 | 2016-08-19 01:46:40 | [diff] [blame] | 2 | <!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). --> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 3 | <html> |
| 4 | <head> |
| Aaron Colwell | aa3c90b | 2014-08-04 17:58:37 | [diff] [blame] | 5 | <title>SourceBuffer.appendWindowStart and SourceBuffer.appendWindowEnd test cases.</title> |
| Aaron Colwell | 06f8ec2 | 2014-03-07 18:09:47 | [diff] [blame] | 6 | <script src="/resources/testharness.js"></script> |
| 7 | <script src="/resources/testharnessreport.js"></script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 8 | <script src="mediasource-util.js"></script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 9 | </head> |
| 10 | <body> |
| 11 | <div id="log"></div> |
| 12 | <script> |
| 13 | mediasource_test(function(test, mediaElement, mediaSource) |
| 14 | { |
| 15 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 16 | assert_true(sourceBuffer != null, "New SourceBuffer returned"); |
| 17 | |
| 18 | sourceBuffer.appendWindowStart = 100.0; |
| 19 | sourceBuffer.appendWindowEnd = 500.0; |
| 20 | assert_equals(sourceBuffer.appendWindowStart, 100.0, "appendWindowStart is correctly set'"); |
| 21 | assert_equals(sourceBuffer.appendWindowEnd, 500.0, "appendWindowEnd is correctly set'"); |
| 22 | |
| 23 | sourceBuffer.appendWindowStart = 200.0; |
| 24 | sourceBuffer.appendWindowEnd = 400.0; |
| 25 | assert_equals(sourceBuffer.appendWindowStart, 200.0, "appendWindowStart is correctly reset'"); |
| 26 | assert_equals(sourceBuffer.appendWindowEnd, 400.0, "appendWindowEnd is correctly reset'"); |
| 27 | test.done(); |
| 28 | }, "Test correctly reset appendWindowStart and appendWindowEnd values"); |
| 29 | |
| 30 | mediasource_test(function(test, mediaElement, mediaSource) |
| 31 | { |
| 32 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 33 | assert_true(sourceBuffer != null, "New SourceBuffer returned"); |
| 34 | sourceBuffer.appendWindowEnd = 500.0; |
| 35 | |
| Aaron Colwell | cffb8af | 2014-05-23 22:27:10 | [diff] [blame] | 36 | assert_throws(new TypeError(), |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 37 | function() { sourceBuffer.appendWindowStart = Number.NEGATIVE_INFINITY; }, |
| 38 | "set appendWindowStart throws an exception for Number.NEGATIVE_INFINITY."); |
| 39 | |
| Aaron Colwell | cffb8af | 2014-05-23 22:27:10 | [diff] [blame] | 40 | assert_throws(new TypeError(), |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 41 | function() { sourceBuffer.appendWindowStart = Number.POSITIVE_INFINITY; }, |
| 42 | "set appendWindowStart throws an exception for Number.POSITIVE_INFINITY."); |
| 43 | |
| Aaron Colwell | cffb8af | 2014-05-23 22:27:10 | [diff] [blame] | 44 | assert_throws(new TypeError(), |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 45 | function() { sourceBuffer.appendWindowStart = Number.NaN; }, |
| 46 | "set appendWindowStart throws an exception for Number.NaN."); |
| 47 | |
| Jean-Yves Avenard | 231e4e1 | 2016-08-01 14:14:13 | [diff] [blame] | 48 | assert_throws(new TypeError(), |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 49 | function() { sourceBuffer.appendWindowStart = 600.0; }, |
| 50 | "set appendWindowStart throws an exception when greater than appendWindowEnd."); |
| 51 | |
| Jean-Yves Avenard | 231e4e1 | 2016-08-01 14:14:13 | [diff] [blame] | 52 | assert_throws(new TypeError(), |
| Aaron Colwell | ab0ee7b | 2014-09-09 21:10:39 | [diff] [blame] | 53 | function() { sourceBuffer.appendWindowStart = sourceBuffer.appendWindowEnd; }, |
| 54 | "set appendWindowStart throws an exception when equal to appendWindowEnd."); |
| 55 | |
| Jean-Yves Avenard | 231e4e1 | 2016-08-01 14:14:13 | [diff] [blame] | 56 | assert_throws(new TypeError(), |
| Aaron Colwell | ab0ee7b | 2014-09-09 21:10:39 | [diff] [blame] | 57 | function() { sourceBuffer.appendWindowEnd = sourceBuffer.appendWindowStart; }, |
| 58 | "set appendWindowEnd throws an exception when equal to appendWindowStart."); |
| 59 | |
| Jean-Yves Avenard | 231e4e1 | 2016-08-01 14:14:13 | [diff] [blame] | 60 | assert_throws(new TypeError(), |
| Aaron Colwell | ab0ee7b | 2014-09-09 21:10:39 | [diff] [blame] | 61 | function() { sourceBuffer.appendWindowEnd = sourceBuffer.appendWindowStart - 1; }, |
| 62 | "set appendWindowEnd throws an exception if less than appendWindowStart."); |
| 63 | |
| Jean-Yves Avenard | 231e4e1 | 2016-08-01 14:14:13 | [diff] [blame] | 64 | assert_throws(new TypeError(), |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 65 | function() { sourceBuffer.appendWindowStart = -100.0; }, |
| 66 | "set appendWindowStart throws an exception when less than 0."); |
| 67 | |
| Jean-Yves Avenard | 231e4e1 | 2016-08-01 14:14:13 | [diff] [blame] | 68 | assert_throws(new TypeError(), |
| Aaron Colwell | ab0ee7b | 2014-09-09 21:10:39 | [diff] [blame] | 69 | function() { sourceBuffer.appendWindowEnd = -100.0; }, |
| 70 | "set appendWindowEnd throws an exception when less than 0."); |
| 71 | |
| Jean-Yves Avenard | 231e4e1 | 2016-08-01 14:14:13 | [diff] [blame] | 72 | assert_throws(new TypeError(), |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 73 | function() { sourceBuffer.appendWindowEnd = Number.NaN; }, |
| 74 | "set appendWindowEnd throws an exception if NaN."); |
| Aaron Colwell | ab0ee7b | 2014-09-09 21:10:39 | [diff] [blame] | 75 | |
| Jean-Yves Avenard | 231e4e1 | 2016-08-01 14:14:13 | [diff] [blame] | 76 | assert_throws(new TypeError(), |
| Aaron Colwell | ab0ee7b | 2014-09-09 21:10:39 | [diff] [blame] | 77 | function() { sourceBuffer.appendWindowEnd = undefined; }, |
| 78 | "set appendWindowEnd throws an exception if undefined."); |
| 79 | |
| 80 | assert_throws({name: "TypeError"}, |
| 81 | function() { sourceBuffer.appendWindowStart = undefined; }, |
| 82 | "set appendWindowStart throws an exception if undefined."); |
| 83 | |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 84 | test.done(); |
| 85 | }, "Test set wrong values to appendWindowStart and appendWindowEnd."); |
| 86 | |
| Aaron Colwell | ab0ee7b | 2014-09-09 21:10:39 | [diff] [blame] | 87 | mediasource_test(function(test, mediaElement, mediaSource) |
| 88 | { |
| 89 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 90 | assert_true(sourceBuffer != null, "New SourceBuffer returned"); |
| 91 | |
| 92 | sourceBuffer.appendWindowStart = ""; |
| 93 | assert_true(sourceBuffer.appendWindowStart == 0, "appendWindowStart is 0"); |
| 94 | |
| 95 | sourceBuffer.appendWindowStart = "10"; |
| 96 | assert_true(sourceBuffer.appendWindowStart == 10, "appendWindowStart is 10"); |
| 97 | |
| 98 | sourceBuffer.appendWindowStart = null; |
| 99 | assert_true(sourceBuffer.appendWindowStart == 0, "appendWindowStart is 0"); |
| 100 | |
| 101 | sourceBuffer.appendWindowStart = true; |
| 102 | assert_true(sourceBuffer.appendWindowStart == 1, "appendWindowStart is 1"); |
| 103 | |
| 104 | sourceBuffer.appendWindowStart = false; |
| 105 | assert_true(sourceBuffer.appendWindowStart == 0, "appendWindowStart is 0"); |
| 106 | |
| 107 | sourceBuffer.appendWindowEnd = "100"; |
| 108 | assert_true(sourceBuffer.appendWindowEnd == 100, "appendWindowEnd is 100"); |
| 109 | |
| 110 | test.done(); |
| 111 | |
| 112 | }, "Test set correct values to appendWindowStart and appendWindowEnd."); |
| 113 | |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 114 | mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
| 115 | { |
| 116 | mediaSource.removeSourceBuffer(sourceBuffer); |
| 117 | assert_throws("InvalidStateError", |
| 118 | function() { sourceBuffer.appendWindowStart = 100.0; }, |
| 119 | "set appendWindowStart throws an exception when mediasource object is not associated with a buffer."); |
| 120 | |
| 121 | assert_throws("InvalidStateError", |
| 122 | function() { sourceBuffer.appendWindowEnd = 500.0; }, |
| 123 | "set appendWindowEnd throws an exception when mediasource object is not associated with a buffer."); |
| 124 | test.done(); |
| 125 | |
| 126 | }, "Test appendwindow throw error when mediasource object is not associated with a sourebuffer."); |
| 127 | |
| 128 | mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
| 129 | { |
| 130 | test.expectEvent(sourceBuffer, "updateend", "sourceBuffer"); |
| 131 | sourceBuffer.appendBuffer(mediaData); |
| 132 | assert_true(sourceBuffer.updating, "updating attribute is true"); |
| 133 | |
| 134 | assert_throws("InvalidStateError", |
| 135 | function() { sourceBuffer.appendWindowStart = 100.0; }, |
| 136 | "set appendWindowStart throws an exception when there is a pending append."); |
| 137 | |
| 138 | assert_throws("InvalidStateError", |
| 139 | function() { sourceBuffer.appendWindowEnd = 500.0; }, |
| 140 | "set appendWindowEnd throws an exception when there is a pending append."); |
| 141 | |
| 142 | test.waitForExpectedEvents(function() |
| 143 | { |
| 144 | assert_false(sourceBuffer.updating, "updating attribute is false"); |
| 145 | test.done(); |
| 146 | }); |
| 147 | }, "Test set appendWindowStart and appendWindowEnd when source buffer updating."); |
| 148 | |
| 149 | mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
| 150 | { |
| 151 | test.expectEvent(sourceBuffer, "updateend", "sourceBuffer"); |
| 152 | sourceBuffer.appendBuffer(mediaData); |
| 153 | assert_true(sourceBuffer.updating, "updating attribute is true"); |
| 154 | |
| 155 | sourceBuffer.abort(); |
| 156 | assert_equals(sourceBuffer.appendWindowStart, 0, "appendWindowStart is 0 after an abort'"); |
| Ms2ger | b8ca067 | 2015-06-29 09:51:41 | [diff] [blame] | 157 | assert_equals(sourceBuffer.appendWindowEnd, Number.POSITIVE_INFINITY, |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 158 | "appendWindowStart is POSITIVE_INFINITY after an abort"); |
| 159 | test.waitForExpectedEvents(function() |
| 160 | { |
| 161 | assert_false(sourceBuffer.updating, "updating attribute is false"); |
| 162 | test.done(); |
| 163 | }); |
| 164 | }, "Test appendWindowStart and appendWindowEnd value after a sourceBuffer.abort()."); |
| 165 | |
| Aaron Colwell | ab0ee7b | 2014-09-09 21:10:39 | [diff] [blame] | 166 | mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
| 167 | { |
| 168 | assert_equals(sourceBuffer.appendWindowStart, 0, "appendWindowStart is 0 initially"); |
| 169 | assert_equals(sourceBuffer.appendWindowEnd, Number.POSITIVE_INFINITY, |
| 170 | "appendWindowStart is POSITIVE_INFINITY initially"); |
| 171 | test.done(); |
| 172 | }, "Test read appendWindowStart and appendWindowEnd initial values."); |
| 173 | |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 174 | </script> |
| 175 | </body> |
| 176 | </html> |