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. | |
18 async_test(function(test) | |
19 { | |
20 var video = document.getElementById("testVideo"); | |
21 var startingObjects = window.internals.activeDOMObjectCount(docu ment); | |
22 | |
23 function numObjectsCreated() | |
24 { | |
25 return window.internals.activeDOMObjectCount(document) - sta rtingObjects; | |
26 } | |
27 | |
28 var mediaKeys = new MediaKeys("org.w3.clearkey"); | |
29 var audioMediaKeySession = null; | |
30 var videoMediaKeySession = null; | |
31 var sessionsCreated = 0; | |
32 | |
33 // Using media content that has different key ids for the audio | |
34 // and video streams. | |
35 var audioKeyId = "1234567890123456"; | |
36 var videoKeyId = "0123456789012345"; | |
37 | |
38 function onNeedKey(event) | |
39 { | |
40 assert_equals(numObjectsCreated(), sessionsCreated); | |
41 var keyId = String.fromCharCode.apply(null, event.initData); | |
42 var newSession = mediaKeys.createSession(event.contentType, event.initData); | |
43 ++sessionsCreated; | |
44 assert_equals(numObjectsCreated(), sessionsCreated); | |
45 if (keyId == videoKeyId) { | |
46 videoMediaKeySession = newSession; | |
47 } else { | |
48 audioMediaKeySession = newSession; | |
49 } | |
50 waitForEventAndRunStep("message", newSession, onMessage, tes t); | |
51 } | |
52 | |
53 function onMessage(event) | |
54 { | |
55 event.target.release(); | |
xhwang
2014/03/26 20:58:32
Is it necessary to go the full process of needkey/
jrummell
2014/03/26 22:19:03
Simplified. Don't get the ready event until after
| |
56 waitForEventAndRunStep("close", event.target, onClose, test) ; | |
57 } | |
58 | |
59 function onClose(event) | |
60 { | |
61 --sessionsCreated; | |
62 if (sessionsCreated > 0) | |
63 return; | |
64 | |
65 // Delay to give time for close to complete. | |
66 setTimeout(finish, 250); | |
67 } | |
68 | |
69 function finish() | |
70 { | |
71 // Since both sessions have been released, dropping the | |
72 // reference to them from JS will result in the session | |
73 // being garbage-collected. | |
74 consoleWrite("Finish"); | |
75 assert_equals(numObjectsCreated(), 2); | |
76 | |
77 videoMediaKeySession = null; | |
78 gc(); | |
79 assert_equals(numObjectsCreated(), 1, "videoMediaKeySession not collected"); | |
80 | |
81 audioMediaKeySession = null; | |
82 gc(); | |
83 assert_equals(numObjectsCreated(), 0, "audioMediaKeySession not collected"); | |
xhwang
2014/03/26 20:58:32
Is it possible to test the case that if there's a
jrummell
2014/03/26 22:19:03
finish() is scheduled to run 250ms after the secon
| |
84 | |
85 test.done(); | |
86 } | |
87 | |
88 waitForEventAndRunStep("needkey", video, onNeedKey, test); | |
89 video.src = "../content/test-encrypted-different-av-keys.webm"; | |
90 video.setMediaKeys(mediaKeys); | |
91 }, "MediaKeySession lifetime using release", { timeout: 60000 }); | |
xhwang
2014/03/26 20:58:32
s/using/after and s/release/release() ?
jrummell
2014/03/26 22:19:03
Done.
| |
92 </script> | |
93 </body> | |
94 </html> | |
OLD | NEW |