| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <!-- |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 3 | This test uses data only, and thus does not require fake media devices. |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 4 | --> |
| 5 | |
| 6 | <html> |
| 7 | <head> |
| 8 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 9 | <title>RTCPeerConnection Data-Only Connection Test with Promises</title> |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 10 | </head> |
| 11 | <body> |
| 12 | <div id="log"></div> |
| 13 | <h2>iceConnectionState info</h2> |
| 14 | <div id="stateinfo"> |
| 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 | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 20 | <script type="text/javascript"> |
| Harald Alvestrand | ba63db8 | 2015-05-19 08:33:40 | [diff] [blame] | 21 | var test = async_test('Can set up a basic WebRTC call with only data using promises.'); |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 22 | |
| 23 | var gFirstConnection = null; |
| 24 | var gSecondConnection = null; |
| 25 | |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 26 | var onIceCandidateToFirst = test.step_func(function(event) { |
| 27 | // If event.candidate is null = no more candidates. |
| 28 | if (event.candidate) { |
| Dominique Hazael-Massieux | a0a5248 | 2015-06-15 09:36:54 | [diff] [blame] | 29 | gSecondConnection.addIceCandidate(event.candidate); |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 30 | } |
| 31 | }); |
| 32 | |
| 33 | var onIceCandidateToSecond = test.step_func(function(event) { |
| 34 | if (event.candidate) { |
| Dominique Hazael-Massieux | a0a5248 | 2015-06-15 09:36:54 | [diff] [blame] | 35 | gFirstConnection.addIceCandidate(event.candidate); |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 36 | } |
| 37 | }); |
| 38 | |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 39 | var onIceConnectionStateChange = test.step_func(function(event) { |
| 40 | assert_equals(event.type, 'iceconnectionstatechange'); |
| 41 | var stateinfo = document.getElementById('stateinfo'); |
| 42 | stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState |
| 43 | + '<br>Second: ' + gSecondConnection.iceConnectionState; |
| 44 | // Note: All these combinations are legal states indicating that the |
| 45 | // call has connected. All browsers should end up in completed/completed, |
| 46 | // but as of this moment, we've chosen to terminate the test early. |
| 47 | // TODO: Revise test to ensure completed/completed is reached. |
| 48 | if (gFirstConnection.iceConnectionState == 'connected' && |
| 49 | gSecondConnection.iceConnectionState == 'connected') { |
| 50 | test.done() |
| 51 | } |
| 52 | if (gFirstConnection.iceConnectionState == 'connected' && |
| 53 | gSecondConnection.iceConnectionState == 'completed') { |
| 54 | test.done() |
| 55 | } |
| 56 | if (gFirstConnection.iceConnectionState == 'completed' && |
| 57 | gSecondConnection.iceConnectionState == 'connected') { |
| 58 | test.done() |
| 59 | } |
| 60 | if (gFirstConnection.iceConnectionState == 'completed' && |
| 61 | gSecondConnection.iceConnectionState == 'completed') { |
| 62 | test.done() |
| 63 | } |
| 64 | }); |
| 65 | |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 66 | // This function starts the test. |
| 67 | test.step(function() { |
| 68 | gFirstConnection = new RTCPeerConnection(null); |
| 69 | gFirstConnection.onicecandidate = onIceCandidateToFirst; |
| 70 | gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
| 71 | |
| 72 | gSecondConnection = new RTCPeerConnection(null); |
| 73 | gSecondConnection.onicecandidate = onIceCandidateToSecond; |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 74 | gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
| 75 | |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 76 | // The createDataChannel is necessary and sufficient to make |
| 77 | // sure the ICE connection be attempted. |
| 78 | gFirstConnection.createDataChannel('channel'); |
| Harald Alvestrand | 4ec420d | 2015-05-18 14:31:52 | [diff] [blame] | 79 | |
| Harald Alvestrand | 1a59665 | 2015-05-19 08:45:32 | [diff] [blame] | 80 | var atStep = 'Create offer'; |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 81 | |
| 82 | gFirstConnection.createOffer() |
| 83 | .then(function(offer) { |
| Harald Alvestrand | f7a8539 | 2015-05-20 08:05:15 | [diff] [blame] | 84 | atStep = 'Set local description at first'; |
| 85 | return gFirstConnection.setLocalDescription(offer); |
| 86 | }) |
| 87 | .then(function() { |
| 88 | atStep = 'Set remote description at second'; |
| 89 | return gSecondConnection.setRemoteDescription( |
| 90 | gFirstConnection.localDescription); |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 91 | }) |
| 92 | .then(function() { |
| Harald Alvestrand | 1a59665 | 2015-05-19 08:45:32 | [diff] [blame] | 93 | atStep = 'Create answer'; |
| Dominique Hazael-Massieux | 7194876 | 2015-06-15 09:01:11 | [diff] [blame] | 94 | return gSecondConnection.createAnswer(); |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 95 | }) |
| 96 | .then(function(answer) { |
| Harald Alvestrand | f7a8539 | 2015-05-20 08:05:15 | [diff] [blame] | 97 | atStep = 'Set local description at second'; |
| 98 | return gSecondConnection.setLocalDescription(answer); |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 99 | }) |
| 100 | .then(function() { |
| Harald Alvestrand | f7a8539 | 2015-05-20 08:05:15 | [diff] [blame] | 101 | atStep = 'Set remote description at first'; |
| 102 | return gFirstConnection.setRemoteDescription( |
| 103 | gSecondConnection.localDescription); |
| 104 | }) |
| 105 | .then(function() { |
| 106 | atStep = 'Negotiation completed'; |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 107 | }) |
| 108 | .catch(test.step_func(function(e) { |
| Harald Alvestrand | ba63db8 | 2015-05-19 08:33:40 | [diff] [blame] | 109 | assert_unreached('Error ' + e.name + ': ' + e.message + |
| Harald Alvestrand | 698efbc | 2015-05-18 08:53:05 | [diff] [blame] | 110 | ' happened at step ' + atStep); |
| 111 | })); |
| Harald Alvestrand | 168935a | 2015-05-13 08:23:14 | [diff] [blame] | 112 | }); |
| 113 | </script> |
| 114 | |
| 115 | </body> |
| 116 | </html> |