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 <video id="testVideo"></video> | |
12 <div id="log"></div> | |
13 <script> | |
14 setup({ timeout: 60000 }); // Timeout for all tests to run. | |
15 | |
16 // Since MediaKeySession (but not MediaKeys) are ActiveDOMObjects, | |
17 // we can determine when they are garbage collected. | |
xhwang
2014/03/26 20:58:32
I'll be nicer to have a more detailed document lev
jrummell
2014/03/26 22:19:03
Done.
| |
18 test(function() | |
19 { | |
20 var video = document.getElementById("testVideo"); | |
xhwang
2014/03/26 20:58:32
Since you are using MediaKeys only, no need to use
jrummell
2014/03/26 22:19:03
Done.
| |
21 var initData = new Uint8Array(['n', 'o', 't', 'h', 'i', 'n', 'g' ]); | |
xhwang
2014/03/26 20:58:32
This is probably not what you intended. I tried it
jrummell
2014/03/26 22:19:03
Done.
| |
22 var startingObjects = window.internals.activeDOMObjectCount(docu ment); | |
xhwang
2014/03/26 20:58:32
startingActiveDOMObjectsCreated?
jrummell
2014/03/26 22:19:03
Done.
| |
23 | |
24 function numObjectsCreated() | |
xhwang
2014/03/26 20:58:32
numActiveDOMObjectsCreated?
jrummell
2014/03/26 22:19:03
Done.
| |
25 { | |
26 return window.internals.activeDOMObjectCount(document) - sta rtingObjects; | |
27 } | |
28 | |
29 var mediaKeys = new MediaKeys("org.w3.clearkey"); | |
30 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); | |
31 | |
32 // Run gc(), should not affect count since MediaKeys are not | |
33 // ActiveDOMObjects. | |
xhwang
2014/03/26 20:58:32
This is a bit confusing... gc() here should not af
jrummell
2014/03/26 22:19:03
Done.
| |
34 gc(); | |
35 assert_equals(numObjectsCreated(), 0, "MediaKeys created an Acti veDOMObject"); | |
36 | |
37 // Create 3 sessions. | |
38 var mediaKeySession1 = mediaKeys.createSession("video/webm", ini tData); | |
39 assert_equals(numObjectsCreated(), 1); | |
40 var mediaKeySession2 = mediaKeys.createSession("video/webm", ini tData); | |
41 assert_equals(numObjectsCreated(), 2); | |
42 var mediaKeySession3 = mediaKeys.createSession("video/webm", ini tData); | |
43 assert_equals(numObjectsCreated(), 3); | |
44 | |
45 // Run gc(). All sessions should remain as we have a reference | |
46 // to each one. | |
47 gc(); | |
48 assert_equals(numObjectsCreated(), 3); | |
49 | |
50 // Now drop references to 2 of the sessions. Even though we | |
51 // don't have a reference, MediaKeys is still around (and the | |
52 // sessions aren't closed), so the objects won't be collected. | |
53 mediaKeySession2 = null; | |
54 mediaKeySession3 = null; | |
55 gc(); | |
56 assert_equals(numObjectsCreated(), 3); | |
57 | |
58 // Now drop the reference to MediaKeys. It and the 2 | |
59 // unreferenced sessions should be collected. Run gc() twice, | |
60 // in case the first pass finds the sessions first, and only | |
61 // frees MediaKeys. | |
xhwang
2014/03/26 20:58:32
Why gc() will only free MediaKeys if in the first
jrummell
2014/03/26 22:19:03
Done.
| |
62 mediaKeys = null; | |
63 gc(); | |
64 gc(); | |
65 assert_equals(numObjectsCreated(), 1); | |
66 | |
67 // Drop the reference to the first session. It should get | |
68 // collected now since MediaKeys is gone. | |
69 mediaKeySession1 = null; | |
70 gc(); | |
71 assert_equals(numObjectsCreated(), 0); | |
72 }, "MediaKeySession lifetime using references", { timeout: 60000 }); | |
xhwang
2014/03/26 20:58:32
s/using references/without release()/ ?
jrummell
2014/03/26 22:19:03
Done.
| |
73 </script> | |
74 </body> | |
75 </html> | |
OLD | NEW |