mediasource-trackdefaultlist.html (3956B)
1 <!DOCTYPE html> 2 <!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). --> 3 <meta charset="utf-8"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script> 7 test(function() 8 { 9 var originalTrackDefaults = [ 10 // Same everything, but different byteStreamTrackID, should be allowed by the constructor. 11 new TrackDefault("audio", "en-US", "label", ["main"], ""), 12 new TrackDefault("audio", "en-US", "label", ["main"], "1"), 13 new TrackDefault("audio", "en-US", "label", ["main"], "2"), 14 new TrackDefault("audio", "en-US", "label", [""], "3"), 15 16 // Same everything, but different type, should be allowed by the constructor. 17 new TrackDefault("video", "en-US", "label", ["main"], ""), 18 new TrackDefault("video", "en-US", "label", ["main"], "1"), 19 new TrackDefault("video", "en-US", "label", ["main"], "2"), 20 new TrackDefault("video", "en-US", "label", [""], "3") 21 ]; 22 23 // Get a new array containing the same objects as |originalTrackDefaults|. 24 var trackDefaults = originalTrackDefaults.slice(); 25 26 var trackDefaultList = new TrackDefaultList(trackDefaults); 27 assert_array_equals(trackDefaultList, originalTrackDefaults, "construction and read-back succeeded"); 28 assert_equals(trackDefaultList[trackDefaultList.length], undefined, "out of range indexed property getter result is undefined"); 29 assert_equals(trackDefaultList[trackDefaultList.length + 1], undefined, "out of range indexed property getter result is undefined"); 30 31 // Introduce same-type, same-empty-string-byteStreamTrackId conflict in trackDefaults[0 vs 4]. 32 trackDefaults[4] = new TrackDefault("audio", "en-US", "label", ["main"], ""); 33 assert_equals(trackDefaults[0].type, trackDefaults[4].type, "same-type conflict setup"); 34 assert_equals(trackDefaults[0].byteStreamTrackID, trackDefaults[4].byteStreamTrackID, "same-byteStreamTrackID conflict setup"); 35 assert_throws_dom("InvalidAccessError", 36 function() { new TrackDefaultList(trackDefaults); }, 37 "TrackDefaultList construction should throw exception due to same type and byteStreamTrackID across at least 2 items in trackDefaults"); 38 39 // Introduce same-type, same-non-empty-string-byteStreamTrackId conflict in trackDefaults[4 vs 5]. 40 trackDefaults[4] = new TrackDefault("video", "en-US", "label", ["main"], "1"); 41 assert_equals(trackDefaults[4].type, trackDefaults[5].type, "same-type conflict setup"); 42 assert_equals(trackDefaults[4].byteStreamTrackID, trackDefaults[5].byteStreamTrackID, "same-byteStreamTrackID conflict setup"); 43 assert_throws_dom("InvalidAccessError", 44 function() { new TrackDefaultList(trackDefaults); }, 45 "TrackDefaultList construction should throw exception due to same type and byteStreamTrackID across at least 2 items in trackDefaults"); 46 47 // Confirm the constructed TrackDefaultList makes a shallow copy of the supplied TrackDefault sequence. 48 assert_array_equals(trackDefaultList, originalTrackDefaults, "read-back of original trackDefaultList unchanged"); 49 50 }, "Test track default list construction, length, and indexed property getter"); 51 52 test(function() 53 { 54 var trackDefaultList = new TrackDefaultList(); 55 assert_array_equals(trackDefaultList, [], "empty list constructable without supplying optional trackDefaults parameter"); 56 57 trackDefaultList = new TrackDefaultList([]); 58 assert_array_equals(trackDefaultList, [], "empty list constructable by supplying empty sequence as optional trackDefaults parameter"); 59 }, "Test empty track default list construction with and without optional trackDefaults parameter"); 60 </script>