| 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 return createGCPromise().then(function() { |
| 26 assert_equals(window.internals.mediaKeysCount(), 0, 'After i
nitial gc()'); |
| 27 assert_equals(window.internals.mediaKeySessionCount(), 0, 'A
fter initial gc()'); |
| 28 |
| 29 return navigator.requestMediaKeySystemAccess('org.w3.clearke
y', getSimpleConfiguration()); |
| 30 }).then(function(access) { |
| 39 initDataType = access.getConfiguration().initDataTypes[0]; | 31 initDataType = access.getConfiguration().initDataTypes[0]; |
| 40 initData = getInitData(initDataType); | 32 initData = getInitData(initDataType); |
| 41 return access.createMediaKeys(); | 33 return access.createMediaKeys(); |
| 42 }).then(function(result) { | 34 }).then(function(result) { |
| 43 mediaKeys = result; | 35 mediaKeys = result; |
| 44 | 36 |
| 45 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()'
); | 37 assert_equals(window.internals.mediaKeysCount(), 1, 'MediaKe
ys.create()'); |
| 46 assert_equals(numMediaKeySessionCreated(), 0, 'MediaKeys.cre
ate()'); | 38 assert_equals(window.internals.mediaKeySessionCount(), 0, 'M
ediaKeys.create()'); |
| 47 | 39 |
| 48 mediaKeySession1 = mediaKeys.createSession(); | 40 mediaKeySession1 = mediaKeys.createSession(); |
| 49 return mediaKeySession1.generateRequest(initDataType, initDa
ta); | 41 return mediaKeySession1.generateRequest(initDataType, initDa
ta); |
| 50 }).then(function() { | 42 }).then(function() { |
| 51 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s
essionId.length > 0); | 43 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s
essionId.length > 0); |
| 52 | 44 |
| 53 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSes
sion(1)'); | 45 assert_equals(window.internals.mediaKeysCount(), 1, 'MediaKe
ys.createSession(1)'); |
| 54 assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.cre
ateSession(1)'); | 46 assert_equals(window.internals.mediaKeySessionCount(), 1, 'M
ediaKeys.createSession(1)'); |
| 55 | 47 |
| 56 mediaKeySession2 = mediaKeys.createSession(); | 48 mediaKeySession2 = mediaKeys.createSession(); |
| 57 return mediaKeySession2.generateRequest(initDataType, initDa
ta); | 49 return mediaKeySession2.generateRequest(initDataType, initDa
ta); |
| 58 }).then(function() { | 50 }).then(function() { |
| 59 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s
essionId.length > 0); | 51 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s
essionId.length > 0); |
| 60 | 52 |
| 61 assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSes
sion(2)'); | 53 assert_equals(window.internals.mediaKeysCount(), 1, 'mediaKe
ys.createSession(2)'); |
| 62 assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.cre
ateSession(2)'); | 54 assert_equals(window.internals.mediaKeySessionCount(), 2, 'm
ediaKeys.createSession(2)'); |
| 63 }).then(function(result) { | 55 }).then(function(result) { |
| 64 // Run gc(). All sessions should remain as we have a | 56 // Run gc(). All sessions should remain as we have a |
| 65 // reference to each one. | 57 // reference to each one. |
| 66 return createGCPromise(); | 58 return createGCPromise(); |
| 67 }).then(function(result) { | 59 }).then(function(result) { |
| 68 assert_equals(numMediaKeysCreated(), 1, 'After gc()'); | 60 assert_equals(window.internals.mediaKeysCount(), 1, 'After g
c()'); |
| 69 assert_equals(numMediaKeySessionCreated(), 2, 'After gc()'); | 61 assert_equals(window.internals.mediaKeySessionCount(), 2, 'A
fter gc()'); |
| 70 | 62 |
| 71 // Close the sessions. Once the close() event is received, | 63 // Close the sessions. Once the close() event is received, |
| 72 // they should get garbage collected as there are no JS | 64 // they should get garbage collected as there are no JS |
| 73 // references to them. | 65 // references to them. |
| 74 var promise = mediaKeySession1.close(); | 66 var promise = mediaKeySession1.close(); |
| 75 mediaKeySession1 = null; | 67 mediaKeySession1 = null; |
| 76 return promise; | 68 return promise; |
| 77 }).then(function(result) { | 69 }).then(function(result) { |
| 78 // Give time so that the close event can be processed by | 70 // Give time so that the close event can be processed by |
| 79 // MediaKeySession. | 71 // MediaKeySession. |
| 80 return delayToAllowEventProcessingPromise(); | 72 return delayToAllowEventProcessingPromise(); |
| 81 }).then(function(result) { | 73 }).then(function(result) { |
| 82 return createGCPromise(); | 74 return createGCPromise(); |
| 83 }).then(function(result) { | 75 }).then(function(result) { |
| 84 assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession1 no
t collected'); | 76 assert_equals(window.internals.mediaKeysCount(), 1, 'mediaKe
ySession1 not collected'); |
| 85 assert_equals(numMediaKeySessionCreated(), 1, 'mediaKeySessi
on1 not collected'); | 77 assert_equals(window.internals.mediaKeySessionCount(), 1, 'm
ediaKeySession1 not collected'); |
| 86 | 78 |
| 87 var promise = mediaKeySession2.close(); | 79 var promise = mediaKeySession2.close(); |
| 88 mediaKeySession2 = null; | 80 mediaKeySession2 = null; |
| 89 return promise; | 81 return promise; |
| 90 }).then(function(result) { | 82 }).then(function(result) { |
| 91 // Provide time for the mediaKeySession2 close event to be | 83 // Provide time for the mediaKeySession2 close event to be |
| 92 // handled. | 84 // handled. |
| 93 return delayToAllowEventProcessingPromise(); | 85 return delayToAllowEventProcessingPromise(); |
| 94 }).then(function(result) { | 86 }).then(function(result) { |
| 95 return createGCPromise(); | 87 return createGCPromise(); |
| 96 }).then(function(result) { | 88 }).then(function(result) { |
| 97 assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession2 no
t collected'); | 89 assert_equals(window.internals.mediaKeysCount(), 1, 'mediaKe
ySession2 not collected'); |
| 98 assert_equals(numMediaKeySessionCreated(), 0, 'mediaKeySessi
on2 not collected'); | 90 assert_equals(window.internals.mediaKeySessionCount(), 0, 'm
ediaKeySession2 not collected'); |
| 99 | 91 |
| 100 assert_not_equals(mediaKeys, null); | 92 assert_not_equals(mediaKeys, null); |
| 101 test.done(); | |
| 102 }).catch(function(error) { | |
| 103 forceTestFailureFromPromise(test, error); | |
| 104 }); | 93 }); |
| 105 }, 'MediaKeySession lifetime after release() without references'); | 94 }, 'MediaKeySession lifetime after release() without references'); |
| 106 </script> | 95 </script> |
| 107 </body> | 96 </body> |
| 108 </html> | 97 </html> |
| OLD | NEW |