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

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

Issue 904823002: webrtc: Fixes WebRtcBrowserTest to use DOM attributes correctly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed a review comment. Created 5 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
« no previous file with comments | « no previous file | 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 * Returns a string on the format ok-(JSON encoded session description). 50 * Returns a string on the format ok-(JSON encoded session description).
51 * 51 *
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-' + stringifyDOMObject_(localOffer));
61 }, 61 },
62 function(error) { failure_('createOffer', error); }, 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 *
(...skipping 11 matching lines...) Expand all
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(error) { failure_('setRemoteDescription', error); }); 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-' + stringifyDOMObject_(answer));
93 }, 93 },
94 function(error) { failure_('createAnswer', error); }, 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.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 * 171 *
172 * Returns a JSON-encoded array of RTCIceCandidate instances to the test. 172 * Returns a JSON-encoded array of RTCIceCandidate instances to the test.
173 */ 173 */
174 function getAllIceCandidates() { 174 function getAllIceCandidates() {
175 if (peerConnection_().iceGatheringState != 'complete') { 175 if (peerConnection_().iceGatheringState != 'complete') {
176 console.log('Still ICE gathering - waiting...'); 176 console.log('Still ICE gathering - waiting...');
177 setTimeout(getAllIceCandidates, 100); 177 setTimeout(getAllIceCandidates, 100);
178 return; 178 return;
179 } 179 }
180 180
181 returnToTest(JSON.stringify(gIceCandidates)); 181 returnToTest(stringifyDOMObject_(gIceCandidates));
182 } 182 }
183 183
184 /** 184 /**
185 * Receives ICE candidates from the peer. 185 * Receives ICE candidates from the peer.
186 * 186 *
187 * Returns ok-received-candidates to the test on success. 187 * Returns ok-received-candidates to the test on success.
188 * 188 *
189 * @param iceCandidatesJson a JSON-encoded array of RTCIceCandidate instances. 189 * @param iceCandidatesJson a JSON-encoded array of RTCIceCandidate instances.
190 */ 190 */
191 function receiveIceCandidates(iceCandidatesJson) { 191 function receiveIceCandidates(iceCandidatesJson) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return gPeerConnection; 238 return gPeerConnection;
239 } 239 }
240 240
241 /** @private */ 241 /** @private */
242 function success_(method) { 242 function success_(method) {
243 debug(method + '(): success.'); 243 debug(method + '(): success.');
244 } 244 }
245 245
246 /** @private */ 246 /** @private */
247 function failure_(method, error) { 247 function failure_(method, error) {
248 throw failTest(method + '() failed: ' + JSON.stringify(error)); 248 throw failTest(method + '() failed: ' + stringifyDOMObject_(error));
249 } 249 }
250 250
251 /** @private */ 251 /** @private */
252 function iceCallback_(event) { 252 function iceCallback_(event) {
253 if (event.candidate) 253 if (event.candidate)
254 gIceCandidates.push(event.candidate); 254 gIceCandidates.push(event.candidate);
255 } 255 }
256 256
257 /** @private */ 257 /** @private */
258 function setLocalDescription(peerConnection, sessionDescription) { 258 function setLocalDescription(peerConnection, sessionDescription) {
(...skipping 14 matching lines...) Expand all
273 attachMediaStream(videoTag, event.stream); 273 attachMediaStream(videoTag, event.stream);
274 } 274 }
275 275
276 /** @private */ 276 /** @private */
277 function removeStreamCallback_(event) { 277 function removeStreamCallback_(event) {
278 debug('Call ended.'); 278 debug('Call ended.');
279 document.getElementById('remote-view').src = ''; 279 document.getElementById('remote-view').src = '';
280 } 280 }
281 281
282 /** 282 /**
283 * Stringifies a DOM object.
284 *
285 * This function stringifies not only own properties but also DOM attributes
286 * which are on a prototype chain. Note that JSON.stringify only stringifies
287 * own properties.
288 * @private
289 */
290 function stringifyDOMObject_(object)
291 {
292 function deepCopy(src) {
293 if (typeof src != "object")
294 return src;
295 var dst = Array.isArray(src) ? [] : {};
296 for (var property in src) {
297 dst[property] = deepCopy(src[property]);
298 }
299 return dst;
300 }
301 return JSON.stringify(deepCopy(object));
302 }
303
304 /**
283 * Parses JSON-encoded session descriptions and ICE candidates. 305 * Parses JSON-encoded session descriptions and ICE candidates.
284 * @private 306 * @private
285 */ 307 */
286 function parseJson_(json) { 308 function parseJson_(json) {
287 // Escape since the \r\n in the SDP tend to get unescaped. 309 // Escape since the \r\n in the SDP tend to get unescaped.
288 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); 310 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n');
289 try { 311 try {
290 return JSON.parse(jsonWithEscapedLineBreaks); 312 return JSON.parse(jsonWithEscapedLineBreaks);
291 } catch (exception) { 313 } catch (exception) {
292 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + 314 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' +
293 exception); 315 exception);
294 } 316 }
295 } 317 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698