Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
|
ddorwin
2014/03/07 01:45:51
We'll need to rename this file in a future CL.
xhwang
2014/03/08 00:37:45
okay.
| |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>MediaKeys</title> | 4 <title>Test unprefixed EME syntax</title> |
|
ddorwin
2014/03/07 01:45:51
"unprefixed " should be removed. This would be irr
xhwang
2014/03/08 00:37:45
Done.
| |
| 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 | |
|
ddorwin
2014/03/07 01:45:51
empty line
xhwang
2014/03/08 00:37:45
Done.
| |
| 9 </head> | |
| 10 <body> | |
| 11 <div id="log"></div> | |
| 6 <script> | 12 <script> |
| 7 function stringToUint8Array(str) | 13 var typeError = new TypeError(); |
| 14 var mediaKeys = null; | |
| 15 var mediaKeySession = null; | |
| 16 var initData = stringToUint8Array('mock'); | |
|
ddorwin
2014/03/07 01:45:51
FWIW, 'mock' is left over from when there was a mo
xhwang
2014/03/08 00:37:45
Done.
| |
| 17 var extraParam = 'extra parameter'; | |
| 18 | |
| 19 function test_syntax(func, params, exception, description) | |
|
ddorwin
2014/03/07 01:45:51
test_invalid_syntax? It's not possible to test val
xhwang
2014/03/08 00:37:45
I am not sure. I was following media source tests.
| |
| 8 { | 20 { |
| 9 var arr=[]; | 21 for (var i = 0; i < params.length; ++i) { |
| 10 for(var i=0,j=str.length;i<j;++i) | 22 test(function() |
| 11 arr[i]=str.charCodeAt(i); | 23 { |
| 12 return new Uint8Array(arr); | 24 assert_throws(exception, function() { func.apply(this, p arams[i]); }); |
| 13 } | 25 }, description + ": '" + params[i].join("', '") + "'."); |
|
ddorwin
2014/03/07 01:45:51
missing the function name?
xhwang
2014/03/08 00:37:45
The name is optional. I skip it because I don't se
| |
| 26 } | |
| 27 }; | |
| 14 | 28 |
| 15 var mediaKeys; | 29 // Not using test_syntax() because there's no easy way to bind a |
| 16 var mediaKeySession; | 30 // constructor to a function. |
| 17 var initData = stringToUint8Array('mock'); | 31 test(function() |
| 32 { | |
| 33 assert_throws(typeError, function() { new MediaKeys(); }); | |
| 34 assert_throws("INVALID_ACCESS_ERR", function() { new MediaKeys(" "); }); | |
| 35 assert_throws("NOT_SUPPORTED_ERR", function() { new MediaKeys(nu ll); }); | |
| 36 assert_throws("NOT_SUPPORTED_ERR", function() { new MediaKeys(un defined); }); | |
| 37 assert_throws("NOT_SUPPORTED_ERR", function() { new MediaKeys("u nsupported"); }); | |
|
ddorwin
2014/03/07 01:45:51
This isn't really a syntax test (nor I guess are n
xhwang
2014/03/08 00:37:45
"null" may also not be testing syntax :) Also, it'
ddorwin
2014/03/10 20:11:44
Let's look at what they _should_ throw, but note t
| |
| 38 }, "Test MediaKeys constructor exceptions."); | |
| 18 | 39 |
| 19 function checkError() | 40 test(function() |
| 20 { | 41 { |
| 21 testExpected('mediaKeySession.error', null, '!='); | 42 assert_equals(typeof window.MediaKeys, "function"); |
| 22 testExpected('mediaKeySession.error.code', MediaKeyError.MEDIA_K EYERR_UNKNOWN); | 43 mediaKeys = new MediaKeys("org.w3.clearkey"); |
| 23 testExpected('mediaKeySession.error.systemCode', 0); | 44 mediaKeys = new MediaKeys("org.w3.clearkey", extraParam); |
|
ddorwin
2014/03/07 01:45:51
s/extraParam/"extra"? Do we need a variable?
xhwang
2014/03/08 00:37:45
Done.
| |
| 24 } | 45 assert_equals(typeof mediaKeys, 'object'); |
| 46 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); | |
| 47 assert_equals(typeof mediaKeys.createSession, 'function'); | |
| 48 }, "Test MediaKeys constructor."); | |
| 25 | 49 |
| 26 function runTest() | 50 test_syntax(mediaKeys.createSession.bind(mediaKeys), [ |
| 51 [], | |
|
ddorwin
2014/03/07 01:45:51
Is this much more readable than l33-37? Especially
xhwang
2014/03/08 00:37:45
Done.
| |
| 52 [''], | |
| 53 [null], | |
| 54 [undefined], | |
| 55 ['video/webm'], | |
| 56 [new Uint8Array(0)], | |
| 57 [initData], | |
| 58 ], typeError, 'Test MediaKeys createSession() type errors'); | |
|
ddorwin
2014/03/07 01:45:51
"too few parameters"?
xhwang
2014/03/08 00:37:45
Added comments.
| |
| 59 | |
| 60 test_syntax(mediaKeys.createSession.bind(mediaKeys), [ | |
| 61 ['video/webm', ''], | |
| 62 ['video/webm', null], | |
| 63 ['video/webm', undefined], | |
| 64 ['video/webm', new Uint8Array(0)], | |
|
ddorwin
2014/03/07 01:45:51
We should test normal arrays, objects, numbers, et
xhwang
2014/03/08 00:37:45
Done.
ddorwin
2014/03/10 20:11:44
As mentioned at new line 22, I don't think we are
| |
| 65 ['', initData], | |
| 66 ], 'InvalidAccessError', 'Test MediaKeys createSession() invalid acc ess errors'); | |
|
ddorwin
2014/03/07 01:45:51
Except for the last one, these are really empty ar
xhwang
2014/03/08 00:37:45
Done.
| |
| 67 | |
| 68 test_syntax(mediaKeys.createSession.bind(mediaKeys), [ | |
| 69 [null, initData], | |
| 70 [undefined, initData], | |
| 71 ["unsupported", initData], | |
| 72 ["Video/webm", initData], | |
| 73 ], 'NotSupportedError', 'Test MediaKeys createSession() not supporte d errors'); | |
| 74 | |
|
ddorwin
2014/03/07 01:45:51
Should we have a basic isTypeSupported() syntax te
xhwang
2014/03/08 00:37:45
Yeah, will do.
| |
| 75 test(function() | |
| 27 { | 76 { |
| 28 consoleWrite("Test MediaKeys."); | 77 mediaKeySession = mediaKeys.createSession('video/webm', initData ); |
| 29 testExpected('typeof window.MediaKeys', 'function'); | 78 mediaKeySession = mediaKeys.createSession('video/webm', initData , extraParam); |
| 30 testDOMException('new MediaKeys("")', "DOMException.INVALID_ACCE SS_ERR"); | 79 assert_equals(typeof mediaKeySession, 'object'); |
| 31 testDOMException('new MediaKeys("unsupported")', "DOMException.N OT_SUPPORTED_ERR"); | 80 assert_equals(typeof mediaKeySession.addEventListener, 'function '); |
|
ddorwin
2014/03/07 01:45:51
Should check MK does not have this.
xhwang
2014/03/08 00:37:45
Done.
| |
| 32 run('mediaKeys = new MediaKeys("org.w3.clearkey")'); | 81 assert_equals(typeof mediaKeySession.update, 'function'); |
| 33 testExpected('typeof mediaKeys', 'object'); | 82 assert_equals(mediaKeySession.error, null); |
| 34 testExpected('mediaKeys.keySystem', 'org.w3.clearkey'); | 83 assert_equals(mediaKeySession.keySystem, 'org.w3.clearkey'); |
| 35 testExpected('typeof mediaKeys.createSession', 'function'); | 84 assert_not_equals(mediaKeySession.sessionId, null); |
|
ddorwin
2014/03/07 01:45:51
Can we actually verify it's a string and not empty
xhwang
2014/03/08 00:37:45
We need to wait for the "ready" if we want to chec
| |
| 85 assert_equals(mediaKeySession.onwebkitkeyadded, undefined); | |
|
ddorwin
2014/03/07 01:45:51
Is this useful? Maybe we should test that none of
xhwang
2014/03/08 00:37:45
Removed.
| |
| 86 assert_equals(mediaKeySession.onwebkitkeyerror, undefined); | |
|
ddorwin
2014/03/07 01:45:51
speaking of which, we should have HTMLMediaElement
xhwang
2014/03/08 00:37:45
Added FIXME.
| |
| 87 assert_equals(mediaKeySession.onwebkitkeymessage, undefined); | |
| 88 }, "Test MediaKeySession creation."); | |
| 36 | 89 |
| 37 testException('mediaKeys.createSession()', '"TypeError: Failed t o execute \'createSession\' on \'MediaKeys\': 2 arguments required, but only 0 p resent."'); | 90 test_syntax(mediaKeySession.update.bind(mediaKeySession), [ |
| 38 testException('mediaKeys.createSession("")', '"TypeError: Failed to execute \'createSession\' on \'MediaKeys\': 2 arguments required, but only 1 present."'); | 91 [], |
| 39 testException('mediaKeys.createSession("video/webm")', '"TypeErr or: Failed to execute \'createSession\' on \'MediaKeys\': 2 arguments required, but only 1 present."'); | 92 ], typeError, 'Test MediaKeySession update() type errors'); |
|
ddorwin
2014/03/07 01:45:51
too few parameters
xhwang
2014/03/08 00:37:45
Done.
| |
| 40 testDOMException('mediaKeys.createSession("", new Uint8Array(1)) ', "DOMException.INVALID_ACCESS_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"); | |
| 44 consoleWrite(""); | |
| 45 | 93 |
|
ddorwin
2014/03/07 01:45:51
Looking at base, I see we lose some verbosity. Goo
xhwang
2014/03/08 00:37:45
Added some comments. Do we need to have descriptio
| |
| 46 consoleWrite("Test MediaKeySession."); | 94 test_syntax(mediaKeySession.update.bind(mediaKeySession), [ |
| 47 run('mediaKeySession = mediaKeys.createSession("video/webm", ini tData)'); | 95 [""], |
| 48 testExpected('typeof mediaKeySession', 'object'); | 96 [null], |
| 49 testExpected('typeof mediaKeySession.addEventListener', 'functio n'); | 97 [undefined], |
| 50 testExpected('typeof mediaKeySession.update', 'function'); | 98 [new Uint8Array(0)], |
| 51 testExpected('mediaKeySession.error', null); | 99 ], 'InvalidAccessError', 'Test MediaKeySession update() invalid acce ss errors'); |
| 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 | 100 |
| 61 run('mediaKeySession.release()'); | 101 test(function() |
| 102 { | |
| 103 mediaKeySession.update(new Uint8Array(1)); | |
| 104 mediaKeySession.update(new Uint8Array(1), extraParam); | |
| 105 }, "Test MediaKeySession update()."); | |
| 62 | 106 |
| 63 endTest(); | 107 test(function() |
| 64 } | 108 { |
| 109 mediaKeySession.release(); | |
| 110 // Extra parameters are ignored. | |
| 111 // TODO(xhwang): This causes Chromium to crash. Uncomment this o nce Chromium is fixed. | |
|
ddorwin
2014/03/07 01:45:51
Yay for tests! :)
Change to:
FIXME:
^ no nam
xhwang
2014/03/08 00:37:45
Done.
| |
| 112 // mediaKeySession.release(extraParam); | |
| 113 }, "Test MediaKeySession release()."); | |
| 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 |