Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1728)

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/unique-origin.js

Issue 2546853003: Add W3C encrypted-media tests (Closed)
Patch Set: rebase now that content files landed Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/unique-origin.js
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/unique-origin.js b/third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/unique-origin.js
new file mode 100644
index 0000000000000000000000000000000000000000..ff1122db4de913755422f5ef5b6c4ef6efe7be8a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/wpt/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.src = 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 = 'data:text/html,' +
+ '<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');
+ }).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');
+}

Powered by Google App Engine
This is Rietveld 408576698