Index: LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html |
diff --git a/LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html b/LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html |
index 7d74a658cd415bc233b8890a78774e69d65c76d0..96c1b54d0fe78ef185960c94697bed6c75e60af7 100644 |
--- a/LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html |
+++ b/LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html |
@@ -155,41 +155,72 @@ |
}, |
{ |
exception: 'TypeError', |
- func: function(mk, _, initData) { return mk.createSession(initData); } |
+ func: function(mk) { var initData = stringToUint8Array('init data'); return mk.createSession(initData); } |
ddorwin
2014/09/09 21:35:24
Is this just trying to test an invalid type? Would
jrummell
2014/09/10 01:18:25
Removed, since it is a TypeError and the previous
|
}, |
+ { |
+ exception: 'TypeError', |
+ func: function(mk) { return mk.createSession('TEMPORARY'); } |
+ } |
+ ]; |
+ |
+ async_test(function(test) |
+ { |
+ MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { |
+ // FIXME: Remove "video/" from the calls to isTypeSupported() once it is updated. |
ddorwin
2014/09/09 21:35:24
I don't think this comment applies to this case.
jrummell
2014/09/10 01:18:25
Done.
|
+ // http://crbug.com/405731. |
+ var sessionPromises = kCreateSessionExceptionsTestCases.map(function(testCase) { |
+ return test_exception(testCase, mediaKeys); |
+ }); |
+ |
+ assert_not_equals(sessionPromises.length, 0); |
+ return Promise.all(sessionPromises); |
+ }).then(function(result) { |
+ test.done(); |
+ }).catch(function(error) { |
+ forceTestFailureFromPromise(test, error, 'createSession() tests failed'); |
+ }); |
+ }, 'Test MediaKeys createSession() exceptions.'); |
+ |
+ var kGenerateRequestExceptionsTestCases = [ |
+ // Tests in this set use a shortened parameter name due to |
+ // format_value() only returning the first 60 characters as the |
+ // result. With a longer name the first 60 characters is not |
+ // enough to determine which test failed. Even with the |
+ // shortened name, the error message for the last couple of |
+ // tests is the same. |
// Invalid parameters. |
{ |
exception: 'InvalidAccessError', |
- func: function(mk, _, initData) { return mk.createSession('', initData); } |
+ func: function(mk1, _, initData) { return mk1.createSession().generateRequest('', initData); } |
}, |
- // Not supported contentTypes. |
+ // Not supported initDataTypes. |
{ |
exception: 'NotSupportedError', |
- func: function(mk, _, initData) { return mk.createSession(null, initData); } |
+ func: function(mk2, _, initData) { return mk2.createSession().generateRequest(null, initData); } |
}, |
{ |
exception: 'NotSupportedError', |
- func: function(mk, _, initData) { return mk.createSession(undefined, initData); } |
+ func: function(mk3, _, initData) { return mk3.createSession().generateRequest(undefined, initData); } |
}, |
{ |
exception: 'NotSupportedError', |
- func: function(mk, _, initData) { return mk.createSession(1, initData); } |
+ func: function(mk4, _, initData) { return mk4.createSession().generateRequest(1, initData); } |
}, |
{ |
exception: 'NotSupportedError', |
- func: function(mk, _, initData) { return mk.createSession(new Uint8Array(0), initData); } |
+ func: function(mk5, _, initData) { return mk5.createSession().generateRequest(new Uint8Array(0), initData); } |
}, |
{ |
exception: 'NotSupportedError', |
- func: function(mk, _, initData) { return mk.createSession('unsupported', initData); } |
+ func: function(mk6, _, initData) { return mk6.createSession().generateRequest('unsupported', initData); } |
}, |
{ |
exception: 'NotSupportedError', |
- func: function(mk, _, initData) { return mk.createSession('video/foo', initData); } |
+ func: function(mk7, _, initData) { return mk7.createSession().generateRequest('video/foo', initData); } |
}, |
{ |
exception: 'NotSupportedError', |
- func: function(mk, _, initData) { return mk.createSession('text/webm', initData); } |
+ func: function(mk8, _, initData) { return mk8.createSession().generateRequest('text/webm', initData); } |
} |
// FIXME: Enable when switching to initDataType from MIME type. |
// http://crbug.com/385874. |
@@ -199,7 +230,7 @@ |
// } |
]; |
- var kTypeSpecificCreateSessionExceptionsTestCases = [ |
+ var kTypeSpecificGenerateRequestExceptionsTestCases = [ |
// Tests in this set use a shortened parameter name due to |
// format_value() only returning the first 60 characters as the |
// result. With a longer name the first 60 characters is not |
@@ -210,54 +241,28 @@ |
// Too few parameters. |
{ |
exception: 'TypeError', |
- func: function(mk, type) { return mk.createSession(type); } |
+ func: function(mk1, type) { return mk1.createSession().generateRequest(type); } |
}, |
// Invalid parameters. |
{ |
exception: 'TypeError', |
- func: function(mk, type) { return mk.createSession(type, ''); } |
+ func: function(mk2, type) { return mk2.createSession().generateRequest(type, ''); } |
}, |
{ |
exception: 'TypeError', |
- func: function(mk, type) { return mk.createSession(type, null); } |
+ func: function(mk3, type) { return mk3.createSession().generateRequest(type, null); } |
}, |
{ |
exception: 'TypeError', |
- func: function(mk, type) { return mk.createSession(type, undefined); } |
+ func: function(mk4, type) { return mk4.createSession().generateRequest(type, undefined); } |
}, |
{ |
exception: 'TypeError', |
- func: function(mk, type) { return mk.createSession(type, 1); } |
+ func: function(mk5, type) { return mk5.createSession().generateRequest(type, 1); } |
}, |
{ |
exception: 'InvalidAccessError', |
- func: function(mk, type) { return mk.createSession(type, new Uint8Array(0)); } |
- }, |
- // Invalid sessionTypes. Added index to each variable name as |
- // otherwise the first 60 characters of func: is the same. |
- { |
- exception: 'TypeError', |
- func: function(mk1, type, initData) { return mk1.createSession(type, initData, ''); } |
- }, |
- { |
- exception: 'TypeError', |
- func: function(mk2, type, initData) { return mk2.createSession(type, initData, null); } |
- }, |
- { |
- exception: 'TypeError', |
- func: function(mk3, type, initData) { return mk3.createSession(type, initData, 1); } |
- }, |
- { |
- exception: 'TypeError', |
- func: function(mk4, type, initData) { return mk4.createSession(type, initData, new Uint8Array(0)); } |
- }, |
- { |
- exception: 'TypeError', |
- func: function(mk5, type, initData) { return mk5.createSession(type, initData, 'unsupported'); } |
- }, |
- { |
- exception: 'TypeError', |
- func: function(mk6, type, initData) { return mk6.createSession(type, initData, 'TEMPORARY'); } |
+ func: function(mk6, type) { return mk6.createSession().generateRequest(type, new Uint8Array(0)); } |
} |
]; |
@@ -267,14 +272,14 @@ |
// FIXME: Remove "video/" from the calls to isTypeSupported() once it is updated. |
// http://crbug.com/405731. |
var initData = stringToUint8Array('init data'); |
- var sessionPromises = kCreateSessionExceptionsTestCases.map(function(testCase) { |
+ var sessionPromises = kGenerateRequestExceptionsTestCases.map(function(testCase) { |
return test_exception(testCase, mediaKeys, '', initData); |
}); |
// Test that WebM sessions generate the expected error, if |
// supported. |
if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm')) { |
- var WebmSessionPromises = kTypeSpecificCreateSessionExceptionsTestCases.map(function(testCase) { |
+ var WebmSessionPromises = kTypeSpecificGenerateRequestExceptionsTestCases.map(function(testCase) { |
return test_exception(testCase, mediaKeys, 'webm', getInitData('webm')); |
}); |
sessionPromises = sessionPromises.concat(WebmSessionPromises); |
@@ -282,7 +287,7 @@ |
// Repeat for MP4, if supported. |
if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4')) { |
- var mp4SessionPromises = kTypeSpecificCreateSessionExceptionsTestCases.map(function(testCase) { |
+ var mp4SessionPromises = kTypeSpecificGenerateRequestExceptionsTestCases.map(function(testCase) { |
return test_exception(testCase, mediaKeys, 'cenc', getInitData('cenc')); |
}); |
sessionPromises = sessionPromises.concat(mp4SessionPromises); |
@@ -293,9 +298,9 @@ |
}).then(function(result) { |
test.done(); |
}).catch(function(error) { |
- forceTestFailureFromPromise(test, error, 'createSession() tests failed'); |
+ forceTestFailureFromPromise(test, error, 'generateRequest() tests failed'); |
}); |
- }, 'Test MediaKeys createSession() exceptions.'); |
+ }, 'Test MediaKeys generateRequest() exceptions.'); |
// All calls to |func| in this group are supposed to succeed. |
// However, the spec notes that some things are optional for |
@@ -309,28 +314,28 @@ |
// Use the default sessionType. |
{ |
- func: function(mk1, type, initData) { return mk1.createSession(type, initData); }, |
+ func: function(mk1) { return mk1.createSession(); }, |
isNotSupportedAllowed: false |
}, |
// Try variations of sessionType. |
{ |
- func: function(mk2, type, initData) { return mk2.createSession(type, initData, 'temporary'); }, |
+ func: function(mk2) { return mk2.createSession('temporary'); }, |
isNotSupportedAllowed: false |
}, |
{ |
- func: function(mk3, type, initData) { return mk3.createSession(type, initData, undefined); }, |
+ func: function(mk3) { return mk3.createSession(undefined); }, |
ddorwin
2014/09/09 21:35:24
Hmm. It seems this should fail. Maybe our IDL infr
jrummell
2014/09/10 01:18:25
In the previous discussion resolve(void) and resol
|
isNotSupportedAllowed: false |
}, |
{ |
// Since this is optional, some Clear Key implementations |
// will succeed, others will return a "NotSupportedError". |
// Both are allowed results. |
- func: function(mk4, type, initData) { return mk4.createSession(type, initData, 'persistent'); }, |
+ func: function(mk4) { return mk4.createSession('persistent'); }, |
isNotSupportedAllowed: true |
}, |
// Try additional parameter, which should be ignored. |
{ |
- func: function(mk5, type, initData) { return mk5.createSession(type, initData, 'temporary', 'extra'); }, |
+ func: function(mk5) { return mk5.createSession('temporary', 'extra'); }, |
isNotSupportedAllowed: false |
} |
]; |
@@ -339,36 +344,55 @@ |
// MediaKeySession object with some default values. It also |
// allows for an NotSupportedError to be generated and treated as a |
// success, if allowed. See comment above kCreateSessionTestCases. |
- function test_createSession(testCase /*...*/) |
+ function test_createSession(testCase, mediaKeys) |
{ |
- var func = testCase.func; |
- var isNotSupportedAllowed = testCase.isNotSupportedAllowed; |
- var args = Array.prototype.slice.call(arguments, 1); |
+ var mediaKeySession = testCase.func.call(null, mediaKeys); |
+ // FIXME: Update this set of tests when done |
+ // implementing the latest spec. |
+ if (mediaKeySession) { |
ddorwin
2014/09/09 21:35:24
If not supported, it will throw! That means this m
jrummell
2014/09/10 01:18:25
Done.
|
+ assert_equals(typeof mediaKeySession, 'object'); |
+ assert_equals(typeof mediaKeySession.addEventListener, 'function'); |
+ assert_equals(typeof mediaKeySession.generateRequest, 'function'); |
+ assert_equals(typeof mediaKeySession.update, 'function'); |
+ assert_equals(typeof mediaKeySession.release, 'function'); |
+ assert_equals(mediaKeySession.error, null); |
+ assert_equals(mediaKeySession.sessionId, ''); |
+ assert_equals(typeof mediaKeySession.sessionId, 'string'); |
+ assert_equals(typeof mediaKeySession.onopen, 'undefined'); |
ddorwin
2014/09/09 21:35:24
As part of the cleanup CL, the event names should
jrummell
2014/09/10 01:18:24
Acknowledged.
|
+ assert_equals(typeof mediaKeySession.onmessage, 'undefined'); |
+ assert_equals(typeof mediaKeySession.onclose, 'undefined'); |
+ assert_equals(typeof mediaKeySession.onerror, 'undefined'); |
+ } else { |
+ assert_true(testCase.isNotSupportedAllowed); |
+ } |
+ } |
- return func.apply(null, args).then( |
- function(mediaKeySession) |
- { |
- // FIXME: Update this set of tests when done |
- // implementing the latest spec. |
- assert_not_equals(mediaKeySession, null); |
- assert_equals(typeof mediaKeySession, 'object'); |
- assert_equals(typeof mediaKeySession.addEventListener, 'function'); |
- assert_equals(typeof mediaKeySession.update, 'function'); |
- assert_equals(mediaKeySession.error, null); |
- assert_true(mediaKeySession.sessionId && mediaKeySession.sessionId.length > 0); |
- assert_equals(typeof mediaKeySession.sessionId, 'string'); |
- assert_equals(typeof mediaKeySession.onopen, 'undefined'); |
- assert_equals(typeof mediaKeySession.onmessage, 'undefined'); |
- assert_equals(typeof mediaKeySession.onclose, 'undefined'); |
- assert_equals(typeof mediaKeySession.onerror, 'undefined'); |
- }, |
- function(error) |
- { |
- assert_true(isNotSupportedAllowed, format_value(func)); |
- assert_equals(error.name, 'NotSupportedError', format_value(func)); |
- assert_not_equals(error.message, "", format_value(func)); |
- } |
- ); |
+ async_test(function(test) |
+ { |
+ MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { |
+ kCreateSessionTestCases.map(function(testCase) { |
+ test_createSession(testCase, mediaKeys); |
+ }); |
+ test.done(); |
+ }).catch(function(error) { |
+ forceTestFailureFromPromise(test, error, 'createSession() tests failed'); |
+ }); |
+ }, 'Test MediaKeys createSession().'); |
+ |
+ // This function checks that calling generateRequest() works for |
+ // various sessions. |testCase.func| creates a MediaKeySession |
+ // object, and then generateRequest() is called on that object. It |
+ // allows for an NotSupportedError to be generated and treated as a |
+ // success, if allowed. See comment above kCreateSessionTestCases. |
+ function test_generateRequest(testCase, mediaKeys, type, initData) |
+ { |
+ var mediaKeySession = testCase.func.call(null, mediaKeys); |
+ if (mediaKeySession) { |
ddorwin
2014/09/09 21:35:24
ditto
jrummell
2014/09/10 01:18:25
Done.
|
+ return mediaKeySession.generateRequest(type, initData); |
+ } else { |
+ assert_true(testCase.isNotSupportedAllowed); |
+ return new Promise(new Promise(function() {})); |
+ } |
} |
async_test(function(test) |
@@ -380,7 +404,7 @@ |
// supported. |
if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm')) { |
var WebmSessionPromises = kCreateSessionTestCases.map(function(testCase) { |
- return test_createSession(testCase, mediaKeys, 'webm', getInitData('webm')); |
+ return test_generateRequest(testCase, mediaKeys, 'webm', getInitData('webm')); |
}); |
sessionPromises = sessionPromises.concat(WebmSessionPromises); |
} |
@@ -388,7 +412,7 @@ |
// Repeat for MP4, if supported. |
if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4')) { |
var mp4SessionPromises = kCreateSessionTestCases.map(function(testCase) { |
- return test_createSession(testCase, mediaKeys, 'cenc', getInitData('cenc')); |
+ return test_generateRequest(testCase, mediaKeys, 'cenc', getInitData('cenc')); |
}); |
sessionPromises = sessionPromises.concat(mp4SessionPromises); |
} |
@@ -398,9 +422,9 @@ |
}).then(function(result) { |
test.done(); |
}).catch(function(error) { |
- forceTestFailureFromPromise(test, error, 'createSession() tests failed'); |
+ forceTestFailureFromPromise(test, error, 'generateRequest() tests failed'); |
}); |
- }, 'Test MediaKeys createSession().'); |
+ }, 'Test MediaKeys generateRequest().'); |
var kUpdateSessionExceptionsTestCases = [ |
// Tests in this set use a shortened parameter name due to |
@@ -436,29 +460,29 @@ |
} |
]; |
- function create_update_exception_test(mediaKeys, type, initData) |
- { |
- var mediaKeySession; |
- var promise = mediaKeys.createSession(type, initData).then(function(mediaKeySession) { |
- var updatePromises = kUpdateSessionExceptionsTestCases.map(function(testCase) { |
- return test_exception(testCase, mediaKeySession); |
- }); |
- return Promise.all(updatePromises); |
- }); |
- return promise; |
- } |
- |
async_test(function(test) |
{ |
MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { |
var promises = []; |
if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm')) { |
- promises.push(create_update_exception_test(mediaKeys, 'webm', getInitData('webm'))); |
+ var WebmSessionPromises = kUpdateSessionExceptionsTestCases.map(function(testCase) { |
+ var mediaKeySession = mediaKeys.createSession(); |
+ return mediaKeySession.generateRequest('webm', getInitData('webm')).then(function(result) { |
+ return test_exception(testCase, mediaKeySession); |
+ }); |
+ }); |
+ promises = promises.concat(WebmSessionPromises); |
} |
if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4')) { |
- promises.push(create_update_exception_test(mediaKeys, 'cenc', getInitData('cenc'))); |
+ var mp4SessionPromises = kUpdateSessionExceptionsTestCases.map(function(testCase) { |
+ var mediaKeySession = mediaKeys.createSession(); |
+ return mediaKeySession.generateRequest('cenc', getInitData('cenc')).then(function(result) { |
+ return test_exception(testCase, mediaKeySession); |
+ }); |
+ }); |
+ promises = promises.concat(mp4SessionPromises); |
} |
assert_not_equals(promises.length, 0); |
@@ -472,9 +496,8 @@ |
function create_update_test(mediaKeys, type, initData) |
{ |
- var mediaKeySession; |
- var promise = mediaKeys.createSession(type, initData).then(function(result) { |
- mediaKeySession = result; |
+ var mediaKeySession = mediaKeys.createSession(); |
+ var promise = mediaKeySession.generateRequest(type, initData).then(function(result) { |
var validLicense = stringToUint8Array(createJWKSet(createJWK(stringToUint8Array('123'), stringToUint8Array('1234567890abcdef')))); |
return mediaKeySession.update(validLicense); |
}).then(function(result) { |
@@ -510,9 +533,8 @@ |
function create_release_test(mediaKeys, type, initData) |
{ |
- var mediaKeySession; |
- var promise = mediaKeys.createSession(type, initData).then(function(result) { |
- mediaKeySession = result; |
+ var mediaKeySession = mediaKeys.createSession(); |
+ var promise = mediaKeySession.generateRequest(type, initData).then(function(result) { |
return mediaKeySession.release(); |
// FIXME: Uncomment once the code supports multiple release() calls. |
// }).then(function(result) { |