-
Notifications
You must be signed in to change notification settings - Fork 3k
/
encrypted-media-lifetime-mediakeysession-release-noreference.html
128 lines (117 loc) · 6.59 KB
/
encrypted-media-lifetime-mediakeysession-release-noreference.html
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
<head>
<title>Test MediaKeySession lifetime after release() without references</title>
<script src="encrypted-media-utils.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
// Since MediaKeySession (and MediaKeys) are ActiveDOMObjects,
// we can determine when they are garbage collected.
// MediaKeySessions remain as long as:
// JavaScript has a reference to it
// OR (MediaKeys is around
// AND the session has not received a close() event)
async_test(function(test)
{
var initDataType;
var initData;
var startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document);
function numActiveDOMObjectsCreated()
{
return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount;
}
// Create 2 sessions.
var mediaKeys;
var mediaKeySession1;
var mediaKeySession2;
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()');
mediaKeySession1 = mediaKeys.createSession();
return mediaKeySession1.generateRequest(initDataType, initData);
}).then(function() {
assert_true(mediaKeySession1.sessionId && mediaKeySession1.sessionId.length > 0);
// 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(1)');
mediaKeySession2 = mediaKeys.createSession();
return mediaKeySession2.generateRequest(initDataType, initData);
}).then(function() {
assert_true(mediaKeySession2.sessionId && mediaKeySession2.sessionId.length > 0);
// Should be 1 MediaKeys + 2 MediaKeySessions.
// In non-Oilpan, numActiveDOMObjectsCreate() == 3.
// In Oilpan, numActiveDOMObjectsCreate() <= 8.
// (1 MediaKeys,
// 1 MediaKeysInitializer and
// 2 MediaKeySystemAccessInitializers,
// 2 ContentDecryptionModuleResultPromise and
// 2 MediaKeySession).
assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 8, 'mediaKeys.createSession(2)');
}).then(function(result) {
// Run gc(). All sessions should remain as we have a
// reference to each one.
return createGCPromise();
}).then(function(result) {
// Should be just 1 MediaKeys + 2 MediaKeySessions.
// In non-Oilpan, there is also something from createGCPromise().
assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 4, 'After gc()');
// Close the sessions. Once the close() event is received,
// they should get garbage collected as there are no JS
// references to them.
var promise = mediaKeySession1.close();
mediaKeySession1 = null;
return promise;
}).then(function(result) {
// Give time so that the close event can be processed by
// MediaKeySession.
return delayToAllowEventProcessingPromise();
}).then(function(result) {
return createGCPromise();
}).then(function(result) {
// Only MediaKeys + mediaKeySession2 should remain.
// In non-Oilpan, there is also something from createGCPromise().
assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 3, 'mediaKeySession1 not collected');
var promise = mediaKeySession2.close();
mediaKeySession2 = null;
return promise;
}).then(function(result) {
// Provide time for the mediaKeySession2 close event to be
// handled.
return delayToAllowEventProcessingPromise();
}).then(function(result) {
return createGCPromise();
}).then(function(result) {
// Only MediaKeys should remain.
// In non-Oilpan, there is also something from createGCPromise().
assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 2, 'mediaKeySession2 not collected');
assert_not_equals(mediaKeys, null);
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
});
}, 'MediaKeySession lifetime after release() without references');
</script>
</body>
</html>