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

Side by Side Diff: third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys-with-session.html

Issue 2587913002: Rename activeDOMObjectsAreSuspended to isContextSuspended (Closed)
Patch Set: temp Created 4 years 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 MediaKeys lifetime when adding a session</title> 4 <title>Test MediaKeys lifetime when adding a session</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 // MediaKeySessions remain as long as: 11 // MediaKeySessions remain as long as:
12 // JavaScript has a reference to it 12 // JavaScript has a reference to it
13 // OR (MediaKeys is around 13 // OR (MediaKeys is around
14 // AND the session has not received a close() event) 14 // AND the session has not received a close() event)
15 // In the tests below, we do not close any session nor keep a 15 // In the tests below, we do not close any session nor keep a
16 // Javascript reference to any session, so MediaKeySessions remain 16 // Javascript reference to any session, so MediaKeySessions remain
17 // as long as the associated MediaKeys object is around. 17 // as long as the associated MediaKeys object is around.
18 18
19 // For this test, create a MediaKeySession and verify lifetime. 19 // For this test, create a MediaKeySession and verify lifetime.
20 async_test(function(test) 20 async_test(function(test)
21 { 21 {
22 var initDataType; 22 var initDataType;
23 var initData; 23 var initData;
24 var mediaKeys; 24 var mediaKeys;
25 var startingActiveDOMObjectCount = window.internals.activeDOMObj ectCount(document); 25 var startingSuspendableObjectCount = window.internals.suspendabl eObjectCount(document);
26 26
27 function numActiveDOMObjectsCreated() 27 function numSuspendableObjectsCreated()
28 { 28 {
29 return window.internals.activeDOMObjectCount(document) - sta rtingActiveDOMObjectCount; 29 return window.internals.suspendableObjectCount(document) - s tartingSuspendableObjectCount;
30 } 30 }
31 31
32 // Create a MediaKeys object with a session. 32 // Create a MediaKeys object with a session.
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 39
40 // Verify MediaKeys is an ActiveDOMObject. 40 // Verify MediaKeys is an SuspendableObject.
41 // In non-Oilpan, numActiveDOMObjectsCreate() == 1. 41 // In non-Oilpan, numSuspendableObjectsCreate() == 1.
42 // In Oilpan, numActiveDOMObjectsCreate() <= 4. 42 // In Oilpan, numSuspendableObjectsCreate() <= 4.
43 // (1 MediaKeys, 43 // (1 MediaKeys,
44 // 1 MediaKeysInitializer and 44 // 1 MediaKeysInitializer and
45 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi aKeySystemAccess() use above), 45 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi aKeySystemAccess() use above),
46 // 1 MediaKeySystemAccessInitializer (isInitDataSupported() (via getSupportedInitDataType()))) 46 // 1 MediaKeySystemAccessInitializer (isInitDataSupported() (via getSupportedInitDataType())))
47 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 4, 'MediaKeys.create()'); 47 assert_between_inclusive(numSuspendableObjectsCreated(), 1, 4, 'MediaKeys.create()');
48 48
49 var mediaKeySession = mediaKeys.createSession(); 49 var mediaKeySession = mediaKeys.createSession();
50 return mediaKeySession.generateRequest(initDataType, initDat a); 50 return mediaKeySession.generateRequest(initDataType, initDat a);
51 }).then(function() { 51 }).then(function() {
52 // Should be 1 MediaKeys + 1 MediaKeySession. 52 // Should be 1 MediaKeys + 1 MediaKeySession.
53 // In non-Oilpan, numActiveDOMObjectsCreate() == 2. 53 // In non-Oilpan, numSuspendableObjectsCreate() == 2.
54 // In Oilpan, numActiveDOMObjectsCreate() <= 6. 54 // In Oilpan, numSuspendableObjectsCreate() <= 6.
55 // (1 MediaKeys, 55 // (1 MediaKeys,
56 // 1 MediaKeysInitializer and 56 // 1 MediaKeysInitializer and
57 // 2 MediaKeySystemAccessInitializer, 57 // 2 MediaKeySystemAccessInitializer,
58 // 1 ContentDecryptionModuleResultPromise and 58 // 1 ContentDecryptionModuleResultPromise and
59 // 1 MediaKeySession). 59 // 1 MediaKeySession).
60 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 6, 'MediaKeys.createSession()'); 60 assert_between_inclusive(numSuspendableObjectsCreated(), 2, 6, 'MediaKeys.createSession()');
61 61
62 // Run gc(), should not affect MediaKeys object nor the 62 // Run gc(), should not affect MediaKeys object nor the
63 // session since we still have a reference to it. 63 // session since we still have a reference to it.
64 64
65 // When enabling oilpan GC, the in-active 65 // When enabling oilpan GC, the in-active
66 // ScriptPromiseResolvers will be destroyed. 66 // ScriptPromiseResolvers will be destroyed.
67 return createGCPromise(); 67 return createGCPromise();
68 }).then(function(result) { 68 }).then(function(result) {
69 assert_equals(typeof mediaKeys.createSession, 'function'); 69 assert_equals(typeof mediaKeys.createSession, 'function');
70 70
71 // MediaKeys + MediaKeySessions should remain. 71 // MediaKeys + MediaKeySessions should remain.
72 // In non-Oilpan, there is also something from createGCPromi se(). 72 // In non-Oilpan, there is also something from createGCPromi se().
73 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 3, 'After gc()'); 73 assert_between_inclusive(numSuspendableObjectsCreated(), 2, 3, 'After gc()');
74 74
75 // Drop reference to the MediaKeys object and run gc() 75 // Drop reference to the MediaKeys object and run gc()
76 // again. Object should be collected this time. Since 76 // again. Object should be collected this time. Since
77 // MediaKeySessions remain alive as long as MediaKeys is 77 // MediaKeySessions remain alive as long as MediaKeys is
78 // around, it is possible that gc() checks the 78 // around, it is possible that gc() checks the
79 // MediaKeySession object first, and doesn't collect it 79 // MediaKeySession object first, and doesn't collect it
80 // since MediaKeys hasn't been collected yet. Thus run gc() 80 // since MediaKeys hasn't been collected yet. Thus run gc()
81 // twice, to ensure that the unreferenced MediaKeySession 81 // twice, to ensure that the unreferenced MediaKeySession
82 // object get collected. 82 // object get collected.
83 mediaKeys = null; 83 mediaKeys = null;
84 return createGCPromise(); 84 return createGCPromise();
85 }).then(function(result) { 85 }).then(function(result) {
86 return createGCPromise(); 86 return createGCPromise();
87 }).then(function(result) { 87 }).then(function(result) {
88 // No MediaKeySessions should remain. 88 // No MediaKeySessions should remain.
89 // In non-Oilpan, there is also something from createGCPromi se(). 89 // In non-Oilpan, there is also something from createGCPromi se().
90 assert_between_inclusive(numActiveDOMObjectsCreated(), 0, 1, 'After final gc()'); 90 assert_between_inclusive(numSuspendableObjectsCreated(), 0, 1, 'After final gc()');
91 91
92 test.done(); 92 test.done();
93 }).catch(function(error) { 93 }).catch(function(error) {
94 forceTestFailureFromPromise(test, error); 94 forceTestFailureFromPromise(test, error);
95 }); 95 });
96 }, 'MediaKeys lifetime with session'); 96 }, 'MediaKeys lifetime with session');
97 </script> 97 </script>
98 </body> 98 </body>
99 </html> 99 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698