summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/Google/chromium_specific_disabled/encrypted-media-lifetime-mediakeys-with-session.html
blob: a892b969c49b5d7b527bd49c534fe00bc596cd62 (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
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>Test MediaKeys lifetime when adding a session</title>
        <script src="encrypted-media-utils.js"></script>
<!--
        Test requires Chromium specific content and is being disabled.
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
-->
    </head>
    <body>
        <div id="log"></div>
        <script>
            // MediaKeySessions remain as long as:
            //   JavaScript has a reference to it
            //   OR (MediaKeys is around
            //       AND the session has not received a close() event)
            // In the tests below, we do not close any session nor keep a
            // Javascript reference to any session, so MediaKeySessions remain
            // as long as the associated MediaKeys object is around.

            // For this test, create a MediaKeySession and verify lifetime.
            async_test(function(test)
            {
                var initDataType;
                var initData;
                var mediaKeys;
                var startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document);

                function numActiveDOMObjectsCreated()
                {
                    return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount;
                }

                // Create a MediaKeys object with a session.
                navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
                    initDataType = access.getConfiguration().initDataTypes[0];
                    initData = getInitData(initDataType);
                    return access.createMediaKeys();
                }).then(function(result) {
                    mediaKeys = result;

                    // Verify MediaKeys is an ActiveDOMObject.
                    // In non-Oilpan, numActiveDOMObjectsCreate() == 1.
                    // In Oilpan, numActiveDOMObjectsCreate() <= 4.
                    // (1 MediaKeys,
                    //  1 MediaKeysInitializer and
                    //  1 MediaKeySystemAccessInitializer (navigator.requestMediaKeySystemAccess() use above),
                    //  1 MediaKeySystemAccessInitializer (isInitDataSupported() (via getSupportedInitDataType())))
                    assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 4, 'MediaKeys.create()');

                    var mediaKeySession = mediaKeys.createSession();
                    return mediaKeySession.generateRequest(initDataType, initData);
                }).then(function() {
                    // Should be 1 MediaKeys + 1 MediaKeySession.
                    // In non-Oilpan, numActiveDOMObjectsCreate() == 2.
                    // In Oilpan, numActiveDOMObjectsCreate() <= 6.
                    // (1 MediaKeys,
                    //  1 MediaKeysInitializer and
                    //  2 MediaKeySystemAccessInitializer,
                    //  1 ContentDecryptionModuleResultPromise and
                    //  1 MediaKeySession).
                    assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 6, 'MediaKeys.createSession()');

                    // Run gc(), should not affect MediaKeys object nor the
                    // session since we still have a reference to it.

                    // When enabling oilpan GC, the in-active
                    // ScriptPromiseResolvers will be destroyed.
                    return createGCPromise();
                }).then(function(result) {
                    assert_equals(typeof mediaKeys.createSession, 'function');

                    // MediaKeys + MediaKeySessions should remain.
                    // In non-Oilpan, there is also something from createGCPromise().
                    assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 3, 'After gc()');

                    // Drop reference to the MediaKeys object and run gc()
                    // again. Object should be collected this time. Since
                    // MediaKeySessions remain alive as long as MediaKeys is
                    // around, it is possible that gc() checks the
                    // MediaKeySession object first, and doesn't collect it
                    // since MediaKeys hasn't been collected yet. Thus run gc()
                    // twice, to ensure that the unreferenced MediaKeySession
                    // object get collected.
                    mediaKeys = null;
                    return createGCPromise();
                }).then(function(result) {
                    return createGCPromise();
                }).then(function(result) {
                    // No MediaKeySessions should remain.
                    // In non-Oilpan, there is also something from createGCPromise().
                    assert_between_inclusive(numActiveDOMObjectsCreated(), 0, 1, 'After final gc()');

                    test.done();
                }).catch(function(error) {
                    forceTestFailureFromPromise(test, error);
                });
            }, 'MediaKeys lifetime with session');
        </script>
    </body>
</html>