Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Test MediaKeySession lifetime</title> | |
| 5 <script src="../w3c-media-utils.js"></script> | |
| 6 <script src="../../resources/testharness.js"></script> | |
| 7 <script src="../../resources/testharnessreport.js"></script> | |
| 8 <script src="../../resources/gc.js"></script> | |
| 9 </head> | |
| 10 <body> | |
| 11 <div id="log"></div> | |
| 12 <script> | |
| 13 // Since MediaKeySession (but not MediaKeys) are ActiveDOMObjects, | |
| 14 // we can determine when they are garbage collected. | |
| 15 // MediaKeySessions remain as long as: | |
| 16 // JavaScript has a reference to it | |
| 17 // OR (MediaKeys is around AND the session has not received a clos e() event) | |
| 18 async_test(function(test) | |
| 19 { | |
| 20 var initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]); | |
| 21 var startingActiveDOMObjectCount = window.internals.activeDOMObj ectCount(document); | |
| 22 | |
| 23 function numActiveDOMObjectsCreated() | |
| 24 { | |
| 25 return window.internals.activeDOMObjectCount(document) - sta rtingActiveDOMObjectCount; | |
| 26 } | |
| 27 | |
| 28 // Create 2 sessions. | |
| 29 var mediaKeys = new MediaKeys("org.w3.clearkey"); | |
| 30 var mediaKeySession1 = mediaKeys.createSession('video/webm', ini tData); | |
| 31 assert_equals(numActiveDOMObjectsCreated(), 1); | |
| 32 var mediaKeySession2 = mediaKeys.createSession('video/webm', ini tData); | |
| 33 assert_equals(numActiveDOMObjectsCreated(), 2); | |
| 34 var openSessions = 2; | |
| 35 | |
| 36 // Release the sessions. Once the close() event is received, | |
| 37 // they should get garbage collected as there are no JS | |
| 38 // references to them. | |
| 39 mediaKeySession1.release(); | |
| 40 waitForEventAndRunStep("close", mediaKeySession1, onClose, test) ; | |
| 41 mediaKeySession1 = null; | |
| 42 mediaKeySession2.release(); | |
| 43 waitForEventAndRunStep("close", mediaKeySession2, onClose, test) ; | |
| 44 mediaKeySession2 = null; | |
| 45 | |
| 46 function onClose(event) | |
| 47 { | |
| 48 --openSessions; | |
|
ddorwin
2014/03/27 18:56:51
assert that mediaKeySession1 and mediaKeySession2
jrummell
2014/03/27 20:12:54
Done.
| |
| 49 if (openSessions > 0) | |
| 50 return; | |
| 51 | |
| 52 // Delay to give time for close to complete since | |
| 53 // event.target is a reference to the MediaKeySession. | |
| 54 setTimeout(finish, 1); | |
| 55 } | |
| 56 | |
| 57 function finish() | |
| 58 { | |
| 59 // Since both sessions have been closed and there are no | |
| 60 // JS references to them, they should be garbage-collected. | |
| 61 consoleWrite("Verifying sessions gone after gc()."); | |
|
ddorwin
2014/03/27 18:56:51
nit: Use similar language ("cleaned up"). Also, we
jrummell
2014/03/27 20:12:54
Removed output.
| |
| 62 gc(); | |
| 63 assert_not_equals(mediaKeys, null); | |
| 64 assert_equals(numActiveDOMObjectsCreated(), 0); | |
| 65 test.done(); | |
| 66 } | |
| 67 }, "MediaKeySession lifetime after release() without references"); | |
| 68 </script> | |
| 69 </body> | |
| 70 </html> | |
| OLD | NEW |