| OLD | NEW |
| 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 // Since MediaKeySession (and MediaKeys) are ActiveDOMObjects, | 11 // Since MediaKeySession (and MediaKeys) are SuspendableObjects, |
| 12 // we can determine when they are garbage collected. | 12 // we can determine when they are garbage collected. |
| 13 // MediaKeySessions remain as long as: | 13 // MediaKeySessions remain as long as: |
| 14 // JavaScript has a reference to it | 14 // JavaScript has a reference to it |
| 15 // OR (MediaKeys is around | 15 // OR (MediaKeys is around |
| 16 // AND the session has not received a close() event) | 16 // AND the session has not received a close() event) |
| 17 async_test(function(test) | 17 async_test(function(test) |
| 18 { | 18 { |
| 19 var mediaKeys; | 19 var mediaKeys; |
| 20 var mediaKeySession1; | 20 var mediaKeySession1; |
| 21 var mediaKeySession2; | 21 var mediaKeySession2; |
| 22 var initDataType; | 22 var initDataType; |
| 23 var initData; | 23 var initData; |
| 24 var startingActiveDOMObjectCount = window.internals.activeDOMObj
ectCount(document); | 24 var startingSuspendableObjectCount = window.internals.suspendabl
eObjectCount(document); |
| 25 | 25 |
| 26 function numActiveDOMObjectsCreated() | 26 function numSuspendableObjectsCreated() |
| 27 { | 27 { |
| 28 return window.internals.activeDOMObjectCount(document) - sta
rtingActiveDOMObjectCount; | 28 return window.internals.suspendableObjectCount(document) - s
tartingSuspendableObjectCount; |
| 29 } | 29 } |
| 30 | 30 |
| 31 // Create 2 sessions. | 31 // Create 2 sessions. |
| 32 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp
leConfiguration()).then(function(access) { | 32 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp
leConfiguration()).then(function(access) { |
| 33 initDataType = access.getConfiguration().initDataTypes[0]; | 33 initDataType = access.getConfiguration().initDataTypes[0]; |
| 34 initData = getInitData(initDataType); | 34 initData = getInitData(initDataType); |
| 35 return access.createMediaKeys(); | 35 return access.createMediaKeys(); |
| 36 }).then(function(result) { | 36 }).then(function(result) { |
| 37 mediaKeys = result; | 37 mediaKeys = result; |
| 38 | 38 |
| 39 // Verify MediaKeys is an ActiveDOMObject. | 39 // Verify MediaKeys is an SuspendableObject. |
| 40 // In non-Oilpan, numActiveDOMObjectsCreate() == 1. | 40 // In non-Oilpan, numSuspendableObjectsCreate() == 1. |
| 41 // In Oilpan, numActiveDOMObjectsCreate() <= 4. | 41 // In Oilpan, numSuspendableObjectsCreate() <= 4. |
| 42 // (1 MediaKeys, | 42 // (1 MediaKeys, |
| 43 // 1 MediaKeysInitializer and | 43 // 1 MediaKeysInitializer and |
| 44 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi
aKeySystemAccess() use above), | 44 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi
aKeySystemAccess() use above), |
| 45 // 1 MediaKeySystemAccessInitializer (isInitDataSupported()
(via getSupportedInitDataType()))) | 45 // 1 MediaKeySystemAccessInitializer (isInitDataSupported()
(via getSupportedInitDataType()))) |
| 46 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 4,
'MediaKeys.create()'); | 46 assert_between_inclusive(numSuspendableObjectsCreated(), 1,
4, 'MediaKeys.create()'); |
| 47 | 47 |
| 48 mediaKeySession1 = mediaKeys.createSession(); | 48 mediaKeySession1 = mediaKeys.createSession(); |
| 49 return mediaKeySession1.generateRequest(initDataType, initDa
ta); | 49 return mediaKeySession1.generateRequest(initDataType, initDa
ta); |
| 50 }).then(function() { | 50 }).then(function() { |
| 51 // Should be 1 MediaKeys + 1 MediaKeySession. | 51 // Should be 1 MediaKeys + 1 MediaKeySession. |
| 52 // In non-Oilpan, numActiveDOMObjectsCreate() == 2. | 52 // In non-Oilpan, numSuspendableObjectsCreate() == 2. |
| 53 // In Oilpan, numActiveDOMObjectsCreate() <= 6. | 53 // In Oilpan, numSuspendableObjectsCreate() <= 6. |
| 54 // (1 MediaKeys, | 54 // (1 MediaKeys, |
| 55 // 1 MediaKeysInitializer, | 55 // 1 MediaKeysInitializer, |
| 56 // 2 MediaKeySystemAccessInitializers, | 56 // 2 MediaKeySystemAccessInitializers, |
| 57 // 1 ContentDecryptionModuleResultPromise and | 57 // 1 ContentDecryptionModuleResultPromise and |
| 58 // 1 MediaKeySession). | 58 // 1 MediaKeySession). |
| 59 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 6,
'MediaKeys.createSession(1)'); | 59 assert_between_inclusive(numSuspendableObjectsCreated(), 2,
6, 'MediaKeys.createSession(1)'); |
| 60 | 60 |
| 61 mediaKeySession2 = mediaKeys.createSession(); | 61 mediaKeySession2 = mediaKeys.createSession(); |
| 62 return mediaKeySession2.generateRequest(initDataType, initDa
ta); | 62 return mediaKeySession2.generateRequest(initDataType, initDa
ta); |
| 63 }).then(function() { | 63 }).then(function() { |
| 64 // Should be 1 MediaKeys + 2 MediaKeySessions. | 64 // Should be 1 MediaKeys + 2 MediaKeySessions. |
| 65 // In non-Oilpan, numActiveDOMObjectsCreate() == 3. | 65 // In non-Oilpan, numSuspendableObjectsCreate() == 3. |
| 66 // In Oilpan, numActiveDOMObjectsCreate() <= 8. | 66 // In Oilpan, numSuspendableObjectsCreate() <= 8. |
| 67 // (1 MediaKeys, | 67 // (1 MediaKeys, |
| 68 // 1 MediaKeysInitializer, | 68 // 1 MediaKeysInitializer, |
| 69 // 2 MediaKeySystemAccessInitializers, | 69 // 2 MediaKeySystemAccessInitializers, |
| 70 // 2 ContentDecryptionModuleResultPromise and | 70 // 2 ContentDecryptionModuleResultPromise and |
| 71 // 2 MediaKeySession). | 71 // 2 MediaKeySession). |
| 72 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 8,
'mediaKeys.createSession(2)'); | 72 assert_between_inclusive(numSuspendableObjectsCreated(), 3,
8, 'mediaKeys.createSession(2)'); |
| 73 | 73 |
| 74 // Close the sessions. Once completed, only the JS | 74 // Close the sessions. Once completed, only the JS |
| 75 // reference to them keeps them around. | 75 // reference to them keeps them around. |
| 76 return mediaKeySession1.close(); | 76 return mediaKeySession1.close(); |
| 77 }).then(function(result) { | 77 }).then(function(result) { |
| 78 return mediaKeySession2.close(); | 78 return mediaKeySession2.close(); |
| 79 }).then(function(result) { | 79 }).then(function(result) { |
| 80 // Since both sessions have been closed, dropping the | 80 // Since both sessions have been closed, dropping the |
| 81 // reference to them from JS will result in the session | 81 // reference to them from JS will result in the session |
| 82 // being garbage-collected. | 82 // being garbage-collected. |
| 83 // Should be 1 MediaKeys + 2 MediaKeySessions. | 83 // Should be 1 MediaKeys + 2 MediaKeySessions. |
| 84 // In non-Oilpan, numActiveDOMObjectsCreate() == 3. | 84 // In non-Oilpan, numSuspendableObjectsCreate() == 3. |
| 85 // In Oilpan, numActiveDOMObjectsCreate() <= 10. | 85 // In Oilpan, numSuspendableObjectsCreate() <= 10. |
| 86 // (1 MediaKeys, | 86 // (1 MediaKeys, |
| 87 // 1 MediaKeysInitializer, | 87 // 1 MediaKeysInitializer, |
| 88 // 2 MediaKeySystemAccessInitializers, | 88 // 2 MediaKeySystemAccessInitializers, |
| 89 // 4 ContentDecryptionModuleResultPromise and | 89 // 4 ContentDecryptionModuleResultPromise and |
| 90 // 2 MediaKeySession). | 90 // 2 MediaKeySession). |
| 91 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 10
, 'after close'); | 91 assert_between_inclusive(numSuspendableObjectsCreated(), 3,
10, 'after close'); |
| 92 | 92 |
| 93 mediaKeySession1 = null; | 93 mediaKeySession1 = null; |
| 94 return createGCPromise(); | 94 return createGCPromise(); |
| 95 }).then(function() { | 95 }).then(function() { |
| 96 // Only MediaKeys + mediaKeySession2 should remain. | 96 // Only MediaKeys + mediaKeySession2 should remain. |
| 97 // In non-Oilpan, there is also something from createGCPromi
se(). | 97 // In non-Oilpan, there is also something from createGCPromi
se(). |
| 98 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 3,
'mediaKeySession1 not collected'); | 98 assert_between_inclusive(numSuspendableObjectsCreated(), 2,
3, 'mediaKeySession1 not collected'); |
| 99 | 99 |
| 100 mediaKeySession2 = null; | 100 mediaKeySession2 = null; |
| 101 return createGCPromise(); | 101 return createGCPromise(); |
| 102 }).then(function() { | 102 }).then(function() { |
| 103 // Only MediaKeys should remain. | 103 // Only MediaKeys should remain. |
| 104 // In non-Oilpan, there is also something from createGCPromi
se(). | 104 // In non-Oilpan, there is also something from createGCPromi
se(). |
| 105 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 2,
'mediaKeySession2 not collected'); | 105 assert_between_inclusive(numSuspendableObjectsCreated(), 1,
2, 'mediaKeySession2 not collected'); |
| 106 test.done(); | 106 test.done(); |
| 107 }).catch(function(error) { | 107 }).catch(function(error) { |
| 108 forceTestFailureFromPromise(test, error); | 108 forceTestFailureFromPromise(test, error); |
| 109 }); | 109 }); |
| 110 }, 'MediaKeySession lifetime after release()'); | 110 }, 'MediaKeySession lifetime after release()'); |
| 111 </script> | 111 </script> |
| 112 </body> | 112 </body> |
| 113 </html> | 113 </html> |
| OLD | NEW |