Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/talk/app/webrtc/peerconnectionendtoend_unittest.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 7.6 KB
Line 
1/*
2 * libjingle
3 * Copyright 2013, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 *  1. Redistributions of source code must retain the above copyright notice,
9 *     this list of conditions and the following disclaimer.
10 *  2. Redistributions in binary form must reproduce the above copyright notice,
11 *     this list of conditions and the following disclaimer in the documentation
12 *     and/or other materials provided with the distribution.
13 *  3. The name of the author may not be used to endorse or promote products
14 *     derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/app/webrtc/test/peerconnectiontestwrapper.h"
29#include "talk/base/gunit.h"
30#include "talk/base/logging.h"
31#include "talk/base/ssladapter.h"
32#include "talk/base/sslstreamadapter.h"
33#include "talk/base/stringencode.h"
34#include "talk/base/stringutils.h"
35
36using webrtc::FakeConstraints;
37using webrtc::MediaConstraintsInterface;
38using webrtc::MediaStreamInterface;
39using webrtc::PeerConnectionInterface;
40
41namespace {
42
43const char kExternalGiceUfrag[] = "1234567890123456";
44const char kExternalGicePwd[] = "123456789012345678901234";
45
46void RemoveLinesFromSdp(const std::string& line_start,
47                               std::string* sdp) {
48  const char kSdpLineEnd[] = "\r\n";
49  size_t ssrc_pos = 0;
50  while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
51      std::string::npos) {
52    size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
53    sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
54  }
55}
56
57// Add |newlines| to the |message| after |line|.
58void InjectAfter(const std::string& line,
59                 const std::string& newlines,
60                 std::string* message) {
61  const std::string tmp = line + newlines;
62  talk_base::replace_substrs(line.c_str(), line.length(),
63                             tmp.c_str(), tmp.length(), message);
64}
65
66void Replace(const std::string& line,
67             const std::string& newlines,
68             std::string* message) {
69  talk_base::replace_substrs(line.c_str(), line.length(),
70                             newlines.c_str(), newlines.length(), message);
71}
72
73void UseExternalSdes(std::string* sdp) {
74  // Remove current crypto specification.
75  RemoveLinesFromSdp("a=crypto", sdp);
76  RemoveLinesFromSdp("a=fingerprint", sdp);
77  // Add external crypto.
78  const char kAudioSdes[] =
79      "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
80      "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR\r\n";
81  const char kVideoSdes[] =
82      "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
83      "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj\r\n";
84  const char kDataSdes[] =
85      "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
86      "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj\r\n";
87  InjectAfter("a=mid:audio\r\n", kAudioSdes, sdp);
88  InjectAfter("a=mid:video\r\n", kVideoSdes, sdp);
89  InjectAfter("a=mid:data\r\n", kDataSdes, sdp);
90}
91
92void UseGice(std::string* sdp) {
93  InjectAfter("t=0 0\r\n", "a=ice-options:google-ice\r\n", sdp);
94
95  std::string ufragline = "a=ice-ufrag:";
96  std::string pwdline = "a=ice-pwd:";
97  RemoveLinesFromSdp(ufragline, sdp);
98  RemoveLinesFromSdp(pwdline, sdp);
99  ufragline.append(kExternalGiceUfrag);
100  ufragline.append("\r\n");
101  pwdline.append(kExternalGicePwd);
102  pwdline.append("\r\n");
103  const std::string ufrag_pwd = ufragline + pwdline;
104
105  InjectAfter("a=mid:audio\r\n", ufrag_pwd, sdp);
106  InjectAfter("a=mid:video\r\n", ufrag_pwd, sdp);
107  InjectAfter("a=mid:data\r\n", ufrag_pwd, sdp);
108}
109
110void RemoveBundle(std::string* sdp) {
111  RemoveLinesFromSdp("a=group:BUNDLE", sdp);
112}
113
114}  // namespace
115
116class PeerConnectionEndToEndTest
117    : public sigslot::has_slots<>,
118      public testing::Test {
119 public:
120  PeerConnectionEndToEndTest()
121      : caller_(new talk_base::RefCountedObject<PeerConnectionTestWrapper>(
122                    "caller")),
123        callee_(new talk_base::RefCountedObject<PeerConnectionTestWrapper>(
124                    "callee")) {
125    talk_base::InitializeSSL(NULL);
126  }
127
128  void CreatePcs() {
129    CreatePcs(NULL);
130  }
131
132  void CreatePcs(const MediaConstraintsInterface* pc_constraints) {
133    EXPECT_TRUE(caller_->CreatePc(pc_constraints));
134    EXPECT_TRUE(callee_->CreatePc(pc_constraints));
135    PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get());
136  }
137
138  void GetAndAddUserMedia() {
139    FakeConstraints audio_constraints;
140    FakeConstraints video_constraints;
141    GetAndAddUserMedia(true, audio_constraints, true, video_constraints);
142  }
143
144  void GetAndAddUserMedia(bool audio, FakeConstraints audio_constraints,
145                          bool video, FakeConstraints video_constraints) {
146    caller_->GetAndAddUserMedia(audio, audio_constraints,
147                                video, video_constraints);
148    callee_->GetAndAddUserMedia(audio, audio_constraints,
149                                video, video_constraints);
150  }
151
152  void Negotiate() {
153    caller_->CreateOffer(NULL);
154  }
155
156  void WaitForCallEstablished() {
157    caller_->WaitForCallEstablished();
158    callee_->WaitForCallEstablished();
159  }
160
161  void SetupLegacySdpConverter() {
162    caller_->SignalOnSdpCreated.connect(
163      this, &PeerConnectionEndToEndTest::ConvertToLegacySdp);
164    callee_->SignalOnSdpCreated.connect(
165      this, &PeerConnectionEndToEndTest::ConvertToLegacySdp);
166  }
167
168  void ConvertToLegacySdp(std::string* sdp) {
169    UseExternalSdes(sdp);
170    UseGice(sdp);
171    RemoveBundle(sdp);
172    LOG(LS_INFO) << "ConvertToLegacySdp: " << *sdp;
173  }
174
175  void SetupGiceConverter() {
176    caller_->SignalOnIceCandidateCreated.connect(
177      this, &PeerConnectionEndToEndTest::AddGiceCredsToCandidate);
178    callee_->SignalOnIceCandidateCreated.connect(
179      this, &PeerConnectionEndToEndTest::AddGiceCredsToCandidate);
180  }
181
182  void AddGiceCredsToCandidate(std::string* sdp) {
183    std::string gice_creds = " username ";
184    gice_creds.append(kExternalGiceUfrag);
185    gice_creds.append(" password ");
186    gice_creds.append(kExternalGicePwd);
187    gice_creds.append("\r\n");
188    Replace("\r\n", gice_creds, sdp);
189    LOG(LS_INFO) << "AddGiceCredsToCandidate: " << *sdp;
190  }
191
192  ~PeerConnectionEndToEndTest() {
193    talk_base::CleanupSSL();
194  }
195
196 protected:
197  talk_base::scoped_refptr<PeerConnectionTestWrapper> caller_;
198  talk_base::scoped_refptr<PeerConnectionTestWrapper> callee_;
199};
200
201// Disable for TSan v2, see
202// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
203#if !defined(THREAD_SANITIZER)
204
205TEST_F(PeerConnectionEndToEndTest, Call) {
206  CreatePcs();
207  GetAndAddUserMedia();
208  Negotiate();
209  WaitForCallEstablished();
210}
211
212TEST_F(PeerConnectionEndToEndTest, CallWithLegacySdp) {
213  FakeConstraints pc_constraints;
214  pc_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
215                              false);
216  CreatePcs(&pc_constraints);
217  SetupLegacySdpConverter();
218  SetupGiceConverter();
219  GetAndAddUserMedia();
220  Negotiate();
221  WaitForCallEstablished();
222}
223
224#endif // if !defined(THREAD_SANITIZER)
Note: See TracBrowser for help on using the repository browser.