4 <title>Test MediaKeySession lifetime after release() without references
</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
)
22 var startingActiveDOMObjectCount
= window
.internals
.activeDOMObjectCount(document
);
24 function numActiveDOMObjectsCreated()
26 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 assert_true(mediaKeySession1
.sessionId
&& mediaKeySession1
.sessionId
.length
> 0);
56 // Should be 1 MediaKeys + 1 MediaKeySession.
57 // In non-Oilpan, numActiveDOMObjectsCreate() == 2.
58 // In Oilpan, numActiveDOMObjectsCreate() <= 6.
60 // 1 MediaKeysInitializer and
61 // 2 MediaKeySystemAccessInitializer,
62 // 1 ContentDecryptionModuleResultPromise and
63 // 1 MediaKeySession).
64 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 6, 'MediaKeys.createSession(1)');
66 mediaKeySession2
= mediaKeys
.createSession();
67 return mediaKeySession2
.generateRequest(initDataType
, initData
);
69 assert_true(mediaKeySession2
.sessionId
&& mediaKeySession2
.sessionId
.length
> 0);
71 // Should be 1 MediaKeys + 2 MediaKeySessions.
72 // In non-Oilpan, numActiveDOMObjectsCreate() == 3.
73 // In Oilpan, numActiveDOMObjectsCreate() <= 8.
75 // 1 MediaKeysInitializer and
76 // 2 MediaKeySystemAccessInitializers,
77 // 2 ContentDecryptionModuleResultPromise and
78 // 2 MediaKeySession).
79 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 8, 'mediaKeys.createSession(2)');
80 }).then(function(result
) {
81 // Run gc(). All sessions should remain as we have a
82 // reference to each one.
83 return createGCPromise();
84 }).then(function(result
) {
85 // Should be just 1 MediaKeys + 2 MediaKeySessions.
86 // In non-Oilpan, there is also something from createGCPromise().
87 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 4, 'After gc()');
89 // Close the sessions. Once the close() event is received,
90 // they should get garbage collected as there are no JS
91 // references to them.
92 var promise
= mediaKeySession1
.close();
93 mediaKeySession1
= null;
95 }).then(function(result
) {
96 // Give time so that the close event can be processed by
98 return delayToAllowEventProcessingPromise();
99 }).then(function(result
) {
100 return createGCPromise();
101 }).then(function(result
) {
102 // Only MediaKeys + mediaKeySession2 should remain.
103 // In non-Oilpan, there is also something from createGCPromise().
104 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 3, 'mediaKeySession1 not collected');
106 var promise
= mediaKeySession2
.close();
107 mediaKeySession2
= null;
109 }).then(function(result
) {
110 // Provide time for the mediaKeySession2 close event to be
112 return delayToAllowEventProcessingPromise();
113 }).then(function(result
) {
114 return createGCPromise();
115 }).then(function(result
) {
116 // Only MediaKeys should remain.
117 // In non-Oilpan, there is also something from createGCPromise().
118 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 2, 'mediaKeySession2 not collected');
120 assert_not_equals(mediaKeys
, null);
122 }).catch(function(error
) {
123 forceTestFailureFromPromise(test
, error
);
125 }, 'MediaKeySession lifetime after release() without references');