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 assert_equals(mediaKeySession1, null); |
| 49 assert_equals(mediaKeySession2, null); |
| 50 --openSessions; |
| 51 if (openSessions > 0) |
| 52 return; |
| 53 |
| 54 // Delay to give time for close to complete since |
| 55 // event.target is a reference to the MediaKeySession. |
| 56 setTimeout(finish, 1); |
| 57 } |
| 58 |
| 59 function finish() |
| 60 { |
| 61 // Since both sessions have been closed and there are no |
| 62 // JS references to them, they should be garbage-collected. |
| 63 assert_equals(openSessions, 0); |
| 64 assert_not_equals(mediaKeys, null); |
| 65 assert_equals(mediaKeySession1, null); |
| 66 assert_equals(mediaKeySession2, null); |
| 67 |
| 68 gc(); |
| 69 assert_equals(numActiveDOMObjectsCreated(), 0); |
| 70 test.done(); |
| 71 } |
| 72 }, "MediaKeySession lifetime after release() without references"); |
| 73 </script> |
| 74 </body> |
| 75 </html> |
OLD | NEW |