OLD | NEW |
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 * The one and only peer connection in this page. | 8 * The one and only peer connection in this page. |
9 * @private | 9 * @private |
10 */ | 10 */ |
(...skipping 28 matching lines...) Expand all Loading... |
39 * @private | 39 * @private |
40 */ | 40 */ |
41 var gDefaultVideoCodec = null; | 41 var gDefaultVideoCodec = null; |
42 | 42 |
43 /** | 43 /** |
44 * Flag to indicate if Opus Dtx should be enabled. | 44 * Flag to indicate if Opus Dtx should be enabled. |
45 * @private | 45 * @private |
46 */ | 46 */ |
47 var gOpusDtx = false; | 47 var gOpusDtx = false; |
48 | 48 |
| 49 /** @private */ |
| 50 var gNegotiationNeededCount = 0; |
| 51 |
49 // Public interface to tests. These are expected to be called with | 52 // Public interface to tests. These are expected to be called with |
50 // ExecuteJavascript invocations from the browser tests and will return answers | 53 // ExecuteJavascript invocations from the browser tests and will return answers |
51 // through the DOM automation controller. | 54 // through the DOM automation controller. |
52 | 55 |
53 /** | 56 /** |
54 * Creates a peer connection. Must be called before most other public functions | 57 * Creates a peer connection. Must be called before most other public functions |
55 * in this file. Alternatively, see |preparePeerConnectionWithCertificate|. | 58 * in this file. Alternatively, see |preparePeerConnectionWithCertificate|. |
56 * @param {Object} keygenAlgorithm Unless null, this is an |AlgorithmIdentifier| | 59 * @param {Object} keygenAlgorithm Unless null, this is an |AlgorithmIdentifier| |
57 * to be used as parameter to |RTCPeerConnection.generateCertificate|. The | 60 * to be used as parameter to |RTCPeerConnection.generateCertificate|. The |
58 * resulting certificate will be used by the peer connection. If null, a default | 61 * resulting certificate will be used by the peer connection. If null, a default |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 }); | 450 }); |
448 } | 451 } |
449 | 452 |
450 /** | 453 /** |
451 * Returns the last iceGatheringState emitted from icegatheringstatechange. | 454 * Returns the last iceGatheringState emitted from icegatheringstatechange. |
452 */ | 455 */ |
453 function getLastGatheringState() { | 456 function getLastGatheringState() { |
454 returnToTest(gIceGatheringState); | 457 returnToTest(gIceGatheringState); |
455 } | 458 } |
456 | 459 |
| 460 /** |
| 461 * Returns "ok-negotiation-count-is-" followed by the number of times |
| 462 * onnegotiationneeded has fired. This will include any currently queued |
| 463 * negotiationneeded events. |
| 464 */ |
| 465 function getNegotiationNeededCount() { |
| 466 window.setTimeout(function() { |
| 467 returnToTest('ok-negotiation-count-is-' + gNegotiationNeededCount); |
| 468 }, 0); |
| 469 } |
| 470 |
457 // Internals. | 471 // Internals. |
458 | 472 |
459 /** @private */ | 473 /** @private */ |
460 function createPeerConnection_(rtcConfig) { | 474 function createPeerConnection_(rtcConfig) { |
461 try { | 475 try { |
462 peerConnection = new RTCPeerConnection(rtcConfig, {}); | 476 peerConnection = new RTCPeerConnection(rtcConfig, {}); |
463 } catch (exception) { | 477 } catch (exception) { |
464 throw failTest('Failed to create peer connection: ' + exception); | 478 throw failTest('Failed to create peer connection: ' + exception); |
465 } | 479 } |
466 peerConnection.onaddstream = addStreamCallback_; | 480 peerConnection.onaddstream = addStreamCallback_; |
467 peerConnection.onremovestream = removeStreamCallback_; | 481 peerConnection.onremovestream = removeStreamCallback_; |
468 peerConnection.onicecandidate = iceCallback_; | 482 peerConnection.onicecandidate = iceCallback_; |
469 peerConnection.onicegatheringstatechange = iceGatheringCallback_; | 483 peerConnection.onicegatheringstatechange = iceGatheringCallback_; |
| 484 peerConnection.onnegotiationneeded = negotiationNeededCallback_; |
470 return peerConnection; | 485 return peerConnection; |
471 } | 486 } |
472 | 487 |
473 /** @private */ | 488 /** @private */ |
474 function peerConnection_() { | 489 function peerConnection_() { |
475 if (gPeerConnection == null) | 490 if (gPeerConnection == null) |
476 throw failTest('Trying to use peer connection, but none was created.'); | 491 throw failTest('Trying to use peer connection, but none was created.'); |
477 return gPeerConnection; | 492 return gPeerConnection; |
478 } | 493 } |
479 | 494 |
480 /** @private */ | 495 /** @private */ |
481 function iceCallback_(event) { | 496 function iceCallback_(event) { |
482 if (event.candidate) | 497 if (event.candidate) |
483 gIceCandidates.push(event.candidate); | 498 gIceCandidates.push(event.candidate); |
484 } | 499 } |
485 | 500 |
486 /** @private */ | 501 /** @private */ |
487 function iceGatheringCallback_() { | 502 function iceGatheringCallback_() { |
488 gIceGatheringState = peerConnection.iceGatheringState; | 503 gIceGatheringState = peerConnection.iceGatheringState; |
489 } | 504 } |
490 | 505 |
| 506 /** @private */ |
| 507 function negotiationNeededCallback_() { |
| 508 ++gNegotiationNeededCount; |
| 509 } |
491 | 510 |
492 /** @private */ | 511 /** @private */ |
493 function setLocalDescription(peerConnection, sessionDescription) { | 512 function setLocalDescription(peerConnection, sessionDescription) { |
494 if (sessionDescription.sdp.search('a=crypto') != -1 || | 513 if (sessionDescription.sdp.search('a=crypto') != -1 || |
495 sessionDescription.sdp.search('a=fingerprint') != -1) | 514 sessionDescription.sdp.search('a=fingerprint') != -1) |
496 gHasSeenCryptoInSdp = 'crypto-seen'; | 515 gHasSeenCryptoInSdp = 'crypto-seen'; |
497 | 516 |
498 peerConnection.setLocalDescription( | 517 peerConnection.setLocalDescription( |
499 sessionDescription, | 518 sessionDescription, |
500 function() { success('setLocalDescription'); }, | 519 function() { success('setLocalDescription'); }, |
(...skipping 20 matching lines...) Expand all Loading... |
521 function parseJson_(json) { | 540 function parseJson_(json) { |
522 // Escape since the \r\n in the SDP tend to get unescaped. | 541 // Escape since the \r\n in the SDP tend to get unescaped. |
523 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); | 542 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); |
524 try { | 543 try { |
525 return JSON.parse(jsonWithEscapedLineBreaks); | 544 return JSON.parse(jsonWithEscapedLineBreaks); |
526 } catch (exception) { | 545 } catch (exception) { |
527 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + | 546 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + |
528 exception); | 547 exception); |
529 } | 548 } |
530 } | 549 } |
OLD | NEW |