Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-release.html

Issue 209103002: Add lifetime tests for MediaKeySession (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add test Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // only the JS reference to them keeps them around.
38 mediaKeySession1.release();
39 waitForEventAndRunStep("close", mediaKeySession1, onClose, test) ;
40 mediaKeySession2.release();
41 waitForEventAndRunStep("close", mediaKeySession2, onClose, test) ;
42
43 function onClose(event)
44 {
45 --openSessions;
46 if (openSessions > 0)
47 return;
48
49 // Delay to give time for close to complete since
50 // event.target is a reference to the MediaKeySession.
51 setTimeout(finish, 1);
52 }
53
54 function finish()
55 {
56 // Since both sessions have been closed, dropping the
57 // reference to them from JS will result in the session
58 // being garbage-collected.
59 consoleWrite("Verifying sessions cleaned up after dropping r eferences.");
ddorwin 2014/03/27 18:56:51 If this is really just a check for the test, maybe
jrummell 2014/03/27 20:12:54 Done.
60 assert_not_equals(mediaKeys, null);
61 assert_equals(numActiveDOMObjectsCreated(), 2);
62
63 mediaKeySession1 = null;
64 gc();
65 assert_equals(numActiveDOMObjectsCreated(), 1, "mediaKeySess ion1 not collected");
66
67 mediaKeySession2 = null;
68 gc();
69 assert_equals(numActiveDOMObjectsCreated(), 0, "mediaKeySess ion2 not collected");
70
71 test.done();
72 }
73 }, "MediaKeySession lifetime after release()");
74 </script>
75 </body>
76 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698