addTransceiver should trigger mid generation in the SDP
[WebKit-https.git] / LayoutTests / webrtc / video-addTransceiver.html
1 <!doctype html>
2 <html>
3     <head>
4         <meta charset="utf-8">
5         <title>Testing basic video exchange from offerer to receiver</title>
6         <script src="../resources/testharness.js"></script>
7         <script src="../resources/testharnessreport.js"></script>
8     </head>
9     <body>
10         <video id="video" autoplay=""></video>
11         <canvas id="canvas" width="640" height="480"></canvas>
12         <script src ="routines.js"></script>
13         <script>
14
15 promise_test((test) => {
16     var pc = new RTCPeerConnection();
17     pc.addTransceiver("video");
18
19     return pc.createOffer().then((offer) => {
20         assert_true(offer.sdp.indexOf("mid:video") !== -1);
21         assert_true(offer.sdp.indexOf("a=recvonly") !== -1);
22
23         pc.addTransceiver("audio");
24         return pc.createOffer();
25     }).then((offer) => {
26         assert_true(offer.sdp.indexOf("mid:audio") !== -1);
27     });
28 }, "Setting up calls with addTransceiver but with no track");
29
30 promise_test((test) => {
31     if (window.testRunner)
32         testRunner.setUserMediaPermission(true);
33
34     return navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
35         var pc = new RTCPeerConnection();
36         pc.addTransceiver("video");
37         pc.getSenders()[0].replaceTrack(stream.getVideoTracks()[0]);
38
39         return pc.createOffer().then((offer) => {
40             assert_true(offer.sdp.indexOf("mid:video") !== -1);
41             // Replacing the track is not done yet so we still set it as a recvonly.
42             assert_true(offer.sdp.indexOf("a=recvonly") !== -1);
43         });
44     });
45 }, "Setting up calls with addTransceiver with a track");
46
47 function testImage()
48 {
49     canvas.width = video.videoWidth;
50     canvas.height = video.videoHeight;
51     canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
52
53     imageData = canvas.getContext('2d').getImageData(10, 325, 250, 1);
54     data = imageData.data;
55
56     var index = 20;
57     assert_true(data[index] < 100);
58     assert_true(data[index + 1] < 100);
59     assert_true(data[index + 2] < 100);
60
61     index = 80;
62     assert_true(data[index] > 200);
63     assert_true(data[index + 1] > 200);
64     assert_true(data[index + 2] > 200);
65
66     index += 80;
67     assert_true(data[index] > 200);
68     assert_true(data[index + 1] > 200);
69     assert_true(data[index + 2] < 100);
70 }
71
72 promise_test((test) => {
73     if (window.testRunner)
74         testRunner.setUserMediaPermission(true);
75
76     return navigator.mediaDevices.getUserMedia({ video: true}).then((stream) => {
77         return new Promise((resolve, reject) => {
78             createConnections((firstConnection) => {
79                 var track = stream.getVideoTracks()[0];
80                 firstConnection.addTransceiver("video");
81                 return firstConnection.getSenders()[0].replaceTrack(stream.getVideoTracks()[0]);
82             }, (secondConnection) => {
83                 secondConnection.ontrack = (trackEvent) => {
84                     resolve(trackEvent.streams[0]);
85                 };
86             });
87             setTimeout(() => reject("Test timed out"), 5000);
88         });
89     }).then((stream) => {
90         video.srcObject = stream;
91         return video.play();
92     }).then(() => {
93         testImage();
94     });
95 }, "Basic video exchange set up with addTransceiver");
96
97         </script>
98     </body>
99 </html>