<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Testing basic video exchange from offerer to receiver</title>
        <script src="../resources/testharness.js"></script>
        <script src="../resources/testharnessreport.js"></script>
    </head>
    <body>
        <video id="video" autoplay playsinline></video>
        <canvas id="canvas" width="640" height="480"></canvas>
        <script src ="routines.js"></script>
        <script>
if (window.testRunner)
    testRunner.setUserMediaPermission(true);

video = document.getElementById("video");
canvas = document.getElementById("canvas");
// FIXME: We should use tracks

function testStream(stream)
{
    video.srcObject = stream;
    video.onplay = setTimeout(() => {
        stream.getTracks()[0].enabled = false;
        checkVideoIsEntirelyBlack(canvas, video).then(finishTest, errorTest);
    }, 2000);
}

var finishTest, errorTest;
promise_test((test) => {
    return navigator.mediaDevices.getUserMedia({ video: true}).then((stream) => {
        return new Promise((resolve, reject) => {
            finishTest = resolve;
            errorTest = reject;
            createConnections((firstConnection) => {
                firstConnection.addTrack(stream.getVideoTracks()[0], stream);
            }, (secondConnection) => {
                secondConnection.ontrack = (trackEvent) => { testStream(trackEvent.streams[0]); };
            });
        });
    });
}, "Disabled source exchange");
        </script>
    </body>
</html>
