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 @@
// as long as the associated MediaKeys object is around.
// For this test, create a MediaKeySession and verify lifetime.
async_test(function(test)
promise_test(function(test)
{
gc();
var initDataType;
var initData;
var mediaKeys;
var startingMediaKeysCount = window.internals.mediaKeysCount();
var startingMediaKeySessionCount = window.internals.mediaKeySessionCount();
function numMediaKeysCreated()
{
return window.internals.mediaKeysCount() - startingMediaKeysCount;
}
// 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()');
function numMediaKeySessionCreated()
{
return window.internals.mediaKeySessionCount() - startingMediaKeySessionCount;
}
// Create a MediaKeys object with a session.
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
// Create a MediaKeys object with a session.
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration());
}).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()');
assert_equals(numMediaKeySessionCreated(), 0, 'After final gc()');
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.create()');
var mediaKeySession = mediaKeys.createSession();
return mediaKeySession.generateRequest(initDataType, initData);
}).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSession()');
assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.createSession()');
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.createSession()');
// Run gc(), should not affect MediaKeys object nor the
// session since we still have a reference to it.
// When enabling oilpan GC, the in-active
// ScriptPromiseResolvers will be destroyed.
return createGCPromise();
}).then(function(result) {
assert_equals(typeof mediaKeys.createSession, 'function');
assert_equals(numMediaKeysCreated(), 1, 'After gc()');
assert_equals(numMediaKeySessionCreated(), 1, 'After gc()');
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'After gc()');
// Drop reference to the MediaKeys object and run gc()
// again. Object should be collected this time. Since
......@@ -78,12 +65,7 @@
}).then(function(result) {
return createGCPromise();
}).then(function(result) {
assert_equals(numMediaKeysCreated(), 0, 'After final gc()');
assert_equals(numMediaKeySessionCreated(), 0, 'After final gc()');
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After final gc()');
});
}, 'MediaKeys lifetime with session');
</script>
......
......@@ -13,71 +13,57 @@
// OR (MediaKeys is around
// AND the session has not received a close() event)
async_test(function(test)
promise_test(function(test)
{
gc();
var mediaKeys;
var mediaKeySession1;
var mediaKeySession2;
var mediaKeySession3;
var initDataType;
var initData;
var startingMediaKeysCount = window.internals.mediaKeysCount();
var startingMediaKeySessionCount = window.internals.mediaKeySessionCount();
function numMediaKeysCreated()
{
return window.internals.mediaKeysCount() - startingMediaKeysCount;
}
// 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()');
function numMediaKeySessionCreated()
{
return window.internals.mediaKeySessionCount() - startingMediaKeySessionCount;
}
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration());
}).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
assert_equals(typeof mediaKeys.createSession, 'function');
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()');
assert_equals(numMediaKeySessionCreated(), 0, 'After final gc()');
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.create()');
// Create 3 sessions.
mediaKeySession1 = mediaKeys.createSession();
return mediaKeySession1.generateRequest(initDataType, initData);
}).then(function() {
assert_true(mediaKeySession1.sessionId && mediaKeySession1.sessionId.length > 0);
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSession(1)');
assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.createSession(1)');
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.createSession(1)');
mediaKeySession2 = mediaKeys.createSession();
return mediaKeySession2.generateRequest(initDataType, initData);
}).then(function() {
assert_true(mediaKeySession2.sessionId && mediaKeySession2.sessionId.length > 0);
assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSession(2)');
assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.createSession(2)');
verifyMediaKeyAndMediaKeySessionCount(1, 2, 'mediaKeys.createSession(2)');
mediaKeySession3 = mediaKeys.createSession();
return mediaKeySession3.generateRequest(initDataType, initData);
}).then(function() {
assert_true(mediaKeySession3.sessionId && mediaKeySession3.sessionId.length > 0);
assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSession(3)');
assert_equals(numMediaKeySessionCreated(), 3, 'mediaKeys.createSession(3)');
verifyMediaKeyAndMediaKeySessionCount(1, 3, 'mediaKeys.createSession(3)');
// Run gc(). All sessions should remain as we have a
// reference to each one. However, running gc()
// asynchronously should free up the last PromiseResolver.
return createGCPromise();
}).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'After gc()');
assert_equals(numMediaKeySessionCreated(), 3, 'After gc()');
verifyMediaKeyAndMediaKeySessionCount(1, 3, 'After gc()');
// Now drop references to 2 of the sessions. Even though we
// don't have a reference, MediaKeys is still around (and
......@@ -89,8 +75,7 @@
}).then(function(result) {
return createGCPromise();
}).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'After second gc()');
assert_equals(numMediaKeySessionCreated(), 3, 'After second gc()');
verifyMediaKeyAndMediaKeySessionCount(1, 3, 'After second gc()');
// Now drop the reference to MediaKeys. It and the 2
// unreferenced sessions should be collected. Since
......@@ -105,20 +90,14 @@
}).then(function(result) {
return createGCPromise();
}).then(function(result) {
assert_equals(numMediaKeysCreated(), 0, 'After mediaKeys = null');
assert_equals(numMediaKeySessionCreated(), 1, 'After mediaKeys = null');
verifyMediaKeyAndMediaKeySessionCount(0, 1, 'After mediaKeys = null');
// Drop the reference to the last session. It should get
// collected now since MediaKeys is gone.
mediaKeySession3 = null;
return createGCPromise();
}).then(function(result) {
assert_equals(numMediaKeysCreated(), 0, 'After final gc()');
assert_equals(numMediaKeySessionCreated(), 0, 'After final gc()');
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After final gc()');
});
}, 'MediaKeySession lifetime without release()');
</script>
......
......@@ -12,61 +12,49 @@
// JavaScript has a reference to it
// OR (MediaKeys is around
// AND the session has not received a close() event)
async_test(function(test)
promise_test(function(test)
{
gc();
var initDataType;
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.
var mediaKeys;
var mediaKeySession1;
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];
initData = getInitData(initDataType);
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()');
assert_equals(numMediaKeySessionCreated(), 0, 'MediaKeys.create()');
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.create()');
mediaKeySession1 = mediaKeys.createSession();
return mediaKeySession1.generateRequest(initDataType, initData);
}).then(function() {
assert_true(mediaKeySession1.sessionId && mediaKeySession1.sessionId.length > 0);
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSession(1)');
assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.createSession(1)');
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.createSession(1)');
mediaKeySession2 = mediaKeys.createSession();
return mediaKeySession2.generateRequest(initDataType, initData);
}).then(function() {
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
// reference to each one.
return createGCPromise();
}).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'After gc()');
assert_equals(numMediaKeySessionCreated(), 2, 'After gc()');
verifyMediaKeyAndMediaKeySessionCount(1, 2, 'After gc()');
// Close the sessions. Once the close() event is received,
// they should get garbage collected as there are no JS
......@@ -81,8 +69,7 @@
}).then(function(result) {
return createGCPromise();
}).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession1 not collected');
assert_equals(numMediaKeySessionCreated(), 1, 'mediaKeySession1 not collected');
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'mediaKeySession1 not collected');
var promise = mediaKeySession2.close();
mediaKeySession2 = null;
......@@ -94,13 +81,8 @@
}).then(function(result) {
return createGCPromise();
}).then(function(result) {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession2 not collected');
assert_equals(numMediaKeySessionCreated(), 0, 'mediaKeySession2 not collected');
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'mediaKeySession2 not collected');
assert_not_equals(mediaKeys, null);
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
});
}, 'MediaKeySession lifetime after release() without references');
</script>
......
......@@ -12,49 +12,40 @@
// JavaScript has a reference to it
// OR (MediaKeys is around
// AND the session has not received a close() event)
async_test(function(test)
promise_test(function(test)
{
gc();
var mediaKeys;
var mediaKeySession1;
var mediaKeySession2;
var initDataType;
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.
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];
initData = getInitData(initDataType);
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()');
assert_equals(numMediaKeySessionCreated(), 0, 'MediaKeys.create()');
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.create()');
mediaKeySession1 = mediaKeys.createSession();
return mediaKeySession1.generateRequest(initDataType, initData);
}).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSession(1)');
assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.createSession(1)');
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.createSession(1)');
mediaKeySession2 = mediaKeys.createSession();
return mediaKeySession2.generateRequest(initDataType, initData);
}).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSession(2)');
assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.createSession(2)');
verifyMediaKeyAndMediaKeySessionCount(1, 2, 'mediaKeys.createSession(2)');
// Close the sessions. Once completed, only the JS
// reference to them keeps them around.
......@@ -65,23 +56,17 @@
// Since both sessions have been closed, dropping the
// reference to them from JS will result in the session
// being garbage-collected.
assert_equals(numMediaKeysCreated(), 1, 'after close');
assert_equals(numMediaKeySessionCreated(), 2, 'after close');
verifyMediaKeyAndMediaKeySessionCount(1, 2, 'after close');
mediaKeySession1 = null;
return createGCPromise();
}).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession1 not collected');
assert_equals(numMediaKeySessionCreated(), 1, 'mediaKeySession1 not collected');
verifyMediaKeyAndMediaKeySessionCount(1, 1, 'mediaKeySession1 not collected');
mediaKeySession2 = null;
return createGCPromise();
}).then(function() {
assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession2 not collected');
assert_equals(numMediaKeySessionCreated(), 0, 'mediaKeySession2 not collected');
test.done();
}).catch(function(error) {
forceTestFailureFromPromise(test, error);
verifyMediaKeyAndMediaKeySessionCount(1, 0, 'mediaKeySession2 not collected');
});
}, 'MediaKeySession lifetime after release()');
</script>
......
......@@ -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>
......
......@@ -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