File's structured serialization should serialize lastModified attribute
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / media-source / mediasource-trackdefault.html
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     function checkConstructionSucceeds(type, language, label, kinds, byteStreamTrackID)
8     {
9         var trackDefault = new TrackDefault(type, language, label, kinds, byteStreamTrackID);
10         assert_equals(trackDefault.type, type, "type");
11         assert_equals(trackDefault.language, language, "language");
12         assert_equals(trackDefault.label, label, "label");
13         assert_equals(trackDefault.byteStreamTrackID, byteStreamTrackID, "byteStreamTrackID");
14         assert_array_equals(trackDefault.kinds, kinds, "kinds");
15     }
16
17     function checkConstructionFails(type, language, label, kinds, byteStreamTrackID)
18     {
19         assert_throws(new TypeError(),
20             function() { new TrackDefault(type, language, label, kinds, byteStreamTrackID); },
21             "TrackDefault construction threw an exception");
22     }
23
24     function trackDefaultConstructionTest(type, language, label, kinds, byteStreamTrackID, expectation, description)
25     {
26         test(function()
27         {
28             if (expectation)
29                 checkConstructionSucceeds(type, language, label, kinds, byteStreamTrackID);
30             else
31                 checkConstructionFails(type, language, label, kinds, byteStreamTrackID);
32         }, description + ": type '" + type + "', language '" + language + "', label '" + label + "', multiple kinds, byteStreamTrackID '" + byteStreamTrackID + "'");
33
34         // If all of |kinds| are expected to succeed, also test each kind individually.
35         if (!expectation || kinds.length <= 1)
36             return;
37         for (var i = 0; i < kinds.length; ++i) {
38             test(function()
39             {
40                 checkConstructionSucceeds(type, language, label, new Array(kinds[i]), byteStreamTrackID);
41             }, description + ": type '" + type + "', language '" + language + "', label '" + label + "', kind '" + kinds[i] + "', byteStreamTrackID '" + byteStreamTrackID + "'");
42         }
43     }
44
45     var VALID_AUDIO_TRACK_KINDS = [
46         "alternative",
47         "descriptions",
48         "main",
49         "main-desc",
50         "translation",
51         "commentary",
52         "",
53     ];
54
55     var VALID_VIDEO_TRACK_KINDS = [
56         "alternative",
57         "captions",
58         "main",
59         "sign",
60         "subtitles",
61         "commentary",
62         "",
63     ];
64
65     var VALID_TEXT_TRACK_KINDS = [
66         "subtitles",
67         "captions",
68         "descriptions",
69         "chapters",
70         "metadata",
71     ];
72
73     trackDefaultConstructionTest("audio", "en-US", "audio label", VALID_AUDIO_TRACK_KINDS, "1", true, "Test valid audio kinds");
74
75     trackDefaultConstructionTest("video", "en-US", "video label", VALID_VIDEO_TRACK_KINDS, "1", true, "Test valid video kinds");
76
77     trackDefaultConstructionTest("text", "en-US", "text label", VALID_TEXT_TRACK_KINDS, "1", true, "Test valid text kinds");
78
79     trackDefaultConstructionTest("audio", "en-US", "audio label", VALID_VIDEO_TRACK_KINDS, "1", false, "Test mixed valid and invalid audio kinds");
80
81     trackDefaultConstructionTest("video", "en-US", "video label", VALID_AUDIO_TRACK_KINDS, "1", false, "Test mixed valid and invalid video kinds");
82
83     trackDefaultConstructionTest("text", "en-US", "text label", VALID_VIDEO_TRACK_KINDS, "1", false, "Test mixed valid and invalid text kinds");
84
85     trackDefaultConstructionTest("invalid type", "en-US", "label", VALID_AUDIO_TRACK_KINDS, "1", false, "Test invalid 'type' parameter type passed to TrackDefault constructor");
86
87     test(function()
88     {
89         checkConstructionFails("audio", "en-US", "label", "this is not a valid sequence", "1");
90     }, "Test invalid 'kinds' parameter type passed to TrackDefault constructor");
91
92     test(function()
93     {
94         var trackDefault = new TrackDefault("audio", "en-US", "label", VALID_AUDIO_TRACK_KINDS, "1");
95         var kinds = trackDefault.kinds;
96         kinds[0] = "invalid kind";
97         assert_equals(kinds[0], "invalid kind", "local kinds is updated");
98         assert_equals(VALID_AUDIO_TRACK_KINDS[0], "alternative", "local original kinds unchanged");
99         assert_array_equals(trackDefault.kinds, VALID_AUDIO_TRACK_KINDS, "trackDefault kinds unchanged");
100     }, "Test updating the retval of TrackDefault.kinds does not modify TrackDefault.kinds");
101 </script>