<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Testing UTF-8 content in SDP</title>
        <script src="../resources/testharness.js"></script>
        <script src="../resources/testharnessreport.js"></script>
    </head>
    <body>
        <video id="video" autoplay=""></video>
        <script src ="routines.js"></script>
        <script>
promise_test(async (test) => {
    if (!window.internals)
        return Promise.reject("internals required");

    const unicodeString = '世界你好';

    const stream = await navigator.mediaDevices.getUserMedia({video: true});
    internals.setMediaStreamTrackIdentifier(stream.getVideoTracks()[0], unicodeString);

    const remoteStream = await new Promise((resolve, reject) => {
        createConnections((firstConnection) => {
            firstConnection.addTrack(stream.getVideoTracks()[0], stream);
        }, (secondConnection) => {
            secondConnection.ontrack = (trackEvent) => {
                resolve(trackEvent.streams[0]);
            };
        });
        setTimeout(() => reject("Test timed out"), 5000);
    });

    assert_equals(remoteStream.getVideoTracks()[0].id, unicodeString);
    video.srcObject = remoteStream;
    return video.play();
}, "Testing video exchange with UTF-8 track id");
        </script>
    </body>
</html>
