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

Side by Side Diff: third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-multiple-mediakeys.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 multiple MediaKeys lifetimes</title> 4 <title>Test multiple MediaKeys lifetimes</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 // For this test, create several MediaKeys and verify lifetime. 11 // For this test, create several MediaKeys and verify lifetime.
12 async_test(function(test) 12 promise_test(function(test)
13 { 13 {
14 gc(); 14 var mediaKeys1;
15 var mediaKeys; 15 var mediaKeys2;
16 var startingMediaKeysCount = window.internals.mediaKeysCount(); 16 var mediaKeys3;
17 17 var mediaKeys4;
18 function numMediaKeysCreated() 18 var mediaKeys5;
19 {
20 return window.internals.mediaKeysCount() - startingMediaKeys Count;
21 }
22 19
23 // Create a MediaKeys object. Returns a promise that resolves 20 // Create a MediaKeys object. Returns a promise that resolves
24 // with the new MediaKeys object. 21 // with the new MediaKeys object.
25 function createMediaKeys() 22 function createMediaKeys()
26 { 23 {
27 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration()).then(function(access) { 24 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration()).then(function(access) {
28 return access.createMediaKeys(); 25 return access.createMediaKeys();
29 }).then(function(mediaKeys) { 26 }).then(function(mediaKeys) {
30 return mediaKeys; 27 return mediaKeys;
31 }); 28 });
32 } 29 }
33 30
34 // Create a few MediaKeys objects. Only keep a reference to the 31 // Create a few MediaKeys objects. Keep references to them,
35 // last one created. 32 // to avoid issues if gc() runs.
36 createMediaKeys().then(function(result) { 33 return createGCPromise().then(function() {
37 assert_equals(numMediaKeysCreated(), 1); 34 assert_equals(window.internals.mediaKeysCount(), 0, 'After i nitial gc()');
38 35
39 return createMediaKeys(); 36 return createMediaKeys();
40 }).then(function(result) { 37 }).then(function(result) {
41 assert_equals(numMediaKeysCreated(), 2); 38 assert_not_equals(result, null);
39 mediaKeys1 = result;
40 assert_equals(window.internals.mediaKeysCount(), 1, 'Create first MediaKeys');
42 41
43 return createMediaKeys(); 42 return createMediaKeys();
44 }).then(function(result) { 43 }).then(function(result) {
45 assert_equals(numMediaKeysCreated(), 3); 44 assert_not_equals(result, null);
45 mediaKeys2 = result;
46 assert_equals(window.internals.mediaKeysCount(), 2, 'Create second MediaKeys');
46 47
47 return createMediaKeys(); 48 return createMediaKeys();
48 }).then(function(result) { 49 }).then(function(result) {
49 assert_equals(numMediaKeysCreated(), 4); 50 assert_not_equals(result, null);
51 mediaKeys3 = result;
52 assert_equals(window.internals.mediaKeysCount(), 3, 'Create third MediaKeys');
50 53
51 return createMediaKeys(); 54 return createMediaKeys();
52 }).then(function(result) { 55 }).then(function(result) {
53 assert_equals(numMediaKeysCreated(), 5); 56 assert_not_equals(result, null);
57 mediaKeys4 = result;
58 assert_equals(window.internals.mediaKeysCount(), 4, 'Create fourth MediaKeys');
54 59
55 // |mediaKeys| refers to the most recently created MediaKeys 60 return createMediaKeys();
56 // object. 61 }).then(function(result) {
57 mediaKeys = result; 62 assert_not_equals(result, null);
63 mediaKeys5 = result;
64 assert_equals(window.internals.mediaKeysCount(), 5, 'Create fifth MediaKeys');
58 65
59 // In order for the MediaKey objects to be garbage 66 // In order for the MediaKey objects to be garbage
60 // collected, it needs time to process any pending events. 67 // collected, it needs time to process any pending events.
61 return delayToAllowEventProcessingPromise(); 68 return delayToAllowEventProcessingPromise();
62 }).then(function(result) { 69 }).then(function() {
63 assert_equals(numMediaKeysCreated(), 5); 70 assert_equals(window.internals.mediaKeysCount(), 5, 'All ali ve');
64 71
65 // As we only have a reference (|mediaKeys|) to the last 72 // Now run garbage collection. Since we have references to
66 // created MediaKeys object, the other 4 MediaKeys objects 73 // all 5 MediaKeys, none will be collected.
67 // are available to be garbage collected.
68 return createGCPromise(); 74 return createGCPromise();
69 }).then(function(result) { 75 }).then(function() {
70 assert_equals(numMediaKeysCreated(), 1); 76 assert_equals(window.internals.mediaKeysCount(), 5, 'All sti ll alive');
71 assert_equals(typeof mediaKeys.createSession, 'function'); 77
78 // Drop references to 4 of the MediaKeys. As we will only
79 // have a reference to the last created MediaKeys object,
80 // the other 4 MediaKeys objects are available to be
81 // garbage collected.
82 mediaKeys1 = null;
83 mediaKeys2 = null;
84 mediaKeys3 = null;
85 mediaKeys4 = null;
86 return createGCPromise();
87 }).then(function() {
88 assert_equals(window.internals.mediaKeysCount(), 1, 'Only 1 left');
72 89
73 // Release the last MediaKeys object created. 90 // Release the last MediaKeys object created.
74 mediaKeys = null; 91 mediaKeys5 = null;
75 92
76 // Run gc() again to reclaim the remaining MediaKeys object. 93 // Run gc() again to reclaim the remaining MediaKeys object.
77 return createGCPromise(); 94 return createGCPromise();
78 }).then(function(result) { 95 }).then(function() {
79 assert_equals(numMediaKeysCreated(), 0); 96 assert_equals(window.internals.mediaKeysCount(), 0, 'After f inal gc()');
80 test.done();
81 }).catch(function(error) {
82 forceTestFailureFromPromise(test, error);
83 }); 97 });
84 }, 'Multiple MediaKeys lifetime'); 98 }, 'Multiple MediaKeys lifetime');
85 </script> 99 </script>
86 </body> 100 </body>
87 </html> 101 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698