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

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: rearrange 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 setup({ timeout: 60000 }); // Timeout for all tests to run.
14
15 // Since MediaKeySession (but not MediaKeys) are ActiveDOMObjects,
16 // we can determine when they are garbage collected.
17 // MediaKeySessions remain as long as:
18 // JavaScript has a reference to it
19 // OR (MediaKeys is around AND the session has not received a clos e() event)
20 async_test(function(test)
21 {
22 var startingActiveDOMObjectCount = window.internals.activeDOMObj ectCount(document);
23
24 function numActiveDOMObjectsCreated()
25 {
26 return window.internals.activeDOMObjectCount(document) - sta rtingActiveDOMObjectCount;
27 }
28
29 // Create 2 sessions.
30 var mediaKeys = new MediaKeys("org.w3.clearkey");
31 var mediaKeySession1 = mediaKeys.createSession('video/webm', new Uint8Array([1, 2, 3]));
32 assert_equals(numActiveDOMObjectsCreated(), 1);
33 var mediaKeySession2 = mediaKeys.createSession('video/webm', new Uint8Array([4, 5]));;
xhwang 2014/03/27 17:07:00 nit: can we do the same as the other file, i.e. v
jrummell 2014/03/27 18:42:56 Done.
34 assert_equals(numActiveDOMObjectsCreated(), 2);
35 var sessionsCreated = 2;
ddorwin 2014/03/27 17:20:36 nit: activeSessions or openSessions? They aren't n
jrummell 2014/03/27 18:42:56 Done.
36
37 // Release the sessions. Once the close() event is received,
38 // only the JS reference to them keeps them around.
ddorwin 2014/03/27 17:20:36 It would be nice to have another test (might make
jrummell 2014/03/27 18:42:56 Good idea. Added another test.
39 mediaKeySession1.release();
40 waitForEventAndRunStep("close", mediaKeySession1, onClose, test) ;
41 mediaKeySession2.release();
42 waitForEventAndRunStep("close", mediaKeySession2, onClose, test) ;
43
44 function onClose(event)
45 {
46 --sessionsCreated;
47 if (sessionsCreated > 0)
48 return;
49
50 // Delay to give time for close to complete since
51 // event.target is a reference to the MediaKeySession.
52 setTimeout(finish, 1);
53 }
54
55 function finish()
56 {
57 // Since both sessions have been closed, dropping the
58 // reference to them from JS will result in the session
59 // being garbage-collected.
60 consoleWrite("Finish");
ddorwin 2014/03/27 17:20:36 nit: Do we need this? Is there a message that woul
jrummell 2014/03/27 18:42:56 Changed. This is just to ensure that it only ran a
61 assert_not_equals(mediaKeys, null);
62 assert_equals(numActiveDOMObjectsCreated(), 2);
63
64 mediaKeySession1 = null;
65 gc();
66 assert_equals(numActiveDOMObjectsCreated(), 1, "mediaKeySess ion1 not collected");
67
68 mediaKeySession2 = null;
69 gc();
70 assert_equals(numActiveDOMObjectsCreated(), 0, "mediaKeySess ion2 not collected");
71
72 test.done();
73 }
74 }, "MediaKeySession lifetime after release()", { timeout: 60000 });
75 </script>
76 </body>
77 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698