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

Unified 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, 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys.html
diff --git a/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys.html b/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys.html
new file mode 100644
index 0000000000000000000000000000000000000000..0bb9594de1e29f10db76379ae34b2480399ef438
--- /dev/null
+++ b/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys.html
@@ -0,0 +1,120 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test MediaKeys lifetime</title>
+ <script src="../../resources/testharness.js"></script>
+ <script src="../../resources/testharnessreport.js"></script>
+ <script src="../../resources/gc.js"></script>
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ // Since MediaKeys are not ActiveDOMObjects, it is hard to
+ // determine when they are garbage collected. For some tests below
+ // a MediaKeySession (which is an ActiveDOMObject) is added so
+ // there is something to count.
+
+ // MediaKeySessions remain as long as:
+ // JavaScript has a reference to it
+ // OR (MediaKeys is around AND the session has not received a close() event)
+ // In the tests below, we do not close any session nor keep a
+ // Javascript reference to any session, so MediaKeySessions remain
+ // as long as the associated MediaKeys object is around.
+
+ var startingActiveDOMObjectCount;
ddorwin 2014/04/02 21:02:36 Initialize. -1 might be best since it should alway
+
+ function numActiveDOMObjectsCreated()
+ {
+ return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount;
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
+ }
+
+ // For this test, simply verify that creating and destroying
+ // MediaKeys doesn't crash.
+ test(function()
+ {
+ // Create a MediaKeys object and free immediately.
+ var mediaKeys = new MediaKeys("org.w3.clearkey");
+ mediaKeys = null;
+ gc();
+
+ // Create a MediaKeys object and make sure gc doesn't free it
+ // as long as we have a reference.
+ mediaKeys = new MediaKeys("org.w3.clearkey");
+ gc();
+ assert_equals(mediaKeys.keySystem, 'org.w3.clearkey');
+ mediaKeys = null;
+ gc();
+
+ }, "MediaKeys lifetime");
+
+ // For this test, create a MediaKeySession (which is an
+ // ActiveDOMObject) and verify lifetime.
+ test(function()
+ {
+ var mediaKeys;
+ var initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
+ startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document);
+ assert_equals(numActiveDOMObjectsCreated(), 0);
+
+ // Create a MediaKeys object with a session.
+ mediaKeys = new MediaKeys("org.w3.clearkey");
+ mediaKeys.createSession("video/webm", initData);
+ assert_equals(numActiveDOMObjectsCreated(), 1);
+
+ // Run gc(), should not affect MediaKeys object nor the session
+ // since we still have a reference to it.
+ gc();
+ assert_equals(mediaKeys.keySystem, 'org.w3.clearkey');
+ assert_equals(numActiveDOMObjectsCreated(), 1);
+
+ // Drop reference to the MediaKeys object and run gc again.
+ // Object should be collected this time. Since
+ // MediaKeySessions remain alive as long as MediaKeys is around,
+ // it is possible that gc() checks the MediaKeySession object
+ // first, and doesn't collect it since MediaKeys hasn't been
+ // collected yet. Thus run gc() twice, to ensure that the
+ // unreferenced MediaKeySession object get collected.
+ mediaKeys = null;
+ gc();
+ gc();
+ assert_equals(numActiveDOMObjectsCreated(), 0);
+
+ }, "MediaKeys lifetime with session");
+
+ // For this test, create several MediaKeys (with MediaKeySessions so
+ // they can be counted) and verify lifetime.
+ test(function()
+ {
+ var mediaKeys;
+ var initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
+ startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document);
+ assert_equals(numActiveDOMObjectsCreated(), 0);
+
+ // Create a few MediaKeys objects. Only keep a reference to the
+ // last one created.
+ for (var i = 0; i < 5; ++i) {
+ mediaKeys = new MediaKeys("org.w3.clearkey");
+ mediaKeys.createSession("video/webm", initData);
+ }
+ assert_equals(numActiveDOMObjectsCreated(), 5);
+
+ // All but the last one created should be garbage collected.
+ // Since MediaKeySessions remain alive as long as MediaKeys is
+ // around, it is possible that gc() checks the MediaKeySession
+ // object first, and doesn't collect it since MediaKeys hasn't
+ // been collected yet. Thus run gc() twice, to ensure that the
+ // unreferenced MediaKeySession objects get collected.
+ gc();
+ gc();
+ assert_equals(numActiveDOMObjectsCreated(), 1);
+ assert_equals(mediaKeys.keySystem, 'org.w3.clearkey');
+
+ // Release the last MediaKeys object created.
+ mediaKeys = null;
+ gc();
+ gc();
+ assert_equals(numActiveDOMObjectsCreated(), 0);
+ }, "Multiple MediaKeys lifetime");
+ </script>
+ </body>
+</html>
« 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