chromium/third_party/blink/web_tests/media/encrypted-media/encrypted-media-setmediakeys-again-after-playback.html

<!DOCTYPE html>
<html>
    <head>
        <title>setMediaKeys() again after playback</title>
        <script src="encrypted-media-utils.js"></script>
        <script src="../../resources/testharness.js"></script>
        <script src="../../resources/testharnessreport.js"></script>
    </head>
    <body>
        <video></video>
        <script>
            promise_test(function(test)
            {
                var video = document.querySelector('video');
                var keyId = stringToUint8Array('0123456789012345');
                var rawKey = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
                                             0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
                var content = '../content/test-encrypted.webm';
                var duration = 0.2;

                return createClearKeyMediaKeysAndInitializeWithOneKey(keyId, rawKey).then(function(mediaKeys) {
                    return video.setMediaKeys(mediaKeys);
                }).then(function() {
                    return playVideoAndWaitForTimeupdate(video, content, duration);
                }).then(function() {
                    // Now create a second MediaKeys.
                    return createClearKeyMediaKeysAndInitializeWithOneKey(keyId, rawKey);
                }).then(function(mediaKeys) {
                    // video is currently playing, so should not be able to
                    // change MediaKeys now.
                    assert_false(video.ended);
                    return video.setMediaKeys(mediaKeys);
                }).then(function() {
                    assert_unreached('Able to change MediaKeys while playing.');
                }, function(error) {
                    // Error expected.
                    assert_equals(error.name, 'InvalidStateError');
                    return Promise.resolve('success');
                });
            }, 'setMediaKeys() again after playback');
        </script>
    </body>
</html>