OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>MediaKeys</title> | 4 <title>MediaKeys</title> |
5 <script src=../video-test.js></script> | 5 <script src=../video-test.js></script> |
6 <script> | 6 <script> |
7 function stringToUint8Array(str) | 7 function stringToUint8Array(str) |
8 { | 8 { |
9 var arr=[]; | 9 var arr=[]; |
10 for(var i=0,j=str.length;i<j;++i) | 10 for(var i=0,j=str.length;i<j;++i) |
11 arr[i]=str.charCodeAt(i); | 11 arr[i]=str.charCodeAt(i); |
12 return new Uint8Array(arr); | 12 return new Uint8Array(arr); |
13 } | 13 } |
14 | 14 |
15 var mediaKeys; | 15 var mediaKeys; |
16 var mediaKeySession; | 16 var mediaKeySession; |
17 var initData = stringToUint8Array('mock'); | 17 var initData = stringToUint8Array('mock'); |
18 var invalidKey = stringToUint8Array('invalid'); | 18 var invalidKey = stringToUint8Array('invalid'); |
19 var validKey = stringToUint8Array('key'); | 19 var validKey = stringToUint8Array('1234567890abcdef'); |
20 | 20 |
21 function runTest() | 21 function runTest() |
22 { | 22 { |
23 // Initialize the MockCDM. It supports the key system 'com.apple
.mock', the | 23 run('mediaKeys = new MediaKeys("org.w3.clearkey")'); |
24 // mime type 'video/mock'. It requires init data to begin with '
mock', and | 24 run('mediaKeySession = mediaKeys.createSession("video/webm", ini
tData)'); |
25 // keys to begin with 'key'. | |
26 if (internals) | |
27 internals.initializeMockCDM(); | |
28 | |
29 run('mediaKeys = new MediaKeys("com.webcore.mock")'); | |
30 run('mediaKeySession = mediaKeys.createSession("video/mock", ini
tData)'); | |
31 waitForEvent('webkitkeymessage', keyMessage, false, false, media
KeySession); | 25 waitForEvent('webkitkeymessage', keyMessage, false, false, media
KeySession); |
32 waitForEvent('webkitkeyerror', keyError, false, false, mediaKeyS
ession); | 26 waitForEvent('webkitkeyerror', keyError, false, false, mediaKeyS
ession); |
33 waitForEvent('webkitkeyadded', null, true, false, mediaKeySessio
n); | 27 waitForEvent('webkitkeyadded', null, true, false, mediaKeySessio
n); |
34 } | 28 } |
35 | 29 |
36 function keyMessage(event) | 30 function keyMessage(event) |
37 { | 31 { |
38 run('mediaKeySession.update(invalidKey)'); | 32 run('mediaKeySession.update(invalidKey)'); |
39 } | 33 } |
40 | 34 |
41 function keyError(event) | 35 function keyError(event) |
42 { | 36 { |
43 run('mediaKeySession.update(validKey)'); | 37 run('mediaKeySession.update(validKey)'); |
44 } | 38 } |
45 </script> | 39 </script> |
46 </head> | 40 </head> |
47 <body onload="runTest()"> | 41 <body onload="runTest()"> |
48 <p>This tests the events created by MediaKeys.</p> | 42 <p>This tests the events created by MediaKeys.</p> |
49 </body> | 43 </body> |
50 </html> | 44 </html> |
OLD | NEW |