summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/Google/migrated_to_root_disabled/encrypted-media-reset-src-after-setmediakeys.html
blob: 15c91a001c36bceb4897bac298511b897b961840 (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
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>Reset src after setMediaKeys()</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="testVideo"></video>
        <div id="log"></div>
        <script>
            async_test(function(test)
            {
                var mediaKeys;
                var encryptedEventIndex = 0;
                var video = document.getElementById('testVideo');
                assert_not_equals(video, null);

                // Content to be played. These files must be the same format.
                var content = 'webm/test-encrypted.webm';
                var alternateContent = 'webm/test-encrypted-different-av-keys.webm';

                var onEncrypted = function(event)
                {
                    ++encryptedEventIndex;
                    assert_not_equals(video.mediaKeys, null);
                    assert_true(video.mediaKeys === mediaKeys);

                    // This event is fired once for the audio stream and once
                    // for the video stream each time .src is set.
                    if (encryptedEventIndex == 2) {
                        // Finished first video; set src to a different video.
                        video.src = alternateContent;
                    } else if (encryptedEventIndex == 4) {
                        // Finished second video.
                        test.done();
                    }
                };

                // Create a MediaKeys object and assign it to video.
                navigator.requestMediaKeySystemAccess('org.w3.clearkey', getConfigurationForFile(content))
                .then(function(access) {
                    assert_equals(access.keySystem, 'org.w3.clearkey');
                    return access.createMediaKeys();
                }).then(function(result) {
                    mediaKeys = result;
                    assert_not_equals(mediaKeys, null);
                    return video.setMediaKeys(mediaKeys);
                }).then(function(result) {
                    assert_not_equals(video.mediaKeys, null, 'not set initially');
                    assert_true(video.mediaKeys === mediaKeys);

                    // Set src to a video.
                    waitForEventAndRunStep('encrypted', video, onEncrypted, test);
                    video.src = content;
                }).catch(function(error) {
                    forceTestFailureFromPromise(test, error);
                });
            }, 'Reset src after setMediaKeys().');
        </script>
    </body>
</html>