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

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

Issue 2618603002: [eme] Convert lifetime tests to promise_tests (Closed)
Patch Set: move to utils 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 // 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 15
16 async_test(function(test) 16 promise_test(function(test)
17 { 17 {
18 gc();
19 var mediaKeys; 18 var mediaKeys;
20 var mediaKeySession1; 19 var mediaKeySession1;
21 var mediaKeySession2; 20 var mediaKeySession2;
22 var mediaKeySession3; 21 var mediaKeySession3;
23 var initDataType; 22 var initDataType;
24 var initData; 23 var initData;
25 var startingMediaKeysCount = window.internals.mediaKeysCount();
26 var startingMediaKeySessionCount = window.internals.mediaKeySess ionCount();
27 24
28 function numMediaKeysCreated() 25 // Even though there should be no existing objects, start by
29 { 26 // running gc() and verifying that none exist. This also
30 return window.internals.mediaKeysCount() - startingMediaKeys Count; 27 // allows the failures to be reported from inside a promise
31 } 28 // so that the test fails properly.
29 return createGCPromise().then(function() {
30 verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After initial g c()');
32 31
33 function numMediaKeySessionCreated() 32 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration());
34 { 33 }).then(function(access) {
35 return window.internals.mediaKeySessionCount() - startingMed iaKeySessionCount;
36 }
37
38 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp leConfiguration()).then(function(access) {
39 initDataType = access.getConfiguration().initDataTypes[0]; 34 initDataType = access.getConfiguration().initDataTypes[0];
40 initData = getInitData(initDataType); 35 initData = getInitData(initDataType);
41 return access.createMediaKeys(); 36 return access.createMediaKeys();
42 }).then(function(result) { 37 }).then(function(result) {
43 mediaKeys = result; 38 mediaKeys = result;
44 assert_equals(typeof mediaKeys.createSession, 'function'); 39 assert_equals(typeof mediaKeys.createSession, 'function');
45 40 verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.creat e()');
46 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()' );
47 assert_equals(numMediaKeySessionCreated(), 0, 'After final g c()');
48 41
49 // Create 3 sessions. 42 // Create 3 sessions.
50 mediaKeySession1 = mediaKeys.createSession(); 43 mediaKeySession1 = mediaKeys.createSession();
51 return mediaKeySession1.generateRequest(initDataType, initDa ta); 44 return mediaKeySession1.generateRequest(initDataType, initDa ta);
52 }).then(function() { 45 }).then(function() {
53 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s essionId.length > 0); 46 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s essionId.length > 0);
54 47 verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.creat eSession(1)');
55 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSes sion(1)');
56 assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.cre ateSession(1)');
57 48
58 mediaKeySession2 = mediaKeys.createSession(); 49 mediaKeySession2 = mediaKeys.createSession();
59 return mediaKeySession2.generateRequest(initDataType, initDa ta); 50 return mediaKeySession2.generateRequest(initDataType, initDa ta);
60 }).then(function() { 51 }).then(function() {
61 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s essionId.length > 0); 52 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s essionId.length > 0);
62 53 verifyMediaKeyAndMediaKeySessionCount(1, 2, 'mediaKeys.creat eSession(2)');
63 assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSes sion(2)');
64 assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.cre ateSession(2)');
65 54
66 mediaKeySession3 = mediaKeys.createSession(); 55 mediaKeySession3 = mediaKeys.createSession();
67 return mediaKeySession3.generateRequest(initDataType, initDa ta); 56 return mediaKeySession3.generateRequest(initDataType, initDa ta);
68 }).then(function() { 57 }).then(function() {
69 assert_true(mediaKeySession3.sessionId && mediaKeySession3.s essionId.length > 0); 58 assert_true(mediaKeySession3.sessionId && mediaKeySession3.s essionId.length > 0);
70 59 verifyMediaKeyAndMediaKeySessionCount(1, 3, 'mediaKeys.creat eSession(3)');
71 assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSes sion(3)');
72 assert_equals(numMediaKeySessionCreated(), 3, 'mediaKeys.cre ateSession(3)');
73 60
74 // Run gc(). All sessions should remain as we have a 61 // Run gc(). All sessions should remain as we have a
75 // reference to each one. However, running gc() 62 // reference to each one. However, running gc()
76 // asynchronously should free up the last PromiseResolver. 63 // asynchronously should free up the last PromiseResolver.
77 return createGCPromise(); 64 return createGCPromise();
78 }).then(function(result) { 65 }).then(function(result) {
79 assert_equals(numMediaKeysCreated(), 1, 'After gc()'); 66 verifyMediaKeyAndMediaKeySessionCount(1, 3, 'After gc()');
80 assert_equals(numMediaKeySessionCreated(), 3, 'After gc()');
81 67
82 // Now drop references to 2 of the sessions. Even though we 68 // Now drop references to 2 of the sessions. Even though we
83 // don't have a reference, MediaKeys is still around (and 69 // don't have a reference, MediaKeys is still around (and
84 // the sessions aren't closed), so the objects won't be 70 // the sessions aren't closed), so the objects won't be
85 // collected. 71 // collected.
86 mediaKeySession1 = null; 72 mediaKeySession1 = null;
87 mediaKeySession2 = null; 73 mediaKeySession2 = null;
88 return createGCPromise(); 74 return createGCPromise();
89 }).then(function(result) { 75 }).then(function(result) {
90 return createGCPromise(); 76 return createGCPromise();
91 }).then(function(result) { 77 }).then(function(result) {
92 assert_equals(numMediaKeysCreated(), 1, 'After second gc()') ; 78 verifyMediaKeyAndMediaKeySessionCount(1, 3, 'After second gc ()');
93 assert_equals(numMediaKeySessionCreated(), 3, 'After second gc()');
94 79
95 // Now drop the reference to MediaKeys. It and the 2 80 // Now drop the reference to MediaKeys. It and the 2
96 // unreferenced sessions should be collected. Since 81 // unreferenced sessions should be collected. Since
97 // MediaKeySessions remain alive as long as MediaKeys is 82 // MediaKeySessions remain alive as long as MediaKeys is
98 // around, it is possible that gc() checks one or both 83 // around, it is possible that gc() checks one or both
99 // MediaKeySession objects first, and doesn't collect them 84 // MediaKeySession objects first, and doesn't collect them
100 // since MediaKeys hasn't been collected yet. Thus run gc() 85 // since MediaKeys hasn't been collected yet. Thus run gc()
101 // twice, to ensure that the unreferenced MediaKeySession 86 // twice, to ensure that the unreferenced MediaKeySession
102 // objects get collected. 87 // objects get collected.
103 mediaKeys = null; 88 mediaKeys = null;
104 return createGCPromise(); 89 return createGCPromise();
105 }).then(function(result) { 90 }).then(function(result) {
106 return createGCPromise(); 91 return createGCPromise();
107 }).then(function(result) { 92 }).then(function(result) {
108 assert_equals(numMediaKeysCreated(), 0, 'After mediaKeys = n ull'); 93 verifyMediaKeyAndMediaKeySessionCount(0, 1, 'After mediaKeys = null');
109 assert_equals(numMediaKeySessionCreated(), 1, 'After mediaKe ys = null');
110 94
111 // Drop the reference to the last session. It should get 95 // Drop the reference to the last session. It should get
112 // collected now since MediaKeys is gone. 96 // collected now since MediaKeys is gone.
113 mediaKeySession3 = null; 97 mediaKeySession3 = null;
114 return createGCPromise(); 98 return createGCPromise();
115 }).then(function(result) { 99 }).then(function(result) {
116 assert_equals(numMediaKeysCreated(), 0, 'After final gc()'); 100 verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After final gc( )');
117 assert_equals(numMediaKeySessionCreated(), 0, 'After final g c()');
118
119 test.done();
120 }).catch(function(error) {
121 forceTestFailureFromPromise(test, error);
122 }); 101 });
123 }, 'MediaKeySession lifetime without release()'); 102 }, 'MediaKeySession lifetime without release()');
124 </script> 103 </script>
125 </body> 104 </body>
126 </html> 105 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698