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 | 18 |
19 function runTest() | 19 function checkError() |
| 20 { |
| 21 testExpected('mediaKeySession.error', null, '!='); |
| 22 testExpected('mediaKeySession.error.code', MediaKeyError.MEDIA_K
EYERR_UNKNOWN); |
| 23 testExpected('mediaKeySession.error.systemCode', 0); |
| 24 } |
| 25 |
| 26 function runTest() |
20 { | 27 { |
21 consoleWrite("Test MediaKeys."); | 28 consoleWrite("Test MediaKeys."); |
22 testExpected('typeof window.MediaKeys', 'function'); | 29 testExpected('typeof window.MediaKeys', 'function'); |
23 testDOMException('new MediaKeys("")', "DOMException.INVALID_ACCE
SS_ERR"); | 30 testDOMException('new MediaKeys("")', "DOMException.INVALID_ACCE
SS_ERR"); |
24 testDOMException('new MediaKeys("unsupported")', "DOMException.N
OT_SUPPORTED_ERR"); | 31 testDOMException('new MediaKeys("unsupported")', "DOMException.N
OT_SUPPORTED_ERR"); |
25 run('mediaKeys = new MediaKeys("org.w3.clearkey")'); | 32 run('mediaKeys = new MediaKeys("org.w3.clearkey")'); |
26 testExpected('typeof mediaKeys', 'object'); | 33 testExpected('typeof mediaKeys', 'object'); |
27 testExpected('mediaKeys.keySystem', 'org.w3.clearkey'); | 34 testExpected('mediaKeys.keySystem', 'org.w3.clearkey'); |
28 testExpected('typeof mediaKeys.createSession', 'function'); | 35 testExpected('typeof mediaKeys.createSession', 'function'); |
| 36 |
| 37 testException('mediaKeys.createSession()', '"TypeError: Failed t
o execute \'createSession\' on \'MediaKeys\': 2 arguments required, but only 0 p
resent."'); |
| 38 testException('mediaKeys.createSession("")', '"TypeError: Failed
to execute \'createSession\' on \'MediaKeys\': 2 arguments required, but only 1
present."'); |
| 39 testException('mediaKeys.createSession("video/webm")', '"TypeErr
or: Failed to execute \'createSession\' on \'MediaKeys\': 2 arguments required,
but only 1 present."'); |
29 testDOMException('mediaKeys.createSession("", new Uint8Array(1))
', "DOMException.INVALID_ACCESS_ERR"); | 40 testDOMException('mediaKeys.createSession("", new Uint8Array(1))
', "DOMException.INVALID_ACCESS_ERR"); |
30 testDOMException('mediaKeys.createSession("unsupported/type")',
"DOMException.NOT_SUPPORTED_ERR"); | 41 testDOMException('mediaKeys.createSession("video/webm", null)',
"DOMException.INVALID_ACCESS_ERR"); |
| 42 testDOMException('mediaKeys.createSession("video/webm", new Uint
8Array(0))', "DOMException.INVALID_ACCESS_ERR"); |
| 43 testDOMException('mediaKeys.createSession("unsupported/type", ne
w Uint8Array(1))', "DOMException.NOT_SUPPORTED_ERR"); |
31 consoleWrite(""); | 44 consoleWrite(""); |
32 | 45 |
33 consoleWrite("Test MediaKeySession."); | 46 consoleWrite("Test MediaKeySession."); |
34 run('mediaKeySession = mediaKeys.createSession("video/webm", ini
tData)'); | 47 run('mediaKeySession = mediaKeys.createSession("video/webm", ini
tData)'); |
35 testExpected('typeof mediaKeySession', 'object'); | 48 testExpected('typeof mediaKeySession', 'object'); |
36 testExpected('typeof mediaKeySession.addEventListener', 'functio
n'); | 49 testExpected('typeof mediaKeySession.addEventListener', 'functio
n'); |
37 testExpected('typeof mediaKeySession.update', 'function'); | 50 testExpected('typeof mediaKeySession.update', 'function'); |
38 testExpected('mediaKeySession.error', null); | 51 testExpected('mediaKeySession.error', null); |
39 testExpected('mediaKeySession.keySystem', 'org.w3.clearkey'); | 52 testExpected('mediaKeySession.keySystem', 'org.w3.clearkey'); |
40 testExpected('mediaKeySession.sessionId', null, '!='); | 53 testExpected('mediaKeySession.sessionId', null, '!='); |
41 testExpected('mediaKeySession.onwebkitkeyadded', null); | 54 testExpected('mediaKeySession.onwebkitkeyadded', null); |
42 testExpected('mediaKeySession.onwebkitkeyerror', null); | 55 testExpected('mediaKeySession.onwebkitkeyerror', null); |
43 testExpected('mediaKeySession.onwebkitkeymessage', null); | 56 testExpected('mediaKeySession.onwebkitkeymessage', null); |
| 57 testException('mediaKeySession.update()', '"TypeError: Failed to
execute \'update\' on \'MediaKeySession\': 1 argument required, but only 0 pres
ent."'); |
44 testDOMException('mediaKeySession.update(null)', "DOMException.I
NVALID_ACCESS_ERR"); | 58 testDOMException('mediaKeySession.update(null)', "DOMException.I
NVALID_ACCESS_ERR"); |
| 59 run('mediaKeySession.update(new Uint8Array(1))'); |
| 60 |
| 61 // FIXME: Test MediaKeySession.release(). |
| 62 |
45 endTest(); | 63 endTest(); |
46 } | 64 } |
47 </script> | 65 </script> |
48 </head> | 66 </head> |
49 <body onload="runTest()"> | 67 <body onload="runTest()"> |
50 <p>This tests the basic API of MediaKeys and MediaKeySession.</p> | 68 <p>This tests the basic API of MediaKeys and MediaKeySession.</p> |
51 </body> | 69 </body> |
52 </html> | 70 </html> |
OLD | NEW |