OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> | 3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> |
4 <script type="text/javascript" src="webrtc_test_common.js"></script> | 4 <script type="text/javascript" src="webrtc_test_common.js"></script> |
5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
6 $ = function(id) { | 6 $ = function(id) { |
7 return document.getElementById(id); | 7 return document.getElementById(id); |
8 }; | 8 }; |
9 | 9 |
10 window.onerror = function(errorMsg, url, lineNumber, column, errorObj) { | 10 window.onerror = function(errorMsg, url, lineNumber, column, errorObj) { |
11 failTest('Error: ' + errorMsg + '\nScript: ' + url + | 11 failTest('Error: ' + errorMsg + '\nScript: ' + url + |
12 '\nLine: ' + lineNumber + '\nColumn: ' + column + | 12 '\nLine: ' + lineNumber + '\nColumn: ' + column + |
13 '\nStackTrace: ' + errorObj); | 13 '\nStackTrace: ' + errorObj); |
14 } | 14 } |
15 | 15 |
16 var gPeerConnection = null; | 16 var gPeerConnection = null; |
17 var gCertificate = null; | 17 var gCertificate = null; |
| 18 var retrievedCertificate = null; |
| 19 var gRtcConfig = null; |
18 | 20 |
19 // This test creates and sets three offers, calling setConfiguration in | 21 // This test creates and sets three offers, calling setConfiguration in |
20 // between each offer, expecting an ICE restart to be triggered by the next | 22 // between each offer, expecting an ICE restart to be triggered by the next |
21 // offer. | 23 // offer. |
22 function testSetConfiguration() { | 24 function testSetAndGetConfiguration() { |
23 gPeerConnection = new RTCPeerConnection( | 25 RTCPeerConnection.generateCertificate({ name:'ECDSA', namedCurve:'P-256' }) |
24 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', | 26 .then(function(cert) { |
25 rtcpMuxPolicy:'require', certificates:[]}); | 27 gRtcConfig = |
26 // Now test successful cases of setConfiguration. Changes should trigger an | 28 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', |
27 // ICE restart in the next offer. To do this, first we need to trigger an | 29 rtcpMuxPolicy:'require', certificates:[cert]}; |
28 // initial ICE gathering phase and wait until it completes. | 30 gPeerConnection = new RTCPeerConnection(gRtcConfig); |
29 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use that | 31 // Now test successful cases of setConfiguration. Changes should trigger
an |
30 // instead of a "null" candidate. | 32 // ICE restart in the next offer. To do this, first we need to trigger a
n |
31 gPeerConnection.onicecandidate = iceCandidateCallback1; | 33 // initial ICE gathering phase and wait until it completes. |
32 createOfferAndSetLocalDescription(); | 34 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use t
hat |
| 35 // instead of a "null" candidate. |
| 36 gPeerConnection.onicecandidate = iceCandidateCallback1; |
| 37 createOfferAndSetLocalDescription(); |
| 38 var retrievedRtcConfig = gPeerConnection.getConfiguration(); |
| 39 assertRtcConfigEquals(gRtcConfig, retrievedRtcConfig); |
| 40 // Tests that the certificates can be successfully retrieved using |
| 41 // getConfiguration() by re-applying the retrieved certification to the |
| 42 // peerconnection. |
| 43 assertEquals(1, retrievedRtcConfig['certificates'].length) |
| 44 retrievedCertificate = gPeerConnection.getConfiguration()['certificates'
][0]; |
| 45 }); |
33 } | 46 } |
34 | 47 |
35 function iceCandidateCallback1(candidate) { | 48 function iceCandidateCallback1(candidate) { |
36 if (gPeerConnection.iceGatheringState === 'complete') { | 49 if (gPeerConnection.iceGatheringState === 'complete') { |
37 gPeerConnection.onicecandidate = iceCandidateCallback2; | 50 gPeerConnection.onicecandidate = iceCandidateCallback2; |
38 // Policy changed. | 51 // Policy changed. |
39 gPeerConnection.setConfiguration( | 52 gRtcConfig = |
40 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced', | 53 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced', |
41 rtcpMuxPolicy:'require', certificates:[]}); | 54 rtcpMuxPolicy:'require', certificates:[retrievedCertificate]}; |
| 55 gPeerConnection.setConfiguration(gRtcConfig); |
42 createOfferAndSetLocalDescription(); | 56 createOfferAndSetLocalDescription(); |
| 57 assertRtcConfigEquals(gRtcConfig, gPeerConnection.getConfiguration()); |
43 } | 58 } |
44 } | 59 } |
45 | 60 |
46 function iceCandidateCallback2(candidate) { | 61 function iceCandidateCallback2(candidate) { |
47 if (gPeerConnection.iceGatheringState === 'complete') { | 62 if (gPeerConnection.iceGatheringState === 'complete') { |
48 gPeerConnection.onicecandidate = iceCandidateCallback3; | 63 gPeerConnection.onicecandidate = iceCandidateCallback3; |
49 // Servers changed. | 64 // Servers changed. |
50 gPeerConnection.setConfiguration( | 65 gRtcConfig = { |
51 {iceServers:[{urls:'stun:foo.invalid'}], iceTransportPolicy:'all', | 66 iceServers:[ |
52 bundlePolicy:'balanced', rtcpMuxPolicy:'require', certificates:[]}); | 67 { |
| 68 'urls': ['stun:stun.invalid.scom:19302', |
| 69 'stun:stun.invalid2.scom:19302'] |
| 70 }, |
| 71 { |
| 72 'urls': ['turn:turn.invalid.udp?transport=udp'], |
| 73 'credential': 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', |
| 74 'username': '28224511:1379330808' |
| 75 }, |
| 76 { |
| 77 'urls': ['turn:turn.invalid.tcp?transport=tcp'], |
| 78 'credential': 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', |
| 79 'username': '28224511:1379330808' |
| 80 } |
| 81 ], |
| 82 iceTransportPolicy:'all', |
| 83 bundlePolicy:'balanced', |
| 84 rtcpMuxPolicy:'require', |
| 85 certificates:[retrievedCertificate] |
| 86 }; |
| 87 gPeerConnection.setConfiguration(gRtcConfig); |
53 createOfferAndSetLocalDescription(); | 88 createOfferAndSetLocalDescription(); |
| 89 assertRtcConfigEquals(gRtcConfig, gPeerConnection.getConfiguration()); |
54 } | 90 } |
55 } | 91 } |
56 | 92 |
57 function iceCandidateCallback3(candidate) { | 93 function iceCandidateCallback3(candidate) { |
58 // Only wait for 'gathering', since it will take a while for the requests to | 94 // Only wait for 'gathering', since it will take a while for the requests to |
59 // 'foo.invalid' to time out. | 95 // 'foo.invalid' to time out. |
60 if (gPeerConnection.iceGatheringState === 'gathering') { | 96 if (gPeerConnection.iceGatheringState === 'gathering') { |
61 reportTestSuccess(); | 97 reportTestSuccess(); |
62 } | 98 } |
63 } | 99 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 150 } |
115 | 151 |
116 function assertThrows(func) { | 152 function assertThrows(func) { |
117 try { | 153 try { |
118 func.apply(arguments.slice(start=1)); | 154 func.apply(arguments.slice(start=1)); |
119 failTest('Expected exception to be thrown by: ' + code); | 155 failTest('Expected exception to be thrown by: ' + code); |
120 } catch (e) { | 156 } catch (e) { |
121 } | 157 } |
122 } | 158 } |
123 | 159 |
| 160 function assertRtcConfigEquals(config1, config2) { |
| 161 assertEquals(config1['iceTransportPolicy'], config2['iceTransportPolicy']); |
| 162 assertEquals(config1['bundlePolicy'], config2['bundlePolicy']); |
| 163 assertEquals(config1['rtcpMuxPolicy'], config2['rtcpMuxPolicy']); |
| 164 assertEquals(config1['iceServers'].length, config2['iceServers'].length); |
| 165 for (var i in config1['iceServers']) { |
| 166 var server1 = config1['iceServers'][i]; |
| 167 var server2 = config2['iceServers'][i]; |
| 168 |
| 169 if (!('username' in server1)) { |
| 170 assertEquals("", server2['username']); |
| 171 } else { |
| 172 assertEquals(server1['username'], server2['username']); |
| 173 } |
| 174 |
| 175 if (!('credential' in server1)) { |
| 176 assertEquals("", server2['credential']); |
| 177 } else { |
| 178 assertEquals(server1['credential'], server2['credential']); |
| 179 } |
| 180 |
| 181 if (!('urls' in server1)) { |
| 182 assertEquals(0, server2['urls'].length); |
| 183 } else { |
| 184 assertEquals(server1['urls'].length, server2['urls'].length); |
| 185 for (var j in server1['urls']) { |
| 186 assertEquals(server1['urls'][j], server2['urls'][j]); |
| 187 } |
| 188 } |
| 189 } |
| 190 } |
| 191 |
124 // Helper function to create and apply offer. | 192 // Helper function to create and apply offer. |
125 function createOfferAndSetLocalDescription() { | 193 function createOfferAndSetLocalDescription() { |
126 gPeerConnection.createOffer({offerToReceiveAudio:1}) | 194 gPeerConnection.createOffer({offerToReceiveAudio:1}) |
127 .then(function(offer) { | 195 .then(function(offer) { |
128 console.log("Setting offer:\n" + offer.sdp); | 196 console.log("Setting offer:\n" + offer.sdp); |
129 gPeerConnection.setLocalDescription(offer).then( | 197 gPeerConnection.setLocalDescription(offer).then( |
130 function() {}, | 198 function() {}, |
131 function() { failTest('Failed to set local description.') } | 199 function() { failTest('Failed to set local description.') } |
132 ); | 200 ); |
133 }, | 201 }, |
134 function() { | 202 function() { |
135 failTest('Failed to generate offer.') | 203 failTest('Failed to generate offer.') |
136 } | 204 } |
137 ); | 205 ); |
138 } | 206 } |
139 | 207 |
140 </script> | 208 </script> |
141 </head> | 209 </head> |
142 <body> | 210 <body> |
143 </body> | 211 </body> |
144 </html> | 212 </html> |
OLD | NEW |