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> |
11 <script> | 11 <script> |
12 test(function () | 12 test(function () |
13 { | 13 { |
14 var mediaSource = new MediaSource(); | 14 var mediaSource = new MediaSource(); |
15 assert_equals(mediaSource.sourceBuffers.length, 0, "sourceBuffers
is empty"); | 15 assert_equals(mediaSource.sourceBuffers.length, 0, 'sourceBuffers
is empty'); |
16 assert_equals(mediaSource.activeSourceBuffers.length, 0, "activeSo
urceBuffers is empty"); | 16 assert_equals(mediaSource.activeSourceBuffers.length, 0, 'activeSo
urceBuffers is empty'); |
17 assert_equals(mediaSource.readyState, "closed", "readyState is 'cl
osed'"); | 17 assert_equals(mediaSource.readyState, 'closed', 'readyState is "cl
osed"'); |
18 assert_true(Number.isNaN(mediaSource.duration), "duration is NaN")
; | 18 assert_true(Number.isNaN(mediaSource.duration), 'duration is NaN')
; |
19 }, "Test attribute values on a closed MediaSource object."); | 19 }, 'Test attribute values on a closed MediaSource object.'); |
20 | 20 |
21 test(function () | 21 test(function () |
22 { | 22 { |
23 var mediaSource = new MediaSource(); | 23 var mediaSource = new MediaSource(); |
24 assert_throws("InvalidStateError", | 24 assert_throws('InvalidStateError', |
25 function() { mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO
_ONLY_TYPE); }, | 25 function() { mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO
_ONLY_TYPE); }, |
26 "addSourceBuffer() throws an exception when closed."); | 26 'addSourceBuffer() throws an exception when closed.'); |
27 }, "Test addSourceBuffer() while closed."); | 27 }, 'Test addSourceBuffer() while closed.'); |
28 | 28 |
29 mediasource_test(function(test, mediaElement, mediaSource) | 29 mediasource_test(function(test, mediaElement, mediaSource) |
30 { | 30 { |
31 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUD
IO_ONLY_TYPE); | 31 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUD
IO_ONLY_TYPE); |
32 | 32 |
33 // Setup a handler to run when the MediaSource closes. | 33 // Setup a handler to run when the MediaSource closes. |
34 mediaSource.addEventListener('sourceclose', test.step_func(functio
n (event) | 34 mediaSource.addEventListener('sourceclose', test.step_func(functio
n (event) |
35 { | 35 { |
36 assert_equals(mediaSource.sourceBuffers.length, 0, "sourceBuff
ers is empty"); | 36 assert_equals(mediaSource.sourceBuffers.length, 0, 'sourceBuff
ers is empty'); |
37 assert_equals(mediaSource.activeSourceBuffers.length, 0, "acti
veSourceBuffers is empty"); | 37 assert_equals(mediaSource.activeSourceBuffers.length, 0, 'acti
veSourceBuffers is empty'); |
38 assert_equals(mediaSource.readyState, "closed", "readyState is
'closed'"); | 38 assert_equals(mediaSource.readyState, 'closed', 'readyState is
"closed"'); |
39 assert_true(Number.isNaN(mediaSource.duration), "duration is N
aN"); | 39 assert_true(Number.isNaN(mediaSource.duration), 'duration is N
aN'); |
40 assert_throws("NotFoundError", | 40 assert_throws('NotFoundError', |
41 function() { mediaSource.removeSourceBuffer(sourceBuffer);
}, | 41 function() { mediaSource.removeSourceBuffer(sourceBuffer);
}, |
42 "removeSourceBuffer() throws an exception when closed."); | 42 'removeSourceBuffer() throws an exception when closed.'); |
43 test.done(); | 43 test.done(); |
44 })); | 44 })); |
45 | 45 |
46 // Trigger the MediaSource to close. | 46 // Trigger the MediaSource to close. |
47 mediaElement.src = ""; | 47 mediaElement.src = ''; |
48 }, "Test removeSourceBuffer() while closed."); | 48 }, 'Test removeSourceBuffer() while closed.'); |
49 | 49 |
50 test(function () | 50 test(function () |
51 { | 51 { |
52 var mediaSource = new MediaSource(); | 52 var mediaSource = new MediaSource(); |
53 assert_throws("InvalidStateError", | 53 assert_throws('InvalidStateError', |
54 function() { mediaSource.endOfStream(); }, | 54 function() { mediaSource.endOfStream(); }, |
55 "endOfStream() throws an exception when closed."); | 55 'endOfStream() throws an exception when closed.'); |
56 }, "Test endOfStream() while closed."); | 56 }, 'Test endOfStream() while closed.'); |
57 | 57 |
58 test(function () | 58 test(function () |
59 { | 59 { |
60 var mediaSource = new MediaSource(); | 60 var mediaSource = new MediaSource(); |
61 assert_throws("InvalidStateError", | 61 assert_throws('InvalidStateError', |
62 function() { mediaSource.endOfStream("decode"); }, | 62 function() { mediaSource.endOfStream('decode'); }, |
63 "endOfStream(decode) throws an exception when closed."); | 63 'endOfStream(decode) throws an exception when closed.'); |
64 }, "Test endOfStream(decode) while closed."); | 64 }, 'Test endOfStream(decode) while closed.'); |
65 | 65 |
66 test(function () | 66 test(function () |
67 { | 67 { |
68 var mediaSource = new MediaSource(); | 68 var mediaSource = new MediaSource(); |
69 assert_throws("InvalidStateError", | 69 assert_throws('InvalidStateError', |
70 function() { mediaSource.endOfStream("network"); }, | 70 function() { mediaSource.endOfStream('network'); }, |
71 "endOfStream(network) throws an exception when closed."); | 71 'endOfStream(network) throws an exception when closed.'); |
72 }, "Test endOfStream(network) while closed."); | 72 }, 'Test endOfStream(network) while closed.'); |
73 | 73 |
74 | 74 |
75 test(function () | 75 test(function () |
76 { | 76 { |
77 var mediaSource = new MediaSource(); | 77 var mediaSource = new MediaSource(); |
78 assert_throws("InvalidStateError", | 78 assert_throws('InvalidStateError', |
79 function() { mediaSource.duration = 10; }, | 79 function() { mediaSource.duration = 10; }, |
80 "Setting duration throws an exception when closed."); | 80 'Setting duration throws an exception when closed.'); |
81 }, "Test setting duration while closed."); | 81 }, 'Test setting duration while closed.'); |
82 | 82 |
83 mediasource_test(function(test, mediaElement, mediaSource) | 83 mediasource_test(function(test, mediaElement, mediaSource) |
84 { | 84 { |
85 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUD
IO_ONLY_TYPE); | 85 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUD
IO_ONLY_TYPE); |
86 | 86 |
87 assert_equals(mediaSource.readyState, "open", "readyState is 'open
'"); | 87 assert_equals(mediaSource.readyState, 'open', 'readyState is "open
"'); |
88 // Setup a handler to run when the MediaSource closes. | 88 // Setup a handler to run when the MediaSource closes. |
89 mediaSource.addEventListener('sourceclose', test.step_func(functio
n (event) | 89 mediaSource.addEventListener('sourceclose', test.step_func(functio
n (event) |
90 { | 90 { |
91 assert_equals(mediaSource.readyState, "closed", "readyState is
'closed'"); | 91 assert_equals(mediaSource.readyState, 'closed', 'readyState is
"closed"'); |
92 assert_throws("InvalidStateError", | 92 assert_throws('InvalidStateError', |
93 function() { mediaSource.duration = 10; }, | 93 function() { mediaSource.duration = 10; }, |
94 "Setting duration when closed throws an exception"); | 94 'Setting duration when closed throws an exception'); |
95 test.done(); | 95 test.done(); |
96 })); | 96 })); |
97 | 97 |
98 // Trigger the MediaSource to close. | 98 // Trigger the MediaSource to close. |
99 mediaElement.src = ""; | 99 mediaElement.src = ''; |
100 }, "Test setting duration while open->closed."); | 100 }, 'Test setting duration while open->closed.'); |
101 | 101 |
102 mediasource_test(function(test, mediaElement, mediaSource) | 102 mediasource_test(function(test, mediaElement, mediaSource) |
103 { | 103 { |
104 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUD
IO_ONLY_TYPE); | 104 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUD
IO_ONLY_TYPE); |
105 | 105 |
106 assert_equals(mediaSource.readyState, "open", "readyState is 'open
'"); | 106 assert_equals(mediaSource.readyState, 'open', 'readyState is "open
"'); |
107 // Setup a handler to run when the MediaSource closes. | 107 // Setup a handler to run when the MediaSource closes. |
108 mediaSource.addEventListener('sourceclose', test.step_func(functio
n (event) | 108 mediaSource.addEventListener('sourceclose', test.step_func(functio
n (event) |
109 { | 109 { |
110 assert_equals(mediaSource.readyState, "closed", "readyState is
'closed'"); | 110 assert_equals(mediaSource.readyState, 'closed', 'readyState is
"closed"'); |
111 assert_true(Number.isNaN(mediaSource.duration), "duration is N
aN"); | 111 assert_true(Number.isNaN(mediaSource.duration), 'duration is N
aN'); |
112 test.done(); | 112 test.done(); |
113 })); | 113 })); |
114 | 114 |
115 // Trigger the MediaSource to close. | 115 // Trigger the MediaSource to close. |
116 mediaElement.src = ""; | 116 mediaElement.src = ''; |
117 }, "Test getting duration while open->closed."); | 117 }, 'Test getting duration while open->closed.'); |
| 118 |
| 119 mediasource_test(function(test, mediaElement, mediaSource) |
| 120 { |
| 121 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUD
IO_ONLY_TYPE); |
| 122 |
| 123 assert_equals(mediaSource.readyState, 'open', 'readyState is open'
); |
| 124 |
| 125 // Setup a handler to run when the MediaSource closes. |
| 126 mediaSource.addEventListener('sourceclose', test.step_func(functio
n (event) |
| 127 { |
| 128 assert_equals(mediaSource.readyState, 'closed', 'readyState is
closed'); |
| 129 assert_throws('InvalidStateError', |
| 130 function() { sourceBuffer.abort(); }, |
| 131 'sourceBuffer.abort() throws INVALID_STATE_ERROR'); |
| 132 test.done(); |
| 133 })); |
| 134 |
| 135 // Trigger the MediaSource to close. |
| 136 mediaElement.src = ''; |
| 137 }, 'Test sourcebuffer.abort when closed.'); |
118 </script> | 138 </script> |
119 </body> | 139 </body> |
120 </html> | 140 </html> |
OLD | NEW |