<!DOCTYPE html>
<html>
<head>
    <title>fps-init-data-cenc</title>
    <script src=../../../media-resources/video-test.js></script>
    <script src=eme2016.js></script>
    <script src=support.js></script>
    <script>
    window.addEventListener('load', async event => {
        startTest().then(endTest).catch(failTest);
    });

    async function startTest() {
        var access = await navigator.requestMediaKeySystemAccess("com.apple.fps", [{
            initDataTypes: ['cenc'],
            videoCapabilities: [{ contentType: 'video/mp4', robustness: '' }],
            distinctiveIdentifier: 'not-allowed',
            persistentState: 'not-allowed',
            sessionTypes: ['temporary'],
        }]);

        consoleWrite('PROMISE: requestMediaKeySystemAccess resolved');
        var keys = await access.createMediaKeys();

        consoleWrite('PROMISE: createMediaKeys resolved');
        var certificateResponse = await fetch('resources/cert.der');

        consoleWrite('FETCH: server certificate recieved');
        var arrayBuffer = await certificateResponse.arrayBuffer();

        consoleWrite('PROMISE: arrayBuffer resolved');
        await keys.setServerCertificate(arrayBuffer);

        consoleWrite('PROMISE: setServerCertificate resolved');
        var session = keys.createSession();

        var initData = Uint8Array.of(
            0x00, 0x00, 0x00, 0x92, 0x70, 0x73, 0x73, 0x68,
            0x01, 0x00, 0x00, 0x00, 0x94, 0xce, 0x86, 0xfb,
            0x07, 0xff, 0x4f, 0x43, 0xad, 0xb8, 0x93, 0xd2,
            0xfa, 0x96, 0x8c, 0xa2, 0x00, 0x00, 0x00, 0x03,
            0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
            0x00, 0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x01, 0x00);

        session.generateRequest('cenc', initData);
    }
    </script>
</head>
<body>
</body>
</html>
