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>
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 close() event)
18 async_test(function(test)
20 var initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
23 var startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document);
25 function numActiveDOMObjectsCreated()
28 return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount;
32 var mediaKeys = new MediaKeys("org.w3.clearkey");
33 var mediaKeySession1 = mediaKeys.createSession('video/webm', initData);
34 assert_equals(numActiveDOMObjectsCreated(), 1);
35 var mediaKeySession2 = mediaKeys.createSession('video/webm', initData);
36 assert_equals(numActiveDOMObjectsCreated(), 2);
39 // Release the sessions. Once the close() event is received,
40 // only the JS reference to them keeps them around.
41 mediaKeySession1.release();
42 waitForEventAndRunStep("close", mediaKeySession1, onClose, test);
43 mediaKeySession2.release();
44 waitForEventAndRunStep("close", mediaKeySession2, onClose, test);
46 function onClose(event)
52 // Delay to give time for close to complete since
53 // event.target is a reference to the MediaKeySession.
54 setTimeout(finish, 1);
59 // Since both sessions have been closed, dropping the
60 // reference to them from JS will result in the session
61 // being garbage-collected.
62 assert_equals(openSessions, 0);
63 assert_not_equals(mediaKeys, null);
64 assert_equals(numActiveDOMObjectsCreated(), 2);
66 mediaKeySession1 = null;
68 assert_equals(numActiveDOMObjectsCreated(), 1, "mediaKeySession1 not collected");
70 mediaKeySession2 = null;
72 assert_equals(numActiveDOMObjectsCreated(), 0, "mediaKeySession2 not collected");
76 }, "MediaKeySession lifetime after release()");