chromium/third_party/blink/web_tests/http/tests/media/encrypted-media/encrypted-media-encrypted-event-same-origin.html

<!DOCTYPE html>
<html>
    <head>
        <title>Initialization Data returned when using same origin</title>
        <script src="/js-test-resources/testharness.js"></script>
        <script src="/js-test-resources/testharnessreport.js"></script>
    </head>
    <body>
        <video id="testVideo"></video>
        <div id="log"></div>
        <script>
            async_test(function(test)
            {
                var video = document.getElementById('testVideo');
                var encryptedEventCount = 0;

                function onEncrypted(event)
                {
                    assert_equals(event.target, video);
                    assert_true(event instanceof window.MediaEncryptedEvent);
                    assert_equals(event.type, 'encrypted');

                    // Since the .src is in the same origin as this test,
                    // both initDataType and initData should contain something.
                    assert_equals(event.initDataType, 'webm');
                    assert_greater_than(event.initData.byteLength, 0);

                    // Both the audio and the video tracks have initData,
                    // so finish once both events are received.
                    if (++encryptedEventCount == 2)
                        test.done();
                }

                navigator.requestMediaKeySystemAccess(
                    'org.w3.clearkey',
                    [{audioCapabilities: [{contentType: 'audio/webm; codecs=vorbis'}]}])
                  .then(function(access) {
                    return access.createMediaKeys();
                }).then(function(mediaKeys) {
                    video.addEventListener('encrypted', test.step_func(onEncrypted), true);
                    return video.setMediaKeys(mediaKeys);
                }).then(function(result) {
                    video.src = 'test-encrypted.webm';
                    video.play();
                });
            }, 'Initialization Data returned when using same origin.');
        </script>
    </body>
</html>