| OLD | NEW |
| 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 <div id="log"></div> | 10 <div id="log"></div> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 { | 28 { |
| 29 var mediaKeys; | 29 var mediaKeys; |
| 30 var startingActiveDOMObjectCount = window.internals.activeDOMObj
ectCount(document); | 30 var startingActiveDOMObjectCount = window.internals.activeDOMObj
ectCount(document); |
| 31 | 31 |
| 32 function numActiveDOMObjectsCreated() | 32 function numActiveDOMObjectsCreated() |
| 33 { | 33 { |
| 34 return window.internals.activeDOMObjectCount(document) - sta
rtingActiveDOMObjectCount; | 34 return window.internals.activeDOMObjectCount(document) - sta
rtingActiveDOMObjectCount; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Create a MediaKeys object with a session. | 37 // Create a MediaKeys object with a session. |
| 38 MediaKeys.create('org.w3.clearkey').then(function(result) { | 38 navigator.requestMediaKeySystemAccess('org.w3.clearkey').then(fu
nction(access) { |
| 39 assert_equals(access.keySystem, 'org.w3.clearkey'); |
| 40 return access.createMediaKeys(); |
| 41 }).then(function(result) { |
| 39 mediaKeys = result; | 42 mediaKeys = result; |
| 40 | 43 |
| 41 // Verify MediaKeys are not an ActiveDOMObject. | 44 // Verify MediaKeys are not an ActiveDOMObject. |
| 42 assert_equals(numActiveDOMObjectsCreated(), 0, 'MediaKeys.cr
eate()'); | 45 assert_equals(numActiveDOMObjectsCreated(), 0, 'MediaKeys.cr
eate()'); |
| 43 | 46 |
| 44 var initDataType = getInitDataType(); | 47 var initDataType = getInitDataType(); |
| 45 var mediaKeySession = mediaKeys.createSession(); | 48 var mediaKeySession = mediaKeys.createSession(); |
| 46 return mediaKeySession.generateRequest(initDataType, getInit
Data(initDataType)); | 49 return mediaKeySession.generateRequest(initDataType, getInit
Data(initDataType)); |
| 47 }).then(function() { | 50 }).then(function() { |
| 48 // 1 MediaKeySession. | 51 // 1 MediaKeySession. |
| 49 assert_equals(numActiveDOMObjectsCreated(), 1, 'MediaKeys.cr
eateSession()'); | 52 assert_equals(numActiveDOMObjectsCreated(), 1, 'MediaKeys.cr
eateSession()'); |
| 50 | 53 |
| 51 // Run gc(), should not affect MediaKeys object nor the | 54 // Run gc(), should not affect MediaKeys object nor the |
| 52 // session since we still have a reference to it. | 55 // session since we still have a reference to it. |
| 53 return createGCPromise(); | 56 return createGCPromise(); |
| 54 }).then(function(result) { | 57 }).then(function(result) { |
| 55 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); | 58 assert_equals(typeof mediaKeys.createSession, 'function'); |
| 56 // Ensure that MediaKeySession (but not PromiseResolver) is | 59 // Ensure that MediaKeySession (but not PromiseResolver) is |
| 57 // still around. | 60 // still around. |
| 58 assert_equals(numActiveDOMObjectsCreated(), 1, 'After gc()')
; | 61 assert_equals(numActiveDOMObjectsCreated(), 1, 'After gc()')
; |
| 59 | 62 |
| 60 // Drop reference to the MediaKeys object and run gc() | 63 // Drop reference to the MediaKeys object and run gc() |
| 61 // again. Object should be collected this time. Since | 64 // again. Object should be collected this time. Since |
| 62 // MediaKeySessions remain alive as long as MediaKeys is | 65 // MediaKeySessions remain alive as long as MediaKeys is |
| 63 // around, it is possible that gc() checks the | 66 // around, it is possible that gc() checks the |
| 64 // MediaKeySession object first, and doesn't collect it | 67 // MediaKeySession object first, and doesn't collect it |
| 65 // since MediaKeys hasn't been collected yet. Thus run gc() | 68 // since MediaKeys hasn't been collected yet. Thus run gc() |
| 66 // twice, to ensure that the unreferenced MediaKeySession | 69 // twice, to ensure that the unreferenced MediaKeySession |
| 67 // object get collected. | 70 // object get collected. |
| 68 mediaKeys = null; | 71 mediaKeys = null; |
| 69 return createGCPromise(); | 72 return createGCPromise(); |
| 70 }).then(function(result) { | 73 }).then(function(result) { |
| 71 return createGCPromise(); | 74 return createGCPromise(); |
| 72 }).then(function(result) { | 75 }).then(function(result) { |
| 73 assert_equals(numActiveDOMObjectsCreated(), 0); | 76 assert_equals(numActiveDOMObjectsCreated(), 0); |
| 74 test.done(); | 77 test.done(); |
| 75 }).catch(function(error) { | 78 }).catch(function(error) { |
| 76 forceTestFailureFromPromise(test, error); | 79 forceTestFailureFromPromise(test, error); |
| 77 }); | 80 }); |
| 78 }, 'MediaKeys lifetime with session'); | 81 }, 'MediaKeys lifetime with session'); |
| 79 </script> | 82 </script> |
| 80 </body> | 83 </body> |
| 81 </html> | 84 </html> |
| OLD | NEW |