Chromium Code Reviews| 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..c9c7d4fea3241e12abcdfe0991204937899a6917 |
| --- /dev/null |
| +++ b/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys.html |
| @@ -0,0 +1,123 @@ |
| +<!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. |
| + |
| + // 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]); |
| + var startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document); |
| + |
| + function numActiveDOMObjectsCreated() |
|
ddorwin
2014/04/01 23:44:52
This could be defined outside the individual tests
jrummell
2014/04/02 01:09:15
Had separate functions as outside the test they wo
|
| + { |
| + return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount; |
| + } |
| + |
| + // 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]); |
| + var startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document); |
| + |
| + function numActiveDOMObjectsCreated() |
| + { |
| + return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount; |
| + } |
| + |
| + // 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); |
| + |
| + // Last MediaKeys object created should still be referenced. |
|
ddorwin
2014/04/01 23:44:52
This comment probably makes sense above 110. Reall
jrummell
2014/04/02 01:09:15
Removed comment. Basically restating what is on li
|
| + 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> |
|
ddorwin
2014/04/01 23:44:52
Do we have a test where the MK is dereferenced, we
jrummell
2014/04/02 01:09:15
encrypted-media-lifetime-mediakeysession-reference
|
| + </body> |
|
ddorwin
2014/04/01 23:44:52
In addition to that, we should be able to have jus
jrummell
2014/04/02 01:09:15
Good idea for another session test. I'll do that i
|
| +</html> |