Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/requestmediakeysystemaccess.js

Issue 2546853003: Add W3C encrypted-media tests (Closed)
Patch Set: rebase now that content files landed Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 function runTest(config, qualifier) {
2
3 var prefix = testnamePrefix(qualifier, config.keysystem) + ', requestMediaKe ySystemAccess: ';
4
5 function expect_error(keySystem, configurations, expectedError, testname) {
6
7 var audioCapabilities = configurations.length ? configurations[0].audioC apabilities : undefined,
8 videoCapabilities = configurations.length ? configurations[0].videoC apabilities : undefined,
9 audiocontenttypes = audioCapabilities ? audioCapabilities.map( funct ion(ac) { return "'" + ac.contentType + "'"; } ).join(',') : '',
10 videocontenttypes = videoCapabilities ? videoCapabilities.map( funct ion(ac) { return "'" + ac.contentType + "'"; } ).join(',') : '',
11 modifiedtestname = testname.replace( '%audiocontenttype', audioconte nttypes ).replace( '%videocontenttype', videocontenttypes );
12
13 promise_test(function(test) {
14 return navigator.requestMediaKeySystemAccess(keySystem, configuratio ns).then(function(a) {
15 assert_unreached('Unexpected requestMediaKeySystemAccess() succe ss.');
16 }, function(e) {
17 assert_equals(e.name, expectedError);
18 });
19 }, prefix + modifiedtestname + ' should result in ' + expectedError );
20 }
21
22 function assert_subset(actual, expected, path) {
23 if (typeof expected == 'string') {
24 assert_equals(actual, expected, path);
25 } else {
26 if (expected.hasOwnProperty('length')) {
27 assert_equals(actual.length, expected.length, path + '.length');
28 }
29 for (property in expected) {
30 assert_subset(actual[property], expected[property], path + '.' + property);
31 }
32 }
33 }
34
35 function expect_config(keySystem, configurations, expectedConfiguration, tes tname) {
36 promise_test(function(test) {
37 return navigator.requestMediaKeySystemAccess(keySystem, configuratio ns).then(function(a) {
38 assert_subset(a.getConfiguration(), expectedConfiguration, testn ame + ': ');
39 });
40 }, testname);
41 }
42
43 // Tests for Key System.
44 expect_error('', [{}], 'TypeError', 'Empty Key System');
45 expect_error('com.example.unsupported', [{}], 'NotSupportedError', 'Unsuppor ted Key System');
46 expect_error(config.keysystem + '.', [{}], 'NotSupportedError', 'Key System ending in "."');
47 expect_error(config.keysystem.toUpperCase(), [{}], 'NotSupportedError', 'Cap italized Key System');
48 expect_error(config.keysystem + '\u028F', [{}], 'NotSupportedError', 'Non-AS CII Key System');
49
50 // Parent of Clear Key not supported.
51 expect_error(config.keysystem.match(/^(.*?)\./)[1], [{}], 'NotSupportedError ', 'Root domain of Key System alone');
52 expect_error(config.keysystem.match(/^(.*?)\./)[0], [{}], 'NotSupportedError ', 'Root domain of Key System, with dot');
53 expect_error(config.keysystem.match(/^(.*?\..*?)\./)[1], [{}], 'NotSupported Error', 'Domain of Key System along');
54 expect_error(config.keysystem.match(/^(.*?\..*?)\./)[0], [{}], 'NotSupported Error', 'Domain of Key System, with dot');
55
56 // Child of Clear Key not supported.
57 expect_error(config.keysystem+'.foo', [{}], 'NotSupportedError', 'Child of K ey System');
58
59 // Prefixed Clear Key not supported.
60 expect_error('webkit-'+config.keysystem, [{}], 'NotSupportedError', 'Prefixe d Key System');
61
62 // Incomplete names.
63 expect_error(config.keysystem.substr(0,7)+config.keysystem.substr(8), [{}], 'NotSupportedError', 'Missing characters in middle of Key System name');
64 expect_error(config.keysystem.substr(0,config.keysystem.length-1), [{}], 'No tSupportedError', 'Missing characters at end of Key System name');
65
66 // Spaces in key system name not supported.
67 expect_error(' '+config.keysystem, [{}], 'NotSupportedError', 'Leading space in Key System name');
68 expect_error(config.keysystem.substr(0,6) + ' ' + config.keysystem.substr(6) , [{}], 'NotSupportedError', 'Extra space in Key System name');
69 expect_error(config.keysystem + ' ', [{}], 'NotSupportedError', 'Trailing sp ace in Key System name');
70
71 // Extra dots in key systems names not supported.
72 expect_error('.' + config.keysystem, [{}], 'NotSupportedError', 'Leading dot in Key System name');
73 expect_error(config.keysystem.substr(0,6) + '.' + config.keysystem.substr(6) , [{}], 'NotSupportedError', 'Extra dot in middle of Key System name');
74 expect_error(config.keysystem + '.', [{}], 'NotSupportedError', 'Trailing do t in Key System name');
75
76 // Key system name is case sensitive.
77 if (config.keysystem !== config.keysystem.toUpperCase()) {
78 expect_error(config.keysystem.toUpperCase(), [{}], 'NotSupportedError', 'Key System name is case sensitive');
79 }
80
81 if (config.keysystem !== config.keysystem.toLowerCase()) {
82 expect_error(config.keysystem.toLowerCase(), [{}], 'NotSupportedError', 'Key System name is case sensitive');
83 }
84
85 // Tests for trivial configurations.
86 expect_error(config.keysystem, [], 'TypeError', 'Empty supportedConfiguratio ns');
87 expect_config(config.keysystem, [{}], {}, 'Empty configuration');
88
89 // Various combinations of supportedConfigurations.
90 expect_config(config.keysystem, [{
91 initDataTypes: [config.initDataType],
92 audioCapabilities: [{contentType: config.audioType}],
93 videoCapabilities: [{contentType: config.videoType}],
94 }], {
95 initDataTypes: [config.initDataType],
96 audioCapabilities: [{contentType: config.audioType}],
97 videoCapabilities: [{contentType: config.videoType}],
98 }, 'Basic supported configuration');
99
100 expect_config(config.keysystem, [{
101 initDataTypes: ['fakeidt', config.initDataType],
102 audioCapabilities: [{contentType: 'audio/fake'}, {contentType: config.au dioType}],
103 videoCapabilities: [{contentType: 'video/fake'}, {contentType: config.vi deoType}],
104 }], {
105 initDataTypes: [config.initDataType],
106 audioCapabilities: [{contentType: config.audioType}],
107 videoCapabilities: [{contentType: config.videoType}],
108 }, 'Partially supported configuration');
109
110 expect_config(config.keysystem, [{
111 audioCapabilities: [{contentType: config.audioType}],
112 }], {
113 audioCapabilities: [{contentType: config.audioType}],
114 }, 'Supported audio codec');
115
116 expect_config(config.keysystem, [{
117 audioCapabilities: [{contentType: config.audioType.replace(/^(.*?);(.*)/ , "$1; $2")}],
118 }], {
119 audioCapabilities: [{contentType: config.audioType.replace(/^(.*?);(.*)/ , "$1; $2")}],
120 }, 'ContentType formatting must be preserved');
121
122 expect_error(config.keysystem, [{
123 audioCapabilities: [{contentType: 'audio/webm; codecs=fake'}],
124 }], 'NotSupportedError', 'Unsupported audio codec (%audiocontenttype)');
125
126 expect_error(config.keysystem, [{
127 audioCapabilities: [{contentType: 'video/webm; codecs=fake'}],
128 }], 'NotSupportedError', 'Unsupported video codec (%videocontenttype)');
129
130 expect_error(config.keysystem, [{
131 audioCapabilities: [
132 {contentType: 'audio/webm; codecs=mp4a'},
133 {contentType: 'audio/webm; codecs=mp4a.40.2'}
134 ],
135 }], 'NotSupportedError', 'Mismatched audio container/codec (%audiocontenttyp e)');
136
137 expect_error(config.keysystem, [{
138 audioCapabilities: [{contentType: config.videoType}],
139 }], 'NotSupportedError', 'Video codec specified in audio field (%audioconten ttype)');
140
141 expect_error(config.keysystem, [{
142 videoCapabilities: [{contentType: config.audioType}],
143 }], 'NotSupportedError', 'Audio codec specified in video field (%videoconten ttype)');
144
145 expect_error(config.keysystem, [{
146 audioCapabilities: [
147 {contentType: 'audio/webm; codecs=avc1'},
148 {contentType: 'audio/webm; codecs=avc1.42e01e'}
149 ],
150 }], 'NotSupportedError', 'Mismatched audio container/codec (%audiocontenttyp e)');
151
152 expect_error(config.keysystem, [{
153 audioCapabilities: [
154 {contentType: 'audio/mp4; codecs=vorbis'}
155 ],
156 }], 'NotSupportedError', 'Mismatched audio container/codec (%audiocontenttyp e)');
157
158 expect_config(config.keysystem, [
159 {initDataTypes: ['fakeidt']},
160 {initDataTypes: [config.initDataType]}
161 ], {initDataTypes: [config.initDataType]}, 'Two configurations, one supporte d');
162
163 expect_config(config.keysystem, [
164 {initDataTypes: [config.initDataType]},
165 {}
166 ], {initDataTypes: [config.initDataType]}, 'Two configurations, both support ed');
167
168 // Audio MIME type does not support video codecs.
169 expect_error(config.keysystem, [{
170 audioCapabilities: [
171 {contentType: 'audio/webm; codecs="vp8,vorbis"'},
172 {contentType: 'audio/webm; codecs="vorbis, vp8"'},
173 {contentType: 'audio/webm; codecs="vp8"'}
174 ],
175 }], 'NotSupportedError', 'Audio MIME type does not support video codecs (web m) (%audiocontenttype)');
176
177 expect_error(config.keysystem, [{
178 audioCapabilities: [
179 {contentType: 'audio/mp4; codecs="avc1"'},
180 {contentType: 'audio/mp4; codecs="avc1.4d401e"'},
181 ],
182 }], 'NotSupportedError', 'Audio MIME type does not support video codecs (mp4 ) (%audiocontenttype)');
183
184 // Video MIME type does not support audio codecs.
185 expect_error(config.keysystem, [{
186 videoCapabilities: [
187 {contentType: 'video/webm; codecs="vp8,vorbis"'},
188 {contentType: 'video/webm; codecs="vorbis, vp8"'},
189 {contentType: 'video/webm; codecs="vorbis"'}
190 ],
191 }], 'NotSupportedError', 'Video MIME type does not support audio codecs (web m) (%videocontenttype)');
192
193 expect_error(config.keysystem, [{
194 videoCapabilities: [
195 {contentType: 'video/mp4; codecs="mp4a"'},
196 {contentType: 'video/mp4; codecs="mp4a.40.2"'}
197 ],
198 }], 'NotSupportedError', 'Video MIME type does not support audio codecs (mp4 ) (%videocontenttype)');
199
200 // WebM does not support AVC1/AAC.
201 expect_error(config.keysystem, [{
202 audioCapabilities: [
203 {contentType: 'audio/webm; codecs="aac"'},
204 {contentType: 'audio/webm; codecs="avc1"'},
205 {contentType: 'audio/webm; codecs="vp8,aac"'}
206 ],
207 }], 'NotSupportedError', 'WebM audio does not support AVC1/AAC (%audioconten ttype)');
208
209 expect_error(config.keysystem, [{
210 videoCapabilities: [
211 {contentType: 'video/webm; codecs="aac"'},
212 {contentType: 'video/webm; codecs="avc1"'},
213 {contentType: 'video/webm; codecs="vp8,aac"'}
214 ],
215 }], 'NotSupportedError', 'WebM video does not support AVC1/AAC (%videoconten ttype)');
216
217 // Extra space is allowed in contentType.
218 expect_config(config.keysystem, [{
219 videoCapabilities: [{contentType: ' ' + config.videoType}],
220 }], {
221 videoCapabilities: [{contentType: ' ' + config.videoType}],
222 }, 'Leading space in contentType');
223
224 expect_config(config.keysystem, [{
225 videoCapabilities: [{contentType: config.videoType.replace( /^(.*?);(.*) /, "$1 ;$2")}],
226 }], {
227 videoCapabilities: [{contentType: config.videoType.replace( /^(.*?);(.*) /, "$1 ;$2")}],
228 }, 'Space before ; in contentType');
229
230
231 expect_config(config.keysystem, [{
232 videoCapabilities: [{contentType: config.videoType + ' '}],
233 }], {
234 videoCapabilities: [{contentType: config.videoType + ' '}],
235 }, 'Trailing space in contentType');
236
237 expect_config(config.keysystem, [{
238 videoCapabilities: [{contentType: config.videoType.replace( /^(.*?codecs =\")(.*)/, "$1 $2")}],
239 }], {
240 videoCapabilities: [{contentType: config.videoType.replace( /^(.*?codecs =\")(.*)/, "$1 $2")}],
241 }, 'Space at start of codecs parameter');
242
243 expect_config(config.keysystem, [{
244 videoCapabilities: [{contentType: config.videoType.replace( /^(.*?codecs =\".*)\"/, "$1 \"")}],
245 }], {
246 videoCapabilities: [{contentType: config.videoType.replace( /^(.*?codecs =\".*)\"/, "$1 \"")}],
247 }, 'Space at end of codecs parameter');
248
249 // contentType is not case sensitive (except the codec names).
250 expect_config(config.keysystem, [{
251 videoCapabilities: [{contentType: 'V' + config.videoType.substr(1)}],
252 }], {
253 videoCapabilities: [{contentType: 'V' + config.videoType.substr(1)}],
254 }, 'Video/' );
255
256 expect_config(config.keysystem, [{
257 videoCapabilities: [{contentType: config.videoType.replace( /^(.*?)c(ode cs.*)/, "$1C$2")}],
258 }], {
259 videoCapabilities: [{contentType: config.videoType.replace( /^(.*?)c(ode cs.*)/, "$1C$2")}],
260 }, 'Codecs=');
261
262 var t = config.videoType.match(/(.*?)(;.*)/);
263 expect_config(config.keysystem, [{
264 videoCapabilities: [{contentType: t[1].toUpperCase() + t[2]}],
265 }], {
266 videoCapabilities: [{contentType: t[1].toUpperCase() + t[2]}],
267 }, 'Upper case MIME type');
268
269 t = config.videoType.match(/(.*?)codecs(.*)/);
270 expect_config(config.keysystem, [{
271 videoCapabilities: [{contentType: t[1] + 'CODECS' + t[2]}],
272 }], {
273 videoCapabilities: [{contentType: t[1] + 'CODECS' + t[2]}],
274 }, 'CODECS=');
275
276 // Unrecognized attributes are not allowed.
277 expect_error(config.keysystem, [{
278 videoCapabilities: [{contentType: 'video/webm; foo="bar"'}],
279 }], 'NotSupportedError', 'Unrecognized foo with webm (%videocontenttype)');
280
281 expect_error(config.keysystem, [{
282 videoCapabilities: [{contentType: 'video/mp4; foo="bar"'}],
283 }], 'NotSupportedError', 'Unrecognized foo with mp4 (%videocontenttype)');
284
285 expect_error(config.keysystem, [{
286 videoCapabilities: [{contentType: config.videoType + '; foo="bar"'}],
287 }], 'NotSupportedError', 'Unrecognized foo with codecs (%videocontenttype)') ;
288
289 // Invalid contentTypes.
290 expect_error(config.keysystem, [{
291 videoCapabilities: [{contentType: 'fake'}],
292 }], 'NotSupportedError', 'contentType: %videocontenttype');
293
294 expect_error(config.keysystem, [{
295 audioCapabilities: [{contentType: 'audio/fake'}],
296 }], 'NotSupportedError', 'contentType: %audiocontenttype');
297
298 expect_error(config.keysystem, [{
299 videoCapabilities: [{contentType: 'video/fake'}],
300 }], 'NotSupportedError', 'contentType: %videocontenttype');
301
302 // The actual codec names are case sensitive.
303 t = config.videoType.match( /(.*?codecs=\")(.*?\")(.*)/ );
304 if (t[2] !== t[2].toUpperCase()) {
305 expect_error(config.keysystem, [{
306 videoCapabilities: [{contentType: t[1] + t[2].toUpperCase() + t[3] } ],
307 }], 'NotSupportedError', 'contentType: %videocontenttype');
308 }
309
310 if (t[2] !== t[2].toLowerCase()) {
311 expect_error(config.keysystem, [{
312 videoCapabilities: [{contentType: t[1] + t[2].toLowerCase() + t[3] } ],
313 }], 'NotSupportedError', 'contentType: %videocontenttype');
314 }
315
316 // Extra comma is not allowed in codecs.
317 expect_error(config.keysystem, [{
318 videoCapabilities: [{contentType: t[1] + ',' + t[2] + t[3] }],
319 }], 'NotSupportedError', 'contentType: %videocontenttype');
320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698