summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/Google/migrated_to_root_disabled/encrypted-media-events.html
blob: a2a70f169c5ef8363ec6dd4bc53a93bedf5e4f7d (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
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>Verify v2 events</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>
        <div id="log"></div>
        <script>
            // Currently Clear Key only generates aynchronous "message" and
            // "keychange" events.
            async_test(function(test)
            {
                var initDataType;
                var initData;
                var mediaKeySession;
                var rawKey = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
                                             0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);

                function processMessage(event)
                {
                    assert_true(event instanceof window.MediaKeyMessageEvent);
                    assert_equals(event.target, mediaKeySession);
                    assert_equals(event.type, 'message');
                    assert_equals(event.messageType, 'license-request');

                    var keyId = extractSingleKeyIdFromMessage(event.message);
                    var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, rawKey)));

                    waitForEventAndRunStep('keystatuseschange', mediaKeySession, test.step_func(processKeyStatusesChange), test);

                    mediaKeySession.update(jwkSet).catch(test.step_func(function(error) {
                        forceTestFailureFromPromise(test, error);
                    }));
                }

                function processKeyStatusesChange(event)
                {
                    assert_true(event instanceof Event);
                    assert_equals(event.target, mediaKeySession);
                    assert_equals(event.type, 'keystatuseschange');
                    test.done();
                }

                navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
                    initDataType = access.getConfiguration().initDataTypes[0];
                    initData = getInitData(initDataType);
                    return access.createMediaKeys();
                }).then(test.step_func(function(mediaKeys) {
                    mediaKeySession = mediaKeys.createSession();
                    waitForEventAndRunStep('message', mediaKeySession, test.step_func(processMessage), test);
                    return mediaKeySession.generateRequest(initDataType, initData);
                })).catch(test.step_func(function(error) {
                    forceTestFailureFromPromise(test, error);
                }));
            }, 'Verify v2 events.');
        </script>
    </body>
</html>