summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/scripts/syntax-mediakeys.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/encrypted-media/scripts/syntax-mediakeys.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/encrypted-media/scripts/syntax-mediakeys.js')
-rw-r--r--testing/web-platform/tests/encrypted-media/scripts/syntax-mediakeys.js184
1 files changed, 184 insertions, 0 deletions
diff --git a/testing/web-platform/tests/encrypted-media/scripts/syntax-mediakeys.js b/testing/web-platform/tests/encrypted-media/scripts/syntax-mediakeys.js
new file mode 100644
index 0000000000..4ec6551e8f
--- /dev/null
+++ b/testing/web-platform/tests/encrypted-media/scripts/syntax-mediakeys.js
@@ -0,0 +1,184 @@
+function runTest(config) {
+ var keysystem = config.keysystem;
+ var testname = testnamePrefix(null, config.keysystem);
+ var initDataType = config.initDataType;
+ var configuration = {
+ initDataTypes: [config.initDataType],
+ audioCapabilities: [{contentType: config.audioType}],
+ videoCapabilities: [{contentType: config.videoType}],
+ sessionTypes: ['temporary']
+ };
+
+ function createMediaKeysAttributeTest() {
+ return new Promise(function (resolve, reject) {
+ var access;
+ isInitDataTypeSupported(keysystem, initDataType).then(function (isTypeSupported) {
+ assert_equals(typeof navigator.requestMediaKeySystemAccess, 'function');
+ assert_true(isTypeSupported, "initDataType should be supported");
+ return navigator.requestMediaKeySystemAccess(keysystem, [configuration]);
+ }).then(function (result) {
+ access = result;
+ assert_equals(access.keySystem, keysystem);
+ return access.createMediaKeys();
+ }).then(function (mediaKeys) {
+ assert_not_equals(mediaKeys, null);
+ assert_equals(typeof mediaKeys, 'object');
+ assert_equals(typeof mediaKeys.createSession, 'function');
+ assert_equals(typeof mediaKeys.setServerCertificate, 'function');
+
+ // Test creation of a second MediaKeys.
+ // The extra parameter is ignored.
+ return access.createMediaKeys('extra');
+ }).then(function (mediaKeys) {
+ assert_not_equals(mediaKeys, null);
+ assert_equals(typeof mediaKeys, 'object');
+ assert_equals(typeof mediaKeys.createSession, 'function');
+ assert_equals(typeof mediaKeys.setServerCertificate, 'function');
+ resolve();
+ }).catch(function (error) {
+ reject(error);
+ });
+ })
+ }
+
+ promise_test(function() {
+ return createMediaKeysAttributeTest();
+ }, testname + ' test MediaKeys attribute syntax');
+
+ var kSetServerCertificateExceptionsTestCases = [
+ // Too few parameters.
+ {
+ exception: 'TypeError',
+ func: function (mk) {
+ return mk.setServerCertificate();
+ }
+ },
+ // Invalid parameters.
+ {
+ exception: 'TypeError',
+ func: function (mk) {
+ return mk.setServerCertificate('');
+ }
+ },
+ {
+ exception: 'TypeError',
+ func: function (mk) {
+ return mk.setServerCertificate(null);
+ }
+ },
+ {
+ exception: 'TypeError',
+ func: function (mk) {
+ return mk.setServerCertificate(undefined);
+ }
+ },
+ {
+ exception: 'TypeError',
+ func: function (mk) {
+ return mk.setServerCertificate(1);
+ }
+ },
+ // Empty array.
+ {
+ exception: 'TypeError',
+ func: function (mk) {
+ return mk.setServerCertificate(new Uint8Array(0));
+ }
+ }
+ ];
+
+
+ function setServerCertificateTestExceptions() {
+ return new Promise(function(resolve, reject) {
+ isInitDataTypeSupported(keysystem, initDataType).then(function (isTypeSupported) {
+ assert_equals(typeof navigator.requestMediaKeySystemAccess, 'function');
+ assert_true(isTypeSupported, "initDataType not supported");
+ return navigator.requestMediaKeySystemAccess(keysystem, [configuration]);
+ }).then(function (access) {
+ return access.createMediaKeys();
+ }).then(function (mediaKeys) {
+ var promises = kSetServerCertificateExceptionsTestCases.map(function (testCase) {
+ return test_exception(testCase, mediaKeys);
+ });
+ assert_not_equals(promises.length, 0);
+ return Promise.all(promises);
+ }).then(function () {
+ resolve();
+ }).catch(function (error) {
+ reject(error);
+ });
+ })
+ }
+ promise_test(function() {
+ return setServerCertificateTestExceptions();
+ }, testname + ' test MediaKeys setServerCertificate() exceptions.');
+
+ // All calls to |func| in this group resolve. setServerCertificate with these cert may either resolve with true
+ // for clearkey or throw a DOMException.
+ var kSetServerCertificateTestCases = [
+ {
+ // Pass in ArrayBufferView
+ func: function (mk) {
+ var cert = new Uint8Array(200);
+ assert_true(ArrayBuffer.isView(cert));
+
+ return new Promise(function (resolve, reject) {
+ mk.setServerCertificate(cert).then(function (value) {
+ resolve(value);
+ }).catch(function (error) {
+ if (Object.prototype.toString.call(error) === "[object DOMException]") {
+ resolve(false);
+ }
+ });
+ })
+ },
+ expected: false
+ },
+ {
+ // Pass in ArrayBuffer.
+ func: function (mk) {
+ var cert = new ArrayBuffer(200);
+ assert_false(ArrayBuffer.isView(cert));
+ return new Promise(function (resolve) {
+ mk.setServerCertificate(cert).then(function (resolveValue) {
+ resolve(resolveValue);
+ }).catch(function (error) {
+ if (Object.prototype.toString.call(error) === "[object DOMException]") {
+ resolve(false);
+ }
+ });
+ })
+ },
+ expected: false
+ }
+ ];
+ function setServerCertificateTest(){
+ return new Promise(function(resolve, reject){
+ var expected_result;
+ isInitDataTypeSupported(keysystem, initDataType).then(function (isTypeSupported) {
+ assert_equals(typeof navigator.requestMediaKeySystemAccess, 'function');
+ assert_true(isTypeSupported, "initDataType not supported");
+ return navigator.requestMediaKeySystemAccess(keysystem, [configuration]);
+ }).then(function (access) {
+ return access.createMediaKeys();
+ }).then(function (mediaKeys) {
+ var promises = kSetServerCertificateTestCases.map(function (testCase) {
+ return testCase.func.call(null, mediaKeys);
+ });
+ expected_result = kSetServerCertificateTestCases.map(function (testCase) {
+ return testCase.expected;
+ });
+ assert_not_equals(promises.length, 0);
+ return Promise.all(promises);
+ }).then(function (result) {
+ assert_array_equals(result, expected_result);
+ resolve();
+ }).catch(function (error) {
+ reject(error);
+ });
+ })
+ }
+ promise_test(function() {
+ return setServerCertificateTest();
+ }, testname + ' test MediaKeys setServerCertificate() syntax with non-empty certificate.');
+}