| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <!-- |
| Dominique Hazael-Massieux | 772c060 | 2015-06-15 09:02:31 | [diff] [blame] | 3 | This test uses the legacy callback API with no media, and thus does not require fake media devices. |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 4 | --> |
| 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 Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 13 | <h2>iceConnectionState info</h2> |
| 14 | <div id="stateinfo"> |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 15 | </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 Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 20 | <script type="text/javascript"> |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 21 | var test = async_test('Can set up a basic WebRTC call with no data.'); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 22 | |
| 23 | var gFirstConnection = null; |
| 24 | var gSecondConnection = null; |
| 25 | |
| 26 | var onOfferCreated = test.step_func(function(offer) { |
| Harald Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 27 | gFirstConnection.setLocalDescription(offer, ignoreSuccess, |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 28 | failed('setLocalDescription first')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 29 | |
| 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 Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 39 | // These functions use the legacy interface extensions to RTCPeerConnection. |
| Harald Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 40 | gSecondConnection.setRemoteDescription(parsedOffer, |
| 41 | function() { |
| 42 | gSecondConnection.createAnswer(onAnswerCreated, |
| 43 | failed('createAnswer')); |
| 44 | }, |
| 45 | failed('setRemoteDescription second')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | var onAnswerCreated = test.step_func(function(answer) { |
| Harald Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 49 | gSecondConnection.setLocalDescription(answer, ignoreSuccess, |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 50 | failed('setLocalDescription second')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 51 | |
| 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 Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 59 | gFirstConnection.setRemoteDescription(parsedAnswer, ignoreSuccess, |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 60 | failed('setRemoteDescription first')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 61 | }; |
| 62 | |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 63 | var onIceCandidateToFirst = test.step_func(function(event) { |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 64 | // If event.candidate is null = no more candidates. |
| 65 | if (event.candidate) { |
| Dominique Hazael-Massieux | 29acbc1 | 2015-06-15 09:03:34 | [diff] [blame] | 66 | gSecondConnection.addIceCandidate(event.candidate); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 67 | } |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 68 | }); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 69 | |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 70 | var onIceCandidateToSecond = test.step_func(function(event) { |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 71 | if (event.candidate) { |
| Dominique Hazael-Massieux | 29acbc1 | 2015-06-15 09:03:34 | [diff] [blame] | 72 | gFirstConnection.addIceCandidate(event.candidate); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 73 | } |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 74 | }); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 75 | |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 76 | var onIceConnectionStateChange = test.step_func(function(event) { |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 77 | assert_equals(event.type, 'iceconnectionstatechange'); |
| Dominique Hazael-Massieux | 027c866 | 2015-06-16 07:45:10 | [diff] [blame] | 78 | assert_not_equals(gFirstConnection.iceConnectionState, "failed", "iceConnectionState of first connection"); |
| 79 | assert_not_equals(gSecondConnection.iceConnectionState, "failed", "iceConnectionState of second connection"); |
| Harald Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 80 | 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 Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 86 | // TODO: Revise test to ensure completed/completed is reached. |
| Harald Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 87 | 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 Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 95 | if (gFirstConnection.iceConnectionState == 'completed' && |
| 96 | gSecondConnection.iceConnectionState == 'connected') { |
| 97 | test.done() |
| 98 | } |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 99 | if (gFirstConnection.iceConnectionState == 'completed' && |
| 100 | gSecondConnection.iceConnectionState == 'completed') { |
| 101 | test.done() |
| 102 | } |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 103 | }); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 104 | |
| 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 Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 112 | // Returns a suitable do-nothing. |
| 113 | function ignoreSuccess(function_name) { |
| 114 | } |
| 115 | |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 116 | // This function starts the test. |
| 117 | test.step(function() { |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 118 | gFirstConnection = new RTCPeerConnection(null); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 119 | gFirstConnection.onicecandidate = onIceCandidateToFirst; |
| 120 | gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
| 121 | |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 122 | gSecondConnection = new RTCPeerConnection(null); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 123 | gSecondConnection.onicecandidate = onIceCandidateToSecond; |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 124 | gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
| 125 | |
| 126 | // The offerToReceiveVideo is necessary and sufficient to make |
| 127 | // an actual connection. |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 128 | gFirstConnection.createOffer(onOfferCreated, failed('createOffer'), |
| 129 | {offerToReceiveVideo: true}); |
| 130 | }); |
| 131 | </script> |
| 132 | |
| 133 | </body> |
| 134 | </html> |