mediasource-appendwindow.html (9154B)
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 <title>SourceBuffer.appendWindowStart and SourceBuffer.appendWindowEnd test cases.</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="mediasource-util.js"></script> 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 36 assert_throws_js(TypeError, 37 function() { sourceBuffer.appendWindowStart = Number.NEGATIVE_INFINITY; }, 38 "set appendWindowStart throws an exception for Number.NEGATIVE_INFINITY."); 39 40 assert_throws_js(TypeError, 41 function() { sourceBuffer.appendWindowStart = Number.POSITIVE_INFINITY; }, 42 "set appendWindowStart throws an exception for Number.POSITIVE_INFINITY."); 43 44 assert_throws_js(TypeError, 45 function() { sourceBuffer.appendWindowStart = Number.NaN; }, 46 "set appendWindowStart throws an exception for Number.NaN."); 47 48 assert_throws_js(TypeError, 49 function() { sourceBuffer.appendWindowStart = 600.0; }, 50 "set appendWindowStart throws an exception when greater than appendWindowEnd."); 51 52 assert_throws_js(TypeError, 53 function() { sourceBuffer.appendWindowStart = sourceBuffer.appendWindowEnd; }, 54 "set appendWindowStart throws an exception when equal to appendWindowEnd."); 55 56 assert_throws_js(TypeError, 57 function() { sourceBuffer.appendWindowEnd = sourceBuffer.appendWindowStart; }, 58 "set appendWindowEnd throws an exception when equal to appendWindowStart."); 59 60 assert_throws_js(TypeError, 61 function() { sourceBuffer.appendWindowEnd = sourceBuffer.appendWindowStart - 1; }, 62 "set appendWindowEnd throws an exception if less than appendWindowStart."); 63 64 assert_throws_js(TypeError, 65 function() { sourceBuffer.appendWindowStart = -100.0; }, 66 "set appendWindowStart throws an exception when less than 0."); 67 68 assert_throws_js(TypeError, 69 function() { sourceBuffer.appendWindowEnd = -100.0; }, 70 "set appendWindowEnd throws an exception when less than 0."); 71 72 assert_throws_js(TypeError, 73 function() { sourceBuffer.appendWindowEnd = Number.NaN; }, 74 "set appendWindowEnd throws an exception if NaN."); 75 76 assert_throws_js(TypeError, 77 function() { sourceBuffer.appendWindowEnd = undefined; }, 78 "set appendWindowEnd throws an exception if undefined."); 79 80 assert_throws_js(TypeError, 81 function() { sourceBuffer.appendWindowStart = undefined; }, 82 "set appendWindowStart throws an exception if undefined."); 83 84 test.done(); 85 }, "Test set wrong values to appendWindowStart and appendWindowEnd."); 86 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_equals(sourceBuffer.appendWindowStart, 0, "appendWindowStart is 0"); 94 95 sourceBuffer.appendWindowStart = "10"; 96 assert_equals(sourceBuffer.appendWindowStart, 10, "appendWindowStart is 10"); 97 98 sourceBuffer.appendWindowStart = null; 99 assert_equals(sourceBuffer.appendWindowStart, 0, "appendWindowStart is 0"); 100 101 sourceBuffer.appendWindowStart = true; 102 assert_equals(sourceBuffer.appendWindowStart, 1, "appendWindowStart is 1"); 103 104 sourceBuffer.appendWindowStart = false; 105 assert_equals(sourceBuffer.appendWindowStart, 0, "appendWindowStart is 0"); 106 107 sourceBuffer.appendWindowEnd = "100"; 108 assert_equals(sourceBuffer.appendWindowEnd, 100, "appendWindowEnd is 100"); 109 110 test.done(); 111 112 }, "Test set correct values to appendWindowStart and appendWindowEnd."); 113 114 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) 115 { 116 mediaSource.removeSourceBuffer(sourceBuffer); 117 assert_throws_dom("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_dom("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_dom("InvalidStateError", 135 function() { sourceBuffer.appendWindowStart = 100.0; }, 136 "set appendWindowStart throws an exception when there is a pending append."); 137 138 assert_throws_dom("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'"); 157 assert_equals(sourceBuffer.appendWindowEnd, Number.POSITIVE_INFINITY, 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 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 174 </script> 175 </body> 176 </html>