OLD | NEW |
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 | |
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) | 17 function isInitDataTypeSupported(initDataType) |
26 { | 18 { |
27 var result = false; | 19 return navigator.requestMediaKeySystemAccess( |
28 switch (initDataType) { | 20 "org.w3.clearkey", [{ initDataTypes : [initDataType] }]
) |
29 case 'webm': | 21 .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 } | 22 } |
41 | 23 |
42 | 24 // Returns a promise that is fulfilled with an initDataType that is supported, |
43 function getInitDataType() | 25 // rejected if neither 'webm' or 'cenc' are supported. |
| 26 function getSupportedInitDataType() |
44 { | 27 { |
45 if (isInitDataTypeSupported('webm')) | 28 return isInitDataTypeSupported('webm').then(function(result) { |
46 return 'webm'; | 29 if (result) { |
47 if (isInitDataTypeSupported('cenc')) | 30 return Promise.resolve('webm'); |
48 return 'cenc'; | 31 } |
49 throw 'No supported Initialization Data Types'; | 32 return isInitDataTypeSupported('cenc').then(function(result) { |
| 33 if (result) { |
| 34 return Promise.resolve('cenc'); |
| 35 } |
| 36 return Promise.reject('No supported initDataType.'); |
| 37 }); |
| 38 }); |
50 } | 39 } |
51 | 40 |
52 function getInitData(initDataType) | 41 function getInitData(initDataType) |
53 { | 42 { |
54 // FIXME: This should be dependent on initDataType. | 43 if (initDataType == 'webm') { |
55 return new Uint8Array([ 0, 1, 2, 3, 4, 5, 6, 7 ]); | 44 return new Uint8Array([ |
| 45 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 46 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F |
| 47 ]); |
| 48 } |
| 49 |
| 50 if (initDataType == 'cenc') { |
| 51 return new Uint8Array([ |
| 52 0x00, 0x00, 0x00, 0x00, // size = 0 |
| 53 0x70, 0x73, 0x73, 0x68, // 'pssh' |
| 54 0x01, // version = 1 |
| 55 0x00, 0x00, 0x00, // flags |
| 56 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // Common SystemID |
| 57 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
| 58 0x00, 0x00, 0x00, 0x01, // key count |
| 59 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // key |
| 60 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 61 0x00, 0x00, 0x00, 0x00 // datasize |
| 62 ]); |
| 63 } |
| 64 |
| 65 throw 'initDataType ' + initDataType + ' not supported.'; |
56 } | 66 } |
57 | 67 |
58 function waitForEventAndRunStep(eventName, element, func, stepTest) | 68 function waitForEventAndRunStep(eventName, element, func, stepTest) |
59 { | 69 { |
60 var eventCallback = function(event) { | 70 var eventCallback = function(event) { |
61 if (func) | 71 if (func) |
62 func(event); | 72 func(event); |
63 } | 73 } |
64 if (stepTest) | 74 if (stepTest) |
65 eventCallback = stepTest.step_func(eventCallback); | 75 eventCallback = stepTest.step_func(eventCallback); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 215 } |
206 | 216 |
207 function forceTestFailureFromPromise(test, error, message) | 217 function forceTestFailureFromPromise(test, error, message) |
208 { | 218 { |
209 // Promises convert exceptions into rejected Promises. Since there is | 219 // Promises convert exceptions into rejected Promises. Since there is |
210 // currently no way to report a failed test in the test harness, errors | 220 // currently no way to report a failed test in the test harness, errors |
211 // are reported using force_timeout(). | 221 // are reported using force_timeout(). |
212 if (message) | 222 if (message) |
213 consoleWrite(message + ': ' + error.message); | 223 consoleWrite(message + ': ' + error.message); |
214 else if (error) | 224 else if (error) |
215 consoleWrite(error.message); | 225 consoleWrite(error); |
216 | 226 |
217 test.force_timeout(); | 227 test.force_timeout(); |
218 test.done(); | 228 test.done(); |
219 } | 229 } |
220 | 230 |
221 function extractSingleKeyIdFromMessage(message) | 231 function extractSingleKeyIdFromMessage(message) |
222 { | 232 { |
223 try { | 233 try { |
224 var json = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(mes
sage))); | 234 var json = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(mes
sage))); |
225 // Decode the first element of 'kids'. | 235 // Decode the first element of 'kids'. |
226 // FIXME: Switch to base64url. See | 236 // FIXME: Switch to base64url. See |
227 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/en
crypted-media.html#using-base64url | 237 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/en
crypted-media.html#using-base64url |
228 assert_equals(1, json.kids.length); | 238 assert_equals(1, json.kids.length); |
229 var decoded_key = base64urlDecode(json.kids[0]); | 239 var decoded_key = base64urlDecode(json.kids[0]); |
230 // Convert to an Uint8Array and return it. | 240 // Convert to an Uint8Array and return it. |
231 return stringToUint8Array(decoded_key); | 241 return stringToUint8Array(decoded_key); |
232 } | 242 } |
233 catch (o) { | 243 catch (o) { |
234 // Not valid JSON, so return message untouched as Uint8Array. | 244 // Not valid JSON, so return message untouched as Uint8Array. |
235 // This is for backwards compatibility. | 245 // This is for backwards compatibility. |
236 // FIXME: Remove this once the code is switched to return JSON all | 246 // FIXME: Remove this once the code is switched to return JSON all |
237 // the time. | 247 // the time. |
238 return new Uint8Array(message); | 248 return new Uint8Array(message); |
239 } | 249 } |
240 } | 250 } |
OLD | NEW |