diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/encrypted-media/scripts/unique-origin.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/encrypted-media/scripts/unique-origin.js')
-rw-r--r-- | testing/web-platform/tests/encrypted-media/scripts/unique-origin.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/testing/web-platform/tests/encrypted-media/scripts/unique-origin.js b/testing/web-platform/tests/encrypted-media/scripts/unique-origin.js new file mode 100644 index 0000000000..015ea9d4e9 --- /dev/null +++ b/testing/web-platform/tests/encrypted-media/scripts/unique-origin.js @@ -0,0 +1,64 @@ +function runTest(config) { + // When the sandbox attribute is present on an iframe, it will + // treat the content as being from a unique origin. So try to + // call createMediaKeys() inside an iframe and it should fail. + + function load_iframe(src, sandbox) { + return new Promise(function (resolve) { + var iframe = document.createElement('iframe'); + iframe.onload = function () { + resolve(iframe); + }; + iframe.sandbox = sandbox; + iframe.srcdoc = src; + document.documentElement.appendChild(iframe); + }); + } + + function wait_for_message() { + return new Promise(function (resolve) { + self.addEventListener('message', function listener(e) { + resolve(e.data); + self.removeEventListener('message', listener); + }); + }); + } + + promise_test(function (test) { + var script = + '<script>' + + ' window.onmessage = function(e) {' + + ' navigator.requestMediaKeySystemAccess("' + config.keysystem + '", [{' + + ' initDataTypes: [\"' + config.initDataType + '\"],' + + ' audioCapabilities: [' + + ' { contentType:\'' + config.audioType + '\'},' + + ' ]' + + ' }]).then(function(access) {' + + ' return access.createMediaKeys();' + + ' }).then(function(mediaKeys) {' + + ' window.parent.postMessage({result: \'allowed\'}, \'*\');' + + ' }, function(error) {' + + ' window.parent.postMessage({result: \'failed\'}, \'*\');' + + ' });' + + ' };' + + '<\/script>'; + + // Verify that this page can create a MediaKeys first. + return navigator.requestMediaKeySystemAccess(config.keysystem, [{ + initDataTypes: [config.initDataType], + audioCapabilities: [ + {contentType: config.audioType}, + ] + }]).then(function (access) { + return access.createMediaKeys(); + }).then(function (mediaKeys) { + // Success, so now create the iframe and try there. + return load_iframe(script, 'allow-scripts allow-secure-context'); + }).then(function (iframe) { + iframe.contentWindow.postMessage({}, '*'); + return wait_for_message(); + }).then(function (message) { + assert_equals(message.result, 'failed'); + }); + }, 'Unique origin is unable to create MediaKeys'); +} |