Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test MediaKeySession lifetime without release()</title> | 4 <title>Test MediaKeySession lifetime without 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 // 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 | 15 |
| 16 async_test(function(test) | 16 promise_test(function(test) |
| 17 { | 17 { |
| 18 gc(); | |
| 19 var mediaKeys; | 18 var mediaKeys; |
| 20 var mediaKeySession1; | 19 var mediaKeySession1; |
| 21 var mediaKeySession2; | 20 var mediaKeySession2; |
| 22 var mediaKeySession3; | 21 var mediaKeySession3; |
| 23 var initDataType; | 22 var initDataType; |
| 24 var initData; | 23 var initData; |
| 25 var startingMediaKeysCount = window.internals.mediaKeysCount(); | |
| 26 var startingMediaKeySessionCount = window.internals.mediaKeySess ionCount(); | |
| 27 | 24 |
| 28 function numMediaKeysCreated() | 25 return createGCPromise().then(function() { |
| 29 { | 26 assert_equals(window.internals.mediaKeysCount(), 0, 'After i nitial gc()'); |
| 30 return window.internals.mediaKeysCount() - startingMediaKeys Count; | 27 assert_equals(window.internals.mediaKeySessionCount(), 0, 'A fter initial gc()'); |
| 31 } | |
| 32 | 28 |
| 33 function numMediaKeySessionCreated() | 29 return navigator.requestMediaKeySystemAccess('org.w3.clearke y', getSimpleConfiguration()); |
| 34 { | 30 }).then(function(access) { |
| 35 return window.internals.mediaKeySessionCount() - startingMed iaKeySessionCount; | |
| 36 } | |
| 37 | |
| 38 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp leConfiguration()).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 assert_equals(typeof mediaKeys.createSession, 'function'); | 36 assert_equals(typeof mediaKeys.createSession, 'function'); |
| 45 | 37 |
| 46 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()' ); | 38 assert_equals(window.internals.mediaKeysCount(), 1, 'MediaKe ys.create()'); |
| 47 assert_equals(numMediaKeySessionCreated(), 0, 'After final g c()'); | 39 assert_equals(window.internals.mediaKeySessionCount(), 0, 'A fter final gc()'); |
|
xhwang
2017/01/05 20:05:06
There two are used in multiple places in multiple
jrummell
2017/01/06 22:10:18
Not sure that a shorter name helps that much. Howe
xhwang
2017/01/09 17:57:17
This looks much cleaner!
Does it make sense to mo
| |
| 48 | 40 |
| 49 // Create 3 sessions. | 41 // Create 3 sessions. |
| 50 mediaKeySession1 = mediaKeys.createSession(); | 42 mediaKeySession1 = mediaKeys.createSession(); |
| 51 return mediaKeySession1.generateRequest(initDataType, initDa ta); | 43 return mediaKeySession1.generateRequest(initDataType, initDa ta); |
| 52 }).then(function() { | 44 }).then(function() { |
| 53 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s essionId.length > 0); | 45 assert_true(mediaKeySession1.sessionId && mediaKeySession1.s essionId.length > 0); |
| 54 | 46 |
| 55 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSes sion(1)'); | 47 assert_equals(window.internals.mediaKeysCount(), 1, 'MediaKe ys.createSession(1)'); |
| 56 assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.cre ateSession(1)'); | 48 assert_equals(window.internals.mediaKeySessionCount(), 1, 'M ediaKeys.createSession(1)'); |
| 57 | 49 |
| 58 mediaKeySession2 = mediaKeys.createSession(); | 50 mediaKeySession2 = mediaKeys.createSession(); |
| 59 return mediaKeySession2.generateRequest(initDataType, initDa ta); | 51 return mediaKeySession2.generateRequest(initDataType, initDa ta); |
| 60 }).then(function() { | 52 }).then(function() { |
| 61 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s essionId.length > 0); | 53 assert_true(mediaKeySession2.sessionId && mediaKeySession2.s essionId.length > 0); |
| 62 | 54 |
| 63 assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSes sion(2)'); | 55 assert_equals(window.internals.mediaKeysCount(), 1, 'mediaKe ys.createSession(2)'); |
| 64 assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.cre ateSession(2)'); | 56 assert_equals(window.internals.mediaKeySessionCount(), 2, 'm ediaKeys.createSession(2)'); |
| 65 | 57 |
| 66 mediaKeySession3 = mediaKeys.createSession(); | 58 mediaKeySession3 = mediaKeys.createSession(); |
| 67 return mediaKeySession3.generateRequest(initDataType, initDa ta); | 59 return mediaKeySession3.generateRequest(initDataType, initDa ta); |
| 68 }).then(function() { | 60 }).then(function() { |
| 69 assert_true(mediaKeySession3.sessionId && mediaKeySession3.s essionId.length > 0); | 61 assert_true(mediaKeySession3.sessionId && mediaKeySession3.s essionId.length > 0); |
| 70 | 62 |
| 71 assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSes sion(3)'); | 63 assert_equals(window.internals.mediaKeysCount(), 1, 'mediaKe ys.createSession(3)'); |
| 72 assert_equals(numMediaKeySessionCreated(), 3, 'mediaKeys.cre ateSession(3)'); | 64 assert_equals(window.internals.mediaKeySessionCount(), 3, 'm ediaKeys.createSession(3)'); |
| 73 | 65 |
| 74 // Run gc(). All sessions should remain as we have a | 66 // Run gc(). All sessions should remain as we have a |
| 75 // reference to each one. However, running gc() | 67 // reference to each one. However, running gc() |
| 76 // asynchronously should free up the last PromiseResolver. | 68 // asynchronously should free up the last PromiseResolver. |
| 77 return createGCPromise(); | 69 return createGCPromise(); |
| 78 }).then(function(result) { | 70 }).then(function(result) { |
| 79 assert_equals(numMediaKeysCreated(), 1, 'After gc()'); | 71 assert_equals(window.internals.mediaKeysCount(), 1, 'After g c()'); |
| 80 assert_equals(numMediaKeySessionCreated(), 3, 'After gc()'); | 72 assert_equals(window.internals.mediaKeySessionCount(), 3, 'A fter gc()'); |
| 81 | 73 |
| 82 // Now drop references to 2 of the sessions. Even though we | 74 // Now drop references to 2 of the sessions. Even though we |
| 83 // don't have a reference, MediaKeys is still around (and | 75 // don't have a reference, MediaKeys is still around (and |
| 84 // the sessions aren't closed), so the objects won't be | 76 // the sessions aren't closed), so the objects won't be |
| 85 // collected. | 77 // collected. |
| 86 mediaKeySession1 = null; | 78 mediaKeySession1 = null; |
| 87 mediaKeySession2 = null; | 79 mediaKeySession2 = null; |
| 88 return createGCPromise(); | 80 return createGCPromise(); |
| 89 }).then(function(result) { | 81 }).then(function(result) { |
| 90 return createGCPromise(); | 82 return createGCPromise(); |
| 91 }).then(function(result) { | 83 }).then(function(result) { |
| 92 assert_equals(numMediaKeysCreated(), 1, 'After second gc()') ; | 84 assert_equals(window.internals.mediaKeysCount(), 1, 'After s econd gc()'); |
| 93 assert_equals(numMediaKeySessionCreated(), 3, 'After second gc()'); | 85 assert_equals(window.internals.mediaKeySessionCount(), 3, 'A fter second gc()'); |
| 94 | 86 |
| 95 // Now drop the reference to MediaKeys. It and the 2 | 87 // Now drop the reference to MediaKeys. It and the 2 |
| 96 // unreferenced sessions should be collected. Since | 88 // unreferenced sessions should be collected. Since |
| 97 // MediaKeySessions remain alive as long as MediaKeys is | 89 // MediaKeySessions remain alive as long as MediaKeys is |
| 98 // around, it is possible that gc() checks one or both | 90 // around, it is possible that gc() checks one or both |
| 99 // MediaKeySession objects first, and doesn't collect them | 91 // MediaKeySession objects first, and doesn't collect them |
| 100 // since MediaKeys hasn't been collected yet. Thus run gc() | 92 // since MediaKeys hasn't been collected yet. Thus run gc() |
| 101 // twice, to ensure that the unreferenced MediaKeySession | 93 // twice, to ensure that the unreferenced MediaKeySession |
| 102 // objects get collected. | 94 // objects get collected. |
| 103 mediaKeys = null; | 95 mediaKeys = null; |
| 104 return createGCPromise(); | 96 return createGCPromise(); |
| 105 }).then(function(result) { | 97 }).then(function(result) { |
| 106 return createGCPromise(); | 98 return createGCPromise(); |
| 107 }).then(function(result) { | 99 }).then(function(result) { |
| 108 assert_equals(numMediaKeysCreated(), 0, 'After mediaKeys = n ull'); | 100 assert_equals(window.internals.mediaKeysCount(), 0, 'After m ediaKeys = null'); |
| 109 assert_equals(numMediaKeySessionCreated(), 1, 'After mediaKe ys = null'); | 101 assert_equals(window.internals.mediaKeySessionCount(), 1, 'A fter mediaKeys = null'); |
| 110 | 102 |
| 111 // Drop the reference to the last session. It should get | 103 // Drop the reference to the last session. It should get |
| 112 // collected now since MediaKeys is gone. | 104 // collected now since MediaKeys is gone. |
| 113 mediaKeySession3 = null; | 105 mediaKeySession3 = null; |
| 114 return createGCPromise(); | 106 return createGCPromise(); |
| 115 }).then(function(result) { | 107 }).then(function(result) { |
| 116 assert_equals(numMediaKeysCreated(), 0, 'After final gc()'); | 108 assert_equals(window.internals.mediaKeysCount(), 0, 'After f inal gc()'); |
| 117 assert_equals(numMediaKeySessionCreated(), 0, 'After final g c()'); | 109 assert_equals(window.internals.mediaKeySessionCount(), 0, 'A fter final gc()'); |
| 118 | |
| 119 test.done(); | |
| 120 }).catch(function(error) { | |
| 121 forceTestFailureFromPromise(test, error); | |
| 122 }); | 110 }); |
| 123 }, 'MediaKeySession lifetime without release()'); | 111 }, 'MediaKeySession lifetime without release()'); |
| 124 </script> | 112 </script> |
| 125 </body> | 113 </body> |
| 126 </html> | 114 </html> |
| OLD | NEW |