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

Side by Side Diff: chrome/test/data/webrtc/peerconnection.js

Issue 306033004: Now catches the error message from RTCPeerConnection and createAnswer/Offer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase error Created 6 years, 6 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
« no previous file with comments | « chrome/test/data/webrtc/manual/peerconnection_manual.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright 2014 The Chromium Authors. All rights reserved. 2 * Copyright 2014 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /** 7 /**
8 * We need a STUN server for some API calls. 8 * We need a STUN server for some API calls.
9 * @private 9 * @private
10 */ 10 */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 * @param {!Object} constraints Any createOffer constraints. 52 * @param {!Object} constraints Any createOffer constraints.
53 */ 53 */
54 function createLocalOffer(constraints) { 54 function createLocalOffer(constraints) {
55 peerConnection_().createOffer( 55 peerConnection_().createOffer(
56 function(localOffer) { 56 function(localOffer) {
57 success_('createOffer'); 57 success_('createOffer');
58 setLocalDescription(peerConnection, localOffer); 58 setLocalDescription(peerConnection, localOffer);
59 59
60 returnToTest('ok-' + JSON.stringify(localOffer)); 60 returnToTest('ok-' + JSON.stringify(localOffer));
61 }, 61 },
62 function() { failure_('createOffer'); }, 62 function(error) { failure_('createOffer', error); },
63 constraints); 63 constraints);
64 } 64 }
65 65
66 /** 66 /**
67 * Asks this page to accept an offer and generate an answer. 67 * Asks this page to accept an offer and generate an answer.
68 * 68 *
69 * Returns a string on the format ok-(JSON encoded session description). 69 * Returns a string on the format ok-(JSON encoded session description).
70 * 70 *
71 * @param {!string} sessionDescJson A JSON-encoded session description of type 71 * @param {!string} sessionDescJson A JSON-encoded session description of type
72 * 'offer'. 72 * 'offer'.
73 * @param {!Object} constraints Any createAnswer constraints. 73 * @param {!Object} constraints Any createAnswer constraints.
74 */ 74 */
75 function receiveOfferFromPeer(sessionDescJson, constraints) { 75 function receiveOfferFromPeer(sessionDescJson, constraints) {
76 offer = parseJson_(sessionDescJson); 76 offer = parseJson_(sessionDescJson);
77 if (!offer.type) 77 if (!offer.type)
78 failTest('Got invalid session description from peer: ' + sessionDescJson); 78 failTest('Got invalid session description from peer: ' + sessionDescJson);
79 if (offer.type != 'offer') 79 if (offer.type != 'offer')
80 failTest('Expected to receive offer from peer, got ' + offer.type); 80 failTest('Expected to receive offer from peer, got ' + offer.type);
81 81
82 var sessionDescription = new RTCSessionDescription(offer); 82 var sessionDescription = new RTCSessionDescription(offer);
83 peerConnection_().setRemoteDescription( 83 peerConnection_().setRemoteDescription(
84 sessionDescription, 84 sessionDescription,
85 function() { success_('setRemoteDescription'); }, 85 function() { success_('setRemoteDescription'); },
86 function() { failure_('setRemoteDescription'); }); 86 function(error) { failure_('setRemoteDescription', error); });
87 87
88 peerConnection_().createAnswer( 88 peerConnection_().createAnswer(
89 function(answer) { 89 function(answer) {
90 success_('createAnswer'); 90 success_('createAnswer');
91 setLocalDescription(peerConnection, answer); 91 setLocalDescription(peerConnection, answer);
92 returnToTest('ok-' + JSON.stringify(answer)); 92 returnToTest('ok-' + JSON.stringify(answer));
93 }, 93 },
94 function() { failure_('createAnswer'); }, 94 function(error) { failure_('createAnswer', error); },
95 constraints); 95 constraints);
96 } 96 }
97 97
98 /** 98 /**
99 * Asks this page to accept an answer generated by the peer in response to a 99 * Asks this page to accept an answer generated by the peer in response to a
100 * previous offer by this page 100 * previous offer by this page
101 * 101 *
102 * Returns a string ok-accepted-answer on success. 102 * Returns a string ok-accepted-answer on success.
103 * 103 *
104 * @param {!string} sessionDescJson A JSON-encoded session description of type 104 * @param {!string} sessionDescJson A JSON-encoded session description of type
105 * 'answer'. 105 * 'answer'.
106 */ 106 */
107 function receiveAnswerFromPeer(sessionDescJson) { 107 function receiveAnswerFromPeer(sessionDescJson) {
108 answer = parseJson_(sessionDescJson); 108 answer = parseJson_(sessionDescJson);
109 if (!answer.type) 109 if (!answer.type)
110 failTest('Got invalid session description from peer: ' + sessionDescJson); 110 failTest('Got invalid session description from peer: ' + sessionDescJson);
111 if (answer.type != 'answer') 111 if (answer.type != 'answer')
112 failTest('Expected to receive answer from peer, got ' + answer.type); 112 failTest('Expected to receive answer from peer, got ' + answer.type);
113 113
114 var sessionDescription = new RTCSessionDescription(answer); 114 var sessionDescription = new RTCSessionDescription(answer);
115 peerConnection_().setRemoteDescription( 115 peerConnection_().setRemoteDescription(
116 sessionDescription, 116 sessionDescription,
117 function() { 117 function() {
118 success_('setRemoteDescription'); 118 success_('setRemoteDescription');
119 returnToTest('ok-accepted-answer'); 119 returnToTest('ok-accepted-answer');
120 }, 120 },
121 function() { failure_('setRemoteDescription'); }); 121 function(error) { failure_('setRemoteDescription', error); });
122 } 122 }
123 123
124 /** 124 /**
125 * Adds the local stream to the peer connection. You will have to re-negotiate 125 * Adds the local stream to the peer connection. You will have to re-negotiate
126 * the call for this to take effect in the call. 126 * the call for this to take effect in the call.
127 */ 127 */
128 function addLocalStream() { 128 function addLocalStream() {
129 addLocalStreamToPeerConnection(peerConnection_()); 129 addLocalStreamToPeerConnection(peerConnection_());
130 returnToTest('ok-added'); 130 returnToTest('ok-added');
131 } 131 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 * Receives ICE candidates from the peer. 203 * Receives ICE candidates from the peer.
204 * 204 *
205 * Returns ok-received-candidates to the test on success. 205 * Returns ok-received-candidates to the test on success.
206 * 206 *
207 * @param iceCandidatesJson a JSON-encoded array of RTCIceCandidate instances. 207 * @param iceCandidatesJson a JSON-encoded array of RTCIceCandidate instances.
208 */ 208 */
209 function receiveIceCandidates(iceCandidatesJson) { 209 function receiveIceCandidates(iceCandidatesJson) {
210 var iceCandidates = parseJson_(iceCandidatesJson); 210 var iceCandidates = parseJson_(iceCandidatesJson);
211 if (!iceCandidates.length) 211 if (!iceCandidates.length)
212 throw failTest('Received invalid ICE candidate list from peer: ' + 212 throw failTest('Received invalid ICE candidate list from peer: ' +
213 iceCandidatesJson); 213 iceCandidatesJson);
214 214
215 iceCandidates.forEach(function(iceCandidate) { 215 iceCandidates.forEach(function(iceCandidate) {
216 if (!iceCandidate.candidate) 216 if (!iceCandidate.candidate)
217 failTest('Received invalid ICE candidate from peer: ' + 217 failTest('Received invalid ICE candidate from peer: ' +
218 iceCandidatesJson); 218 iceCandidatesJson);
219 219
220 peerConnection_().addIceCandidate(new RTCIceCandidate(iceCandidate)); 220 peerConnection_().addIceCandidate(new RTCIceCandidate(iceCandidate,
221 function() { success_('addIceCandidate'); },
222 function(error) { failure_('addIceCandidate', error); }
223 ));
221 }); 224 });
222 225
223 returnToTest('ok-received-candidates'); 226 returnToTest('ok-received-candidates');
224 } 227 }
225 228
226 /** 229 /**
227 * Returns 230 * Returns
228 */ 231 */
229 function hasSeenCryptoInSdp() { 232 function hasSeenCryptoInSdp() {
230 returnToTest(gHasSeenCryptoInSdp); 233 returnToTest(gHasSeenCryptoInSdp);
(...skipping 22 matching lines...) Expand all
253 return gPeerConnection; 256 return gPeerConnection;
254 } 257 }
255 258
256 /** @private */ 259 /** @private */
257 function success_(method) { 260 function success_(method) {
258 debug(method + '(): success.'); 261 debug(method + '(): success.');
259 } 262 }
260 263
261 /** @private */ 264 /** @private */
262 function failure_(method, error) { 265 function failure_(method, error) {
263 throw failTest(method + '() failed: ' + error); 266 throw failTest(method + '() failed: ' + JSON.stringify(error));
264 } 267 }
265 268
266 /** @private */ 269 /** @private */
267 function iceCallback_(event) { 270 function iceCallback_(event) {
268 if (event.candidate) 271 if (event.candidate)
269 gIceCandidates.push(event.candidate); 272 gIceCandidates.push(event.candidate);
270 } 273 }
271 274
272 /** @private */ 275 /** @private */
273 function setLocalDescription(peerConnection, sessionDescription) { 276 function setLocalDescription(peerConnection, sessionDescription) {
274 if (sessionDescription.sdp.search('a=crypto') != -1 || 277 if (sessionDescription.sdp.search('a=crypto') != -1 ||
275 sessionDescription.sdp.search('a=fingerprint') != -1) 278 sessionDescription.sdp.search('a=fingerprint') != -1)
276 gHasSeenCryptoInSdp = 'crypto-seen'; 279 gHasSeenCryptoInSdp = 'crypto-seen';
277 280
278 peerConnection.setLocalDescription( 281 peerConnection.setLocalDescription(
279 sessionDescription, 282 sessionDescription,
280 function() { success_('setLocalDescription'); }, 283 function() { success_('setLocalDescription'); },
281 function() { failure_('setLocalDescription'); }); 284 function(error) { failure_('setLocalDescription', error); });
282 } 285 }
283 286
284 /** @private */ 287 /** @private */
285 function addStreamCallback_(event) { 288 function addStreamCallback_(event) {
286 debug('Receiving remote stream...'); 289 debug('Receiving remote stream...');
287 var videoTag = document.getElementById('remote-view'); 290 var videoTag = document.getElementById('remote-view');
288 attachMediaStream(videoTag, event.stream); 291 attachMediaStream(videoTag, event.stream);
289 } 292 }
290 293
291 /** @private */ 294 /** @private */
292 function removeStreamCallback_(event) { 295 function removeStreamCallback_(event) {
293 debug('Call ended.'); 296 debug('Call ended.');
294 document.getElementById('remote-view').src = ''; 297 document.getElementById('remote-view').src = '';
295 } 298 }
296 299
297 /** 300 /**
298 * Parses JSON-encoded session descriptions and ICE candidates. 301 * Parses JSON-encoded session descriptions and ICE candidates.
299 * @private 302 * @private
300 */ 303 */
301 function parseJson_(json) { 304 function parseJson_(json) {
302 // Escape since the \r\n in the SDP tend to get unescaped. 305 // Escape since the \r\n in the SDP tend to get unescaped.
303 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); 306 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n');
304 try { 307 try {
305 return JSON.parse(jsonWithEscapedLineBreaks); 308 return JSON.parse(jsonWithEscapedLineBreaks);
306 } catch (exception) { 309 } catch (exception) {
307 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + 310 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' +
308 exception); 311 exception);
309 } 312 }
310 } 313 }
OLDNEW
« no previous file with comments | « chrome/test/data/webrtc/manual/peerconnection_manual.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698