Commit 284ba384 authored by jrummell's avatar jrummell Committed by Commit bot

[eme] Convert lifetime tests to promise_tests

Now that there is support to count the number of active MediaKey
and MediaKeySession objects, update the tests to check the count
directly (there should be no such objects at the start of the test,
and if there are then something else is running and the counts
will be wrong anyway). By converting these tests to promise tests,
we get better logging if the test fails.

BUG=445324
TEST=updated tests pass

Review-Url: https://codereview.chromium.org/2618603002
Cr-Commit-Position: refs/heads/master@{#443113}
parent 57c86c65
...@@ -17,53 +17,40 @@ ...@@ -17,53 +17,40 @@
// as long as the associated MediaKeys object is around. // as long as the associated MediaKeys object is around.
// For this test, create a MediaKeySession and verify lifetime. // For this test, create a MediaKeySession and verify lifetime.
async_test(function(test) promise_test(function(test)
{ {
gc();
var initDataType; var initDataType;
var initData; var initData;
var mediaKeys; var mediaKeys;
var startingMediaKeysCount = window.internals.mediaKeysCount();
var startingMediaKeySessionCount = window.internals.mediaKeySessionCount();
function numMediaKeysCreated() // Even though there should be no existing objects, start by
{ // running gc() and verifying that none exist. This also
return window.internals.mediaKeysCount() - startingMediaKeysCount; // 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()');
function numMediaKeySessionCreated() // Create a MediaKeys object with a session.
{ return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration());
return window.internals.mediaKeySessionCount() - startingMediaKeySessionCount; }).then(function(access) {
}
// Create a MediaKeys object with a session.
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0]; initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType); initData = getInitData(initDataType);
return access.createMediaKeys(); return access.createMediaKeys();
}).then(function(result) { }).then(function(result) {
mediaKeys = result; mediaKeys = result;
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.create()');
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()');
assert_equals(numMediaKeySessionCreated(), 0, 'After final gc()');
var mediaKeySession = mediaKeys.createSession(); var mediaKeySession = mediaKeys.createSession();
return mediaKeySession.generateRequest(initDataType, initData); return mediaKeySession.generateRequest(initDataType, initData);
}).then(function() { }).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSession()'); verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.createSession()');
assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.createSession()');
// Run gc(), should not affect MediaKeys object nor the // Run gc(), should not affect MediaKeys object nor the
// session since we still have a reference to it. // session since we still have a reference to it.
// When enabling oilpan GC, the in-active
// ScriptPromiseResolvers will be destroyed.
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(typeof mediaKeys.createSession, 'function'); assert_equals(typeof mediaKeys.createSession, 'function');
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'After gc()');
assert_equals(numMediaKeysCreated(), 1, 'After gc()');
assert_equals(numMediaKeySessionCreated(), 1, 'After gc()');
// Drop reference to the MediaKeys object and run gc() // Drop reference to the MediaKeys object and run gc()
// again. Object should be collected this time. Since // again. Object should be collected this time. Since
...@@ -78,12 +65,7 @@ ...@@ -78,12 +65,7 @@
}).then(function(result) { }).then(function(result) {
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 0, 'After final gc()'); verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After final gc()');
assert_equals(numMediaKeySessionCreated(), 0, 'After final gc()');
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
}); });
}, 'MediaKeys lifetime with session'); }, 'MediaKeys lifetime with session');
</script> </script>
......
...@@ -13,71 +13,57 @@ ...@@ -13,71 +13,57 @@
// OR (MediaKeys is around // OR (MediaKeys is around
// AND the session has not received a close() event) // AND the session has not received a close() event)
async_test(function(test) promise_test(function(test)
{ {
gc();
var mediaKeys; var mediaKeys;
var mediaKeySession1; var mediaKeySession1;
var mediaKeySession2; var mediaKeySession2;
var mediaKeySession3; var mediaKeySession3;
var initDataType; var initDataType;
var initData; var initData;
var startingMediaKeysCount = window.internals.mediaKeysCount();
var startingMediaKeySessionCount = window.internals.mediaKeySessionCount();
function numMediaKeysCreated() // Even though there should be no existing objects, start by
{ // running gc() and verifying that none exist. This also
return window.internals.mediaKeysCount() - startingMediaKeysCount; // 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()');
function numMediaKeySessionCreated() return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration());
{ }).then(function(access) {
return window.internals.mediaKeySessionCount() - startingMediaKeySessionCount;
}
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0]; initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType); initData = getInitData(initDataType);
return access.createMediaKeys(); return access.createMediaKeys();
}).then(function(result) { }).then(function(result) {
mediaKeys = result; mediaKeys = result;
assert_equals(typeof mediaKeys.createSession, 'function'); assert_equals(typeof mediaKeys.createSession, 'function');
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.create()');
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()');
assert_equals(numMediaKeySessionCreated(), 0, 'After final gc()');
// Create 3 sessions. // Create 3 sessions.
mediaKeySession1 = mediaKeys.createSession(); mediaKeySession1 = mediaKeys.createSession();
return mediaKeySession1.generateRequest(initDataType, initData); return mediaKeySession1.generateRequest(initDataType, initData);
}).then(function() { }).then(function() {
assert_true(mediaKeySession1.sessionId && mediaKeySession1.sessionId.length > 0); assert_true(mediaKeySession1.sessionId && mediaKeySession1.sessionId.length > 0);
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.createSession(1)');
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSession(1)');
assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.createSession(1)');
mediaKeySession2 = mediaKeys.createSession(); mediaKeySession2 = mediaKeys.createSession();
return mediaKeySession2.generateRequest(initDataType, initData); return mediaKeySession2.generateRequest(initDataType, initData);
}).then(function() { }).then(function() {
assert_true(mediaKeySession2.sessionId && mediaKeySession2.sessionId.length > 0); assert_true(mediaKeySession2.sessionId && mediaKeySession2.sessionId.length > 0);
verifyMediaKeyAndMediaKeySessionCount(1, 2, 'mediaKeys.createSession(2)');
assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSession(2)');
assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.createSession(2)');
mediaKeySession3 = mediaKeys.createSession(); mediaKeySession3 = mediaKeys.createSession();
return mediaKeySession3.generateRequest(initDataType, initData); return mediaKeySession3.generateRequest(initDataType, initData);
}).then(function() { }).then(function() {
assert_true(mediaKeySession3.sessionId && mediaKeySession3.sessionId.length > 0); assert_true(mediaKeySession3.sessionId && mediaKeySession3.sessionId.length > 0);
verifyMediaKeyAndMediaKeySessionCount(1, 3, 'mediaKeys.createSession(3)');
assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSession(3)');
assert_equals(numMediaKeySessionCreated(), 3, 'mediaKeys.createSession(3)');
// Run gc(). All sessions should remain as we have a // Run gc(). All sessions should remain as we have a
// reference to each one. However, running gc() // reference to each one. However, running gc()
// asynchronously should free up the last PromiseResolver. // asynchronously should free up the last PromiseResolver.
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'After gc()'); verifyMediaKeyAndMediaKeySessionCount(1, 3, 'After gc()');
assert_equals(numMediaKeySessionCreated(), 3, 'After gc()');
// Now drop references to 2 of the sessions. Even though we // Now drop references to 2 of the sessions. Even though we
// don't have a reference, MediaKeys is still around (and // don't have a reference, MediaKeys is still around (and
...@@ -89,8 +75,7 @@ ...@@ -89,8 +75,7 @@
}).then(function(result) { }).then(function(result) {
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'After second gc()'); verifyMediaKeyAndMediaKeySessionCount(1, 3, 'After second gc()');
assert_equals(numMediaKeySessionCreated(), 3, 'After second gc()');
// Now drop the reference to MediaKeys. It and the 2 // Now drop the reference to MediaKeys. It and the 2
// unreferenced sessions should be collected. Since // unreferenced sessions should be collected. Since
...@@ -105,20 +90,14 @@ ...@@ -105,20 +90,14 @@
}).then(function(result) { }).then(function(result) {
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 0, 'After mediaKeys = null'); verifyMediaKeyAndMediaKeySessionCount(0, 1, 'After mediaKeys = null');
assert_equals(numMediaKeySessionCreated(), 1, 'After mediaKeys = null');
// Drop the reference to the last session. It should get // Drop the reference to the last session. It should get
// collected now since MediaKeys is gone. // collected now since MediaKeys is gone.
mediaKeySession3 = null; mediaKeySession3 = null;
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 0, 'After final gc()'); verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After final gc()');
assert_equals(numMediaKeySessionCreated(), 0, 'After final gc()');
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
}); });
}, 'MediaKeySession lifetime without release()'); }, 'MediaKeySession lifetime without release()');
</script> </script>
......
...@@ -12,61 +12,49 @@ ...@@ -12,61 +12,49 @@
// JavaScript has a reference to it // JavaScript has a reference to it
// OR (MediaKeys is around // OR (MediaKeys is around
// AND the session has not received a close() event) // AND the session has not received a close() event)
async_test(function(test) promise_test(function(test)
{ {
gc();
var initDataType; var initDataType;
var initData; var initData;
var startingMediaKeysCount = window.internals.mediaKeysCount();
var startingMediaKeySessionCount = window.internals.mediaKeySessionCount();
function numMediaKeysCreated()
{
return window.internals.mediaKeysCount() - startingMediaKeysCount;
}
function numMediaKeySessionCreated()
{
return window.internals.mediaKeySessionCount() - startingMediaKeySessionCount;
}
// Create 2 sessions. // Create 2 sessions.
var mediaKeys; var mediaKeys;
var mediaKeySession1; var mediaKeySession1;
var mediaKeySession2; var mediaKeySession2;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) { // 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 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration());
}).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0]; initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType); initData = getInitData(initDataType);
return access.createMediaKeys(); return access.createMediaKeys();
}).then(function(result) { }).then(function(result) {
mediaKeys = result; mediaKeys = result;
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.create()');
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()');
assert_equals(numMediaKeySessionCreated(), 0, 'MediaKeys.create()');
mediaKeySession1 = mediaKeys.createSession(); mediaKeySession1 = mediaKeys.createSession();
return mediaKeySession1.generateRequest(initDataType, initData); return mediaKeySession1.generateRequest(initDataType, initData);
}).then(function() { }).then(function() {
assert_true(mediaKeySession1.sessionId && mediaKeySession1.sessionId.length > 0); assert_true(mediaKeySession1.sessionId && mediaKeySession1.sessionId.length > 0);
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.createSession(1)');
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSession(1)');
assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.createSession(1)');
mediaKeySession2 = mediaKeys.createSession(); mediaKeySession2 = mediaKeys.createSession();
return mediaKeySession2.generateRequest(initDataType, initData); return mediaKeySession2.generateRequest(initDataType, initData);
}).then(function() { }).then(function() {
assert_true(mediaKeySession2.sessionId && mediaKeySession2.sessionId.length > 0); assert_true(mediaKeySession2.sessionId && mediaKeySession2.sessionId.length > 0);
verifyMediaKeyAndMediaKeySessionCount(1, 2, 'mediaKeys.createSession(2)');
assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSession(2)');
assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.createSession(2)');
}).then(function(result) {
// Run gc(). All sessions should remain as we have a // Run gc(). All sessions should remain as we have a
// reference to each one. // reference to each one.
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'After gc()'); verifyMediaKeyAndMediaKeySessionCount(1, 2, 'After gc()');
assert_equals(numMediaKeySessionCreated(), 2, 'After gc()');
// Close the sessions. Once the close() event is received, // Close the sessions. Once the close() event is received,
// they should get garbage collected as there are no JS // they should get garbage collected as there are no JS
...@@ -81,8 +69,7 @@ ...@@ -81,8 +69,7 @@
}).then(function(result) { }).then(function(result) {
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession1 not collected'); verifyMediaKeyAndMediaKeySessionCount(1, 1, 'mediaKeySession1 not collected');
assert_equals(numMediaKeySessionCreated(), 1, 'mediaKeySession1 not collected');
var promise = mediaKeySession2.close(); var promise = mediaKeySession2.close();
mediaKeySession2 = null; mediaKeySession2 = null;
...@@ -94,13 +81,8 @@ ...@@ -94,13 +81,8 @@
}).then(function(result) { }).then(function(result) {
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession2 not collected'); verifyMediaKeyAndMediaKeySessionCount(1, 0, 'mediaKeySession2 not collected');
assert_equals(numMediaKeySessionCreated(), 0, 'mediaKeySession2 not collected');
assert_not_equals(mediaKeys, null); assert_not_equals(mediaKeys, null);
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
}); });
}, 'MediaKeySession lifetime after release() without references'); }, 'MediaKeySession lifetime after release() without references');
</script> </script>
......
...@@ -12,49 +12,40 @@ ...@@ -12,49 +12,40 @@
// JavaScript has a reference to it // JavaScript has a reference to it
// OR (MediaKeys is around // OR (MediaKeys is around
// AND the session has not received a close() event) // AND the session has not received a close() event)
async_test(function(test) promise_test(function(test)
{ {
gc();
var mediaKeys; var mediaKeys;
var mediaKeySession1; var mediaKeySession1;
var mediaKeySession2; var mediaKeySession2;
var initDataType; var initDataType;
var initData; var initData;
var startingMediaKeysCount = window.internals.mediaKeysCount();
var startingMediaKeySessionCount = window.internals.mediaKeySessionCount();
function numMediaKeysCreated()
{
return window.internals.mediaKeysCount() - startingMediaKeysCount;
}
function numMediaKeySessionCreated()
{
return window.internals.mediaKeySessionCount() - startingMediaKeySessionCount;
}
// Create 2 sessions. // Create 2 sessions.
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) { // 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 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration());
}).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0]; initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType); initData = getInitData(initDataType);
return access.createMediaKeys(); return access.createMediaKeys();
}).then(function(result) { }).then(function(result) {
mediaKeys = result; mediaKeys = result;
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.create()');
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()');
assert_equals(numMediaKeySessionCreated(), 0, 'MediaKeys.create()');
mediaKeySession1 = mediaKeys.createSession(); mediaKeySession1 = mediaKeys.createSession();
return mediaKeySession1.generateRequest(initDataType, initData); return mediaKeySession1.generateRequest(initDataType, initData);
}).then(function() { }).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSession(1)'); verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.createSession(1)');
assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.createSession(1)');
mediaKeySession2 = mediaKeys.createSession(); mediaKeySession2 = mediaKeys.createSession();
return mediaKeySession2.generateRequest(initDataType, initData); return mediaKeySession2.generateRequest(initDataType, initData);
}).then(function() { }).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSession(2)'); verifyMediaKeyAndMediaKeySessionCount(1, 2, 'mediaKeys.createSession(2)');
assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.createSession(2)');
// Close the sessions. Once completed, only the JS // Close the sessions. Once completed, only the JS
// reference to them keeps them around. // reference to them keeps them around.
...@@ -65,23 +56,17 @@ ...@@ -65,23 +56,17 @@
// Since both sessions have been closed, dropping the // Since both sessions have been closed, dropping the
// reference to them from JS will result in the session // reference to them from JS will result in the session
// being garbage-collected. // being garbage-collected.
assert_equals(numMediaKeysCreated(), 1, 'after close'); verifyMediaKeyAndMediaKeySessionCount(1, 2, 'after close');
assert_equals(numMediaKeySessionCreated(), 2, 'after close');
mediaKeySession1 = null; mediaKeySession1 = null;
return createGCPromise(); return createGCPromise();
}).then(function() { }).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession1 not collected'); verifyMediaKeyAndMediaKeySessionCount(1, 1, 'mediaKeySession1 not collected');
assert_equals(numMediaKeySessionCreated(), 1, 'mediaKeySession1 not collected');
mediaKeySession2 = null; mediaKeySession2 = null;
return createGCPromise(); return createGCPromise();
}).then(function() { }).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession2 not collected'); verifyMediaKeyAndMediaKeySessionCount(1, 0, 'mediaKeySession2 not collected');
assert_equals(numMediaKeySessionCreated(), 0, 'mediaKeySession2 not collected');
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
}); });
}, 'MediaKeySession lifetime after release()'); }, 'MediaKeySession lifetime after release()');
</script> </script>
......
...@@ -9,16 +9,13 @@ ...@@ -9,16 +9,13 @@
<body> <body>
<script> <script>
// For this test, create several MediaKeys and verify lifetime. // For this test, create several MediaKeys and verify lifetime.
async_test(function(test) promise_test(function(test)
{ {
gc(); var mediaKeys1;
var mediaKeys; var mediaKeys2;
var startingMediaKeysCount = window.internals.mediaKeysCount(); var mediaKeys3;
var mediaKeys4;
function numMediaKeysCreated() var mediaKeys5;
{
return window.internals.mediaKeysCount() - startingMediaKeysCount;
}
// Create a MediaKeys object. Returns a promise that resolves // Create a MediaKeys object. Returns a promise that resolves
// with the new MediaKeys object. // with the new MediaKeys object.
...@@ -26,60 +23,79 @@ ...@@ -26,60 +23,79 @@
{ {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) { return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return access.createMediaKeys(); return access.createMediaKeys();
}).then(function(mediaKeys) {
return mediaKeys;
}); });
} }
// Create a few MediaKeys objects. Only keep a reference to the // Create a few MediaKeys objects. Keep references to them,
// last one created. // to avoid issues if gc() runs.
createMediaKeys().then(function(result) { // Even though there should be no existing objects, start by
assert_equals(numMediaKeysCreated(), 1); // 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(); return createMediaKeys();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 2); assert_not_equals(result, null);
mediaKeys1 = result;
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'Create first MediaKeys');
return createMediaKeys(); return createMediaKeys();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 3); assert_not_equals(result, null);
mediaKeys2 = result;
verifyMediaKeyAndMediaKeySessionCount(2, 0, 'Create second MediaKeys');
return createMediaKeys(); return createMediaKeys();
}).then(function(result) { }).then(function(result) {
assert_equals(numMediaKeysCreated(), 4); assert_not_equals(result, null);
mediaKeys3 = result;
verifyMediaKeyAndMediaKeySessionCount(3, 0, 'Create third MediaKeys');
return createMediaKeys(); return createMediaKeys();
}).then(function(result) { }).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 return createMediaKeys();
// object. }).then(function(result) {
mediaKeys = result; assert_not_equals(result, null);
mediaKeys5 = result;
verifyMediaKeyAndMediaKeySessionCount(5, 0, 'Create fifth MediaKeys');
// In order for the MediaKey objects to be garbage // In order for the MediaKey objects to be garbage
// collected, it needs time to process any pending events. // collected, it needs time to process any pending events.
return delayToAllowEventProcessingPromise(); return delayToAllowEventProcessingPromise();
}).then(function(result) { }).then(function() {
assert_equals(numMediaKeysCreated(), 5); verifyMediaKeyAndMediaKeySessionCount(5, 0, 'All alive');
// As we only have a reference (|mediaKeys|) to the last // Now run garbage collection. Since we have references to
// created MediaKeys object, the other 4 MediaKeys objects // all 5 MediaKeys, none will be collected.
// are available to be garbage collected.
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function() {
assert_equals(numMediaKeysCreated(), 1); verifyMediaKeyAndMediaKeySessionCount(5, 0, 'All still alive');
assert_equals(typeof mediaKeys.createSession, 'function');
// 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. // Release the last MediaKeys object created.
mediaKeys = null; mediaKeys5 = null;
// Run gc() again to reclaim the remaining MediaKeys object. // Run gc() again to reclaim the remaining MediaKeys object.
return createGCPromise(); return createGCPromise();
}).then(function(result) { }).then(function() {
assert_equals(numMediaKeysCreated(), 0); verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After final gc()');
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
}); });
}, 'Multiple MediaKeys lifetime'); }, 'Multiple MediaKeys lifetime');
</script> </script>
......
...@@ -329,3 +329,16 @@ function playVideoAndWaitForTimeupdate(video, content, duration) ...@@ -329,3 +329,16 @@ function playVideoAndWaitForTimeupdate(video, content, duration)
}); });
}); });
} }
// Verifies that the number of existing MediaKey and MediaKeySession objects
// match what is expected.
function verifyMediaKeyAndMediaKeySessionCount(
expectedMediaKeysCount, expectedMediaKeySessionCount, description)
{
assert_equals(window.internals.mediaKeysCount(),
expectedMediaKeysCount,
description + ', MediaKeys:');
assert_equals(window.internals.mediaKeySessionCount(),
expectedMediaKeySessionCount,
description + ', MediaKeySession:');
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment