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

Unified 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: Simplified one 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-release.html
diff --git a/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-release.html b/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-release.html
new file mode 100644
index 0000000000000000000000000000000000000000..83647a15fce88a71ba8daea77fe7aefb9b4b0b38
--- /dev/null
+++ b/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-release.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test MediaKeySession lifetime</title>
+ <script src="../w3c-media-utils.js"></script>
+ <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>
+ setup({ timeout: 60000 }); // Timeout for all tests to run.
+
+ // Since MediaKeySession (but not MediaKeys) are ActiveDOMObjects,
+ // we can determine when they are garbage collected.
+ // MediaKeySessions remain as long as:
+ // JavaScript has a reference to it
+ // OR (MediaKeys is around AND the session is not CLOSED)
+ async_test(function(test)
+ {
+ var startingActiveDOMObjectsCreated = window.internals.activeDOMObjectCount(document);
xhwang 2014/03/26 22:59:09 ditto
jrummell 2014/03/26 23:32:09 Done.
+
+ function numActiveDOMObjectsCreated()
+ {
+ return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectsCreated;
+ }
+
+ var mediaKeys = new MediaKeys("org.w3.clearkey");
+ var audioMediaKeySession = null;
+ var videoMediaKeySession = null;
+ var sessionsCreated = 0;
+
+ function onMessage(event)
+ {
+ event.target.release();
+ waitForEventAndRunStep("close", event.target, onClose, test);
+ }
+
+ function onClose(event)
+ {
+ --sessionsCreated;
+ if (sessionsCreated > 0)
+ return;
+
+ // Delay to give time for close to complete.
+ setTimeout(finish, 250);
xhwang 2014/03/26 22:59:09 Why do we need this?
jrummell 2014/03/26 23:32:09 The onClose() event is fired against the MediaKeyS
+ }
+
+ function finish()
+ {
+ // Since both sessions have been released, dropping the
+ // reference to them from JS will result in the session
+ // being garbage-collected.
+ consoleWrite("Finish");
xhwang 2014/03/26 22:59:09 Do we need this?
xhwang 2014/03/26 22:59:09 Double check that mediaKeys is not null here?
jrummell 2014/03/26 23:32:09 No more than we need the EVENT(xx) messages. This
jrummell 2014/03/26 23:32:09 Done.
+ assert_equals(numActiveDOMObjectsCreated(), 2);
+
+ videoMediaKeySession = null;
+ gc();
+ assert_equals(numActiveDOMObjectsCreated(), 1, "videoMediaKeySession not collected");
+
+ audioMediaKeySession = null;
+ gc();
+ assert_equals(numActiveDOMObjectsCreated(), 0, "audioMediaKeySession not collected");
+
+ test.done();
+ }
+
+ // Create 2 sessions.
+ audioMediaKeySession = mediaKeys.createSession('video/webm', new Uint8Array([1, 2, 3]));
+ waitForEventAndRunStep("message", audioMediaKeySession, onMessage, test);
xhwang 2014/03/26 22:59:09 Double checked. We actually don't need to wait for
jrummell 2014/03/26 23:32:09 Done.
+ videoMediaKeySession = mediaKeys.createSession('video/webm', new Uint8Array([4, 5]));
xhwang 2014/03/26 22:59:09 Just use mediaKeySession1 and mediaKeySession2 to
jrummell 2014/03/26 23:32:09 Done.
+ waitForEventAndRunStep("message", videoMediaKeySession, onMessage, test);
+ sessionsCreated = 2;
+ }, "MediaKeySession lifetime after release()", { timeout: 60000 });
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698