Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: content/test/data/media/peerconnection-setAndGetConfiguration.html

Issue 2706563003: Create the API that returns the RTCConfiguration of the PeerConnection.
Patch Set: rebaselining Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 gRtcConfig = null;
18 19
19 // This test creates and sets three offers, calling setConfiguration in 20 // This test creates and sets three offers, calling setConfiguration in
20 // between each offer, expecting an ICE restart to be triggered by the next 21 // between each offer, expecting an ICE restart to be triggered by the next
21 // offer. 22 // offer.
22 function testSetConfiguration() { 23 function testSetAndGetConfiguration() {
23 gPeerConnection = new RTCPeerConnection( 24 gRtcConfig =
24 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', 25 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced',
25 rtcpMuxPolicy:'require', certificates:[]}); 26 rtcpMuxPolicy:'require', certificates:[]};
27 gPeerConnection = new RTCPeerConnection(gRtcConfig);
26 // Now test successful cases of setConfiguration. Changes should trigger an 28 // Now test successful cases of setConfiguration. Changes should trigger an
27 // ICE restart in the next offer. To do this, first we need to trigger an 29 // ICE restart in the next offer. To do this, first we need to trigger an
28 // initial ICE gathering phase and wait until it completes. 30 // initial ICE gathering phase and wait until it completes.
29 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use that 31 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use that
30 // instead of a "null" candidate. 32 // instead of a "null" candidate.
31 gPeerConnection.onicecandidate = iceCandidateCallback1; 33 gPeerConnection.onicecandidate = iceCandidateCallback1;
32 createOfferAndSetLocalDescription(); 34 createOfferAndSetLocalDescription();
35 assertRtcConfigEquals(gRtcConfig, gPeerConnection.getConfiguration());
33 } 36 }
34 37
35 function iceCandidateCallback1(candidate) { 38 function iceCandidateCallback1(candidate) {
36 if (gPeerConnection.iceGatheringState === 'complete') { 39 if (gPeerConnection.iceGatheringState === 'complete') {
37 gPeerConnection.onicecandidate = iceCandidateCallback2; 40 gPeerConnection.onicecandidate = iceCandidateCallback2;
38 // Policy changed. 41 // Policy changed.
39 gPeerConnection.setConfiguration( 42 gRtcConfig =
40 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced', 43 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced',
41 rtcpMuxPolicy:'require', certificates:[]}); 44 rtcpMuxPolicy:'require', certificates:[]};
45 gPeerConnection.setConfiguration(gRtcConfig);
42 createOfferAndSetLocalDescription(); 46 createOfferAndSetLocalDescription();
47 assertRtcConfigEquals(gRtcConfig, gPeerConnection.getConfiguration());
43 } 48 }
44 } 49 }
45 50
46 function iceCandidateCallback2(candidate) { 51 function iceCandidateCallback2(candidate) {
47 if (gPeerConnection.iceGatheringState === 'complete') { 52 if (gPeerConnection.iceGatheringState === 'complete') {
48 gPeerConnection.onicecandidate = iceCandidateCallback3; 53 gPeerConnection.onicecandidate = iceCandidateCallback3;
49 // Servers changed. 54 // Servers changed.
50 gPeerConnection.setConfiguration( 55 gRtcConfig = {
51 {iceServers:[{urls:'stun:foo.invalid'}], iceTransportPolicy:'all', 56 iceServers:[
52 bundlePolicy:'balanced', rtcpMuxPolicy:'require', certificates:[]}); 57 {
58 'urls': ['stun:stun.invalid.scom:19302',
59 'stun:stun.invalid2.scom:19302']
60 },
61 {
62 'urls': ['turn:turn.invalid.udp?transport=udp'],
63 'credential': 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
64 'username': '28224511:1379330808'
65 },
66 {
67 'urls': ['turn:turn.invalid.tcp?transport=tcp'],
68 'credential': 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
69 'username': '28224511:1379330808'
70 }
71 ],
72 iceTransportPolicy:'all',
73 bundlePolicy:'balanced',
74 rtcpMuxPolicy:'require',
75 certificates:[]
76 };
77 gPeerConnection.setConfiguration(gRtcConfig);
53 createOfferAndSetLocalDescription(); 78 createOfferAndSetLocalDescription();
79 assertRtcConfigEquals(gRtcConfig, gPeerConnection.getConfiguration());
54 } 80 }
55 } 81 }
56 82
57 function iceCandidateCallback3(candidate) { 83 function iceCandidateCallback3(candidate) {
58 // Only wait for 'gathering', since it will take a while for the requests to 84 // Only wait for 'gathering', since it will take a while for the requests to
59 // 'foo.invalid' to time out. 85 // 'foo.invalid' to time out.
60 if (gPeerConnection.iceGatheringState === 'gathering') { 86 if (gPeerConnection.iceGatheringState === 'gathering') {
61 reportTestSuccess(); 87 reportTestSuccess();
62 } 88 }
63 } 89 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 140 }
115 141
116 function assertThrows(func) { 142 function assertThrows(func) {
117 try { 143 try {
118 func.apply(arguments.slice(start=1)); 144 func.apply(arguments.slice(start=1));
119 failTest('Expected exception to be thrown by: ' + code); 145 failTest('Expected exception to be thrown by: ' + code);
120 } catch (e) { 146 } catch (e) {
121 } 147 }
122 } 148 }
123 149
150 function assertRtcConfigEquals(config1, config2) {
151 assertEquals(config1['iceTransportPolicy'], config2['iceTransportPolicy']);
152 assertEquals(config1['bundlePolicy'], config2['bundlePolicy']);
153 assertEquals(config1['rtcpMuxPolicy'], config2['rtcpMuxPolicy']);
154 assertEquals(config1['iceServers'].length, config2['iceServers'].length);
155 for (var i in config1['iceServers']) {
156 var server1 = config1['iceServers'][i];
157 var server2 = config2['iceServers'][i];
158
159 if (!('username' in server1)) {
160 assertEquals("", server2['username']);
161 } else {
162 assertEquals(server1['username'], server2['username']);
163 }
164
165 if (!('credential' in server1)) {
166 assertEquals("", server2['credential']);
167 } else {
168 assertEquals(server1['credential'], server2['credential']);
169 }
170
171 if (!('urls' in server1)) {
172 assertEquals(0, server2['urls'].length);
173 } else {
174 assertEquals(server1['urls'].length, server2['urls'].length);
175 for (var j in server1['urls']) {
176 assertEquals(server1['urls'][j], server2['urls'][j]);
177 }
178 }
179 }
180 }
181
124 // Helper function to create and apply offer. 182 // Helper function to create and apply offer.
125 function createOfferAndSetLocalDescription() { 183 function createOfferAndSetLocalDescription() {
126 gPeerConnection.createOffer({offerToReceiveAudio:1}) 184 gPeerConnection.createOffer({offerToReceiveAudio:1})
127 .then(function(offer) { 185 .then(function(offer) {
128 console.log("Setting offer:\n" + offer.sdp); 186 console.log("Setting offer:\n" + offer.sdp);
129 gPeerConnection.setLocalDescription(offer).then( 187 gPeerConnection.setLocalDescription(offer).then(
130 function() {}, 188 function() {},
131 function() { failTest('Failed to set local description.') } 189 function() { failTest('Failed to set local description.') }
132 ); 190 );
133 }, 191 },
134 function() { 192 function() {
135 failTest('Failed to generate offer.') 193 failTest('Failed to generate offer.')
136 } 194 }
137 ); 195 );
138 } 196 }
139 197
140 </script> 198 </script>
141 </head> 199 </head>
142 <body> 200 <body>
143 </body> 201 </body>
144 </html> 202 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698