4 <script src=
"/w3c/resources/testharness.js"></script>
5 <script src=
"/w3c/resources/testharnessreport.js"></script>
7 <link rel='stylesheet' href='/w3c/resources/testharness.css'
>
12 function checkConstructionSucceeds(type
, language
, label
, kinds
, byteStreamTrackID
)
14 var trackDefault
= new TrackDefault(type
, language
, label
, kinds
, byteStreamTrackID
);
15 assert_equals(trackDefault
.type
, type
, "type");
16 assert_equals(trackDefault
.language
, language
, "language");
17 assert_equals(trackDefault
.label
, label
, "label");
18 assert_equals(trackDefault
.byteStreamTrackID
, byteStreamTrackID
, "byteStreamTrackID");
19 assert_array_equals(trackDefault
.kinds
, kinds
, "kinds");
22 function checkConstructionFails(type
, language
, label
, kinds
, byteStreamTrackID
)
24 assert_throws(new TypeError(),
25 function() { new TrackDefault(type
, language
, label
, kinds
, byteStreamTrackID
); },
26 "TrackDefault construction threw an exception");
29 function trackDefaultConstructionTest(type
, language
, label
, kinds
, byteStreamTrackID
, expectation
, description
)
34 checkConstructionSucceeds(type
, language
, label
, kinds
, byteStreamTrackID
);
36 checkConstructionFails(type
, language
, label
, kinds
, byteStreamTrackID
);
37 }, description
+ ": type '" + type
+ "', language '" + language
+ "', label '" + label
+ "', multiple kinds, byteStreamTrackID '" + byteStreamTrackID
+ "'");
39 // If all of |kinds| are expected to succeed, also test each kind individually.
40 if (!expectation
|| kinds
.length
<= 1)
42 for (var i
= 0; i
< kinds
.length
; ++i
) {
45 checkConstructionSucceeds(type
, language
, label
, new Array(kinds
[i
]), byteStreamTrackID
);
46 }, description
+ ": type '" + type
+ "', language '" + language
+ "', label '" + label
+ "', kind '" + kinds
[i
] + "', byteStreamTrackID '" + byteStreamTrackID
+ "'");
50 var VALID_AUDIO_TRACK_KINDS
= [
60 var VALID_VIDEO_TRACK_KINDS
= [
70 var VALID_TEXT_TRACK_KINDS
= [
78 trackDefaultConstructionTest("audio", "en-US", "audio label", VALID_AUDIO_TRACK_KINDS
, "1", true, "Test valid audio kinds");
80 trackDefaultConstructionTest("video", "en-US", "video label", VALID_VIDEO_TRACK_KINDS
, "1", true, "Test valid video kinds");
82 trackDefaultConstructionTest("text", "en-US", "text label", VALID_TEXT_TRACK_KINDS
, "1", true, "Test valid text kinds");
84 trackDefaultConstructionTest("audio", "en-US", "audio label", VALID_VIDEO_TRACK_KINDS
, "1", false, "Test mixed valid and invalid audio kinds");
86 trackDefaultConstructionTest("video", "en-US", "video label", VALID_AUDIO_TRACK_KINDS
, "1", false, "Test mixed valid and invalid video kinds");
88 trackDefaultConstructionTest("text", "en-US", "text label", VALID_VIDEO_TRACK_KINDS
, "1", false, "Test mixed valid and invalid text kinds");
90 trackDefaultConstructionTest("invalid type", "en-US", "label", VALID_AUDIO_TRACK_KINDS
, "1", false, "Test invalid 'type' parameter type passed to TrackDefault constructor");
94 checkConstructionFails("audio", "en-US", "label", "this is not a valid sequence", "1");
95 }, "Test invalid 'kinds' parameter type passed to TrackDefault constructor");
99 var trackDefault
= new TrackDefault("audio", "en-US", "label", VALID_AUDIO_TRACK_KINDS
, "1");
100 var kinds
= trackDefault
.kinds
;
101 kinds
[0] = "invalid kind";
102 assert_equals(kinds
[0], "invalid kind", "local kinds is updated");
103 assert_equals(VALID_AUDIO_TRACK_KINDS
[0], "alternative", "local original kinds unchanged");
104 assert_array_equals(trackDefault
.kinds
, VALID_AUDIO_TRACK_KINDS
, "trackDefault kinds unchanged");
105 }, "Test updating the retval of TrackDefault.kinds does not modify TrackDefault.kinds");