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

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

Issue 1004843003: Use requestMediaKeySystemAccess() to check type support in EME layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « LayoutTests/media/encrypted-media/encrypted-media-syntax.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var console = null; 1 var console = null;
2 2
3 function consoleWrite(text) 3 function consoleWrite(text)
4 { 4 {
5 if (!console && document.body) { 5 if (!console && document.body) {
6 console = document.createElement('div'); 6 console = document.createElement('div');
7 document.body.appendChild(console); 7 document.body.appendChild(console);
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 console.appendChild(span); 12 console.appendChild(span);
13 } 13 }
14 14
15 // FIXME: Detect EME support rather than just general container support. 15 // Returns a promise that is fulfilled with true if |initDataType| is supported,
16 // http://crbug.com/441585 16 // or false if not.
17 // For now, assume that implementations that support a container type for clear 17 // For now, assume that implementations that support a container type for clear
ddorwin 2015/03/12 23:18:08 This comment is obsolete.
jrummell 2015/03/13 18:05:30 Done.
18 // content and are running these tests also support that container with EME. 18 // content and are running these tests also support that container with EME.
19 // The element used for this will is not released to avoid interfering with the
20 // ActiveDOMObject counts in the lifetime tests.
21 var canPlayTypeElement = new Audio();
22 var isWebMSupported = ('' != canPlayTypeElement.canPlayType('video/webm'));
23 var isCencSupported = ('' != canPlayTypeElement.canPlayType('video/mp4'));
24
25 function isInitDataTypeSupported(initDataType) 19 function isInitDataTypeSupported(initDataType)
26 { 20 {
27 var result = false; 21 return navigator.requestMediaKeySystemAccess(
28 switch (initDataType) { 22 "org.w3.clearkey", [{ initDataTypes : [initDataType] }] )
29 case 'webm': 23 .then(function() { return(true); }, function() { return(false); });
30 result = isWebMSupported;
31 break;
32 case 'cenc':
33 result = isCencSupported;
34 break;
35 default:
36 result = false;
37 }
38
39 return result;
40 } 24 }
41 25
42 26 // Returns a promise that is fulfilled with an initDataType that is supported,
27 // rejected if neither 'webm' or 'cenc' are supported.
43 function getInitDataType() 28 function getInitDataType()
ddorwin 2015/03/12 23:18:08 getSupported...
jrummell 2015/03/13 18:05:30 Done.
44 { 29 {
45 if (isInitDataTypeSupported('webm')) 30 return isInitDataTypeSupported('webm').then(function(result) {
46 return 'webm'; 31 if (result) {
47 if (isInitDataTypeSupported('cenc')) 32 return 'webm';
ddorwin 2015/03/12 23:18:08 Does this end up being a promise resolved with 'we
jrummell 2015/03/13 18:05:30 Done.
48 return 'cenc'; 33 }
49 throw 'No supported Initialization Data Types'; 34 return isInitDataTypeSupported('cenc').then(function(result) {
35 if (result) {
36 return 'cenc';
37 }
38 return Promise.reject('No supported initDataType.');
39 });
40 });
50 } 41 }
51 42
52 function getInitData(initDataType) 43 function getInitData(initDataType)
53 { 44 {
54 // FIXME: This should be dependent on initDataType. 45 if (initDataType == 'webm') {
55 return new Uint8Array([ 0, 1, 2, 3, 4, 5, 6, 7 ]); 46 return new Uint8Array([
47 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
48 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
49 ]);
50 }
51
52 if (initDataType == 'cenc') {
53 return new Uint8Array([
54 0x00, 0x00, 0x00, 0x00, // size = 0
55 0x70, 0x73, 0x73, 0x68, // 'pssh'
56 0x01, // version = 1
57 0x00, 0x00, 0x00, // flags
58 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // Common SystemID
59 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
60 0x00, 0x00, 0x00, 0x01, // key count
61 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // key
62 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
63 0x00, 0x00, 0x00, 0x00 // datasize
64 ]);
65 }
66
67 throw 'initDataType ' + initDataType + ' not supported.';
56 } 68 }
57 69
58 function waitForEventAndRunStep(eventName, element, func, stepTest) 70 function waitForEventAndRunStep(eventName, element, func, stepTest)
59 { 71 {
60 var eventCallback = function(event) { 72 var eventCallback = function(event) {
61 if (func) 73 if (func)
62 func(event); 74 func(event);
63 } 75 }
64 if (stepTest) 76 if (stepTest)
65 eventCallback = stepTest.step_func(eventCallback); 77 eventCallback = stepTest.step_func(eventCallback);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return stringToUint8Array(decoded_key); 243 return stringToUint8Array(decoded_key);
232 } 244 }
233 catch (o) { 245 catch (o) {
234 // Not valid JSON, so return message untouched as Uint8Array. 246 // Not valid JSON, so return message untouched as Uint8Array.
235 // This is for backwards compatibility. 247 // This is for backwards compatibility.
236 // FIXME: Remove this once the code is switched to return JSON all 248 // FIXME: Remove this once the code is switched to return JSON all
237 // the time. 249 // the time.
238 return new Uint8Array(message); 250 return new Uint8Array(message);
239 } 251 }
240 } 252 }
OLDNEW
« no previous file with comments | « LayoutTests/media/encrypted-media/encrypted-media-syntax.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698