4 <title>Unique origin is unable to create MediaKeys
</title>
5 <script src=
"../../resources/testharness.js"></script>
6 <script src=
"../../resources/testharnessreport.js"></script>
11 // When the sandbox attribute is present on an iframe, it will
12 // treat the content as being from a unique origin. So try to
13 // call createMediaKeys() inside an iframe and it should fail.
15 function load_iframe(src
, sandbox
) {
16 return new Promise(function(resolve
) {
17 var iframe
= document
.createElement('iframe');
18 iframe
.onload = function() { resolve(iframe
); };
19 iframe
.sandbox
= sandbox
;
21 document
.documentElement
.appendChild(iframe
);
25 function wait_for_message() {
26 return new Promise(function(resolve
) {
27 self
.addEventListener('message', function listener(e
) {
29 self
.removeEventListener(listener
);
34 promise_test(function(test
) {
35 var script
= 'data:text/html,' +
37 ' window.onmessage = function(e) {' +
38 ' navigator.requestMediaKeySystemAccess(\'org.w3.clearkey\', [{}]).then(function(access) {' +
39 ' return access.createMediaKeys();' +
40 ' }).then(function(mediaKeys) {' +
41 ' window.parent.postMessage({result: \'allowed\'}, \'*\');' +
42 ' }, function(error) {' +
43 ' window.parent.postMessage({result: \'failed\'}, \'*\');' +
48 // Verify that this page can create a MediaKeys first.
49 navigator
.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access
) {
50 return access
.createMediaKeys();
51 }).then(function(mediaKeys
) {
52 // Success, so now create the iframe and try there.
53 return load_iframe(script
, 'allow-scripts')
54 }).then(function(iframe
) {
55 iframe
.contentWindow
.postMessage({}, '*');
56 return wait_for_message();
57 }).then(function(message
) {
58 assert_equals(message
.result
, 'failed');
60 }, 'Unique origin is unable to create MediaKeys');