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

Side by Side Diff: third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-utils.js

Issue 2084053002: EME: Update tests so 'audioCapabilities' always provided (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: auto detection of initDataType Created 4 years, 5 months 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
1 var consoleDiv = null; 1 var consoleDiv = null;
2 2
3 function consoleWrite(text) 3 function consoleWrite(text)
4 { 4 {
5 if (!consoleDiv && document.body) { 5 if (!consoleDiv && document.body) {
6 consoleDiv = document.createElement('div'); 6 consoleDiv = document.createElement('div');
7 document.body.appendChild(consoleDiv); 7 document.body.appendChild(consoleDiv);
8 } 8 }
9 var span = document.createElement('span'); 9 var span = document.createElement('span');
10 span.appendChild(document.createTextNode(text)); 10 span.appendChild(document.createTextNode(text));
11 span.appendChild(document.createElement('br')); 11 span.appendChild(document.createElement('br'));
12 consoleDiv.appendChild(span); 12 consoleDiv.appendChild(span);
13 } 13 }
14 14
15 // Returns a promise that is fulfilled with true if |initDataType| is supported, 15 // Returns a promise that is fulfilled with true if |initDataType| is supported,
16 // or false if not. 16 // or false if not.
17 function isInitDataTypeSupported(initDataType) 17 function isInitDataTypeSupported(initDataType)
18 { 18 {
19 return navigator.requestMediaKeySystemAccess( 19 return navigator.requestMediaKeySystemAccess(
20 "org.w3.clearkey", [{ initDataTypes : [initDataType] }] ) 20 "org.w3.clearkey", simpleConfigurationForInitDataType(i nitDataType))
21 .then(function() { return(true); }, function() { return(false); }); 21 .then(function() { return(true); }, function() { return(false); });
22 } 22 }
23 23
24 // Returns a promise that is fulfilled with an initDataType that is supported,
25 // rejected if none are supported.
26 function getSupportedInitDataType()
27 {
28 var configuration = [{ initDataTypes : [ 'webm', 'cenc', 'keyids' ] }];
29 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', configuratio n)
30 .then(function(access) {
31 var initDataTypes = access.getConfiguration().initDataTypes;
32 assert_greater_than(initDataTypes.length, 0);
33 return Promise.resolve(initDataTypes[0]);
34 }, function(error) {
35 return Promise.reject('No supported initDataType.');
36 });
37 }
38
39 function getInitData(initDataType) 24 function getInitData(initDataType)
40 { 25 {
41 if (initDataType == 'webm') { 26 if (initDataType == 'webm') {
42 return new Uint8Array([ 27 return new Uint8Array([
43 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 28 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
44 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 29 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
45 ]); 30 ]);
46 } 31 }
47 32
48 if (initDataType == 'cenc') { 33 if (initDataType == 'cenc') {
(...skipping 15 matching lines...) Expand all
64 var keyId = new Uint8Array([ 49 var keyId = new Uint8Array([
65 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 50 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
66 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 51 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
67 ]); 52 ]);
68 return stringToUint8Array(createKeyIDs(keyId)); 53 return stringToUint8Array(createKeyIDs(keyId));
69 } 54 }
70 55
71 throw 'initDataType ' + initDataType + ' not supported.'; 56 throw 'initDataType ' + initDataType + ' not supported.';
72 } 57 }
73 58
59 // Returns an array of audioCapabilities that includes entries for a set of
60 // codecs that should cover all user agents.
61 function getPossibleAudioCapabilities()
62 {
63 return [
64 { contentType: 'audio/mp4; codecs="mp4a.40.2"' },
65 { contentType: 'audio/webm; codecs="opus"' },
66 ];
67 }
68
69 // Returns a trivial MediaKeySystemConfiguration that should includes entries
ddorwin 2016/07/20 17:05:28 Trying to make this a bit clearer. Maybe: ... that
jrummell 2016/07/20 19:07:49 Done.
70 // that all user agents support some part of.
71 function simpleConfiguration()
ddorwin 2016/07/20 17:05:28 These three methods are not named as actions like
jrummell 2016/07/20 19:07:49 Done.
72 {
73 return [ {
74 initDataTypes : [ 'webm', 'cenc', 'keyids' ],
75 audioCapabilities: getPossibleAudioCapabilities()
76 } ];
77 }
78
79 // Returns a MediaKeySystemConfiguration for |initDataType|. This includes
80 // entries that should cover all user agents that support |initDataType|.
ddorwin 2016/07/20 17:05:27 Similar text change.
jrummell 2016/07/20 19:07:48 Done.
81 function simpleConfigurationForInitDataType(initDataType)
82 {
83 return [ {
84 initDataTypes: [ initDataType ],
85 audioCapabilities: getPossibleAudioCapabilities()
86 } ];
87 }
88
89 // Returns a MediaKeySystemConfiguration for |mediaFormat| that specifies
90 // both audio and video capabilities.
ddorwin 2016/07/20 17:05:27 When the change below is made, add "... for the sp
jrummell 2016/07/20 19:07:48 Done.
91 function avConfiguration(mediaFormat)
ddorwin 2016/07/20 17:05:27 Longer-term (for spec tests), it might make sense
jrummell 2016/07/20 19:07:49 Done.
92 {
93 if (mediaFormat == 'webm') {
94 return [ {
95 initDataTypes: [ 'webm' ],
96 audioCapabilities: [ { contentType: 'audio/webm; codecs="opus"' } ],
97 videoCapabilities: [ { contentType: 'video/webm; codecs="vp8"' } ]
98 } ];
99 }
100
101 // NOTE: Supporting other mediaFormats not currently implemented as
ddorwin 2016/07/20 17:05:27 nit: *is* not...
jrummell 2016/07/20 19:07:48 Done.
102 // Chromium only tests with WebM files.
103 throw 'mediaFormat ' + mediaFormat + ' not supported.';
104 }
105
74 function waitForEventAndRunStep(eventName, element, func, stepTest) 106 function waitForEventAndRunStep(eventName, element, func, stepTest)
75 { 107 {
76 var eventCallback = function(event) { 108 var eventCallback = function(event) {
77 if (func) 109 if (func)
78 func(event); 110 func(event);
79 } 111 }
80 if (stepTest) 112 if (stepTest)
81 eventCallback = stepTest.step_func(eventCallback); 113 eventCallback = stepTest.step_func(eventCallback);
82 114
83 element.addEventListener(eventName, eventCallback, true); 115 element.addEventListener(eventName, eventCallback, true);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // Decode the first element of 'kids'. 286 // Decode the first element of 'kids'.
255 assert_equals(1, json.kids.length); 287 assert_equals(1, json.kids.length);
256 var decoded_key = base64urlDecode(json.kids[0]); 288 var decoded_key = base64urlDecode(json.kids[0]);
257 // Convert to an Uint8Array and return it. 289 // Convert to an Uint8Array and return it.
258 return stringToUint8Array(decoded_key); 290 return stringToUint8Array(decoded_key);
259 } 291 }
260 292
261 // Create a MediaKeys object for Clear Key with 1 session. KeyId and key 293 // Create a MediaKeys object for Clear Key with 1 session. KeyId and key
262 // required for the video are already known and provided. Returns a promise 294 // required for the video are already known and provided. Returns a promise
263 // that resolves to the MediaKeys object created. 295 // that resolves to the MediaKeys object created.
264 function createMediaKeys(keyId, key) 296 function createMediaKeys(keyId, key)
ddorwin 2016/07/20 17:05:27 In a separate CL, we should rename this. It does m
jrummell 2016/07/20 19:07:48 Acknowledged.
265 { 297 {
266 var mediaKeys; 298 var mediaKeys;
267 var mediaKeySession; 299 var mediaKeySession;
268 var request = stringToUint8Array(createKeyIDs(keyId)); 300 var request = stringToUint8Array(createKeyIDs(keyId));
269 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, key))); 301 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, key)));
270 302
271 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(f unction(access) { 303 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', simpleConfig urationForInitDataType('keyids')).then(function(access) {
272 return access.createMediaKeys(); 304 return access.createMediaKeys();
273 }).then(function(result) { 305 }).then(function(result) {
274 mediaKeys = result; 306 mediaKeys = result;
275 mediaKeySession = mediaKeys.createSession(); 307 mediaKeySession = mediaKeys.createSession();
276 return mediaKeySession.generateRequest('keyids', request); 308 return mediaKeySession.generateRequest('keyids', request);
277 }).then(function() { 309 }).then(function() {
278 return mediaKeySession.update(jwkSet); 310 return mediaKeySession.update(jwkSet);
279 }).then(function() { 311 }).then(function() {
280 return Promise.resolve(mediaKeys); 312 return Promise.resolve(mediaKeys);
281 }); 313 });
282 } 314 }
283 315
284 // Play the specified |content| on |video|. Returns a promise that is resolved 316 // Play the specified |content| on |video|. Returns a promise that is resolved
285 // after the video plays for |duration| seconds. 317 // after the video plays for |duration| seconds.
286 function playVideoAndWaitForTimeupdate(video, content, duration) 318 function playVideoAndWaitForTimeupdate(video, content, duration)
287 { 319 {
288 video.src = content; 320 video.src = content;
289 video.play(); 321 video.play();
290 return new Promise(function(resolve) { 322 return new Promise(function(resolve) {
291 video.addEventListener('timeupdate', function listener(event) { 323 video.addEventListener('timeupdate', function listener(event) {
292 if (event.target.currentTime < duration) 324 if (event.target.currentTime < duration)
293 return; 325 return;
294 video.removeEventListener('timeupdate', listener); 326 video.removeEventListener('timeupdate', listener);
295 resolve('success'); 327 resolve('success');
296 }); 328 });
297 }); 329 });
298 } 330 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698