4 <title>Test navigator.requestMediaKeySystemAccess()
</title>
5 <script src=
"encrypted-media-utils.js"></script>
6 <script src=
"../../resources/testharness.js"></script>
7 <script src=
"../../resources/testharnessreport.js"></script>
12 function expect_error(keySystem
, configurations
, expectedError
, testName
) {
13 promise_test(function(test
) {
14 return navigator
.requestMediaKeySystemAccess(keySystem
, configurations
).then(function(a
) {
15 assert_unreached('Unexpected requestMediaKeySystemAccess() success.');
17 assert_equals(e
.name
, expectedError
);
22 function assert_subset(actual
, expected
, path
) {
23 if (typeof expected
== 'string') {
24 assert_equals(actual
, expected
, path
);
26 if (expected
.hasOwnProperty('length'))
27 assert_equals(actual
.length
, expected
.length
, path
+ '.length');
28 for (property
in expected
)
29 assert_subset(actual
[property
], expected
[property
], path
+ '.' + property
);
33 function expect_config(keySystem
, configurations
, expectedConfiguration
, testName
) {
34 promise_test(function(test
) {
35 return navigator
.requestMediaKeySystemAccess(keySystem
, configurations
).then(function(a
) {
36 assert_subset(a
.getConfiguration(), expectedConfiguration
, 'getConfiguration()');
41 // Tests for keySystem.
42 expect_error('', [{}], 'InvalidAccessError', 'Empty keySystem');
43 expect_error('com.example.unsupported', [{}], 'NotSupportedError', 'Unsupported keySystem');
44 expect_error('org.w3.clearkey.', [{}], 'NotSupportedError', 'keySystem ends with "."');
45 expect_error('org.w3.ClearKey', [{}], 'NotSupportedError', 'Capitalized keySystem');
46 expect_error('org.w3.clearke\u028F', [{}], 'NotSupportedError', 'Non-ASCII keySystem');
48 // Parent of Clear Key not supported.
49 expect_error('org', [{}], 'NotSupportedError', 'Parent of Clear Key (org)');
50 expect_error('org.', [{}], 'NotSupportedError', 'Parent of Clear Key (org.)');
51 expect_error('org.w3', [{}], 'NotSupportedError', 'Parent of Clear Key (org.w3)');
52 expect_error('org.w3.', [{}], 'NotSupportedError', 'Parent of Clear Key (org.w3.)');
54 // Child of Clear Key not supported.
55 expect_error('org.w3.clearkey.foo', [{}], 'NotSupportedError', 'Child of Clear Key');
57 // Prefixed Clear Key not supported.
58 expect_error('webkit-org.w3.clearkey', [{}], 'NotSupportedError', 'Prefixed Clear Key');
61 expect_error('org.w3.learkey', [{}], 'NotSupportedError', 'Incomplete name org.w3.learkey');
62 expect_error('org.w3.clearke', [{}], 'NotSupportedError', 'Incomplete name org.w3.clearke');
63 expect_error('or.w3.clearkey', [{}], 'NotSupportedError', 'Incomplete name or.w3.clearkey');
65 // Spaces in key system name not supported.
66 expect_error(' org.w3.clearkey', [{}], 'NotSupportedError', 'Leading space in key system name');
67 expect_error('org.w3. clearkey', [{}], 'NotSupportedError', 'Extra space in key system name');
68 expect_error('org.w3.clearkey ', [{}], 'NotSupportedError', 'Trailing space in key system name');
70 // Extra dots in key systems names not supported.
71 expect_error('.org.w3.clearkey', [{}], 'NotSupportedError', 'Leading dot in key systems name');
72 expect_error('org.w3.clearkey.', [{}], 'NotSupportedError', 'Trailing dot in key systems name');
73 expect_error('org.w3..clearkey', [{}], 'NotSupportedError', 'Double dot in key systems name');
74 expect_error('org.w3.clear.key', [{}], 'NotSupportedError', 'Extra dot in key systems name');
76 // Key system name is case sensitive.
77 expect_error('org.w3.Clearkey', [{}], 'NotSupportedError', 'Key system name is case sensitive');
78 expect_error('Org.w3.clearkey', [{}], 'NotSupportedError', 'Key system name is case sensitive');
80 // Tests for trivial configurations.
81 expect_error('org.w3.clearkey', [], 'InvalidAccessError', 'Empty supportedConfigurations');
82 expect_config('org.w3.clearkey', [{}], {}, 'Empty configuration');
84 // Various combinations of supportedConfigurations.
85 expect_config('org.w3.clearkey', [{
86 initDataTypes
: ['webm'],
87 audioCapabilities
: [{contentType
: 'audio/webm'}],
88 videoCapabilities
: [{contentType
: 'video/webm'}],
90 initDataTypes
: ['webm'],
91 audioCapabilities
: [{contentType
: 'audio/webm'}],
92 videoCapabilities
: [{contentType
: 'video/webm'}],
93 }, 'Basic supported configuration');
95 expect_config('org.w3.clearkey', [{
96 initDataTypes
: ['fakeidt', 'webm'],
97 audioCapabilities
: [{contentType
: 'audio/fake'}, {contentType
: 'audio/webm'}],
98 videoCapabilities
: [{contentType
: 'video/fake'}, {contentType
: 'video/webm'}],
100 initDataTypes
: ['webm'],
101 audioCapabilities
: [{contentType
: 'audio/webm'}],
102 videoCapabilities
: [{contentType
: 'video/webm'}],
103 }, 'Partially supported configuration');
105 expect_config('org.w3.clearkey', [{
106 audioCapabilities
: [{contentType
: 'audio/webm; codecs=vorbis'}],
108 audioCapabilities
: [{contentType
: 'audio/webm; codecs=vorbis'}],
109 }, 'Supported audio codec');
111 expect_config('org.w3.clearkey', [{
112 audioCapabilities
: [{contentType
: 'audio/webm; codecs="vorbis"'}],
114 audioCapabilities
: [{contentType
: 'audio/webm; codecs="vorbis"'}],
115 }, 'ContentType formatting must be preserved');
117 expect_error('org.w3.clearkey', [{
118 audioCapabilities
: [{contentType
: 'audio/webm; codecs=fake'}],
119 }], 'NotSupportedError', 'Unsupported audio codec');
121 expect_error('org.w3.clearkey', [{
123 {contentType
: 'audio/webm; codecs=mp4a'},
124 {contentType
: 'audio/webm; codecs=mp4a.40.2'}
126 }], 'NotSupportedError', 'Mismatched audio container/codec');
128 expect_config('org.w3.clearkey', [{
129 videoCapabilities
: [{contentType
: 'video/webm; codecs=vp8'}],
131 videoCapabilities
: [{contentType
: 'video/webm; codecs=vp8'}],
132 }, 'Supported video codec');
134 expect_error('org.w3.clearkey', [{
135 audioCapabilities
: [{contentType
: 'video/webm; codecs=vp8'}],
136 }], 'NotSupportedError', 'Video codec specified in audio field');
138 expect_error('org.w3.clearkey', [{
139 videoCapabilities
: [{contentType
: 'audio/webm; codecs=vorbis'}],
140 }], 'NotSupportedError', 'Audio codec specified in video field');
142 expect_error('org.w3.clearkey', [{
143 audioCapabilities
: [{contentType
: 'video/webm; codecs=fake'}],
144 }], 'NotSupportedError', 'Unsupported video codec');
146 expect_error('org.w3.clearkey', [{
148 {contentType
: 'audio/webm; codecs=avc1'},
149 {contentType
: 'audio/webm; codecs=avc1.42e01e'}
151 }], 'NotSupportedError', 'Mismatched video container/codec');
153 expect_config('org.w3.clearkey', [
154 {initDataTypes
: ['fakeidt']},
155 {initDataTypes
: ['webm']}
156 ], {initDataTypes
: ['webm']}, 'Two configurations, one supported');
158 expect_config('org.w3.clearkey', [
159 {initDataTypes
: ['webm']},
161 ], {initDataTypes
: ['webm']}, 'Two configurations, both supported');
163 // Audio MIME type does not support video codecs.
164 expect_error('org.w3.clearkey', [{
166 {contentType
: 'audio/webm; codecs="vp8,vorbis"'},
167 {contentType
: 'audio/webm; codecs="vorbis, vp8"'},
168 {contentType
: 'audio/webm; codecs="vp8"'}
170 }], 'NotSupportedError', 'Audio MIME type does not support video codecs.');
172 // Video MIME type does not support audio codecs.
173 expect_error('org.w3.clearkey', [{
175 {contentType
: 'video/webm; codecs="vp8,vorbis"'},
176 {contentType
: 'video/webm; codecs="vorbis, vp8"'},
177 {contentType
: 'video/webm; codecs="vorbis"'}
179 }], 'NotSupportedError', 'Video MIME type does not support audio codecs.');
181 // WebM does not support AVC1/AAC.
182 expect_error('org.w3.clearkey', [{
184 {contentType
: 'audio/webm; codecs="aac"'},
185 {contentType
: 'audio/webm; codecs="avc1"'},
186 {contentType
: 'audio/webm; codecs="vp8,aac"'}
188 }], 'NotSupportedError', 'WebM audio does not support AVC1/AAC.');
190 expect_error('org.w3.clearkey', [{
192 {contentType
: 'video/webm; codecs="aac"'},
193 {contentType
: 'video/webm; codecs="avc1"'},
194 {contentType
: 'video/webm; codecs="vp8,aac"'}
196 }], 'NotSupportedError', 'WebM video does not support AVC1/AAC.');
198 // Extra space is allowed in contentType.
199 expect_config('org.w3.clearkey', [{
200 videoCapabilities
: [{contentType
: ' video/webm; codecs="vp8"'}],
202 videoCapabilities
: [{contentType
: ' video/webm; codecs="vp8"'}],
203 }, 'Leading space in contentType');
205 expect_config('org.w3.clearkey', [{
206 videoCapabilities
: [{contentType
: 'video/webm ; codecs="vp8"'}],
208 videoCapabilities
: [{contentType
: 'video/webm ; codecs="vp8"'}],
209 }, 'Space before ; in contentType');
211 expect_config('org.w3.clearkey', [{
212 videoCapabilities
: [{contentType
: 'video/webm; codecs="vp8"'}],
214 videoCapabilities
: [{contentType
: 'video/webm; codecs="vp8"'}],
215 }, 'Extra spaces after ; in contentType');
217 // TODO(jrummell): contentType should allow white space at the
218 // end of the string. http://crbug.com/487392
219 // expect_config('org.w3.clearkey', [{
220 // videoCapabilities: [{contentType: 'video/webm; codecs="vp8" '}],
222 // videoCapabilities: [{contentType: 'video/webm; codecs="vp8" '}],
223 // }, 'Trailing space in contentType');
225 expect_config('org.w3.clearkey', [{
226 videoCapabilities
: [{contentType
: 'video/webm; codecs=" vp8"'}],
228 videoCapabilities
: [{contentType
: 'video/webm; codecs=" vp8"'}],
229 }, 'Space at start of codecs parameter');
231 expect_config('org.w3.clearkey', [{
232 videoCapabilities
: [{contentType
: 'video/webm; codecs="vp8 "'}],
234 videoCapabilities
: [{contentType
: 'video/webm; codecs="vp8 "'}],
235 }, 'Space at end of codecs parameter');
237 // contentType is not case sensitive (except the codec names).
238 expect_config('org.w3.clearkey', [{
239 videoCapabilities
: [{contentType
: 'Video/webm; codecs="vp8"'}],
241 videoCapabilities
: [{contentType
: 'Video/webm; codecs="vp8"'}],
244 expect_config('org.w3.clearkey', [{
245 videoCapabilities
: [{contentType
: 'video/Webm; codecs="vp8"'}],
247 videoCapabilities
: [{contentType
: 'video/Webm; codecs="vp8"'}],
250 expect_config('org.w3.clearkey', [{
251 videoCapabilities
: [{contentType
: 'video/webm; Codecs="vp8"'}],
253 videoCapabilities
: [{contentType
: 'video/webm; Codecs="vp8"'}],
256 expect_config('org.w3.clearkey', [{
257 videoCapabilities
: [{contentType
: 'VIDEO/WEBM; CODECS="vp8"'}],
259 videoCapabilities
: [{contentType
: 'VIDEO/WEBM; CODECS="vp8"'}],
262 // Unrecognized attributes are not allowed.
263 // TODO(jrummell): Unrecognized attributes are ignored currently.
264 // http://crbug.com/449690
265 // expect_error('org.w3.clearkey', [{
266 // videoCapabilities: [{contentType: 'video/webm; foo="bar"'}],
267 // }], 'NotSupportedError', 'Unrecognized foo');
268 // expect_error('org.w3.clearkey', [{
269 // videoCapabilities: [{contentType: 'video/webm; foo="bar"; codecs="vp8"'}],
270 // }], 'NotSupportedError', 'Unrecognized foo with codecs');
272 // Invalid contentTypes.
273 expect_error('org.w3.clearkey', [{
274 videoCapabilities
: [{contentType
: 'fake'}],
275 }], 'NotSupportedError', 'contentType fake');
277 expect_error('org.w3.clearkey', [{
278 audioCapabilities
: [{contentType
: 'audio/fake'}],
279 }], 'NotSupportedError', 'contentType audio/fake');
281 expect_error('org.w3.clearkey', [{
282 videoCapabilities
: [{contentType
: 'video/fake'}],
283 }], 'NotSupportedError', 'contentType video/fake');
285 // The actual codec names are case sensitive.
286 expect_error('org.w3.clearkey', [{
287 videoCapabilities
: [{contentType
: 'video/webm; codecs="Vp8"'}],
288 }], 'NotSupportedError', 'codecs Vp8');
290 expect_error('org.w3.clearkey', [{
291 videoCapabilities
: [{contentType
: 'video/webm; codecs="VP8"'}],
292 }], 'NotSupportedError', 'codecs VP8');
294 // Extra comma is not allowed in codecs.
295 expect_error('org.w3.clearkey', [{
296 videoCapabilities
: [{contentType
: 'video/webm; codecs=",vp8"'}],
297 }], 'NotSupportedError', 'Leading , in codecs');
299 expect_error('org.w3.clearkey', [{
300 videoCapabilities
: [{contentType
: 'video/webm; codecs="vp8,"'}],
301 }], 'NotSupportedError', 'Trailing , in codecs');
303 expect_error('org.w3.clearkey', [{
304 videoCapabilities
: [{contentType
: 'video/webm; codecs=",vp8,"'}],
305 }], 'NotSupportedError', 'Leading and trailing , in codecs');