blob: b2186dcb1c72615d1e1bb51b56cb1762982d92ac [file] [log] [blame]
Harald Alvestrand2ee104d2015-04-28 10:44:521<!doctype html>
2<!--
Dominique Hazael-Massieux772c0602015-06-15 09:02:313This test uses the legacy callback API with no media, and thus does not require fake media devices.
Harald Alvestrand2ee104d2015-04-28 10:44:524-->
5
6<html>
7<head>
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9 <title>RTCPeerConnection No-Media Connection Test</title>
10</head>
11<body>
12 <div id="log"></div>
Harald Alvestrande42bf762015-05-12 08:47:5613 <h2>iceConnectionState info</h2>
14 <div id="stateinfo">
Harald Alvestrand2ee104d2015-04-28 10:44:5215 </div>
16
17 <!-- These files are in place when executing on W3C. -->
18 <script src="/resources/testharness.js"></script>
19 <script src="/resources/testharnessreport.js"></script>
20 <script src="/common/vendor-prefix.js"
21 data-prefixed-objects=
Harald Alvestrande42bf762015-05-12 08:47:5622 '[{"ancestors":["window"], "name":"RTCPeerConnection"},
Harald Alvestrandd6918932015-05-12 10:19:4223 {"ancestors":["window"], "name":"RTCSessionDescription"},
24 {"ancestors":["window"], "name":"RTCIceCandidate"}]'
Harald Alvestrandf50f28c2015-05-11 12:55:4225 >
Harald Alvestrand2ee104d2015-04-28 10:44:5226 </script>
27 <script type="text/javascript">
Harald Alvestrandf50f28c2015-05-11 12:55:4228 var test = async_test('Can set up a basic WebRTC call with no data.');
Harald Alvestrand2ee104d2015-04-28 10:44:5229
30 var gFirstConnection = null;
31 var gSecondConnection = null;
32
33 var onOfferCreated = test.step_func(function(offer) {
Harald Alvestrandd6918932015-05-12 10:19:4234 gFirstConnection.setLocalDescription(offer, ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4235 failed('setLocalDescription first'));
Harald Alvestrand2ee104d2015-04-28 10:44:5236
37 // This would normally go across the application's signaling solution.
38 // In our case, the "signaling" is to call this function.
39 receiveCall(offer.sdp);
40 });
41
42 function receiveCall(offerSdp) {
43
44 var parsedOffer = new RTCSessionDescription({ type: 'offer',
45 sdp: offerSdp });
Harald Alvestrandf50f28c2015-05-11 12:55:4246 // These functions use the legacy interface extensions to RTCPeerConnection.
Harald Alvestrande42bf762015-05-12 08:47:5647 gSecondConnection.setRemoteDescription(parsedOffer,
48 function() {
49 gSecondConnection.createAnswer(onAnswerCreated,
50 failed('createAnswer'));
51 },
52 failed('setRemoteDescription second'));
Harald Alvestrand2ee104d2015-04-28 10:44:5253 };
54
55 var onAnswerCreated = test.step_func(function(answer) {
Harald Alvestrandd6918932015-05-12 10:19:4256 gSecondConnection.setLocalDescription(answer, ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4257 failed('setLocalDescription second'));
Harald Alvestrand2ee104d2015-04-28 10:44:5258
59 // Similarly, this would go over the application's signaling solution.
60 handleAnswer(answer.sdp);
61 });
62
63 function handleAnswer(answerSdp) {
64 var parsedAnswer = new RTCSessionDescription({ type: 'answer',
65 sdp: answerSdp });
Harald Alvestrandd6918932015-05-12 10:19:4266 gFirstConnection.setRemoteDescription(parsedAnswer, ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4267 failed('setRemoteDescription first'));
Harald Alvestrand2ee104d2015-04-28 10:44:5268 };
69
Harald Alvestrandf50f28c2015-05-11 12:55:4270 var onIceCandidateToFirst = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5271 // If event.candidate is null = no more candidates.
72 if (event.candidate) {
Dominique Hazael-Massieux29acbc12015-06-15 09:03:3473 gSecondConnection.addIceCandidate(event.candidate);
Harald Alvestrand2ee104d2015-04-28 10:44:5274 }
Harald Alvestrandf50f28c2015-05-11 12:55:4275 });
Harald Alvestrand2ee104d2015-04-28 10:44:5276
Harald Alvestrandf50f28c2015-05-11 12:55:4277 var onIceCandidateToSecond = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5278 if (event.candidate) {
Dominique Hazael-Massieux29acbc12015-06-15 09:03:3479 gFirstConnection.addIceCandidate(event.candidate);
Harald Alvestrand2ee104d2015-04-28 10:44:5280 }
Harald Alvestrandf50f28c2015-05-11 12:55:4281 });
Harald Alvestrand2ee104d2015-04-28 10:44:5282
83 var onRemoteStream = test.step_func(function(event) {
84 assert_unreached('WebRTC received a stream when there was none');
85 });
86
Harald Alvestrandf50f28c2015-05-11 12:55:4287 var onIceConnectionStateChange = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5288 assert_equals(event.type, 'iceconnectionstatechange');
Harald Alvestrande42bf762015-05-12 08:47:5689 var stateinfo = document.getElementById('stateinfo');
90 stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState
91 + '<br>Second: ' + gSecondConnection.iceConnectionState;
92 // Note: All these combinations are legal states indicating that the
93 // call has connected. All browsers should end up in completed/completed,
94 // but as of this moment, we've chosen to terminate the test early.
Harald Alvestrandd6918932015-05-12 10:19:4295 // TODO: Revise test to ensure completed/completed is reached.
Harald Alvestrande42bf762015-05-12 08:47:5696 if (gFirstConnection.iceConnectionState == 'connected' &&
97 gSecondConnection.iceConnectionState == 'connected') {
98 test.done()
99 }
100 if (gFirstConnection.iceConnectionState == 'connected' &&
101 gSecondConnection.iceConnectionState == 'completed') {
102 test.done()
103 }
Harald Alvestrand2ee104d2015-04-28 10:44:52104 if (gFirstConnection.iceConnectionState == 'completed' &&
105 gSecondConnection.iceConnectionState == 'connected') {
106 test.done()
107 }
Harald Alvestrand2ee104d2015-04-28 10:44:52108 if (gFirstConnection.iceConnectionState == 'completed' &&
109 gSecondConnection.iceConnectionState == 'completed') {
110 test.done()
111 }
Harald Alvestrandf50f28c2015-05-11 12:55:42112 });
Harald Alvestrand2ee104d2015-04-28 10:44:52113
114 // Returns a suitable error callback.
115 function failed(function_name) {
116 return test.step_func(function() {
117 assert_unreached('WebRTC called error callback for ' + function_name);
118 });
119 }
120
Harald Alvestrandd6918932015-05-12 10:19:42121 // Returns a suitable do-nothing.
122 function ignoreSuccess(function_name) {
123 }
124
Harald Alvestrand2ee104d2015-04-28 10:44:52125 // This function starts the test.
126 test.step(function() {
Harald Alvestrandf50f28c2015-05-11 12:55:42127 gFirstConnection = new RTCPeerConnection(null);
Harald Alvestrand2ee104d2015-04-28 10:44:52128 gFirstConnection.onicecandidate = onIceCandidateToFirst;
129 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange;
130
Harald Alvestrandf50f28c2015-05-11 12:55:42131 gSecondConnection = new RTCPeerConnection(null);
Harald Alvestrand2ee104d2015-04-28 10:44:52132 gSecondConnection.onicecandidate = onIceCandidateToSecond;
133 gSecondConnection.onaddstream = onRemoteStream;
134 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange;
135
136 // The offerToReceiveVideo is necessary and sufficient to make
137 // an actual connection.
Harald Alvestrand2ee104d2015-04-28 10:44:52138 gFirstConnection.createOffer(onOfferCreated, failed('createOffer'),
139 {offerToReceiveVideo: true});
140 });
141</script>
142
143</body>
144</html>