4 <title>MediaKeySession lifetime after release()
</title>
5 <script src=
"encrypted-media-utils.js"></script>
6 <script src=
"../../resources/testharness.js"></script>
7 <script src=
"../../resources/testharnessreport.js"></script>
12 // Since MediaKeySession (and MediaKeys) are ActiveDOMObjects,
13 // we can determine when they are garbage collected.
14 // MediaKeySessions remain as long as:
15 // JavaScript has a reference to it
16 // OR (MediaKeys is around
17 // AND the session has not received a close() event)
18 async_test(function(test
)
25 var startingActiveDOMObjectCount
= window
.internals
.activeDOMObjectCount(document
);
27 function numActiveDOMObjectsCreated()
29 return window
.internals
.activeDOMObjectCount(document
) - startingActiveDOMObjectCount
;
33 getSupportedInitDataType().then(function(type
) {
35 initData
= getInitData(initDataType
);
36 return navigator
.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
37 }).then(function(access
) {
38 return access
.createMediaKeys();
39 }).then(function(result
) {
42 // Verify MediaKeys is an ActiveDOMObject.
43 // In non-Oilpan, numActiveDOMObjectsCreate() == 1.
44 // In Oilpan, numActiveDOMObjectsCreate() <= 4.
46 // 1 MediaKeysInitializer and
47 // 1 MediaKeySystemAccessInitializer (navigator.requestMediaKeySystemAccess() use above),
48 // 1 MediaKeySystemAccessInitializer (isInitDataSupported() (via getSupportedInitDataType())))
49 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 4, 'MediaKeys.create()');
51 mediaKeySession1
= mediaKeys
.createSession();
52 return mediaKeySession1
.generateRequest(initDataType
, initData
);
54 // Should be 1 MediaKeys + 1 MediaKeySession.
55 // In non-Oilpan, numActiveDOMObjectsCreate() == 2.
56 // In Oilpan, numActiveDOMObjectsCreate() <= 6.
58 // 1 MediaKeysInitializer,
59 // 2 MediaKeySystemAccessInitializers,
60 // 1 ContentDecryptionModuleResultPromise and
61 // 1 MediaKeySession).
62 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 6, 'MediaKeys.createSession(1)');
64 mediaKeySession2
= mediaKeys
.createSession();
65 return mediaKeySession2
.generateRequest(initDataType
, initData
);
67 // Should be 1 MediaKeys + 2 MediaKeySessions.
68 // In non-Oilpan, numActiveDOMObjectsCreate() == 3.
69 // In Oilpan, numActiveDOMObjectsCreate() <= 8.
71 // 1 MediaKeysInitializer,
72 // 2 MediaKeySystemAccessInitializers,
73 // 2 ContentDecryptionModuleResultPromise and
74 // 2 MediaKeySession).
75 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 8, 'mediaKeys.createSession(2)');
77 // Close the sessions. Once completed, only the JS
78 // reference to them keeps them around.
79 return mediaKeySession1
.close();
80 }).then(function(result
) {
81 return mediaKeySession2
.close();
82 }).then(function(result
) {
83 // Since both sessions have been closed, dropping the
84 // reference to them from JS will result in the session
85 // being garbage-collected.
86 // Should be 1 MediaKeys + 2 MediaKeySessions.
87 // In non-Oilpan, numActiveDOMObjectsCreate() == 3.
88 // In Oilpan, numActiveDOMObjectsCreate() <= 10.
90 // 1 MediaKeysInitializer,
91 // 2 MediaKeySystemAccessInitializers,
92 // 4 ContentDecryptionModuleResultPromise and
93 // 2 MediaKeySession).
94 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 10, 'after close');
96 mediaKeySession1
= null;
97 return createGCPromise();
99 // Only MediaKeys + mediaKeySession2 should remain.
100 // In non-Oilpan, there is also something from createGCPromise().
101 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 3, 'mediaKeySession1 not collected');
103 mediaKeySession2
= null;
104 return createGCPromise();
106 // Only MediaKeys should remain.
107 // In non-Oilpan, there is also something from createGCPromise().
108 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 2, 'mediaKeySession2 not collected');
110 }).catch(function(error
) {
111 forceTestFailureFromPromise(test
, error
);
113 }, 'MediaKeySession lifetime after release()');