| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test MediaKeySession lifetime after release() without references<
/title> | 4 <title>Test MediaKeySession lifetime after release() without references<
/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 initDataType; | 17 var initDataType; |
| 19 var initData; | 18 var initData; |
| 20 var startingMediaKeysCount = window.internals.mediaKeysCount(); | |
| 21 var startingMediaKeySessionCount = window.internals.mediaKeySess
ionCount(); | |
| 22 | |
| 23 function numMediaKeysCreated() | |
| 24 { | |
| 25 return window.internals.mediaKeysCount() - startingMediaKeys
Count; | |
| 26 } | |
| 27 | |
| 28 function numMediaKeySessionCreated() | |
| 29 { | |
| 30 return window.internals.mediaKeySessionCount() - startingMed
iaKeySessionCount; | |
| 31 } | |
| 32 | 19 |
| 33 // Create 2 sessions. | 20 // Create 2 sessions. |
| 34 var mediaKeys; | 21 var mediaKeys; |
| 35 var mediaKeySession1; | 22 var mediaKeySession1; |
| 36 var mediaKeySession2; | 23 var mediaKeySession2; |
| 37 | 24 |
| 38 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp
leConfiguration()).then(function(access) { | 25 // Even though there should be no existing objects, start by |
| 26 // running gc() and verifying that none exist. This also |
| 27 // allows the failures to be reported from inside a promise |
| 28 // so that the test fails properly. |
| 29 return createGCPromise().then(function() { |
| 30 verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After initial g
c()'); |
| 31 |
| 32 return navigator.requestMediaKeySystemAccess('org.w3.clearke
y', getSimpleConfiguration()); |
| 33 }).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 | 39 verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.creat
e()'); |
| 45 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()'
); | |
| 46 assert_equals(numMediaKeySessionCreated(), 0, 'MediaKeys.cre
ate()'); | |
| 47 | 40 |
| 48 mediaKeySession1 = mediaKeys.createSession(); | 41 mediaKeySession1 = mediaKeys.createSession(); |
| 49 return mediaKeySession1.generateRequest(initDataType, initDa
ta); | 42 return mediaKeySession1.generateRequest(initDataType, initDa
ta); |
| 50 }).then(function() { | 43 }).then(function() { |
| 51 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s
essionId.length > 0); | 44 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s
essionId.length > 0); |
| 52 | 45 verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.crea
teSession(1)'); |
| 53 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSes
sion(1)'); | |
| 54 assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.cre
ateSession(1)'); | |
| 55 | 46 |
| 56 mediaKeySession2 = mediaKeys.createSession(); | 47 mediaKeySession2 = mediaKeys.createSession(); |
| 57 return mediaKeySession2.generateRequest(initDataType, initDa
ta); | 48 return mediaKeySession2.generateRequest(initDataType, initDa
ta); |
| 58 }).then(function() { | 49 }).then(function() { |
| 59 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s
essionId.length > 0); | 50 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s
essionId.length > 0); |
| 51 verifyMediaKeyAndMediaKeySessionCount(1, 2, 'mediaKeys.creat
eSession(2)'); |
| 60 | 52 |
| 61 assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSes
sion(2)'); | |
| 62 assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.cre
ateSession(2)'); | |
| 63 }).then(function(result) { | |
| 64 // Run gc(). All sessions should remain as we have a | 53 // Run gc(). All sessions should remain as we have a |
| 65 // reference to each one. | 54 // reference to each one. |
| 66 return createGCPromise(); | 55 return createGCPromise(); |
| 67 }).then(function(result) { | 56 }).then(function(result) { |
| 68 assert_equals(numMediaKeysCreated(), 1, 'After gc()'); | 57 verifyMediaKeyAndMediaKeySessionCount(1, 2, 'After gc()'); |
| 69 assert_equals(numMediaKeySessionCreated(), 2, 'After gc()'); | |
| 70 | 58 |
| 71 // Close the sessions. Once the close() event is received, | 59 // Close the sessions. Once the close() event is received, |
| 72 // they should get garbage collected as there are no JS | 60 // they should get garbage collected as there are no JS |
| 73 // references to them. | 61 // references to them. |
| 74 var promise = mediaKeySession1.close(); | 62 var promise = mediaKeySession1.close(); |
| 75 mediaKeySession1 = null; | 63 mediaKeySession1 = null; |
| 76 return promise; | 64 return promise; |
| 77 }).then(function(result) { | 65 }).then(function(result) { |
| 78 // Give time so that the close event can be processed by | 66 // Give time so that the close event can be processed by |
| 79 // MediaKeySession. | 67 // MediaKeySession. |
| 80 return delayToAllowEventProcessingPromise(); | 68 return delayToAllowEventProcessingPromise(); |
| 81 }).then(function(result) { | 69 }).then(function(result) { |
| 82 return createGCPromise(); | 70 return createGCPromise(); |
| 83 }).then(function(result) { | 71 }).then(function(result) { |
| 84 assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession1 no
t collected'); | 72 verifyMediaKeyAndMediaKeySessionCount(1, 1, 'mediaKeySession
1 not collected'); |
| 85 assert_equals(numMediaKeySessionCreated(), 1, 'mediaKeySessi
on1 not collected'); | |
| 86 | 73 |
| 87 var promise = mediaKeySession2.close(); | 74 var promise = mediaKeySession2.close(); |
| 88 mediaKeySession2 = null; | 75 mediaKeySession2 = null; |
| 89 return promise; | 76 return promise; |
| 90 }).then(function(result) { | 77 }).then(function(result) { |
| 91 // Provide time for the mediaKeySession2 close event to be | 78 // Provide time for the mediaKeySession2 close event to be |
| 92 // handled. | 79 // handled. |
| 93 return delayToAllowEventProcessingPromise(); | 80 return delayToAllowEventProcessingPromise(); |
| 94 }).then(function(result) { | 81 }).then(function(result) { |
| 95 return createGCPromise(); | 82 return createGCPromise(); |
| 96 }).then(function(result) { | 83 }).then(function(result) { |
| 97 assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession2 no
t collected'); | 84 verifyMediaKeyAndMediaKeySessionCount(1, 0, 'mediaKeySession
2 not collected'); |
| 98 assert_equals(numMediaKeySessionCreated(), 0, 'mediaKeySessi
on2 not collected'); | |
| 99 | |
| 100 assert_not_equals(mediaKeys, null); | 85 assert_not_equals(mediaKeys, null); |
| 101 test.done(); | |
| 102 }).catch(function(error) { | |
| 103 forceTestFailureFromPromise(test, error); | |
| 104 }); | 86 }); |
| 105 }, 'MediaKeySession lifetime after release() without references'); | 87 }, 'MediaKeySession lifetime after release() without references'); |
| 106 </script> | 88 </script> |
| 107 </body> | 89 </body> |
| 108 </html> | 90 </html> |
| OLD | NEW |