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

Side by Side Diff: LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-reference.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>
ddorwin 2014/03/27 17:20:36 Once the Decryptor lifetimes are fixed, we'll want
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.
ddorwin 2014/03/27 17:20:36 We shouldn't need these anymore: https://src.chrom
jrummell 2014/03/27 18:42:56 Done.
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 test(function()
21 {
22 var initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
23 var startingActiveDOMObjectCount = window.internals.activeDOMObj ectCount(document);
24
25 function numActiveDOMObjectsCreated()
26 {
27 return window.internals.activeDOMObjectCount(document) - sta rtingActiveDOMObjectCount;
28 }
29
30 var mediaKeys = new MediaKeys("org.w3.clearkey");
31 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey');
32
33 // Verify MediaKeys are not ActiveDOMObjects.
34 assert_equals(numActiveDOMObjectsCreated(), 0, "MediaKeys create d an ActiveDOMObject");
35
36 // Create 3 sessions.
37 var mediaKeySession1 = mediaKeys.createSession("video/webm", ini tData);
38 assert_equals(numActiveDOMObjectsCreated(), 1);
39 var mediaKeySession2 = mediaKeys.createSession("video/webm", ini tData);
40 assert_equals(numActiveDOMObjectsCreated(), 2);
41 var mediaKeySession3 = mediaKeys.createSession("video/webm", ini tData);
42 assert_equals(numActiveDOMObjectsCreated(), 3);
43
44 // Run gc(). All sessions should remain as we have a reference
45 // to each one.
46 gc();
47 assert_equals(numActiveDOMObjectsCreated(), 3);
48
49 // Now drop references to 2 of the sessions. Even though we
50 // don't have a reference, MediaKeys is still around (and the
51 // sessions aren't closed), so the objects won't be collected.
52 mediaKeySession2 = null;
53 mediaKeySession3 = null;
54 gc();
55 assert_equals(numActiveDOMObjectsCreated(), 3);
56
57 // Now drop the reference to MediaKeys. It and the 2
58 // unreferenced sessions should be collected. Since
59 // MediaKeySessions remain alive as long as MediaKeys is around,
60 // it is possible that gc() checks one or both MediaKeySession
61 // objects first, and doesn't collect them since MediaKeys
62 // hasn't been collected yet. Thus run gc() twice, to ensure
63 // that the unreferenced MediaKeySession objects get collected.
64 mediaKeys = null;
65 gc();
66 gc();
67 assert_equals(numActiveDOMObjectsCreated(), 1);
68
69 // Drop the reference to the first session. It should get
70 // collected now since MediaKeys is gone.
71 mediaKeySession1 = null;
72 gc();
73 assert_equals(numActiveDOMObjectsCreated(), 0);
74 }, "MediaKeySession lifetime without release()", { timeout: 60000 }) ;
75 </script>
76 </body>
77 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698