blob: c4979e8521478a0f8175a5f945cd217f8c60d548 [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>
Harald Alvestrand2ee104d2015-04-28 10:44:5220 <script type="text/javascript">
Harald Alvestrandf50f28c2015-05-11 12:55:4221 var test = async_test('Can set up a basic WebRTC call with no data.');
Harald Alvestrand2ee104d2015-04-28 10:44:5222
23 var gFirstConnection = null;
24 var gSecondConnection = null;
25
26 var onOfferCreated = test.step_func(function(offer) {
Harald Alvestrandd6918932015-05-12 10:19:4227 gFirstConnection.setLocalDescription(offer, ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4228 failed('setLocalDescription first'));
Harald Alvestrand2ee104d2015-04-28 10:44:5229
30 // This would normally go across the application's signaling solution.
31 // In our case, the "signaling" is to call this function.
32 receiveCall(offer.sdp);
33 });
34
35 function receiveCall(offerSdp) {
36
37 var parsedOffer = new RTCSessionDescription({ type: 'offer',
38 sdp: offerSdp });
Harald Alvestrandf50f28c2015-05-11 12:55:4239 // These functions use the legacy interface extensions to RTCPeerConnection.
Harald Alvestrande42bf762015-05-12 08:47:5640 gSecondConnection.setRemoteDescription(parsedOffer,
41 function() {
42 gSecondConnection.createAnswer(onAnswerCreated,
43 failed('createAnswer'));
44 },
45 failed('setRemoteDescription second'));
Harald Alvestrand2ee104d2015-04-28 10:44:5246 };
47
48 var onAnswerCreated = test.step_func(function(answer) {
Harald Alvestrandd6918932015-05-12 10:19:4249 gSecondConnection.setLocalDescription(answer, ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4250 failed('setLocalDescription second'));
Harald Alvestrand2ee104d2015-04-28 10:44:5251
52 // Similarly, this would go over the application's signaling solution.
53 handleAnswer(answer.sdp);
54 });
55
56 function handleAnswer(answerSdp) {
57 var parsedAnswer = new RTCSessionDescription({ type: 'answer',
58 sdp: answerSdp });
Harald Alvestrandd6918932015-05-12 10:19:4259 gFirstConnection.setRemoteDescription(parsedAnswer, ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4260 failed('setRemoteDescription first'));
Harald Alvestrand2ee104d2015-04-28 10:44:5261 };
62
Harald Alvestrandf50f28c2015-05-11 12:55:4263 var onIceCandidateToFirst = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5264 // If event.candidate is null = no more candidates.
65 if (event.candidate) {
Dominique Hazael-Massieux29acbc12015-06-15 09:03:3466 gSecondConnection.addIceCandidate(event.candidate);
Harald Alvestrand2ee104d2015-04-28 10:44:5267 }
Harald Alvestrandf50f28c2015-05-11 12:55:4268 });
Harald Alvestrand2ee104d2015-04-28 10:44:5269
Harald Alvestrandf50f28c2015-05-11 12:55:4270 var onIceCandidateToSecond = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5271 if (event.candidate) {
Dominique Hazael-Massieux29acbc12015-06-15 09:03:3472 gFirstConnection.addIceCandidate(event.candidate);
Harald Alvestrand2ee104d2015-04-28 10:44:5273 }
Harald Alvestrandf50f28c2015-05-11 12:55:4274 });
Harald Alvestrand2ee104d2015-04-28 10:44:5275
Harald Alvestrandf50f28c2015-05-11 12:55:4276 var onIceConnectionStateChange = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5277 assert_equals(event.type, 'iceconnectionstatechange');
Dominique Hazael-Massieux027c8662015-06-16 07:45:1078 assert_not_equals(gFirstConnection.iceConnectionState, "failed", "iceConnectionState of first connection");
79 assert_not_equals(gSecondConnection.iceConnectionState, "failed", "iceConnectionState of second connection");
Harald Alvestrande42bf762015-05-12 08:47:5680 var stateinfo = document.getElementById('stateinfo');
81 stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState
82 + '<br>Second: ' + gSecondConnection.iceConnectionState;
83 // Note: All these combinations are legal states indicating that the
84 // call has connected. All browsers should end up in completed/completed,
85 // but as of this moment, we've chosen to terminate the test early.
Harald Alvestrandd6918932015-05-12 10:19:4286 // TODO: Revise test to ensure completed/completed is reached.
Harald Alvestrande42bf762015-05-12 08:47:5687 if (gFirstConnection.iceConnectionState == 'connected' &&
88 gSecondConnection.iceConnectionState == 'connected') {
89 test.done()
90 }
91 if (gFirstConnection.iceConnectionState == 'connected' &&
92 gSecondConnection.iceConnectionState == 'completed') {
93 test.done()
94 }
Harald Alvestrand2ee104d2015-04-28 10:44:5295 if (gFirstConnection.iceConnectionState == 'completed' &&
96 gSecondConnection.iceConnectionState == 'connected') {
97 test.done()
98 }
Harald Alvestrand2ee104d2015-04-28 10:44:5299 if (gFirstConnection.iceConnectionState == 'completed' &&
100 gSecondConnection.iceConnectionState == 'completed') {
101 test.done()
102 }
Harald Alvestrandf50f28c2015-05-11 12:55:42103 });
Harald Alvestrand2ee104d2015-04-28 10:44:52104
105 // Returns a suitable error callback.
106 function failed(function_name) {
107 return test.step_func(function() {
108 assert_unreached('WebRTC called error callback for ' + function_name);
109 });
110 }
111
Harald Alvestrandd6918932015-05-12 10:19:42112 // Returns a suitable do-nothing.
113 function ignoreSuccess(function_name) {
114 }
115
Harald Alvestrand2ee104d2015-04-28 10:44:52116 // This function starts the test.
117 test.step(function() {
Harald Alvestrandf50f28c2015-05-11 12:55:42118 gFirstConnection = new RTCPeerConnection(null);
Harald Alvestrand2ee104d2015-04-28 10:44:52119 gFirstConnection.onicecandidate = onIceCandidateToFirst;
120 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange;
121
Harald Alvestrandf50f28c2015-05-11 12:55:42122 gSecondConnection = new RTCPeerConnection(null);
Harald Alvestrand2ee104d2015-04-28 10:44:52123 gSecondConnection.onicecandidate = onIceCandidateToSecond;
Harald Alvestrand2ee104d2015-04-28 10:44:52124 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange;
125
126 // The offerToReceiveVideo is necessary and sufficient to make
127 // an actual connection.
Harald Alvestrand2ee104d2015-04-28 10:44:52128 gFirstConnection.createOffer(onOfferCreated, failed('createOffer'),
129 {offerToReceiveVideo: true});
130 });
131</script>
132
133</body>
134</html>