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

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

Issue 180203002: Add EME content test that forces garbage collection (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: global numActiveDOMObjectsCreated() Created 6 years, 8 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
« no previous file with comments | « no previous file | LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 </head>
9 <body>
10 <div id="log"></div>
11 <script>
12 // Since MediaKeys are not ActiveDOMObjects, it is hard to
13 // determine when they are garbage collected. For some tests below
14 // a MediaKeySession (which is an ActiveDOMObject) is added so
15 // there is something to count.
16
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 // In the tests below, we do not close any session nor keep a
21 // Javascript reference to any session, so MediaKeySessions remain
22 // as long as the associated MediaKeys object is around.
23
24 var startingActiveDOMObjectCount;
ddorwin 2014/04/02 21:02:36 Initialize. -1 might be best since it should alway
25
26 function numActiveDOMObjectsCreated()
27 {
28 return window.internals.activeDOMObjectCount(document) - startin gActiveDOMObjectCount;
ddorwin 2014/04/02 21:02:36 I missed the fact that this relied on the other va
jrummell 2014/04/02 21:58:21 The test framework ends up allocating a couple of
29 }
30
31 // For this test, simply verify that creating and destroying
32 // MediaKeys doesn't crash.
33 test(function()
34 {
35 // Create a MediaKeys object and free immediately.
36 var mediaKeys = new MediaKeys("org.w3.clearkey");
37 mediaKeys = null;
38 gc();
39
40 // Create a MediaKeys object and make sure gc doesn't free it
41 // as long as we have a reference.
42 mediaKeys = new MediaKeys("org.w3.clearkey");
43 gc();
44 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey');
45 mediaKeys = null;
46 gc();
47
48 }, "MediaKeys lifetime");
49
50 // For this test, create a MediaKeySession (which is an
51 // ActiveDOMObject) and verify lifetime.
52 test(function()
53 {
54 var mediaKeys;
55 var initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
56 startingActiveDOMObjectCount = window.internals.activeDOMObjectC ount(document);
57 assert_equals(numActiveDOMObjectsCreated(), 0);
58
59 // Create a MediaKeys object with a session.
60 mediaKeys = new MediaKeys("org.w3.clearkey");
61 mediaKeys.createSession("video/webm", initData);
62 assert_equals(numActiveDOMObjectsCreated(), 1);
63
64 // Run gc(), should not affect MediaKeys object nor the session
65 // since we still have a reference to it.
66 gc();
67 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey');
68 assert_equals(numActiveDOMObjectsCreated(), 1);
69
70 // Drop reference to the MediaKeys object and run gc again.
71 // Object should be collected this time. Since
72 // MediaKeySessions remain alive as long as MediaKeys is around,
73 // it is possible that gc() checks the MediaKeySession object
74 // first, and doesn't collect it since MediaKeys hasn't been
75 // collected yet. Thus run gc() twice, to ensure that the
76 // unreferenced MediaKeySession object get collected.
77 mediaKeys = null;
78 gc();
79 gc();
80 assert_equals(numActiveDOMObjectsCreated(), 0);
81
82 }, "MediaKeys lifetime with session");
83
84 // For this test, create several MediaKeys (with MediaKeySessions so
85 // they can be counted) and verify lifetime.
86 test(function()
87 {
88 var mediaKeys;
89 var initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
90 startingActiveDOMObjectCount = window.internals.activeDOMObjectC ount(document);
91 assert_equals(numActiveDOMObjectsCreated(), 0);
92
93 // Create a few MediaKeys objects. Only keep a reference to the
94 // last one created.
95 for (var i = 0; i < 5; ++i) {
96 mediaKeys = new MediaKeys("org.w3.clearkey");
97 mediaKeys.createSession("video/webm", initData);
98 }
99 assert_equals(numActiveDOMObjectsCreated(), 5);
100
101 // All but the last one created should be garbage collected.
102 // Since MediaKeySessions remain alive as long as MediaKeys is
103 // around, it is possible that gc() checks the MediaKeySession
104 // object first, and doesn't collect it since MediaKeys hasn't
105 // been collected yet. Thus run gc() twice, to ensure that the
106 // unreferenced MediaKeySession objects get collected.
107 gc();
108 gc();
109 assert_equals(numActiveDOMObjectsCreated(), 1);
110 assert_equals(mediaKeys.keySystem, 'org.w3.clearkey');
111
112 // Release the last MediaKeys object created.
113 mediaKeys = null;
114 gc();
115 gc();
116 assert_equals(numActiveDOMObjectsCreated(), 0);
117 }, "Multiple MediaKeys lifetime");
118 </script>
119 </body>
120 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698