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..5735d5f6fc4a78d7a0251b166feddfc613ff8cae |
--- /dev/null |
+++ b/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeysession-release.html |
@@ -0,0 +1,94 @@ |
+<!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> |
+ <video id="testVideo"></video> |
+ <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. |
+ async_test(function(test) |
+ { |
+ var video = document.getElementById("testVideo"); |
+ var startingObjects = window.internals.activeDOMObjectCount(document); |
+ |
+ function numObjectsCreated() |
+ { |
+ return window.internals.activeDOMObjectCount(document) - startingObjects; |
+ } |
+ |
+ var mediaKeys = new MediaKeys("org.w3.clearkey"); |
+ var audioMediaKeySession = null; |
+ var videoMediaKeySession = null; |
+ var sessionsCreated = 0; |
+ |
+ // Using media content that has different key ids for the audio |
+ // and video streams. |
+ var audioKeyId = "1234567890123456"; |
+ var videoKeyId = "0123456789012345"; |
+ |
+ function onNeedKey(event) |
+ { |
+ assert_equals(numObjectsCreated(), sessionsCreated); |
+ var keyId = String.fromCharCode.apply(null, event.initData); |
+ var newSession = mediaKeys.createSession(event.contentType, event.initData); |
+ ++sessionsCreated; |
+ assert_equals(numObjectsCreated(), sessionsCreated); |
+ if (keyId == videoKeyId) { |
+ videoMediaKeySession = newSession; |
+ } else { |
+ audioMediaKeySession = newSession; |
+ } |
+ waitForEventAndRunStep("message", newSession, onMessage, test); |
+ } |
+ |
+ function onMessage(event) |
+ { |
+ event.target.release(); |
xhwang
2014/03/26 20:58:32
Is it necessary to go the full process of needkey/
jrummell
2014/03/26 22:19:03
Simplified. Don't get the ready event until after
|
+ 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); |
+ } |
+ |
+ 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"); |
+ assert_equals(numObjectsCreated(), 2); |
+ |
+ videoMediaKeySession = null; |
+ gc(); |
+ assert_equals(numObjectsCreated(), 1, "videoMediaKeySession not collected"); |
+ |
+ audioMediaKeySession = null; |
+ gc(); |
+ assert_equals(numObjectsCreated(), 0, "audioMediaKeySession not collected"); |
xhwang
2014/03/26 20:58:32
Is it possible to test the case that if there's a
jrummell
2014/03/26 22:19:03
finish() is scheduled to run 250ms after the secon
|
+ |
+ test.done(); |
+ } |
+ |
+ waitForEventAndRunStep("needkey", video, onNeedKey, test); |
+ video.src = "../content/test-encrypted-different-av-keys.webm"; |
+ video.setMediaKeys(mediaKeys); |
+ }, "MediaKeySession lifetime using release", { timeout: 60000 }); |
xhwang
2014/03/26 20:58:32
s/using/after and s/release/release() ?
jrummell
2014/03/26 22:19:03
Done.
|
+ </script> |
+ </body> |
+</html> |