WebRTC: Make MediaEndpointPeerConnection handle remotely assigned mids correctly
[WebKit-https.git] / LayoutTests / fast / mediastream / RTCPeerConnection-remotely-assigned-transceiver-mid.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3     <head>
4         <script src="../../resources/js-test-pre.js"></script>
5         <script src="resources/promise-utils.js"></script>
6     </head>
7     <body>
8         <script>
9             let stream;
10             let midAssignedByA;
11             let event;
12
13             description("Test the case where an RTCRtpTransceiver gets a remotely assigned mid and also unmute the associated source");
14
15             if (window.testRunner)
16                 testRunner.setUserMediaPermission(true);
17             else {
18                 debug("This test can not be run without the testRunner");
19                 finishJSTest();
20             }
21
22             const pcA = new webkitRTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]});
23             const pcB = new webkitRTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]});
24
25             pcA.ontrack = function (evt) {
26                 testPassed("A: got remote track event");
27             };
28
29             pcB.ontrack = function (e) {
30                 event = e;
31
32                 testPassed("B: got remote track event");
33                 shouldBeType("event.track", "MediaStreamTrack");
34
35                 event.track.onunmute = function () {
36                     testPassed("B: remote track unmute event");
37                     finishJSTest();
38                 };
39             };
40
41             navigator.mediaDevices.getUserMedia({ "audio": true })
42             .then(function (s) {
43                 stream = s;
44
45                 evalAndLog("pcA.addTrack(stream.getAudioTracks()[0], stream)");
46                 debug("A's transceiver is not yet associated with a media description and should have a null mid");
47                 shouldBeNull("pcA.getTransceivers()[0].mid");
48
49                 return pcA.createOffer();
50             })
51             .then(function (offer) {
52                 return pcA.setLocalDescription(offer);
53             })
54             .then(function () {
55                 debug("A: local offer set (mid gets defined)");
56
57                 evalAndLog("midAssignedByA = pcA.getTransceivers()[0].mid");
58                 shouldBeTrue("midAssignedByA !== null");
59
60                 evalAndLog("pcB.addTrack(stream.getAudioTracks()[0], stream)");
61                 debug("B's transceiver is not yet associated with a media description and should have a null mid");
62                 shouldBeNull("pcB.getTransceivers()[0].mid");
63
64                 return pcB.setRemoteDescription(pcA.localDescription);
65             })
66             .then(function () {
67                 debug("B: remote offer set (mid gets defined)");
68
69                 debug("B's transceiver should get its mid from the remote side (A)");
70                 shouldBe("pcB.getTransceivers()[0].mid", "midAssignedByA");
71
72                 return pcB.createAnswer();
73             })
74             .then(function (answer) {
75                 return pcB.setLocalDescription(answer);
76             })
77             .then(function () {
78                 return pcA.setRemoteDescription(pcB.localDescription);
79             })
80             .then(function () {
81                 testPassed("Offer/answer dialog completed")
82
83                 window.internals.emulateRTCPeerConnectionPlatformEvent(pcB, "unmute-remote-sources-by-mid");
84             })
85             .catch(function (error) {
86                 testFailed("Error in promise chain: " + error);
87                 finishJSTest();
88             });
89
90             window.jsTestIsAsync = true;
91             window.successfullyParsed = true;
92
93         </script>
94         <script src="../../resources/js-test-post.js"></script>
95     </body>
96 </html>