Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / media-source / mediasource-sourcebufferlist.html
blobe2d8c49bb2fce314ee3dca14631c2d0066d71bed
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/w3c/resources/testharness.js"></script>
5 <script src="/w3c/resources/testharnessreport.js"></script>
6 <script src="mediasource-util.js"></script>
8 <link rel='stylesheet' href='/w3c/resources/testharness.css'>
9 </head>
10 <body>
11 <div id="log"></div>
12 <script>
13 function verifySourceBufferLists(mediaSource, expected)
15 assert_equals(mediaSource.sourceBuffers.length, expected.length, "sourceBuffers length");
16 assert_equals(mediaSource.activeSourceBuffers.length, 0, "activeSourceBuffers length");
17 for (var i = 0; i < expected.length; ++i)
18 assert_equals(mediaSource.sourceBuffers[i], expected[i], "Verifying mediaSource.sourceBuffers[" + i + "]");
21 mediasource_test(function(test, mediaElement, mediaSource)
23 test.expectEvent(mediaSource.sourceBuffers, "addsourcebuffer", "sourceBuffers");
24 var sourceBufferA = mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO_ONLY_TYPE);
25 var sourceBufferB = null;
27 test.waitForExpectedEvents(function()
29 test.expectEvent(mediaSource.sourceBuffers, "addsourcebuffer", "sourceBuffers");
30 sourceBufferB = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_ONLY_TYPE);
32 verifySourceBufferLists(mediaSource, [sourceBufferA, sourceBufferB]);
33 });
35 test.waitForExpectedEvents(function()
37 test.expectEvent(mediaSource.sourceBuffers, "removesourcebuffer", "sourceBuffers");
38 mediaSource.removeSourceBuffer(sourceBufferA);
40 verifySourceBufferLists(mediaSource, [sourceBufferB]);
42 test.expectEvent(mediaSource.sourceBuffers, "addsourcebuffer", "sourceBuffers");
43 sourceBufferA = mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO_ONLY_TYPE);
45 verifySourceBufferLists(mediaSource, [sourceBufferB, sourceBufferA]);
46 });
48 test.waitForExpectedEvents(function()
50 test.done();
51 });
52 }, "Test SourceBufferList event dispatching.");
54 mediasource_test(function(test, mediaElement, mediaSource)
56 test.expectEvent(mediaSource.sourceBuffers, "addsourcebuffer", "sourceBuffers");
57 test.expectEvent(mediaSource.sourceBuffers, "addsourcebuffer", "sourceBuffers");
58 var sourceBufferA = mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO_ONLY_TYPE);
59 var sourceBufferB = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_ONLY_TYPE);
61 verifySourceBufferLists(mediaSource, [sourceBufferA, sourceBufferB]);
63 test.waitForExpectedEvents(function()
65 verifySourceBufferLists(mediaSource, [sourceBufferA, sourceBufferB]);
67 // Force the media element to close the MediaSource object.
68 test.expectEvent(mediaSource.sourceBuffers, "removesourcebuffer", "sourceBuffers");
69 test.expectEvent(mediaSource, "sourceclose", "mediaSource closing");
70 test.expectEvent(mediaElement, "error", "mediaElement error loading");
71 mediaElement.src = "";
72 });
74 test.waitForExpectedEvents(function()
76 assert_equals(mediaElement.error.code, MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, "Expected error code");
77 assert_equals(mediaSource.readyState, "closed", "mediaSource is closed.");
79 verifySourceBufferLists(mediaSource, []);
80 test.done();
81 });
82 }, "Test that only 1 removesourcebuffer event fires on sourceBuffers when the MediaSource closes.");
84 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
86 // FIXME: Test two activeSourceBuffers, either demuxed or once multitrack is supported.
87 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
89 test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
90 test.expectEvent(mediaElement, "loadedmetadata", "loadedmetadata done.");
91 sourceBuffer.appendBuffer(initSegment);
93 test.waitForExpectedEvents(function()
95 assert_equals(mediaSource.sourceBuffers.length, 1, "mediaSource sourceBuffers");
96 assert_equals(mediaSource.activeSourceBuffers.length, 1, "mediaSource activeSourceBuffers");
98 // Force the media element to close the MediaSource object.
99 test.expectEvent(mediaSource.sourceBuffers, "removesourcebuffer", "sourcebuffers");
100 test.expectEvent(mediaSource.activeSourceBuffers, "removesourcebuffer", "activesourcebuffers");
101 test.expectEvent(mediaSource, "sourceclose", "mediaSource closing");
102 test.expectEvent(mediaElement, "error", "mediaElement error loading");
103 mediaElement.src = "";
106 test.waitForExpectedEvents(function()
108 assert_equals(mediaElement.error.code, MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, "Expected error code");
109 assert_equals(mediaSource.readyState, "closed", "mediaSource is closed.");
110 assert_equals(mediaSource.sourceBuffers.length, 0, "mediaSource sourceBuffers");
111 assert_equals(mediaSource.activeSourceBuffers.length, 0, "mediaSource activeSourceBuffers");
112 test.done();
114 }, "Test removesourcebuffer event firing on sourceBuffers and activeSourceBuffers when MediaSource closes.", { allow_media_element_error: true } );
116 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
118 // Basic checks
119 assert_equals(mediaSource.sourceBuffers.length, 1, "mediaSource sourceBuffers length");
120 assert_equals(mediaSource.sourceBuffers[0], sourceBuffer, "matching sourceBuffer");
121 assert_not_equals(undefined, null, "null is different from undefined");
123 // SourceBufferList's indexed property getter is anonymous. At least ensure no 'item' is defined.
124 assert_equals(mediaSource.sourceBuffers.item, undefined, "'item' is undefined for MediaSource.sourceBuffers");
126 // Out-of-range indices should result in undefined.
127 assert_equals(mediaSource.sourceBuffers[1], undefined, "undefined result for out-of-range (+1 index)");
128 assert_equals(mediaSource.sourceBuffers[2], undefined, "undefined result for out-of-range (+2 index)");
129 assert_equals(mediaSource.sourceBuffers[undefined], undefined, "undefined result for out-of-range (undefined index)")
130 assert_equals(mediaSource.sourceBuffers[null], undefined, "undefined result for out-of-range (null index)");
131 assert_equals(mediaSource.sourceBuffers[""], undefined, "undefined result for out-of-range (empty string index)");
132 assert_equals(mediaSource.sourceBuffers["invalid index"], undefined, "undefined result for out-of-range (string index)");
134 test.done();
135 }, "Test out-of-range SourceBufferList indexed property getter behavior");
136 </script>
137 </body>
138 </html>