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

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: 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-reference.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Even though there should be no existing objects, start by
30 { 27 // running gc() and verifying that none exist. This also
31 return window.internals.mediaKeysCount() - startingMediaKeys Count; 28 // allows the failures to be reported from inside a promise
32 } 29 // so that the test fails properly.
30 return createGCPromise().then(function() {
31 verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After initial g c()');
33 32
34 function numMediaKeySessionCreated() 33 // Create a MediaKeys object with a session.
35 { 34 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration());
36 return window.internals.mediaKeySessionCount() - startingMed iaKeySessionCount; 35 }).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]; 36 initDataType = access.getConfiguration().initDataTypes[0];
42 initData = getInitData(initDataType); 37 initData = getInitData(initDataType);
43 return access.createMediaKeys(); 38 return access.createMediaKeys();
44 }).then(function(result) { 39 }).then(function(result) {
45 mediaKeys = result; 40 mediaKeys = result;
46 41 verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.creat e()');
47 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()' );
48 assert_equals(numMediaKeySessionCreated(), 0, 'After final g c()');
49 42
50 var mediaKeySession = mediaKeys.createSession(); 43 var mediaKeySession = mediaKeys.createSession();
51 return mediaKeySession.generateRequest(initDataType, initDat a); 44 return mediaKeySession.generateRequest(initDataType, initDat a);
52 }).then(function() { 45 }).then(function() {
53 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSes sion()'); 46 verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.creat eSession()');
54 assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.cre ateSession()');
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
59 // When enabling oilpan GC, the in-active
60 // ScriptPromiseResolvers will be destroyed.
61 return createGCPromise(); 50 return createGCPromise();
62 }).then(function(result) { 51 }).then(function(result) {
63 assert_equals(typeof mediaKeys.createSession, 'function'); 52 assert_equals(typeof mediaKeys.createSession, 'function');
64 53 verifyMediaKeyAndMediaKeySessionCount(1, 1, 'After gc()');
65 assert_equals(numMediaKeysCreated(), 1, 'After gc()');
66 assert_equals(numMediaKeySessionCreated(), 1, 'After gc()');
67 54
68 // Drop reference to the MediaKeys object and run gc() 55 // Drop reference to the MediaKeys object and run gc()
69 // again. Object should be collected this time. Since 56 // again. Object should be collected this time. Since
70 // MediaKeySessions remain alive as long as MediaKeys is 57 // MediaKeySessions remain alive as long as MediaKeys is
71 // around, it is possible that gc() checks the 58 // around, it is possible that gc() checks the
72 // MediaKeySession object first, and doesn't collect it 59 // MediaKeySession object first, and doesn't collect it
73 // since MediaKeys hasn't been collected yet. Thus run gc() 60 // since MediaKeys hasn't been collected yet. Thus run gc()
74 // twice, to ensure that the unreferenced MediaKeySession 61 // twice, to ensure that the unreferenced MediaKeySession
75 // object get collected. 62 // object get collected.
76 mediaKeys = null; 63 mediaKeys = null;
77 return createGCPromise(); 64 return createGCPromise();
78 }).then(function(result) { 65 }).then(function(result) {
79 return createGCPromise(); 66 return createGCPromise();
80 }).then(function(result) { 67 }).then(function(result) {
81 assert_equals(numMediaKeysCreated(), 0, 'After final gc()'); 68 verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After final gc( )');
82 assert_equals(numMediaKeySessionCreated(), 0, 'After final g c()');
83
84 test.done();
85 }).catch(function(error) {
86 forceTestFailureFromPromise(test, error);
87 }); 69 });
88 }, 'MediaKeys lifetime with session'); 70 }, 'MediaKeys lifetime with session');
89 </script> 71 </script>
90 </body> 72 </body>
91 </html> 73 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-reference.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698