<!DOCTYPE html>
<html>
<head>
<title>Test MediaKeySession.update() fails after close()</title>
<script src="encrypted-media-utils.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
// This test verifies that calls on MediaKeySession fail after
// close() has been called. For simplicity we'll just call update()
// after close(), and expect it to fail.
promise_test(() => {
var initDataType;
var initData;
var mediaKeySession;
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then((access) => {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return access.createMediaKeys();
}).then((mediaKeys) => {
mediaKeySession = mediaKeys.createSession();
return mediaKeySession.generateRequest(initDataType, initData);
}).then(() => {
var p1 = mediaKeySession.close();
// Update() first checks for closing or closed and returns
// InvalidStateError if true. Later it checks for empty
// array and returns TypeError if true. So pass empty array
// to verify that closing is checked first.
var p2 = mediaKeySession.update(new Uint8Array([])).then(
() => { assert_unreached('Update() resolved unexpectedly'); },
(error) => { assert_equals(error.name, 'InvalidStateError'); } );
return Promise.all([p1, p2]);
});
}, 'Test calls fail after MediaKeySession.close().');
</script>
</body>
</html>