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 |
| index f6548eeca753c24586df8f2afbd40955da6c90cb..ffd3d66a590f73e7c50563b3ae0686fab8d6e9fb 100644 |
| --- a/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys.html |
| +++ b/LayoutTests/media/encrypted-media/encrypted-media-lifetime-mediakeys.html |
| @@ -1,121 +1,126 @@ |
| <!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() |
| - { |
| - 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); |
| - 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> |
| +<head> |
| +<title>Test MediaKeys lifetime</title> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="../../resources/js-test.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 t = async_test("MediaKeys Lifetime"); |
| +t.step(step1); |
| + |
| +var mediaKeys; |
| +var initData; |
| +var startingActiveDOMObjectCount; |
| + |
| +function numActiveDOMObjectsCreated() |
| +{ |
| + return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount; |
| +} |
| + |
| +// For this test, simply verify that creating and destroying |
| +// MediaKeys doesn't crash. |
| +function step1() { |
| + // Create a MediaKeys object and free immediately. |
| + mediaKeys = new MediaKeys("org.w3.clearkey"); |
| + mediaKeys = null; |
| + asyncGC(step2); |
| +} |
| + |
| +function step2() { |
| + // 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"); |
| + asyncGC(step3); |
| +} |
| + |
| +function step3() { |
| + assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); |
| + mediaKeys = null; |
| + asyncGC(step4); |
| +} |
| + |
| +// For this test, create a MediaKeySession (which is an |
| +// ActiveDOMObject) and verify lifetime. |
| +function step4() { |
| + initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]); |
| + startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document); |
| + |
| + // 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(); |
|
haraken
2014/05/27 14:51:17
Hmm, I rewrote the test using asyncGC(), but the r
|
| + 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; |
| + asyncGC(step6); |
| +} |
| + |
| +function step6() { |
| + assert_equals(numActiveDOMObjectsCreated(), 0); |
| + asyncGC(step7); |
| +} |
| + |
| +// For this test, create several MediaKeys (with MediaKeySessions so |
| +// they can be counted) and verify lifetime. |
| +function step7() { |
| + initData = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]); |
| + startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document); |
| + |
| + // 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(); |
| + assert_equals(numActiveDOMObjectsCreated(), 1); |
| + assert_equals(mediaKeys.keySystem, 'org.w3.clearkey'); |
| + |
| + // Release the last MediaKeys object created. |
| + mediaKeys = null; |
| + asyncGC(step9); |
| +} |
| + |
| +function step9() { |
| + assert_equals(numActiveDOMObjectsCreated(), 0); |
| + t.done(); |
| +} |
| +</script> |
| +</body> |
| </html> |