summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/Google/migrated_to_root_disabled/encrypted-media-setmediakeys-multiple-times-with-different-mediakeys.html
blob: 31cc61079640c74f7c6f863b0816b2f22d12862b (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
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>setMediaKeys() multiple times with different MediaKeys.</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>
        <video id="video"></video>
        <div id="log"></div>
        <script>
            promise_test(function(test)
            {
                var video = document.getElementById('video');
                var content = 'webm/test-encrypted.webm';
                var keySystemAccess;
                var mediaKeys1;
                var mediaKeys2;

                assert_equals(video.mediaKeys, null);

                return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getConfigurationForFile(content)).then(function(access) {
                    keySystemAccess = access;
                    // Create a mediaKeys.
                    return keySystemAccess.createMediaKeys();
                }).then(function(result) {
                    mediaKeys1 = result;
                    assert_not_equals(mediaKeys1, null);
                    // Create a second mediaKeys.
                    return keySystemAccess.createMediaKeys();
                }).then(function(result) {
                    mediaKeys2 = result;
                    assert_not_equals(mediaKeys2, null);
                    // Set mediaKeys1 on video.
                    return video.setMediaKeys(mediaKeys1);
                }).then(function() {
                    assert_true(video.mediaKeys === mediaKeys1);
                    // Set mediaKeys2 on video (switching MediaKeys).
                    return video.setMediaKeys(mediaKeys2);
                }).then(function() {
                    assert_true(video.mediaKeys === mediaKeys2);
                    // Clear mediaKeys from video.
                    return video.setMediaKeys(null);
                }).then(function() {
                    assert_equals(video.mediaKeys, null);
                    // Set mediaKeys1 on video again.
                    return video.setMediaKeys(mediaKeys1);
                }).then(function() {
                    assert_true(video.mediaKeys === mediaKeys1);
                    // Load the media element to create the WebMediaPlayer.
                    video.src = content;
                    // Set mediaKeys2 on video (switching MediaKeys) not
                    // supported after WebMediaPlayer is created.
                    return video.setMediaKeys(mediaKeys2);
                }).then(function() {
                    assert_unreached('Switching mediaKeys after setting src should have failed.');
                }, function(error) {
                    assert_true(video.mediaKeys === mediaKeys1);
                    assert_equals(error.name, 'InvalidStateError');
                    assert_not_equals(error.message, '');
                    // Return something so the promise resolves properly.
                    return Promise.resolve();
                }).then(function() {
                    // Set null mediaKeys on video (clearing MediaKeys) not
                    // supported after WebMediaPlayer is created.
                    return video.setMediaKeys(null);
                }).then(function() {
                    assert_unreached('Clearing mediaKeys after setting src should have failed.');
                }, function(error) {
                    assert_true(video.mediaKeys === mediaKeys1);
                    assert_equals(error.name, 'InvalidStateError');
                    assert_not_equals(error.message, '');
                    return Promise.resolve();
                });
            }, 'setMediaKeys() multiple times with different MediaKeys.');
        </script>
    </body>
</html>