diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/encrypted-media/scripts/setmediakeys.js | |
parent | Initial commit. (diff) | |
download | firefox-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/setmediakeys.js')
-rw-r--r-- | testing/web-platform/tests/encrypted-media/scripts/setmediakeys.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/testing/web-platform/tests/encrypted-media/scripts/setmediakeys.js b/testing/web-platform/tests/encrypted-media/scripts/setmediakeys.js new file mode 100644 index 0000000000..a85adeaeaf --- /dev/null +++ b/testing/web-platform/tests/encrypted-media/scripts/setmediakeys.js @@ -0,0 +1,50 @@ +function runTest(config, qualifier) { + var testname = testnamePrefix( qualifier, config.keysystem ) + + ', setMediaKeys'; + + var configuration = getSimpleConfigurationForContent( config.content ); + + if ( config.initDataType && config.initData ) { + configuration.initDataTypes = [ config.initDataType ]; + } + + async_test (function (test) { + var _video = config.video, + _mediaKeys; + + // Test MediaKeys assignment. + assert_equals(_video.mediaKeys, null); + assert_equals(typeof _video.setMediaKeys, 'function'); + + function onFailure(error) { + forceTestFailureFromPromise(test, error); + } + + // Try setting mediaKeys to null. + _video.setMediaKeys(null).then(function(result) { + assert_equals(_video.mediaKeys, null); + + // setMediaKeys should fail when setting to the wrong type of object - Date. + return _video.setMediaKeys(new Date()); + }).then(function (result) { + assert_unreached('setMediaKeys should fail when setting to wrong kind of object (Date)'); + }, function(error) { + // The error should be TypeError. + assert_throws_js(TypeError, () => { throw error; }, + 'setMediaKeys should return a TypeError when setting to wrong kind of object (Date)'); + return navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]); + }).then(function(access) { + assert_equals(access.keySystem, config.keysystem) + return access.createMediaKeys(); + }).then(function(result) { + _mediaKeys = result; + assert_not_equals(_mediaKeys, null); + assert_equals(typeof _mediaKeys.createSession, 'function'); + return _video.setMediaKeys(_mediaKeys); + }).then(function(result) { + assert_not_equals(_video.mediaKeys, null); + assert_equals(_video.mediaKeys, _mediaKeys); + test.done(); + }).catch(onFailure); + }, testname); +} |