OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Unique origin is unable to create MediaKeys</title> | 4 <title>requestMediaKeySystemAccess() is not available on unique origin</
title> |
5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
7 </head> | 7 </head> |
8 <body> | 8 <body> |
9 <script> | 9 <script> |
10 // When the sandbox attribute is present on an iframe, it will | 10 // When the sandbox attribute is present on an iframe, it will |
11 // treat the content as being from a unique origin. So try to | 11 // treat the content as being from a unique origin. So try to |
12 // call createMediaKeys() inside an iframe and it should fail. | 12 // call createMediaKeys() inside an iframe and it should fail. |
13 | 13 |
14 function load_iframe(src, sandbox) { | 14 function load_iframe(src, sandbox) { |
15 return new Promise(function(resolve) { | 15 return new Promise(function(resolve) { |
16 var iframe = document.createElement('iframe'); | 16 var iframe = document.createElement('iframe'); |
17 iframe.onload = function() { resolve(iframe); }; | 17 iframe.onload = function() { resolve(iframe); }; |
18 iframe.sandbox = sandbox; | 18 iframe.sandbox = sandbox; |
19 iframe.src = src; | 19 iframe.src = src; |
20 document.documentElement.appendChild(iframe); | 20 document.documentElement.appendChild(iframe); |
21 }); | 21 }); |
22 } | 22 } |
23 | 23 |
24 function wait_for_message() { | 24 function wait_for_message() { |
25 return new Promise(function(resolve) { | 25 return new Promise(function(resolve) { |
26 self.addEventListener('message', function listener(e) { | 26 self.addEventListener('message', function listener(e) { |
27 resolve(e.data); | 27 resolve(e.data); |
28 self.removeEventListener('message', listener); | 28 self.removeEventListener('message', listener); |
29 }); | 29 }); |
30 }); | 30 }); |
31 } | 31 } |
32 | 32 |
33 promise_test(function(test) { | 33 promise_test(function(test) { |
| 34 // TODO(xhwang): Also check other EME APIs. |
34 var script = 'data:text/html,' + | 35 var script = 'data:text/html,' + |
35 '<script>' + | 36 '<script>' + |
36 ' window.onmessage = function(e) {' + | 37 ' window.onmessage = function(e) {' + |
37 ' navigator.requestMediaKeySystemAccess(\'org.w3.clea
rkey\', [{' + | 38 ' if (\'requestMediaKeySystemAccess\' in navigator) {
' + |
38 ' initDataTypes: [ \'keyids\' ],' + | 39 ' window.parent.postMessage({result: \'available\
'}, \'*\');' + |
39 ' audioCapabilities: [' + | 40 ' } else { ' + |
40 ' { contentType: \'audio/mp4; codecs="mp4a.40.
2"\' },' + | 41 ' window.parent.postMessage({result: \'unavailabl
e\'}, \'*\');' + |
41 ' { contentType: \'audio/webm; codecs="opus"\'
}' + | 42 ' }' + |
42 ' ]' + | |
43 ' }]).then(function(access) {' + | |
44 ' return access.createMediaKeys();' + | |
45 ' }).then(function(mediaKeys) {' + | |
46 ' window.parent.postMessage({result: \'allowed\'}
, \'*\');' + | |
47 ' }, function(error) {' + | |
48 ' window.parent.postMessage({result: \'failed\'},
\'*\');' + | |
49 ' });' + | |
50 ' };' + | 43 ' };' + |
51 '<\/script>'; | 44 '<\/script>'; |
52 | 45 |
53 // Verify that this page can create a MediaKeys first. | 46 // Verify that this page can create a MediaKeys first. |
54 return navigator.requestMediaKeySystemAccess('org.w3.clearkey',
[{ | 47 return navigator.requestMediaKeySystemAccess('org.w3.clearkey',
[{ |
55 initDataTypes: [ 'keyids' ], | 48 initDataTypes: [ 'keyids' ], |
56 audioCapabilities: [ | 49 audioCapabilities: [ |
57 { contentType: 'audio/mp4; codecs="mp4a.40.2"' }, | 50 { contentType: 'audio/mp4; codecs="mp4a.40.2"' }, |
58 { contentType: 'audio/webm; codecs="opus"' } | 51 { contentType: 'audio/webm; codecs="opus"' } |
59 ] | 52 ] |
60 }]).then(function(access) { | 53 }]).then(function(access) { |
61 return access.createMediaKeys(); | 54 return access.createMediaKeys(); |
62 }).then(function(mediaKeys) { | 55 }).then(function(mediaKeys) { |
63 // Success, so now create the iframe and try there. | 56 // Success, so now create the iframe and try there. |
64 return load_iframe(script, 'allow-scripts'); | 57 return load_iframe(script, 'allow-scripts'); |
65 }).then(function(iframe) { | 58 }).then(function(iframe) { |
66 iframe.contentWindow.postMessage({}, '*'); | 59 iframe.contentWindow.postMessage({}, '*'); |
67 return wait_for_message(); | 60 return wait_for_message(); |
68 }).then(function(message) { | 61 }).then(function(message) { |
69 assert_equals(message.result, 'failed'); | 62 assert_equals(message.result, 'unavailable'); |
70 }); | 63 }); |
71 }, 'Unique origin is unable to create MediaKeys'); | 64 }, 'requestMediaKeySystemAccess() is not available on unique origin'
); |
72 </script> | 65 </script> |
73 </body> | 66 </body> |
74 </html> | 67 </html> |
OLD | NEW |