summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/scripts/setmediakeys-at-same-time.js
blob: 6d67d95b1f0c8a02a490bb53b6370e047d906d70 (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
function runTest(config, qualifier) {
    var testname = testnamePrefix(qualifier, config.keysystem)
                                             + ', setmediakeys at same time';

    var configuration = getSimpleConfigurationForContent(config.content);

    async_test(function(test) {
        var _video = config.video,
            _access,
            _mediaKeys1,
            _mediaKeys2,
            _mediaKeys3,
            _mediaKeys4,
            _mediaKeys5;

        // Test MediaKeys assignment.
        assert_equals(_video.mediaKeys, null);
        assert_equals(typeof _video.setMediaKeys, 'function');

        function onFailure(error) {
            forceTestFailureFromPromise(test, error);
        }

        function setMediaKeys(mediaKeys) {
            return _video.setMediaKeys(mediaKeys)
                .then(function() {return 1}, function() {return 0})
        }

        navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]).then(function(access) {
            _access = access;
            return _access.createMediaKeys();
        }).then(function(result) {
            _mediaKeys1 = result;
            return _access.createMediaKeys();
        }).then(function(result) {
            _mediaKeys2 = result;
            return _access.createMediaKeys();
        }).then(function(result) {
            _mediaKeys3 = result;
            return _access.createMediaKeys();
        }).then(function(result) {
            _mediaKeys4 = result;
            return _access.createMediaKeys();
        }).then(function(result) {
            _mediaKeys5 = result;
            return Promise.all([
                setMediaKeys(_mediaKeys1),
                setMediaKeys(_mediaKeys2),
                setMediaKeys(_mediaKeys3),
                setMediaKeys(_mediaKeys4),
                setMediaKeys(_mediaKeys5)
            ]);
        }).then(function(results) {
            var sum = results.reduce((a, b) => a + b, 0);
            assert_in_array(sum,[1,5]);
            test.done();
        }).catch(onFailure);
    }, testname);
}