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

Side by Side Diff: third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-release.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>MediaKeySession lifetime after release()</title> 4 <title>MediaKeySession lifetime after 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 async_test(function(test) 15 promise_test(function(test)
16 { 16 {
17 gc();
18 var mediaKeys; 17 var mediaKeys;
19 var mediaKeySession1; 18 var mediaKeySession1;
20 var mediaKeySession2; 19 var mediaKeySession2;
21 var initDataType; 20 var initDataType;
22 var initData; 21 var initData;
23 var startingMediaKeysCount = window.internals.mediaKeysCount();
24 var startingMediaKeySessionCount = window.internals.mediaKeySess ionCount();
25
26 function numMediaKeysCreated()
27 {
28 return window.internals.mediaKeysCount() - startingMediaKeys Count;
29 }
30
31 function numMediaKeySessionCreated()
32 {
33 return window.internals.mediaKeySessionCount() - startingMed iaKeySessionCount;
34 }
35 22
36 // Create 2 sessions. 23 // Create 2 sessions.
37 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp leConfiguration()).then(function(access) { 24 return createGCPromise().then(function() {
25 assert_equals(window.internals.mediaKeysCount(), 0, 'After i nitial gc()');
26 assert_equals(window.internals.mediaKeySessionCount(), 0, 'A fter initial gc()');
27
28 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration());
29 }).then(function(access) {
38 initDataType = access.getConfiguration().initDataTypes[0]; 30 initDataType = access.getConfiguration().initDataTypes[0];
39 initData = getInitData(initDataType); 31 initData = getInitData(initDataType);
40 return access.createMediaKeys(); 32 return access.createMediaKeys();
41 }).then(function(result) { 33 }).then(function(result) {
42 mediaKeys = result; 34 mediaKeys = result;
43 35
44 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()' ); 36 assert_equals(window.internals.mediaKeysCount(), 1, 'MediaKe ys.create()');
45 assert_equals(numMediaKeySessionCreated(), 0, 'MediaKeys.cre ate()'); 37 assert_equals(window.internals.mediaKeySessionCount(), 0, 'M ediaKeys.create()');
46 38
47 mediaKeySession1 = mediaKeys.createSession(); 39 mediaKeySession1 = mediaKeys.createSession();
48 return mediaKeySession1.generateRequest(initDataType, initDa ta); 40 return mediaKeySession1.generateRequest(initDataType, initDa ta);
49 }).then(function() { 41 }).then(function() {
50 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSes sion(1)'); 42 assert_equals(window.internals.mediaKeysCount(), 1, 'MediaKe ys.createSession(1)');
51 assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.cre ateSession(1)'); 43 assert_equals(window.internals.mediaKeySessionCount(), 1, 'M ediaKeys.createSession(1)');
52 44
53 mediaKeySession2 = mediaKeys.createSession(); 45 mediaKeySession2 = mediaKeys.createSession();
54 return mediaKeySession2.generateRequest(initDataType, initDa ta); 46 return mediaKeySession2.generateRequest(initDataType, initDa ta);
55 }).then(function() { 47 }).then(function() {
56 assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSes sion(2)'); 48 assert_equals(window.internals.mediaKeysCount(), 1, 'mediaKe ys.createSession(2)');
57 assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.cre ateSession(2)'); 49 assert_equals(window.internals.mediaKeySessionCount(), 2, 'm ediaKeys.createSession(2)');
58 50
59 // Close the sessions. Once completed, only the JS 51 // Close the sessions. Once completed, only the JS
60 // reference to them keeps them around. 52 // reference to them keeps them around.
61 return mediaKeySession1.close(); 53 return mediaKeySession1.close();
62 }).then(function(result) { 54 }).then(function(result) {
63 return mediaKeySession2.close(); 55 return mediaKeySession2.close();
64 }).then(function(result) { 56 }).then(function(result) {
65 // Since both sessions have been closed, dropping the 57 // Since both sessions have been closed, dropping the
66 // reference to them from JS will result in the session 58 // reference to them from JS will result in the session
67 // being garbage-collected. 59 // being garbage-collected.
68 assert_equals(numMediaKeysCreated(), 1, 'after close'); 60 assert_equals(window.internals.mediaKeysCount(), 1, 'after c lose');
69 assert_equals(numMediaKeySessionCreated(), 2, 'after close') ; 61 assert_equals(window.internals.mediaKeySessionCount(), 2, 'a fter close');
70 62
71 mediaKeySession1 = null; 63 mediaKeySession1 = null;
72 return createGCPromise(); 64 return createGCPromise();
73 }).then(function() { 65 }).then(function() {
74 assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession1 no t collected'); 66 assert_equals(window.internals.mediaKeysCount(), 1, 'mediaKe ySession1 not collected');
75 assert_equals(numMediaKeySessionCreated(), 1, 'mediaKeySessi on1 not collected'); 67 assert_equals(window.internals.mediaKeySessionCount(), 1, 'm ediaKeySession1 not collected');
76 68
77 mediaKeySession2 = null; 69 mediaKeySession2 = null;
78 return createGCPromise(); 70 return createGCPromise();
79 }).then(function() { 71 }).then(function() {
80 assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession2 no t collected'); 72 assert_equals(window.internals.mediaKeysCount(), 1, 'mediaKe ySession2 not collected');
81 assert_equals(numMediaKeySessionCreated(), 0, 'mediaKeySessi on2 not collected'); 73 assert_equals(window.internals.mediaKeySessionCount(), 0, 'm ediaKeySession2 not collected');
82 test.done();
83 }).catch(function(error) {
84 forceTestFailureFromPromise(test, error);
85 }); 74 });
86 }, 'MediaKeySession lifetime after release()'); 75 }, 'MediaKeySession lifetime after release()');
87 </script> 76 </script>
88 </body> 77 </body>
89 </html> 78 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698