Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test multiple MediaKeys lifetimes</title> | 4 <title>Test multiple MediaKeys lifetimes</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 // For this test, create several MediaKeys and verify lifetime. | 11 // For this test, create several MediaKeys and verify lifetime. |
| 12 async_test(function(test) | 12 async_test(function(test) |
| 13 { | 13 { |
| 14 gc(); | |
| 14 var mediaKeys; | 15 var mediaKeys; |
| 15 var startingSuspendableObjectCount = window.internals.suspendabl eObjectCount(document); | 16 var startingMediaKeysCount = window.internals.mediaKeysCount(doc ument); |
|
sof
2016/12/26 08:00:47
Curious that an unused |document| is passed as arg
haraken
2016/12/26 08:17:18
Will remove.
| |
| 16 | 17 |
| 17 function numSuspendableObjectsCreated() | 18 function numMediaKeysCreated() |
| 18 { | 19 { |
| 19 return window.internals.suspendableObjectCount(document) - s tartingSuspendableObjectCount; | 20 return window.internals.mediaKeysCount(document) - startingM ediaKeysCount; |
| 20 } | 21 } |
| 21 | 22 |
| 22 // Create a MediaKeys object. Returns a promise that resolves | 23 // Create a MediaKeys object. Returns a promise that resolves |
| 23 // with the new MediaKeys object. | 24 // with the new MediaKeys object. |
| 24 function createMediaKeys() | 25 function createMediaKeys() |
| 25 { | 26 { |
| 26 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration()).then(function(access) { | 27 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration()).then(function(access) { |
| 27 return access.createMediaKeys(); | 28 return access.createMediaKeys(); |
| 28 }).then(function(mediaKeys) { | 29 }).then(function(mediaKeys) { |
| 29 return mediaKeys; | 30 return mediaKeys; |
| 30 }); | 31 }); |
| 31 } | 32 } |
| 32 | 33 |
| 33 // Create a few MediaKeys objects. Only keep a reference to the | 34 // Create a few MediaKeys objects. Only keep a reference to the |
| 34 // last one created. | 35 // last one created. |
| 35 createMediaKeys().then(function(result) { | 36 createMediaKeys().then(function(result) { |
| 36 // Should be 1 MediaKeys. | 37 assert_equals(numMediaKeysCreated(), 1); |
| 37 // In non-Oilpan, numSuspendableObjectsCreate() == 1. | |
| 38 // In Oilpan, numSuspendableObjectsCreated() <= 4. | |
| 39 // (1 MediaKeysInitializer, | |
| 40 // 1 MediaKeySystemAccessInitializer (navigator.requestMedi aKeySystemAccess() use above), | |
| 41 // 1 MediaKeySystemAccessInitializer (isInitDataSupported() (via getSupportedInitDataType())) and | |
| 42 // 1 ContentDecryptionModuleResultPromise). | |
| 43 assert_between_inclusive(numSuspendableObjectsCreated(), 1, 4); | |
| 44 | 38 |
| 45 return createMediaKeys(); | 39 return createMediaKeys(); |
| 46 }).then(function(result) { | 40 }).then(function(result) { |
| 47 // Should be 2 MediaKeys. | 41 assert_equals(numMediaKeysCreated(), 2); |
| 48 // In non-Oilpan, numSuspendableObjectsCreate() == 2. | |
| 49 // In Oilpan, numSuspendableObjectsCreate() <= 8. | |
| 50 // (2 MediaKeysInitializer, | |
| 51 // 4 MediaKeySystemAccessInitializer and | |
| 52 // 2 ContentDecryptionModuleResultPromise). | |
| 53 assert_between_inclusive(numSuspendableObjectsCreated(), 2, 8); | |
| 54 | 42 |
| 55 return createMediaKeys(); | 43 return createMediaKeys(); |
| 56 }).then(function(result) { | 44 }).then(function(result) { |
| 57 // Should be 3 MediaKeys. | 45 assert_equals(numMediaKeysCreated(), 3); |
| 58 // In non-Oilpan, numSuspendableObjectsCreate() == 3. | |
| 59 // In Oilpan, numSuspendableObjectsCreate() <= 12. | |
| 60 // (3 MediaKeysInitializer, | |
| 61 // 6 MediaKeySystemAccessInitializer and | |
| 62 // 3 ContentDecryptionModuleResultPromise). | |
| 63 assert_between_inclusive(numSuspendableObjectsCreated(), 3, 12); | |
| 64 | 46 |
| 65 return createMediaKeys(); | 47 return createMediaKeys(); |
| 66 }).then(function(result) { | 48 }).then(function(result) { |
| 67 // Should be 4 MediaKeys. | 49 assert_equals(numMediaKeysCreated(), 4); |
| 68 // In non-Oilpan, numSuspendableObjectsCreate() == 4. | |
| 69 // In Oilpan, numSuspendableObjectsCreate() <= 16. | |
| 70 // (4 MediaKeysInitializer, | |
| 71 // 8 MediaKeySystemAccessInitializer and | |
| 72 // 4 ContentDecryptionModuleResultPromise). | |
| 73 assert_between_inclusive(numSuspendableObjectsCreated(), 4, 16); | |
| 74 | 50 |
| 75 return createMediaKeys(); | 51 return createMediaKeys(); |
| 76 }).then(function(result) { | 52 }).then(function(result) { |
| 77 // Should be 5 MediaKeys. | 53 assert_equals(numMediaKeysCreated(), 5); |
| 78 // In non-Oilpan, numSuspendableObjectsCreate() == 5. | |
| 79 // In Oilpan, numSuspendableObjectsCreate() <= 20. | |
| 80 // (5 MediaKeysInitializer, | |
| 81 // 10 MediaKeySystemAccessInitializer and | |
| 82 // 5 ContentDecryptionModuleResultPromise). | |
| 83 assert_between_inclusive(numSuspendableObjectsCreated(), 5, 20); | |
| 84 | 54 |
| 85 // |mediaKeys| refers to the most recently created MediaKeys | 55 // |mediaKeys| refers to the most recently created MediaKeys |
| 86 // object. | 56 // object. |
| 87 mediaKeys = result; | 57 mediaKeys = result; |
| 88 | 58 |
| 89 // In order for the MediaKey objects to be garbage | 59 // In order for the MediaKey objects to be garbage |
| 90 // collected, it needs time to process any pending events. | 60 // collected, it needs time to process any pending events. |
| 91 return delayToAllowEventProcessingPromise(); | 61 return delayToAllowEventProcessingPromise(); |
| 92 }).then(function(result) { | 62 }).then(function(result) { |
| 93 // In non-Oilpan, numSuspendableObjectsCreated() == 5 | 63 assert_equals(numMediaKeysCreated(), 5); |
| 94 // (5 MediaKeySession objects). | |
| 95 // In Oilpan, numSuspendableObjectsCreated() <= 23 | |
| 96 // (5 MediaKeysInitializer, | |
| 97 // 12 MediaKeySystemAccessInitializer, | |
| 98 // 5 ContentDecryptionModuleResultPromise and | |
| 99 // 1 DOMTimer (in delayToAllowEventProcessingPromise)) | |
| 100 assert_between_inclusive(numSuspendableObjectsCreated(), 5, 23); | |
| 101 | 64 |
| 102 // As we only have a reference (|mediaKeys|) to the last | 65 // As we only have a reference (|mediaKeys|) to the last |
| 103 // created MediaKeys object, the other 4 MediaKeys objects | 66 // created MediaKeys object, the other 4 MediaKeys objects |
| 104 // are available to be garbage collected. | 67 // are available to be garbage collected. |
| 105 return createGCPromise(); | 68 return createGCPromise(); |
| 106 }).then(function(result) { | 69 }).then(function(result) { |
| 107 // Should be 1 MediaKeys and DOMTimer. | 70 assert_equals(numMediaKeysCreated(), 1); |
| 108 assert_less_than_equal(numSuspendableObjectsCreated(), 2); | |
| 109 assert_equals(typeof mediaKeys.createSession, 'function'); | 71 assert_equals(typeof mediaKeys.createSession, 'function'); |
| 110 | 72 |
| 111 // Release the last MediaKeys object created. | 73 // Release the last MediaKeys object created. |
| 112 mediaKeys = null; | 74 mediaKeys = null; |
| 113 | 75 |
| 114 // Run gc() again to reclaim the remaining MediaKeys object. | 76 // Run gc() again to reclaim the remaining MediaKeys object. |
| 115 return createGCPromise(); | 77 return createGCPromise(); |
| 116 }).then(function(result) { | 78 }).then(function(result) { |
| 117 // Should be just a DOMTimer. | 79 assert_equals(numMediaKeysCreated(), 0); |
| 118 assert_less_than_equal(numSuspendableObjectsCreated(), 1); | |
| 119 test.done(); | 80 test.done(); |
| 120 }).catch(function(error) { | 81 }).catch(function(error) { |
| 121 forceTestFailureFromPromise(test, error); | 82 forceTestFailureFromPromise(test, error); |
| 122 }); | 83 }); |
| 123 }, 'Multiple MediaKeys lifetime'); | 84 }, 'Multiple MediaKeys lifetime'); |
| 124 </script> | 85 </script> |
| 125 </body> | 86 </body> |
| 126 </html> | 87 </html> |
| OLD | NEW |