| 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 // 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 initDataType; | 19 var initDataType; |
| 20 var initData; | 20 var initData; |
| 21 var startingActiveDOMObjectCount = window.internals.activeDOMObj
ectCount(document); | 21 var startingSuspendableObjectCount = window.internals.suspendabl
eObjectCount(document); |
| 22 | 22 |
| 23 function numActiveDOMObjectsCreated() | 23 function numSuspendableObjectsCreated() |
| 24 { | 24 { |
| 25 return window.internals.activeDOMObjectCount(document) - sta
rtingActiveDOMObjectCount; | 25 return window.internals.suspendableObjectCount(document) - s
tartingSuspendableObjectCount; |
| 26 } | 26 } |
| 27 | 27 |
| 28 // Create 2 sessions. | 28 // Create 2 sessions. |
| 29 var mediaKeys; | 29 var mediaKeys; |
| 30 var mediaKeySession1; | 30 var mediaKeySession1; |
| 31 var mediaKeySession2; | 31 var mediaKeySession2; |
| 32 | 32 |
| 33 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp
leConfiguration()).then(function(access) { | 33 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp
leConfiguration()).then(function(access) { |
| 34 initDataType = access.getConfiguration().initDataTypes[0]; | 34 initDataType = access.getConfiguration().initDataTypes[0]; |
| 35 initData = getInitData(initDataType); | 35 initData = getInitData(initDataType); |
| 36 return access.createMediaKeys(); | 36 return access.createMediaKeys(); |
| 37 }).then(function(result) { | 37 }).then(function(result) { |
| 38 mediaKeys = result; | 38 mediaKeys = result; |
| 39 | 39 |
| 40 // Verify MediaKeys is an ActiveDOMObject. | 40 // Verify MediaKeys is an SuspendableObject. |
| 41 // In non-Oilpan, numActiveDOMObjectsCreate() == 1. | 41 // In non-Oilpan, numSuspendableObjectsCreate() == 1. |
| 42 // In Oilpan, numActiveDOMObjectsCreate() <= 4. | 42 // In Oilpan, numSuspendableObjectsCreate() <= 4. |
| 43 // (1 MediaKeys, | 43 // (1 MediaKeys, |
| 44 // 1 MediaKeysInitializer and | 44 // 1 MediaKeysInitializer and |
| 45 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi
aKeySystemAccess() use above), | 45 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi
aKeySystemAccess() use above), |
| 46 // 1 MediaKeySystemAccessInitializer (isInitDataSupported()
(via getSupportedInitDataType()))) | 46 // 1 MediaKeySystemAccessInitializer (isInitDataSupported()
(via getSupportedInitDataType()))) |
| 47 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 4,
'MediaKeys.create()'); | 47 assert_between_inclusive(numSuspendableObjectsCreated(), 1,
4, 'MediaKeys.create()'); |
| 48 | 48 |
| 49 mediaKeySession1 = mediaKeys.createSession(); | 49 mediaKeySession1 = mediaKeys.createSession(); |
| 50 return mediaKeySession1.generateRequest(initDataType, initDa
ta); | 50 return mediaKeySession1.generateRequest(initDataType, initDa
ta); |
| 51 }).then(function() { | 51 }).then(function() { |
| 52 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s
essionId.length > 0); | 52 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s
essionId.length > 0); |
| 53 | 53 |
| 54 // Should be 1 MediaKeys + 1 MediaKeySession. | 54 // Should be 1 MediaKeys + 1 MediaKeySession. |
| 55 // In non-Oilpan, numActiveDOMObjectsCreate() == 2. | 55 // In non-Oilpan, numSuspendableObjectsCreate() == 2. |
| 56 // In Oilpan, numActiveDOMObjectsCreate() <= 6. | 56 // In Oilpan, numSuspendableObjectsCreate() <= 6. |
| 57 // (1 MediaKeys, | 57 // (1 MediaKeys, |
| 58 // 1 MediaKeysInitializer and | 58 // 1 MediaKeysInitializer and |
| 59 // 2 MediaKeySystemAccessInitializer, | 59 // 2 MediaKeySystemAccessInitializer, |
| 60 // 1 ContentDecryptionModuleResultPromise and | 60 // 1 ContentDecryptionModuleResultPromise and |
| 61 // 1 MediaKeySession). | 61 // 1 MediaKeySession). |
| 62 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 6,
'MediaKeys.createSession(1)'); | 62 assert_between_inclusive(numSuspendableObjectsCreated(), 2,
6, 'MediaKeys.createSession(1)'); |
| 63 | 63 |
| 64 mediaKeySession2 = mediaKeys.createSession(); | 64 mediaKeySession2 = mediaKeys.createSession(); |
| 65 return mediaKeySession2.generateRequest(initDataType, initDa
ta); | 65 return mediaKeySession2.generateRequest(initDataType, initDa
ta); |
| 66 }).then(function() { | 66 }).then(function() { |
| 67 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s
essionId.length > 0); | 67 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s
essionId.length > 0); |
| 68 | 68 |
| 69 // Should be 1 MediaKeys + 2 MediaKeySessions. | 69 // Should be 1 MediaKeys + 2 MediaKeySessions. |
| 70 // In non-Oilpan, numActiveDOMObjectsCreate() == 3. | 70 // In non-Oilpan, numSuspendableObjectsCreate() == 3. |
| 71 // In Oilpan, numActiveDOMObjectsCreate() <= 8. | 71 // In Oilpan, numSuspendableObjectsCreate() <= 8. |
| 72 // (1 MediaKeys, | 72 // (1 MediaKeys, |
| 73 // 1 MediaKeysInitializer and | 73 // 1 MediaKeysInitializer and |
| 74 // 2 MediaKeySystemAccessInitializers, | 74 // 2 MediaKeySystemAccessInitializers, |
| 75 // 2 ContentDecryptionModuleResultPromise and | 75 // 2 ContentDecryptionModuleResultPromise and |
| 76 // 2 MediaKeySession). | 76 // 2 MediaKeySession). |
| 77 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 8,
'mediaKeys.createSession(2)'); | 77 assert_between_inclusive(numSuspendableObjectsCreated(), 3,
8, 'mediaKeys.createSession(2)'); |
| 78 }).then(function(result) { | 78 }).then(function(result) { |
| 79 // Run gc(). All sessions should remain as we have a | 79 // Run gc(). All sessions should remain as we have a |
| 80 // reference to each one. | 80 // reference to each one. |
| 81 return createGCPromise(); | 81 return createGCPromise(); |
| 82 }).then(function(result) { | 82 }).then(function(result) { |
| 83 // Should be just 1 MediaKeys + 2 MediaKeySessions. | 83 // Should be just 1 MediaKeys + 2 MediaKeySessions. |
| 84 // In non-Oilpan, there is also something from createGCPromi
se(). | 84 // In non-Oilpan, there is also something from createGCPromi
se(). |
| 85 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 4,
'After gc()'); | 85 assert_between_inclusive(numSuspendableObjectsCreated(), 3,
4, 'After gc()'); |
| 86 | 86 |
| 87 // Close the sessions. Once the close() event is received, | 87 // Close the sessions. Once the close() event is received, |
| 88 // they should get garbage collected as there are no JS | 88 // they should get garbage collected as there are no JS |
| 89 // references to them. | 89 // references to them. |
| 90 var promise = mediaKeySession1.close(); | 90 var promise = mediaKeySession1.close(); |
| 91 mediaKeySession1 = null; | 91 mediaKeySession1 = null; |
| 92 return promise; | 92 return promise; |
| 93 }).then(function(result) { | 93 }).then(function(result) { |
| 94 // Give time so that the close event can be processed by | 94 // Give time so that the close event can be processed by |
| 95 // MediaKeySession. | 95 // MediaKeySession. |
| 96 return delayToAllowEventProcessingPromise(); | 96 return delayToAllowEventProcessingPromise(); |
| 97 }).then(function(result) { | 97 }).then(function(result) { |
| 98 return createGCPromise(); | 98 return createGCPromise(); |
| 99 }).then(function(result) { | 99 }).then(function(result) { |
| 100 // Only MediaKeys + mediaKeySession2 should remain. | 100 // Only MediaKeys + mediaKeySession2 should remain. |
| 101 // In non-Oilpan, there is also something from createGCPromi
se(). | 101 // In non-Oilpan, there is also something from createGCPromi
se(). |
| 102 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 3,
'mediaKeySession1 not collected'); | 102 assert_between_inclusive(numSuspendableObjectsCreated(), 2,
3, 'mediaKeySession1 not collected'); |
| 103 | 103 |
| 104 var promise = mediaKeySession2.close(); | 104 var promise = mediaKeySession2.close(); |
| 105 mediaKeySession2 = null; | 105 mediaKeySession2 = null; |
| 106 return promise; | 106 return promise; |
| 107 }).then(function(result) { | 107 }).then(function(result) { |
| 108 // Provide time for the mediaKeySession2 close event to be | 108 // Provide time for the mediaKeySession2 close event to be |
| 109 // handled. | 109 // handled. |
| 110 return delayToAllowEventProcessingPromise(); | 110 return delayToAllowEventProcessingPromise(); |
| 111 }).then(function(result) { | 111 }).then(function(result) { |
| 112 return createGCPromise(); | 112 return createGCPromise(); |
| 113 }).then(function(result) { | 113 }).then(function(result) { |
| 114 // Only MediaKeys should remain. | 114 // Only MediaKeys should remain. |
| 115 // In non-Oilpan, there is also something from createGCPromi
se(). | 115 // In non-Oilpan, there is also something from createGCPromi
se(). |
| 116 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 2,
'mediaKeySession2 not collected'); | 116 assert_between_inclusive(numSuspendableObjectsCreated(), 1,
2, 'mediaKeySession2 not collected'); |
| 117 | 117 |
| 118 assert_not_equals(mediaKeys, null); | 118 assert_not_equals(mediaKeys, null); |
| 119 test.done(); | 119 test.done(); |
| 120 }).catch(function(error) { | 120 }).catch(function(error) { |
| 121 forceTestFailureFromPromise(test, error); | 121 forceTestFailureFromPromise(test, error); |
| 122 }); | 122 }); |
| 123 }, 'MediaKeySession lifetime after release() without references'); | 123 }, 'MediaKeySession lifetime after release() without references'); |
| 124 </script> | 124 </script> |
| 125 </body> | 125 </body> |
| 126 </html> | 126 </html> |
| OLD | NEW |