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() { |
foolip
2017/03/21 08:37:14
It looks like much of this could be tested in web-
| |
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:[], iceCandidatePoolSize:0}); | 27 gRtcConfig = |
26 // Change ICE candidate pool size, which will succeed before | 28 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', |
27 // setLocalDescription is called. | 29 rtcpMuxPolicy:'require', certificates:[cert]}; |
28 gPeerConnection.setConfiguration( | 30 gPeerConnection = new RTCPeerConnection(gRtcConfig); |
29 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', | 31 // Now test successful cases of setConfiguration. Changes should trigger an |
30 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1}); | 32 // ICE restart in the next offer. To do this, first we need to trigger a n |
31 // Now test successful cases of setConfiguration. Changes should trigger an | 33 // initial ICE gathering phase and wait until it completes. |
32 // ICE restart in the next offer. To do this, first we need to trigger an | 34 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use t hat |
33 // initial ICE gathering phase and wait until it completes. | 35 // instead of a "null" candidate. |
34 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use that | 36 gPeerConnection.onicecandidate = iceCandidateCallback1; |
35 // instead of a "null" candidate. | 37 createOfferAndSetLocalDescription(); |
36 gPeerConnection.onicecandidate = iceCandidateCallback1; | 38 var retrievedRtcConfig = gPeerConnection.getConfiguration(); |
37 createOfferAndSetLocalDescription(); | 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 }); | |
38 } | 46 } |
39 | 47 |
40 function iceCandidateCallback1(candidate) { | 48 function iceCandidateCallback1(candidate) { |
41 if (gPeerConnection.iceGatheringState === 'complete') { | 49 if (gPeerConnection.iceGatheringState === 'complete') { |
42 gPeerConnection.onicecandidate = iceCandidateCallback2; | 50 gPeerConnection.onicecandidate = iceCandidateCallback2; |
43 // Policy changed. | 51 // Policy changed. |
44 gPeerConnection.setConfiguration( | 52 gRtcConfig = |
45 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced', | 53 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced', |
46 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1}); | 54 rtcpMuxPolicy:'require', certificates:[retrievedCertificate]}; |
55 gPeerConnection.setConfiguration(gRtcConfig); | |
47 createOfferAndSetLocalDescription(); | 56 createOfferAndSetLocalDescription(); |
57 assertRtcConfigEquals(gRtcConfig, gPeerConnection.getConfiguration()); | |
48 } | 58 } |
49 } | 59 } |
50 | 60 |
51 function iceCandidateCallback2(candidate) { | 61 function iceCandidateCallback2(candidate) { |
52 if (gPeerConnection.iceGatheringState === 'complete') { | 62 if (gPeerConnection.iceGatheringState === 'complete') { |
53 gPeerConnection.onicecandidate = iceCandidateCallback3; | 63 gPeerConnection.onicecandidate = iceCandidateCallback3; |
54 // Servers changed. | 64 // Servers changed. |
55 gPeerConnection.setConfiguration( | 65 gRtcConfig = { |
56 {iceServers:[{urls:'stun:foo.invalid'}], iceTransportPolicy:'all', | 66 iceServers:[ |
57 bundlePolicy:'balanced', rtcpMuxPolicy:'require', certificates:[], | 67 { |
58 iceCandidatePoolSize:1}); | 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); | |
59 createOfferAndSetLocalDescription(); | 88 createOfferAndSetLocalDescription(); |
89 assertRtcConfigEquals(gRtcConfig, gPeerConnection.getConfiguration()); | |
60 } | 90 } |
61 } | 91 } |
62 | 92 |
63 function iceCandidateCallback3(candidate) { | 93 function iceCandidateCallback3(candidate) { |
64 // 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 |
65 // 'foo.invalid' to time out. | 95 // 'foo.invalid' to time out. |
66 if (gPeerConnection.iceGatheringState === 'gathering') { | 96 if (gPeerConnection.iceGatheringState === 'gathering') { |
67 reportTestSuccess(); | 97 reportTestSuccess(); |
68 } | 98 } |
69 } | 99 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 } | 173 } |
144 | 174 |
145 function assertThrows(func) { | 175 function assertThrows(func) { |
146 try { | 176 try { |
147 func.apply(arguments.slice(start=1)); | 177 func.apply(arguments.slice(start=1)); |
148 failTest('Expected exception to be thrown by: ' + code); | 178 failTest('Expected exception to be thrown by: ' + code); |
149 } catch (e) { | 179 } catch (e) { |
150 } | 180 } |
151 } | 181 } |
152 | 182 |
183 function assertRtcConfigEquals(config1, config2) { | |
184 assertEquals(config1['iceTransportPolicy'], config2['iceTransportPolicy']); | |
185 assertEquals(config1['bundlePolicy'], config2['bundlePolicy']); | |
186 assertEquals(config1['rtcpMuxPolicy'], config2['rtcpMuxPolicy']); | |
187 assertEquals(config1['iceServers'].length, config2['iceServers'].length); | |
188 for (var i in config1['iceServers']) { | |
189 var server1 = config1['iceServers'][i]; | |
190 var server2 = config2['iceServers'][i]; | |
191 | |
192 if (!('username' in server1)) { | |
193 assertEquals("", server2['username']); | |
194 } else { | |
195 assertEquals(server1['username'], server2['username']); | |
196 } | |
197 | |
198 if (!('credential' in server1)) { | |
199 assertEquals("", server2['credential']); | |
200 } else { | |
201 assertEquals(server1['credential'], server2['credential']); | |
202 } | |
203 | |
204 if (!('urls' in server1)) { | |
205 assertEquals(0, server2['urls'].length); | |
206 } else { | |
207 assertEquals(server1['urls'].length, server2['urls'].length); | |
foolip
2017/03/21 08:37:14
I think this will fail due to normalization if the
| |
208 for (var j in server1['urls']) { | |
209 assertEquals(server1['urls'][j], server2['urls'][j]); | |
210 } | |
211 } | |
212 } | |
213 } | |
214 | |
153 // Helper function to create and apply offer. | 215 // Helper function to create and apply offer. |
154 function createOfferAndSetLocalDescription() { | 216 function createOfferAndSetLocalDescription() { |
155 gPeerConnection.createOffer({offerToReceiveAudio:1}) | 217 gPeerConnection.createOffer({offerToReceiveAudio:1}) |
156 .then(function(offer) { | 218 .then(function(offer) { |
157 console.log("Setting offer:\n" + offer.sdp); | 219 console.log("Setting offer:\n" + offer.sdp); |
158 gPeerConnection.setLocalDescription(offer).then( | 220 gPeerConnection.setLocalDescription(offer).then( |
159 function() {}, | 221 function() {}, |
160 function() { failTest('Failed to set local description.') } | 222 function() { failTest('Failed to set local description.') } |
161 ); | 223 ); |
162 }, | 224 }, |
163 function() { | 225 function() { |
164 failTest('Failed to generate offer.') | 226 failTest('Failed to generate offer.') |
165 } | 227 } |
166 ); | 228 ); |
167 } | 229 } |
168 | 230 |
169 </script> | 231 </script> |
170 </head> | 232 </head> |
171 <body> | 233 <body> |
172 </body> | 234 </body> |
173 </html> | 235 </html> |
OLD | NEW |