Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-reference.html

Issue 2587913002: Rename activeDOMObjectsAreSuspended to isContextSuspended (Closed)
Patch Set: temp Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>Test MediaKeySession lifetime without release()</title> 4 <title>Test MediaKeySession lifetime without release()</title>
5 <script src="encrypted-media-utils.js"></script> 5 <script src="encrypted-media-utils.js"></script>
6 <script src="../../resources/testharness.js"></script> 6 <script src="../../resources/testharness.js"></script>
7 <script src="../../resources/testharnessreport.js"></script> 7 <script src="../../resources/testharnessreport.js"></script>
8 </head> 8 </head>
9 <body> 9 <body>
10 <script> 10 <script>
11 // Since MediaKeySession (and MediaKeys) are ActiveDOMObjects, 11 // Since MediaKeySession (and MediaKeys) are SuspendableObjects,
12 // we can determine when they are garbage collected. 12 // we can determine when they are garbage collected.
13 // MediaKeySessions remain as long as: 13 // MediaKeySessions remain as long as:
14 // JavaScript has a reference to it 14 // JavaScript has a reference to it
15 // OR (MediaKeys is around 15 // OR (MediaKeys is around
16 // AND the session has not received a close() event) 16 // AND the session has not received a close() event)
17 17
18 async_test(function(test) 18 async_test(function(test)
19 { 19 {
20 var mediaKeys; 20 var mediaKeys;
21 var mediaKeySession1; 21 var mediaKeySession1;
22 var mediaKeySession2; 22 var mediaKeySession2;
23 var mediaKeySession3; 23 var mediaKeySession3;
24 var initDataType; 24 var initDataType;
25 var initData; 25 var initData;
26 var startingActiveDOMObjectCount = window.internals.activeDOMObj ectCount(document); 26 var startingSuspendableObjectCount = window.internals.suspendabl eObjectCount(document);
27 27
28 function numActiveDOMObjectsCreated() 28 function numSuspendableObjectsCreated()
29 { 29 {
30 return window.internals.activeDOMObjectCount(document) - sta rtingActiveDOMObjectCount; 30 return window.internals.suspendableObjectCount(document) - s tartingSuspendableObjectCount;
31 } 31 }
32 32
33 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp leConfiguration()).then(function(access) { 33 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp leConfiguration()).then(function(access) {
34 initDataType = access.getConfiguration().initDataTypes[0]; 34 initDataType = access.getConfiguration().initDataTypes[0];
35 initData = getInitData(initDataType); 35 initData = getInitData(initDataType);
36 return access.createMediaKeys(); 36 return access.createMediaKeys();
37 }).then(function(result) { 37 }).then(function(result) {
38 mediaKeys = result; 38 mediaKeys = result;
39 assert_equals(typeof mediaKeys.createSession, 'function'); 39 assert_equals(typeof mediaKeys.createSession, 'function');
40 40
41 // Verify MediaKeys is an ActiveDOMObject. 41 // Verify MediaKeys is an SuspendableObject.
42 // In non-Oilpan, numActiveDOMObjectsCreate() == 1. 42 // In non-Oilpan, numSuspendableObjectsCreate() == 1.
43 // In Oilpan, numActiveDOMObjectsCreate() <= 4. 43 // In Oilpan, numSuspendableObjectsCreate() <= 4.
44 // (1 MediaKeys, 44 // (1 MediaKeys,
45 // 1 MediaKeysInitializer and 45 // 1 MediaKeysInitializer and
46 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi aKeySystemAccess() use above), 46 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi aKeySystemAccess() use above),
47 // 1 MediaKeySystemAccessInitializer (isInitDataSupported() (via getSupportedInitDataType()))) 47 // 1 MediaKeySystemAccessInitializer (isInitDataSupported() (via getSupportedInitDataType())))
48 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 4, 'MediaKeys.create()'); 48 assert_between_inclusive(numSuspendableObjectsCreated(), 1, 4, 'MediaKeys.create()');
49 49
50 // Create 3 sessions. 50 // Create 3 sessions.
51 mediaKeySession1 = mediaKeys.createSession(); 51 mediaKeySession1 = mediaKeys.createSession();
52 return mediaKeySession1.generateRequest(initDataType, initDa ta); 52 return mediaKeySession1.generateRequest(initDataType, initDa ta);
53 }).then(function() { 53 }).then(function() {
54 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s essionId.length > 0); 54 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s essionId.length > 0);
55 55
56 // Should be 1 MediaKeys + 1 MediaKeySession. 56 // Should be 1 MediaKeys + 1 MediaKeySession.
57 // In non-Oilpan, numActiveDOMObjectsCreate() == 2. 57 // In non-Oilpan, numSuspendableObjectsCreate() == 2.
58 // In Oilpan, numActiveDOMObjectsCreate() <= 6. 58 // In Oilpan, numSuspendableObjectsCreate() <= 6.
59 // (1 MediaKeys, 59 // (1 MediaKeys,
60 // 1 MediaKeysInitializer and 60 // 1 MediaKeysInitializer and
61 // 2 MediaKeySystemAccessInitializer, 61 // 2 MediaKeySystemAccessInitializer,
62 // 1 ContentDecryptionModuleResultPromise and 62 // 1 ContentDecryptionModuleResultPromise and
63 // 1 MediaKeySession). 63 // 1 MediaKeySession).
64 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 6, 'MediaKeys.createSession(1)'); 64 assert_between_inclusive(numSuspendableObjectsCreated(), 2, 6, 'MediaKeys.createSession(1)');
65 65
66 mediaKeySession2 = mediaKeys.createSession(); 66 mediaKeySession2 = mediaKeys.createSession();
67 return mediaKeySession2.generateRequest(initDataType, initDa ta); 67 return mediaKeySession2.generateRequest(initDataType, initDa ta);
68 }).then(function() { 68 }).then(function() {
69 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s essionId.length > 0); 69 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s essionId.length > 0);
70 70
71 // Should be 1 MediaKeys + 2 MediaKeySessions. 71 // Should be 1 MediaKeys + 2 MediaKeySessions.
72 // In non-Oilpan, numActiveDOMObjectsCreate() == 3. 72 // In non-Oilpan, numSuspendableObjectsCreate() == 3.
73 // In Oilpan, numActiveDOMObjectsCreate() <= 8. 73 // In Oilpan, numSuspendableObjectsCreate() <= 8.
74 // (1 MediaKeys, 74 // (1 MediaKeys,
75 // 1 MediaKeysInitializer and 75 // 1 MediaKeysInitializer and
76 // 2 MediaKeySystemAccessInitializers, 76 // 2 MediaKeySystemAccessInitializers,
77 // 2 ContentDecryptionModuleResultPromise and 77 // 2 ContentDecryptionModuleResultPromise and
78 // 2 MediaKeySession). 78 // 2 MediaKeySession).
79 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 8, 'mediaKeys.createSession(2)'); 79 assert_between_inclusive(numSuspendableObjectsCreated(), 3, 8, 'mediaKeys.createSession(2)');
80 80
81 mediaKeySession3 = mediaKeys.createSession(); 81 mediaKeySession3 = mediaKeys.createSession();
82 return mediaKeySession3.generateRequest(initDataType, initDa ta); 82 return mediaKeySession3.generateRequest(initDataType, initDa ta);
83 }).then(function() { 83 }).then(function() {
84 assert_true(mediaKeySession3.sessionId && mediaKeySession3.s essionId.length > 0); 84 assert_true(mediaKeySession3.sessionId && mediaKeySession3.s essionId.length > 0);
85 85
86 // Should be 1 MediaKeys + 3 MediaKeySessions. 86 // Should be 1 MediaKeys + 3 MediaKeySessions.
87 // In non-Oilpan, numActiveDOMObjectsCreate() == 4. 87 // In non-Oilpan, numSuspendableObjectsCreate() == 4.
88 // In Oilpan, numActiveDOMObjectsCreate() <= 10. 88 // In Oilpan, numSuspendableObjectsCreate() <= 10.
89 // (1 MediaKeys, 89 // (1 MediaKeys,
90 // 1 MediaKeysInitializer and 90 // 1 MediaKeysInitializer and
91 // 2 MediaKeySystemAccessInitializers, 91 // 2 MediaKeySystemAccessInitializers,
92 // 3 ContentDecryptionModuleResultPromise and 92 // 3 ContentDecryptionModuleResultPromise and
93 // 3 MediaKeySession). 93 // 3 MediaKeySession).
94 assert_between_inclusive(numActiveDOMObjectsCreated(), 4, 10 , 'mediaKeys.createSession(3)'); 94 assert_between_inclusive(numSuspendableObjectsCreated(), 4, 10, 'mediaKeys.createSession(3)');
95 95
96 // Run gc(). All sessions should remain as we have a 96 // Run gc(). All sessions should remain as we have a
97 // reference to each one. However, running gc() 97 // reference to each one. However, running gc()
98 // asynchronously should free up the last PromiseResolver. 98 // asynchronously should free up the last PromiseResolver.
99 return createGCPromise(); 99 return createGCPromise();
100 }).then(function(result) { 100 }).then(function(result) {
101 // Only MediaKeys + 3 MediaKeySessions should remain. 101 // Only MediaKeys + 3 MediaKeySessions should remain.
102 // In non-Oilpan, there is also something from createGCPromi se(). 102 // In non-Oilpan, there is also something from createGCPromi se().
103 assert_between_inclusive(numActiveDOMObjectsCreated(), 4, 5, 'After gc()'); 103 assert_between_inclusive(numSuspendableObjectsCreated(), 4, 5, 'After gc()');
104 104
105 // Now drop references to 2 of the sessions. Even though we 105 // Now drop references to 2 of the sessions. Even though we
106 // don't have a reference, MediaKeys is still around (and 106 // don't have a reference, MediaKeys is still around (and
107 // the sessions aren't closed), so the objects won't be 107 // the sessions aren't closed), so the objects won't be
108 // collected. 108 // collected.
109 mediaKeySession1 = null; 109 mediaKeySession1 = null;
110 mediaKeySession2 = null; 110 mediaKeySession2 = null;
111 return createGCPromise(); 111 return createGCPromise();
112 }).then(function(result) { 112 }).then(function(result) {
113 return createGCPromise(); 113 return createGCPromise();
114 }).then(function(result) { 114 }).then(function(result) {
115 // MediaKeys + 3 MediaKeySessions should remain. 115 // MediaKeys + 3 MediaKeySessions should remain.
116 // In non-Oilpan, there is also something from createGCPromi se(). 116 // In non-Oilpan, there is also something from createGCPromi se().
117 assert_between_inclusive(numActiveDOMObjectsCreated(), 4, 5, 'After second gc()'); 117 assert_between_inclusive(numSuspendableObjectsCreated(), 4, 5, 'After second gc()');
118 118
119 // Now drop the reference to MediaKeys. It and the 2 119 // Now drop the reference to MediaKeys. It and the 2
120 // unreferenced sessions should be collected. Since 120 // unreferenced sessions should be collected. Since
121 // MediaKeySessions remain alive as long as MediaKeys is 121 // MediaKeySessions remain alive as long as MediaKeys is
122 // around, it is possible that gc() checks one or both 122 // around, it is possible that gc() checks one or both
123 // MediaKeySession objects first, and doesn't collect them 123 // MediaKeySession objects first, and doesn't collect them
124 // since MediaKeys hasn't been collected yet. Thus run gc() 124 // since MediaKeys hasn't been collected yet. Thus run gc()
125 // twice, to ensure that the unreferenced MediaKeySession 125 // twice, to ensure that the unreferenced MediaKeySession
126 // objects get collected. 126 // objects get collected.
127 mediaKeys = null; 127 mediaKeys = null;
128 return createGCPromise(); 128 return createGCPromise();
129 }).then(function(result) { 129 }).then(function(result) {
130 return createGCPromise(); 130 return createGCPromise();
131 }).then(function(result) { 131 }).then(function(result) {
132 // Only 1 MediaKeySessions should remain. 132 // Only 1 MediaKeySessions should remain.
133 // In non-Oilpan, there is also something from createGCPromi se(). 133 // In non-Oilpan, there is also something from createGCPromi se().
134 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 2, 'After mediaKeys = null'); 134 assert_between_inclusive(numSuspendableObjectsCreated(), 1, 2, 'After mediaKeys = null');
135 135
136 // Drop the reference to the last session. It should get 136 // Drop the reference to the last session. It should get
137 // collected now since MediaKeys is gone. 137 // collected now since MediaKeys is gone.
138 mediaKeySession3 = null; 138 mediaKeySession3 = null;
139 return createGCPromise(); 139 return createGCPromise();
140 }).then(function(result) { 140 }).then(function(result) {
141 // No MediaKeySessions should remain. 141 // No MediaKeySessions should remain.
142 // In non-Oilpan, there is also something from createGCPromi se(). 142 // In non-Oilpan, there is also something from createGCPromi se().
143 assert_between_inclusive(numActiveDOMObjectsCreated(), 0, 1, 'After final gc()'); 143 assert_between_inclusive(numSuspendableObjectsCreated(), 0, 1, 'After final gc()');
144 144
145 test.done(); 145 test.done();
146 }).catch(function(error) { 146 }).catch(function(error) {
147 forceTestFailureFromPromise(test, error); 147 forceTestFailureFromPromise(test, error);
148 }); 148 });
149 }, 'MediaKeySession lifetime without release()'); 149 }, 'MediaKeySession lifetime without release()');
150 </script> 150 </script>
151 </body> 151 </body>
152 </html> 152 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698