Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>MediaKeys</title> | 4 <title>Test EME syntax</title> |
| 5 <script src=../video-test.js></script> | 5 <script src="encrypted-media-utils.js"></script> |
| 6 <script src="../../resources/testharness.js"></script> | |
| 7 <script src="../../resources/testharnessreport.js"></script> | |
| 8 </head> | |
| 9 <body> | |
| 10 <div id="log"></div> | |
| 6 <script> | 11 <script> |
| 7 function stringToUint8Array(str) | 12 var typeError = new TypeError(); |
| 13 var mediaKeys = null; | |
| 14 var mediaKeySession = null; | |
| 15 var initData = stringToUint8Array('init data'); | |
| 16 | |
| 17 test(function() | |
| 8 { | 18 { |
| 9 var arr=[]; | 19 // Too few parameters. |
| 10 for(var i=0,j=str.length;i<j;++i) | 20 assert_throws(typeError, function() { new MediaKeys(); }); |
| 11 arr[i]=str.charCodeAt(i); | 21 // Invalid parameters. |
| 12 return new Uint8Array(arr); | 22 assert_throws('INVALID_ACCESS_ERR', function() { new MediaKeys(' '); }); |
| 13 } | 23 // Invalid key systems. |
| 24 assert_throws('NOT_SUPPORTED_ERR', function() { new MediaKeys(nu ll); }); | |
| 25 assert_throws('NOT_SUPPORTED_ERR', function() { new MediaKeys(un defined); }); | |
| 26 assert_throws('NOT_SUPPORTED_ERR', function() { new MediaKeys('u nsupported'); }); | |
| 27 assert_throws('NOT_SUPPORTED_ERR', function() { new MediaKeys(1) ; }); | |
| 28 assert_throws('NOT_SUPPORTED_ERR', function() { new MediaKeys(ne w Uint8Array(0)); }); | |
|
ddorwin
2014/03/11 00:30:06
Interesting. Does a 1-element Uint8Array do the sa
xhwang
2014/03/11 01:00:53
Yes, same thing.
| |
| 29 }, 'Test MediaKeys constructor exceptions.'); | |
| 14 | 30 |
| 15 var mediaKeys; | 31 test(function() |
| 16 var mediaKeySession; | 32 { |
| 17 var initData = stringToUint8Array('mock'); | 33 assert_equals(typeof window.MediaKeys, 'function'); |
| 34 assert_not_equals(new MediaKeys('org.w3.clearkey', 'extra'), nul l); | |
| 35 mediaKeys = new MediaKeys('org.w3.clearkey'); | |
| 36 assert_not_equals(mediaKeys, null); | |
| 37 assert_equals(typeof mediaKeys, 'object'); | |
| 38 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); | |
| 39 assert_equals(typeof mediaKeys.createSession, 'function'); | |
| 40 assert_equals(typeof mediaKeys.addEventListener, 'undefined'); | |
| 41 }, 'Test MediaKeys constructor.'); | |
| 18 | 42 |
| 19 function checkError() | 43 test(function() |
| 20 { | 44 { |
| 21 testExpected('mediaKeySession.error', null, '!='); | 45 // Too few parameters. |
| 22 testExpected('mediaKeySession.error.code', MediaKeyError.MEDIA_K EYERR_UNKNOWN); | 46 assert_throws(typeError, function() { mediaKeys.createSession(); }); |
| 23 testExpected('mediaKeySession.error.systemCode', 0); | 47 assert_throws(typeError, function() { mediaKeys.createSession('' ); }); |
| 24 } | 48 assert_throws(typeError, function() { mediaKeys.createSession(nu ll); }); |
| 49 assert_throws(typeError, function() { mediaKeys.createSession(un defined); }); | |
| 50 assert_throws(typeError, function() { mediaKeys.createSession('v ideo/webm'); }); | |
| 51 assert_throws(typeError, function() { mediaKeys.createSession(ne w Uint8Array(0)); }); | |
| 52 assert_throws(typeError, function() { mediaKeys.createSession(in itData); }); | |
| 53 // Invalid parameters. | |
| 54 assert_throws('InvalidAccessError', function() { mediaKeys.creat eSession('video/webm', ''); }); | |
| 55 assert_throws('InvalidAccessError', function() { mediaKeys.creat eSession('video/webm', null); }); | |
| 56 assert_throws('InvalidAccessError', function() { mediaKeys.creat eSession('video/webm', undefined); }); | |
| 57 assert_throws('InvalidAccessError', function() { mediaKeys.creat eSession('video/webm', 1); }); | |
| 58 assert_throws('InvalidAccessError', function() { mediaKeys.creat eSession('video/webm', new Uint8Array(0)); }); | |
| 59 assert_throws('InvalidAccessError', function() { mediaKeys.creat eSession('', initData); }); | |
| 60 // Not supported contentTypes. | |
| 61 assert_throws('NotSupportedError', function() { mediaKeys.create Session(null, initData); }); | |
| 62 assert_throws('NotSupportedError', function() { mediaKeys.create Session(undefined, initData); }); | |
| 63 assert_throws('NotSupportedError', function() { mediaKeys.create Session(new Uint8Array(0), initData); }); | |
| 64 assert_throws('NotSupportedError', function() { mediaKeys.create Session(1, initData); }); | |
| 65 assert_throws('NotSupportedError', function() { mediaKeys.create Session('unsupported', initData); }); | |
| 66 assert_throws('NotSupportedError', function() { mediaKeys.create Session('video/foo', initData); }); | |
| 67 assert_throws('NotSupportedError', function() { mediaKeys.create Session('text/webm', initData); }); | |
| 68 }, 'Test MediaKeys createSession() exceptions.'); | |
| 25 | 69 |
| 26 function runTest() | 70 test(function() |
| 27 { | 71 { |
| 28 consoleWrite("Test MediaKeys."); | 72 assert_not_equals(mediaKeys.createSession('video/webm', initData , 'extra'), null); |
| 29 testExpected('typeof window.MediaKeys', 'function'); | 73 mediaKeySession = mediaKeys.createSession('video/webm', initData ); |
| 30 testDOMException('new MediaKeys("")', "DOMException.INVALID_ACCE SS_ERR"); | 74 assert_not_equals(mediaKeySession, null); |
| 31 testDOMException('new MediaKeys("unsupported")', "DOMException.N OT_SUPPORTED_ERR"); | 75 assert_equals(typeof mediaKeySession, 'object'); |
| 32 run('mediaKeys = new MediaKeys("org.w3.clearkey")'); | 76 assert_equals(typeof mediaKeySession.addEventListener, 'function '); |
| 33 testExpected('typeof mediaKeys', 'object'); | 77 assert_equals(typeof mediaKeySession.update, 'function'); |
| 34 testExpected('mediaKeys.keySystem', 'org.w3.clearkey'); | 78 assert_equals(mediaKeySession.error, null); |
| 35 testExpected('typeof mediaKeys.createSession', 'function'); | 79 assert_equals(mediaKeySession.keySystem, 'org.w3.clearkey'); |
| 80 assert_equals(typeof mediaKeySession.sessionId, 'string'); | |
| 81 assert_equals(typeof mediaKeySession.onopen, 'undefined'); | |
| 82 assert_equals(typeof mediaKeySession.onmessage, 'undefined'); | |
| 83 assert_equals(typeof mediaKeySession.onclose, 'undefined'); | |
| 84 assert_equals(typeof mediaKeySession.onerror, 'undefined'); | |
| 85 }, 'Test MediaKeys createSession().'); | |
| 36 | 86 |
| 37 testException('mediaKeys.createSession()', '"TypeError: Failed t o execute \'createSession\' on \'MediaKeys\': 2 arguments required, but only 0 p resent."'); | 87 test(function() |
| 38 testException('mediaKeys.createSession("")', '"TypeError: Failed to execute \'createSession\' on \'MediaKeys\': 2 arguments required, but only 1 present."'); | 88 { |
| 39 testException('mediaKeys.createSession("video/webm")', '"TypeErr or: Failed to execute \'createSession\' on \'MediaKeys\': 2 arguments required, but only 1 present."'); | 89 // Too few parameters. |
| 40 testDOMException('mediaKeys.createSession("", new Uint8Array(1)) ', "DOMException.INVALID_ACCESS_ERR"); | 90 assert_throws(typeError, function() { mediaKeySession.update(); }); |
| 41 testDOMException('mediaKeys.createSession("video/webm", null)', "DOMException.INVALID_ACCESS_ERR"); | 91 // Invalid parameters. |
| 42 testDOMException('mediaKeys.createSession("video/webm", new Uint 8Array(0))', "DOMException.INVALID_ACCESS_ERR"); | 92 assert_throws('InvalidAccessError', function() { mediaKeySession .update(''); }); |
| 43 testDOMException('mediaKeys.createSession("unsupported/type", ne w Uint8Array(1))', "DOMException.NOT_SUPPORTED_ERR"); | 93 assert_throws('InvalidAccessError', function() { mediaKeySession .update(null); }); |
| 44 consoleWrite(""); | 94 assert_throws('InvalidAccessError', function() { mediaKeySession .update(undefined); }); |
| 95 assert_throws('InvalidAccessError', function() { mediaKeySession .update(1); }); | |
| 96 assert_throws('InvalidAccessError', function() { mediaKeySession .update(new Uint8Array(0)); }); | |
| 97 }, 'Test MediaKeySession update() exceptions.'); | |
| 45 | 98 |
| 46 consoleWrite("Test MediaKeySession."); | 99 test(function() |
| 47 run('mediaKeySession = mediaKeys.createSession("video/webm", ini tData)'); | 100 { |
| 48 testExpected('typeof mediaKeySession', 'object'); | 101 mediaKeySession.update(new Uint8Array(1), 'extra'); |
| 49 testExpected('typeof mediaKeySession.addEventListener', 'functio n'); | 102 mediaKeySession.update(new Uint8Array(1)); |
| 50 testExpected('typeof mediaKeySession.update', 'function'); | 103 }, 'Test MediaKeySession update().'); |
| 51 testExpected('mediaKeySession.error', null); | |
| 52 testExpected('mediaKeySession.keySystem', 'org.w3.clearkey'); | |
| 53 testExpected('mediaKeySession.sessionId', null, '!='); | |
| 54 testExpected('mediaKeySession.onwebkitkeyadded', null); | |
| 55 testExpected('mediaKeySession.onwebkitkeyerror', 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."'); | |
| 58 testDOMException('mediaKeySession.update(null)', "DOMException.I NVALID_ACCESS_ERR"); | |
| 59 run('mediaKeySession.update(new Uint8Array(1))'); | |
| 60 | 104 |
| 61 run('mediaKeySession.release()'); | 105 test(function() |
| 106 { | |
| 107 mediaKeySession.release(); | |
| 108 // FIXME: This causes Chromium to crash. Uncomment this once Chr omium is fixed. | |
| 109 // mediaKeySession.release('extra'); | |
| 110 }, 'Test MediaKeySession release().'); | |
| 62 | 111 |
| 63 endTest(); | 112 // FIXME: Add syntax checks for MediaKeys.IsTypeSupported(). |
|
ddorwin
2014/03/11 00:30:06
Should we add FIXME: for MediaKeyError (crbug.com/
xhwang
2014/03/11 01:00:53
Updated FIXME. I'll fix the FIXMEs after this CL.
| |
| 64 } | 113 // FIXME: Add HTMLMediaElement syntax checks, e.g. setMediaKeys, med iakeys, onneedkey. |
| 65 </script> | 114 </script> |
| 66 </head> | |
| 67 <body onload="runTest()"> | |
| 68 <p>This tests the basic API of MediaKeys and MediaKeySession.</p> | |
| 69 </body> | 115 </body> |
| 70 </html> | 116 </html> |
| OLD | NEW |