<!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>
        <script src ="routines.js"></script>
        <script>
var firstConnection, secondConnection;
promise_test((test) => {
    if (window.testRunner)
        testRunner.setUserMediaPermission(true);

    return navigator.mediaDevices.getUserMedia({ video: true}).then((stream) => {
        return new Promise((resolve, reject) => {
            createConnections((connection) => {
                firstConnection = connection;
                var track = stream.getVideoTracks()[0];
                firstConnection.addTrack(stream.getVideoTracks()[0], stream);
                assert_equals(firstConnection.getSenders()[0].track, track, "first connection track");
            }, (connection) => {
                secondConnection = connection;
                secondConnection.ontrack = (trackEvent) => {
                    assert_equals(secondConnection.getReceivers()[0].track, trackEvent.track, "second connection track");
                    resolve(trackEvent.streams[0]);
                };
            });
            setTimeout(() => reject("Test timed out"), 5000);
        });
    });
}, "Basic video exchange checking getReceivers");
        </script>
    </body>
</html>
