summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/scripts/generate-request-disallowed-input.js
blob: 9fd42ee85fa7d9390cbadba60dc4236891e99a54 (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
function runTest(config,qualifier) {
    var tests = [ ], initData, keyId;
    function push_test(keysystem, initDataType, initData, testname) {
        tests.push({ keysystem: keysystem, initDataType: initDataType, initData: initData, testname: testname });
    }

    initData = new Uint8Array(70000);
    push_test(config.keysystem, 'webm', initData, testnamePrefix( qualifier, config.keysystem ) + ', temporary, webm, initData longer than 64Kb characters');

    initData = new Uint8Array(70000);
    push_test(config.keysystem, 'cenc', initData, testnamePrefix( qualifier, config.keysystem ) + ', temporary, cenc, initData longer than 64Kb characters');

    initData = new Uint8Array(70000);
    push_test(config.keysystem, 'keyids', initData, testnamePrefix( qualifier, config.keysystem ) + ', temporary, keyids, initData longer than 64Kb characters');

    // Invalid 'pssh' box as the size specified is larger than what
    // is provided.
    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
    ]);
    push_test(config.keysystem, 'cenc', initData, testnamePrefix( qualifier, config.keysystem ) + ', temporary, cenc, invalid initdata (invalid pssh)');

    // Invalid data as type = 'psss'.
    initData = new Uint8Array([
        0x00, 0x00, 0x00, 0x00,                          // size = 0
        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
    ]);
    push_test(config.keysystem, 'cenc', initData, testnamePrefix( qualifier, config.keysystem ) + ', temporary, cenc, invalid initdata (not pssh)');

    // Valid key ID size must be at least 1 character for keyids.
    keyId = new Uint8Array(0);
    initData = stringToUint8Array(createKeyIDs(keyId));
    push_test(config.keysystem, 'keyids', initData, testnamePrefix( qualifier, config.keysystem ) + ', temporary, keyids, invalid initdata (too short key ID)');

    // Valid key ID size must be less than 512 characters for keyids.
    keyId = new Uint8Array(600);
    initData = stringToUint8Array(createKeyIDs(keyId));
    push_test(config.keysystem, 'keyids', initData, testnamePrefix( qualifier, config.keysystem ) + ', temporary, keyids, invalid initdata (too long key ID)');

    Promise.all( tests.map(function(testspec) {
        return isInitDataTypeSupported(testspec.keysystem,testspec.initDataType);
    })).then(function(results) {
        tests.filter(function(testspec, i) { return results[i]; } ).forEach(function(testspec) {
            promise_test(function(test) {
                // Create a "temporary" session for |keysystem| and call generateRequest()
                // with the provided initData. generateRequest() should fail with an
                // TypeError. Returns a promise that is resolved
                // if the error occurred and rejected otherwise.
                var p = navigator.requestMediaKeySystemAccess(testspec.keysystem, getSimpleConfigurationForInitDataType(testspec.initDataType)).then(function(access) {
                    return access.createMediaKeys();
                }).then(function(mediaKeys) {
                    var mediaKeySession = mediaKeys.createSession("temporary");
                    return mediaKeySession.generateRequest(testspec.initDataType, testspec.initData);
                });

                return promise_rejects_js(test, TypeError, p,
                                          "generateRequest() should fail");
            }, testspec.testname);
        });
    });
}