| Index: third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-multiple-mediakeys.html
|
| diff --git a/third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-multiple-mediakeys.html b/third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-multiple-mediakeys.html
|
| index 2ccba75ea2252f822f79fd2ccca29a01a7aec6a3..dc65e58eccd4e8387bf4a3146457a1a297455f98 100644
|
| --- a/third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-multiple-mediakeys.html
|
| +++ b/third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-lifetime-multiple-mediakeys.html
|
| @@ -9,16 +9,13 @@
|
| <body>
|
| <script>
|
| // For this test, create several MediaKeys and verify lifetime.
|
| - async_test(function(test)
|
| + promise_test(function(test)
|
| {
|
| - gc();
|
| - var mediaKeys;
|
| - var startingMediaKeysCount = window.internals.mediaKeysCount();
|
| -
|
| - function numMediaKeysCreated()
|
| - {
|
| - return window.internals.mediaKeysCount() - startingMediaKeysCount;
|
| - }
|
| + var mediaKeys1;
|
| + var mediaKeys2;
|
| + var mediaKeys3;
|
| + var mediaKeys4;
|
| + var mediaKeys5;
|
|
|
| // Create a MediaKeys object. Returns a promise that resolves
|
| // with the new MediaKeys object.
|
| @@ -26,60 +23,79 @@
|
| {
|
| return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
|
| return access.createMediaKeys();
|
| - }).then(function(mediaKeys) {
|
| - return mediaKeys;
|
| });
|
| }
|
|
|
| - // Create a few MediaKeys objects. Only keep a reference to the
|
| - // last one created.
|
| - createMediaKeys().then(function(result) {
|
| - assert_equals(numMediaKeysCreated(), 1);
|
| + // Create a few MediaKeys objects. Keep references to them,
|
| + // to avoid issues if gc() runs.
|
| + // Even though there should be no existing objects, start by
|
| + // running gc() and verifying that none exist. This also
|
| + // allows the failures to be reported from inside a promise
|
| + // so that the test fails properly.
|
| + return createGCPromise().then(function() {
|
| + verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After initial gc()');
|
|
|
| return createMediaKeys();
|
| }).then(function(result) {
|
| - assert_equals(numMediaKeysCreated(), 2);
|
| + assert_not_equals(result, null);
|
| + mediaKeys1 = result;
|
| + verifyMediaKeyAndMediaKeySessionCount(1, 0, 'Create first MediaKeys');
|
|
|
| return createMediaKeys();
|
| }).then(function(result) {
|
| - assert_equals(numMediaKeysCreated(), 3);
|
| + assert_not_equals(result, null);
|
| + mediaKeys2 = result;
|
| + verifyMediaKeyAndMediaKeySessionCount(2, 0, 'Create second MediaKeys');
|
|
|
| return createMediaKeys();
|
| }).then(function(result) {
|
| - assert_equals(numMediaKeysCreated(), 4);
|
| + assert_not_equals(result, null);
|
| + mediaKeys3 = result;
|
| + verifyMediaKeyAndMediaKeySessionCount(3, 0, 'Create third MediaKeys');
|
|
|
| return createMediaKeys();
|
| }).then(function(result) {
|
| - assert_equals(numMediaKeysCreated(), 5);
|
| + assert_not_equals(result, null);
|
| + mediaKeys4 = result;
|
| + verifyMediaKeyAndMediaKeySessionCount(4, 0, 'Create fourth MediaKeys');
|
|
|
| - // |mediaKeys| refers to the most recently created MediaKeys
|
| - // object.
|
| - mediaKeys = result;
|
| + return createMediaKeys();
|
| + }).then(function(result) {
|
| + assert_not_equals(result, null);
|
| + mediaKeys5 = result;
|
| + verifyMediaKeyAndMediaKeySessionCount(5, 0, 'Create fifth MediaKeys');
|
|
|
| // In order for the MediaKey objects to be garbage
|
| // collected, it needs time to process any pending events.
|
| return delayToAllowEventProcessingPromise();
|
| - }).then(function(result) {
|
| - assert_equals(numMediaKeysCreated(), 5);
|
| + }).then(function() {
|
| + verifyMediaKeyAndMediaKeySessionCount(5, 0, 'All alive');
|
|
|
| - // As we only have a reference (|mediaKeys|) to the last
|
| - // created MediaKeys object, the other 4 MediaKeys objects
|
| - // are available to be garbage collected.
|
| + // Now run garbage collection. Since we have references to
|
| + // all 5 MediaKeys, none will be collected.
|
| return createGCPromise();
|
| - }).then(function(result) {
|
| - assert_equals(numMediaKeysCreated(), 1);
|
| - assert_equals(typeof mediaKeys.createSession, 'function');
|
| + }).then(function() {
|
| + verifyMediaKeyAndMediaKeySessionCount(5, 0, 'All still alive');
|
| +
|
| + // Drop references to 4 of the MediaKeys. As we will only
|
| + // have a reference to the last created MediaKeys object,
|
| + // the other 4 MediaKeys objects are available to be
|
| + // garbage collected.
|
| + mediaKeys1 = null;
|
| + mediaKeys2 = null;
|
| + mediaKeys3 = null;
|
| + mediaKeys4 = null;
|
| + return createGCPromise();
|
| + }).then(function() {
|
| + verifyMediaKeyAndMediaKeySessionCount(1, 0, 'Only 1 left');
|
|
|
| // Release the last MediaKeys object created.
|
| - mediaKeys = null;
|
| + mediaKeys5 = null;
|
|
|
| // Run gc() again to reclaim the remaining MediaKeys object.
|
| return createGCPromise();
|
| - }).then(function(result) {
|
| - assert_equals(numMediaKeysCreated(), 0);
|
| - test.done();
|
| - }).catch(function(error) {
|
| - forceTestFailureFromPromise(test, error);
|
| + }).then(function() {
|
| + verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After final gc()');
|
| });
|
| }, 'Multiple MediaKeys lifetime');
|
| </script>
|
|
|