summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/scripts/syntax-mediakeysystemaccess.js
blob: bbc7b6700bcbfc19658aae0c85311e4819294e5e (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
function runTest(config) {
    var keysystem = config.keysystem;
    var testname  = testnamePrefix(null, config.keysystem);
    var initDataType = config.initDataType;
    var configuration = {
        initDataTypes: [config.initDataType],
        audioCapabilities: [{contentType: config.audioType}],
        videoCapabilities: [{contentType: config.videoType}],
        sessionTypes: ['temporary']
    };

    var kRequestMediaKeySystemAccessExceptionsTestCases = [
        // Too few parameters.
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess();
            }
        },
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(keysystem);
            }
        },
        // Invalid key systems. Note that JavaScript converts all these
        // values into strings by calling toString(), so they fail due
        // to the key system not being supported, not due to the type.
        {
            exception: 'NotSupportedError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(null, [{}]);
            }
        },
        {
            exception: 'NotSupportedError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(undefined, [{}]);
            }
        },
        {
            exception: 'NotSupportedError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(1, [{}]);
            }
        },
        {
            exception: 'NotSupportedError',
            func: function () {
                return navigator.requestMediaKeySystemAccess('unsupported', [{}]);
            }
        },
        // Empty keysystem string should be rejected with TypeError.
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess('', [{}]);
            }
        },
        // (new Uint8Array(0)).toString() should return ''. So this case should be the same
        // as the above.
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(new Uint8Array(0), [{}]);
            }
        },
        // Non-ASCII names.
        {
            exception: 'NotSupportedError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(keysystem + '\u263A', [{}]);
            }
        },
        // Empty sequence of MediaKeySystemConfiguration.
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(keysystem, []);
            }
        },
        // Things that don't convert to valid sequences of MediaKeySystemConfigurations.
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(keysystem, {});
            }
        },
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(keysystem, "invalid");
            }
        },
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(keysystem, [{}, 6]);
            }
        },
        {
            exception: 'TypeError',
            func: function () {
                return navigator.requestMediaKeySystemAccess(keysystem, ["invalid", "upsupported"]);
            }
        }
    ];

    function requestMediaKeySystemAccessTestExceptions(){
        return new Promise(function(resolve, reject){
            var createPromises = kRequestMediaKeySystemAccessExceptionsTestCases.map(function (testCase) {
                return test_exception(testCase);
            });
            Promise.all(createPromises).then(function (result) {
                resolve();
            }).catch(function (error) {
                reject(error);
            });
        })
    }
    promise_test(function() {
        return requestMediaKeySystemAccessTestExceptions();
    }, testname + ' test requestMediaKeySystemAccess() exceptions.');

    function requestMediaKeySystemAccessTestAttributes(){
        return new Promise(function(resolve, reject){
            isInitDataTypeSupported(keysystem, initDataType).then(function (isTypeSupported) {
                    assert_equals(typeof navigator.requestMediaKeySystemAccess, 'function');
                    assert_true(isTypeSupported, "initDataType not supported");
                    return navigator.requestMediaKeySystemAccess(keysystem, [configuration]);
                }).then(function (access) {
                    assert_not_equals(access, null);
                    assert_equals(typeof access, 'object');
                    assert_equals(access.keySystem, keysystem);
                    assert_equals(typeof access.getConfiguration, 'function');
                    assert_equals(typeof access.createMediaKeys, 'function');
                    resolve();
                }).catch(function(error){
                    reject(error);
                })
        })
    }
    promise_test(function() {
        return requestMediaKeySystemAccessTestAttributes();
    }, testname + ' test MediaKeySystemAccess attribute syntax.');

}