summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/Google/migrated_to_root_disabled/encrypted-media-unique-origin.html
blob: ffb67679f119312d7a98025779c839bfb778be79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>Unique origin is unable to create MediaKeys</title>
<!--
        Test has been migrated to the root directory and is being disabled here.
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
-->
    </head>
    <body>
        <div id="log"></div>
        <script>
            // 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(\'org.w3.clearkey\', [{' +
                    '           initDataTypes: [ \'keyids\' ],' +
                    '           audioCapabilities: [' +
                    '               { contentType: \'audio/mp4; codecs="mp4a.40.2"\' },' +
                    '               { contentType: \'audio/webm; codecs="opus"\' }' +
                    '           ]' +
                    '       }]).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.
                navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{
                    initDataTypes: [ 'keyids' ],
                    audioCapabilities: [
                        { contentType: 'audio/mp4; codecs="mp4a.40.2"' },
                        { contentType: 'audio/webm; codecs="opus"' }
                    ]
                }]).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');
        </script>
    </body>
</html>