OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <title>Test MediaKeys lifetime</title> | |
5 <script src="../../resources/testharness.js"></script> | |
6 <script src="../../resources/testharnessreport.js"></script> | |
7 <script src="../../resources/gc.js"></script> | |
8 <script src="encrypted-media-utils.js"></script> | |
9 </head> | |
10 <body> | |
11 <div id="log"></div> | |
12 <script> | |
13 // Since MediaKeys are not ActiveDOMObjects, it is hard to | |
14 // determine when they are garbage collected. For this test, we add | |
15 // a MediaKeySession (which are ActiveDOMObjects) to each one so | |
ddorwin
2014/02/27 22:28:17
You should explain why this works and what we assu
jrummell
2014/02/28 00:08:38
Done.
| |
16 // we can count. | |
17 test(function() | |
18 { | |
19 var mediaKeys; | |
20 var initData = stringToUint8Array("mock"); | |
21 var startingObjects = window.internals.activeDOMObjectCount(docu ment); | |
22 | |
23 function objectsCreated() | |
ddorwin
2014/02/27 22:28:17
This sounds like an event handler. :) Maybe numObj
jrummell
2014/02/28 00:08:38
Done.
| |
24 { | |
25 return window.internals.activeDOMObjectCount(document) - sta rtingObjects; | |
26 } | |
27 | |
28 // Create a MediaKeys object. | |
ddorwin
2014/02/27 22:28:17
We could probably have a simple test that releases
jrummell
2014/02/28 00:08:38
Done.
| |
29 mediaKeys = new MediaKeys("org.w3.clearkey"); | |
30 mediaKeys.createSession("video/webm", initData); | |
ddorwin
2014/02/27 22:28:17
Maybe this is just testing the rest of Blink, but
jrummell
2014/02/28 00:08:38
Done.
| |
31 assert_not_equals(mediaKeys, null); | |
ddorwin
2014/02/27 22:28:17
not really necessary.
jrummell
2014/02/28 00:08:38
Done.
| |
32 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); | |
ddorwin
2014/02/27 22:28:17
This is probably checking that the mediaKeys is va
jrummell
2014/02/28 00:08:38
Done.
| |
33 assert_equals(objectsCreated(), 1); | |
34 | |
35 // Run gc(), should not affect MediaKeys object since we have | |
ddorwin
2014/02/27 22:28:17
This is basically the test in my comment at line 3
jrummell
2014/02/28 00:08:38
Done.
| |
36 // a reference to it. | |
37 gc(); | |
38 assert_not_equals(mediaKeys, null); | |
39 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); | |
40 assert_equals(objectsCreated(), 1); | |
41 | |
42 // Drop reference to the MediaKeys object and run gc again. | |
43 // Object should be collected this time. Running gc() twice | |
ddorwin
2014/02/27 22:28:17
This is basically my comment at line 28. BUT, we s
jrummell
2014/02/28 00:08:38
Done.
| |
44 // as the first pass may not actually get the created session. | |
45 mediaKeys = null; | |
46 gc(); | |
47 gc(); | |
ddorwin
2014/02/27 22:28:17
explain
jrummell
2014/02/28 00:08:38
Expanded comment.
| |
48 assert_equals(objectsCreated(), 0); | |
49 | |
ddorwin
2014/02/27 22:28:17
We should probably rerun the above tests here but
jrummell
2014/02/28 00:08:38
Not sure the benefit of a separate test.
| |
50 // Create a large number of MediaKeys objects. | |
ddorwin
2014/02/27 22:28:17
I'm not sure what this does.
If we keep it, it sho
jrummell
2014/02/28 00:08:38
ditto.
| |
51 for (var i = 0; i < 100; ++i) { | |
52 mediaKeys = new MediaKeys("org.w3.clearkey"); | |
53 mediaKeys.createSession("video/webm", initData); | |
54 } | |
55 assert_equals(objectsCreated(), 100); | |
56 | |
57 // All but the last one created should be garbage collected. | |
58 gc(); | |
59 gc(); | |
60 assert_equals(objectsCreated(), 1); | |
61 | |
62 // Last MediaKeys object created should still be referenced. | |
63 assert_not_equals(mediaKeys, null); | |
64 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); | |
65 | |
66 // Release the last MediaKeys object created. | |
67 mediaKeys = null; | |
68 gc(); | |
69 gc(); | |
70 assert_equals(objectsCreated(), 0); | |
71 }, "MediaKeys lifetime"); | |
72 </script> | |
73 </body> | |
74 </html> | |
OLD | NEW |