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..f6de0893d19a290c82cfc74ef24e7995ebf73900 |
--- /dev/null |
+++ b/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys.html |
@@ -0,0 +1,89 @@ |
+<!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> |
+ <script src="encrypted-media-utils.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 this test, we add |
+ // a MediaKeySession (which are ActiveDOMObjects) to each one so |
+ // we can count. MediaKeySession objects will not be garbage collected |
+ // as long as the MediaKeys object is around (or the session gets |
+ // closed, which isn't happening in this test). |
+ test(function() |
+ { |
+ var mediaKeys; |
+ var initData = stringToUint8Array("mock"); |
+ var startingObjects = window.internals.activeDOMObjectCount(document); |
+ |
+ function numObjectsCreated() |
+ { |
+ return window.internals.activeDOMObjectCount(document) - startingObjects; |
+ } |
+ |
+ // Create a MediaKeys object and free immediately. |
+ 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(); |
+ |
+ // Create a MediaKeys object with a session. |
ddorwin
2014/02/28 05:09:38
By using separate test()'s, you can clearly separa
jrummell
2014/04/01 19:06:43
Done.
|
+ mediaKeys = new MediaKeys("org.w3.clearkey"); |
+ mediaKeys.createSession("video/webm", initData); |
+ assert_equals(numObjectsCreated(), 1); |
+ |
+ // Run gc(), should not affect MediaKeys object since we have |
+ // a reference to it, nor the session. |
ddorwin
2014/02/28 05:09:38
I think you mean to add the new text after "object
jrummell
2014/04/01 19:06:43
Done.
|
+ gc(); |
+ assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); |
+ assert_equals(numObjectsCreated(), 1); |
+ |
+ // Drop reference to the MediaKeys object and run gc again. |
+ // Object should be collected this time. Running gc() twice |
+ // as the first pass may not actually collect the created |
+ // session (session is only collected if the MediaKeys object |
+ // is gone, which won't happen if the first pass happens to |
+ // check the session object first). |
+ mediaKeys = null; |
+ gc(); |
+ gc(); |
+ assert_equals(numObjectsCreated(), 0); |
+ |
+ // Create a few MediaKeys objects. We don't want to trigger |
+ // a gc due to memory pressure. |
ddorwin
2014/02/28 05:09:38
Is that really likely? I don't think that's enough
jrummell
2014/04/01 19:06:43
Comment updated.
|
+ for (var i = 0; i < 5; ++i) { |
+ mediaKeys = new MediaKeys("org.w3.clearkey"); |
+ mediaKeys.createSession("video/webm", initData); |
+ } |
+ assert_equals(numObjectsCreated(), 5); |
+ |
+ // All but the last one created should be garbage collected. |
+ gc(); |
+ gc(); |
+ assert_equals(numObjectsCreated(), 1); |
+ |
+ // Last MediaKeys object created should still be referenced. |
+ assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); |
+ |
+ // Release the last MediaKeys object created. |
+ mediaKeys = null; |
+ gc(); |
+ gc(); |
+ assert_equals(numObjectsCreated(), 0); |
+ }, "MediaKeys lifetime"); |
+ </script> |
+ </body> |
+</html> |