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

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

Issue 2618603002: [eme] Convert lifetime tests to promise_tests (Closed)
Patch Set: 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 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 promise_test(function(test)
21 { 21 {
22 gc();
23 var initDataType; 22 var initDataType;
24 var initData; 23 var initData;
25 var mediaKeys; 24 var mediaKeys;
26 var startingMediaKeysCount = window.internals.mediaKeysCount();
27 var startingMediaKeySessionCount = window.internals.mediaKeySess ionCount();
28 25
29 function numMediaKeysCreated() 26 return createGCPromise().then(function() {
xhwang 2017/01/05 20:05:06 Could you please add a comment about why we need t
jrummell 2017/01/06 22:10:18 Done.
30 { 27 assert_equals(window.internals.mediaKeysCount(), 0, 'After i nitial gc()');
31 return window.internals.mediaKeysCount() - startingMediaKeys Count; 28 assert_equals(window.internals.mediaKeySessionCount(), 0, 'A fter initial gc()');
32 }
33 29
34 function numMediaKeySessionCreated() 30 // Create a MediaKeys object with a session.
35 { 31 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration());
36 return window.internals.mediaKeySessionCount() - startingMed iaKeySessionCount; 32 }).then(function(access) {
37 }
38
39 // Create a MediaKeys object with a session.
40 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp leConfiguration()).then(function(access) {
41 initDataType = access.getConfiguration().initDataTypes[0]; 33 initDataType = access.getConfiguration().initDataTypes[0];
42 initData = getInitData(initDataType); 34 initData = getInitData(initDataType);
43 return access.createMediaKeys(); 35 return access.createMediaKeys();
44 }).then(function(result) { 36 }).then(function(result) {
45 mediaKeys = result; 37 mediaKeys = result;
46 38
47 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()' ); 39 assert_equals(window.internals.mediaKeysCount(), 1, 'MediaKe ys.create()');
48 assert_equals(numMediaKeySessionCreated(), 0, 'After final g c()'); 40 assert_equals(window.internals.mediaKeySessionCount(), 0, 'A fter final gc()');
49 41
50 var mediaKeySession = mediaKeys.createSession(); 42 var mediaKeySession = mediaKeys.createSession();
51 return mediaKeySession.generateRequest(initDataType, initDat a); 43 return mediaKeySession.generateRequest(initDataType, initDat a);
52 }).then(function() { 44 }).then(function() {
53 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSes sion()'); 45 assert_equals(window.internals.mediaKeysCount(), 1, 'MediaKe ys.createSession()');
54 assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.cre ateSession()'); 46 assert_equals(window.internals.mediaKeySessionCount(), 1, 'M ediaKeys.createSession()');
55 47
56 // Run gc(), should not affect MediaKeys object nor the 48 // Run gc(), should not affect MediaKeys object nor the
57 // session since we still have a reference to it. 49 // session since we still have a reference to it.
58 50
59 // When enabling oilpan GC, the in-active 51 // When enabling oilpan GC, the in-active
60 // ScriptPromiseResolvers will be destroyed. 52 // ScriptPromiseResolvers will be destroyed.
61 return createGCPromise(); 53 return createGCPromise();
62 }).then(function(result) { 54 }).then(function(result) {
63 assert_equals(typeof mediaKeys.createSession, 'function'); 55 assert_equals(typeof mediaKeys.createSession, 'function');
64 56
65 assert_equals(numMediaKeysCreated(), 1, 'After gc()'); 57 assert_equals(window.internals.mediaKeysCount(), 1, 'After g c()');
66 assert_equals(numMediaKeySessionCreated(), 1, 'After gc()'); 58 assert_equals(window.internals.mediaKeySessionCount(), 1, 'A fter gc()');
67 59
68 // Drop reference to the MediaKeys object and run gc() 60 // Drop reference to the MediaKeys object and run gc()
69 // again. Object should be collected this time. Since 61 // again. Object should be collected this time. Since
70 // MediaKeySessions remain alive as long as MediaKeys is 62 // MediaKeySessions remain alive as long as MediaKeys is
71 // around, it is possible that gc() checks the 63 // around, it is possible that gc() checks the
72 // MediaKeySession object first, and doesn't collect it 64 // MediaKeySession object first, and doesn't collect it
73 // since MediaKeys hasn't been collected yet. Thus run gc() 65 // since MediaKeys hasn't been collected yet. Thus run gc()
74 // twice, to ensure that the unreferenced MediaKeySession 66 // twice, to ensure that the unreferenced MediaKeySession
75 // object get collected. 67 // object get collected.
76 mediaKeys = null; 68 mediaKeys = null;
77 return createGCPromise(); 69 return createGCPromise();
78 }).then(function(result) { 70 }).then(function(result) {
79 return createGCPromise(); 71 return createGCPromise();
80 }).then(function(result) { 72 }).then(function(result) {
81 assert_equals(numMediaKeysCreated(), 0, 'After final gc()'); 73 assert_equals(window.internals.mediaKeysCount(), 0, 'After f inal gc()');
82 assert_equals(numMediaKeySessionCreated(), 0, 'After final g c()'); 74 assert_equals(window.internals.mediaKeySessionCount(), 0, 'A fter final gc()');
83
84 test.done();
85 }).catch(function(error) {
86 forceTestFailureFromPromise(test, error);
87 }); 75 });
88 }, 'MediaKeys lifetime with session'); 76 }, 'MediaKeys lifetime with session');
89 </script> 77 </script>
90 </body> 78 </body>
91 </html> 79 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698