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

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

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

Powered by Google App Engine
This is Rietveld 408576698