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'
>
14 function sourceBufferTrackDefaultsTest(callback
, description
)
16 mediasource_test(function(test
, mediaElement
, mediaSource
)
18 var sourceBuffer
= mediaSource
.addSourceBuffer(MediaSourceUtil
.AUDIO_VIDEO_TYPE
);
19 assert_array_equals(sourceBuffer
.trackDefaults
, [], "Empty initial SourceBuffer.trackDefaults");
20 callback(test
, mediaElement
, mediaSource
, sourceBuffer
);
24 sourceBufferTrackDefaultsTest(function(test
, mediaElement
, mediaSource
, sourceBuffer
)
26 var emptyList
= new TrackDefaultList([]);
27 assert_not_equals(sourceBuffer
.trackDefaults
, emptyList
, "Initial trackDefaults object differs from new empty list");
29 sourceBuffer
.trackDefaults
= emptyList
;
31 assert_array_equals(sourceBuffer
.trackDefaults
, [], "Round-tripped empty trackDefaults");
32 assert_equals(sourceBuffer
.trackDefaults
, emptyList
, "Round-tripped the empty TrackDefaultList object");
34 }, "Test round-trip of empty SourceBuffer.trackDefaults");
36 sourceBufferTrackDefaultsTest(function(test
, mediaElement
, mediaSource
, sourceBuffer
)
38 var trackDefault
= new TrackDefault("audio", "en-US", "audio label", ["main"], "1");
39 var trackDefaults
= new TrackDefaultList([ trackDefault
]);
41 sourceBuffer
.trackDefaults
= trackDefaults
;
43 assert_array_equals(sourceBuffer
.trackDefaults
, trackDefaults
, "Round-tripped non-empty trackDefaults");
44 assert_equals(sourceBuffer
.trackDefaults
.length
, 1, "Confirmed non-empty trackDefaults");
45 assert_equals(sourceBuffer
.trackDefaults
, trackDefaults
, "Round-tripped the non-empty TrackDefaultList object");
47 }, "Test round-trip of non-empty SourceBuffer.trackDefaults");
49 sourceBufferTrackDefaultsTest(function(test
, mediaElement
, mediaSource
, sourceBuffer
)
51 mediaSource
.removeSourceBuffer(sourceBuffer
);
52 assert_throws("InvalidStateError",
53 function() { sourceBuffer
.trackDefaults
= new TrackDefaultList([]); },
54 "Exception thrown when setting trackDefaults on SourceBuffer that is removed from MediaSource");
56 }, "Test setting trackDefaults on an already-removed SourceBuffer");
58 mediasource_testafterdataloaded(function(test
, mediaElement
, mediaSource
, segmentInfo
, sourceBuffer
, mediaData
)
60 assert_array_equals(sourceBuffer
.trackDefaults
, [], "Empty initial SourceBuffer.trackDefaults");
61 test
.expectEvent(sourceBuffer
, "updateend", "Append ended");
62 sourceBuffer
.appendBuffer(mediaData
);
63 assert_true(sourceBuffer
.updating
, "SourceBuffer is updating");
65 assert_throws("InvalidStateError",
66 function() { sourceBuffer
.trackDefaults
= new TrackDefaultList([]); },
67 "Exception thrown when setting trackDefaults on SourceBuffer that is updating");
69 test
.waitForExpectedEvents(function()
71 assert_false(sourceBuffer
.updating
, "SourceBuffer is not updating");
72 sourceBuffer
.trackDefaults
= new TrackDefaultList([]);
75 }, "Test setting trackDefaults on a SourceBuffer that is updating");
77 sourceBufferTrackDefaultsTest(function(test
, mediaElement
, mediaSource
, sourceBuffer
)
79 assert_throws(new TypeError(),
80 function() { sourceBuffer
.trackDefaults
= null; },
81 "null should be disallowed by trackDefaults setter");
83 }, "Test setting null SourceBuffer.trackDefaults");