summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/Google/migrated_to_root_disabled/encrypted-media-generate-request-disallowed-input.html
blob: 53e5c95b78a0d707f6aacf0516958339f9cb219e (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>Test handling of invalid initData for generateRequest().</title>
        <script src="encrypted-media-utils.js"></script>
<!--
        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>
            // Create a session and call generateRequest() with |initDataType|
            // and |initData|. generateRequest() should fail with an
            // InvalidAccessError. Returns a promise that resolves successfully
            // if the error happened, rejects otherwise.
            function test_session(initDataType, initData)
            {
                return isInitDataTypeSupported(initDataType).then(function(result) {
                    // If |initDataType| is not supported, simply succeed.
                    if (!result)
                        return Promise.resolve('Not supported');

                    return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfigurationForInitDataType(initDataType)).then(function(access) {
                        return access.createMediaKeys();
                    }).then(function(mediaKeys) {
                        var mediaKeySession = mediaKeys.createSession();
                        return mediaKeySession.generateRequest(initDataType, initData);
                    }).then(function() {
                        assert_unreached('generateRequest() succeeded');
                    }, function(error) {
                        assert_equals(error.name, 'InvalidAccessError');
                        return Promise.resolve('success');
                    });
                })
            }

            promise_test(function()
            {
                var initData = new Uint8Array(70000);
                return test_session('webm', initData);
            }, 'generateRequest() with webm initData longer than 64Kb characters.');

            promise_test(function()
            {
                var initData = new Uint8Array(70000);
                return test_session('cenc', initData);
            }, 'generateRequest() with cenc initData longer than 64Kb characters.');

            promise_test(function()
            {
                var initData = new Uint8Array(70000);
                return test_session('keyids', initData);
            }, 'generateRequest() with keyids initData longer than 64Kb characters.');

            promise_test(function()
            {
                // Invalid 'pssh' box as the size specified is larger than what
                // is provided.
                var initData = new Uint8Array([
                    0x00, 0x00, 0xff, 0xff,                          // size = huge
                    0x70, 0x73, 0x73, 0x68,                          // 'pssh'
                    0x00,                                            // version = 0
                    0x00, 0x00, 0x00,                                // flags
                    0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02,  // Common SystemID
                    0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
                    0x00, 0x00, 0x00, 0x00                           // datasize
                ]);
                return test_session('cenc', initData);
            }, 'generateRequest() with invalid pssh box size.');

            promise_test(function()
            {
                // Invalid data as type = 'psss'.
                var initData = new Uint8Array([
                    0x00, 0x00, 0x00, 0x20,                          // size = 32
                    0x70, 0x73, 0x73, 0x73,                          // 'psss'
                    0x00,                                            // version = 0
                    0x00, 0x00, 0x00,                                // flags
                    0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02,  // Common SystemID
                    0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
                    0x00, 0x00, 0x00, 0x00                           // datasize
                ]);
                return test_session('cenc', initData);
            }, 'generateRequest() with non pssh data.');

            promise_test(function()
            {
                // Valid key ID size must be at least 1 character for keyids.
                var keyId = new Uint8Array(0);
                var initData = stringToUint8Array(createKeyIDs(keyId));
                return test_session('keyids', initData);
            }, 'generateRequest() with too short key ID.');

            promise_test(function()
            {
                // Valid key ID size must be less than 512 characters for keyids.
                var keyId = new Uint8Array(600);
                var initData = stringToUint8Array(createKeyIDs(keyId));
                return test_session('keyids', initData);
            }, 'generateRequest() with too long key ID.');
        </script>
    </body>
</html>