Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <tuple> |
| 12 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 13 | #include "absl/memory/memory.h" |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 14 | #include "api/jsep.h" |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 15 | #include "api/peerconnectionproxy.h" |
| 16 | #include "media/base/fakemediaengine.h" |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 17 | #include "p2p/client/basicportallocator.h" |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 18 | #include "pc/mediasession.h" |
| 19 | #include "pc/peerconnection.h" |
| 20 | #include "pc/peerconnectionfactory.h" |
| 21 | #include "pc/peerconnectionwrapper.h" |
| 22 | #include "pc/sdputils.h" |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 23 | #include "pc/test/fakesctptransport.h" |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 24 | #include "rtc_base/fakenetwork.h" |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 25 | #include "rtc_base/gunit.h" |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 26 | #include "rtc_base/virtualsocketserver.h" |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 27 | #include "system_wrappers/include/metrics_default.h" |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
| 31 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 32 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
| 33 | using ::testing::Values; |
| 34 | |
| 35 | static constexpr int kDefaultTimeout = 10000; |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 36 | static const rtc::SocketAddress kDefaultLocalAddress("1.1.1.1", 0); |
| 37 | static const rtc::SocketAddress kPrivateLocalAddress("10.1.1.1", 0); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 38 | |
| 39 | int MakeUsageFingerprint(std::set<PeerConnection::UsageEvent> events) { |
| 40 | int signature = 0; |
| 41 | for (const auto it : events) { |
| 42 | signature |= static_cast<int>(it); |
| 43 | } |
| 44 | return signature; |
| 45 | } |
| 46 | |
| 47 | class PeerConnectionFactoryForUsageHistogramTest |
| 48 | : public rtc::RefCountedObject<PeerConnectionFactory> { |
| 49 | public: |
| 50 | PeerConnectionFactoryForUsageHistogramTest() |
| 51 | : rtc::RefCountedObject<PeerConnectionFactory>( |
| 52 | rtc::Thread::Current(), |
| 53 | rtc::Thread::Current(), |
| 54 | rtc::Thread::Current(), |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 55 | absl::make_unique<cricket::FakeMediaEngine>(), |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 56 | CreateCallFactory(), |
| 57 | nullptr) {} |
| 58 | |
| 59 | void ActionsBeforeInitializeForTesting(PeerConnectionInterface* pc) override { |
| 60 | PeerConnection* internal_pc = static_cast<PeerConnection*>(pc); |
| 61 | if (return_histogram_very_quickly_) { |
| 62 | internal_pc->ReturnHistogramVeryQuicklyForTesting(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void ReturnHistogramVeryQuickly() { return_histogram_very_quickly_ = true; } |
| 67 | |
| 68 | private: |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 69 | bool return_histogram_very_quickly_ = false; |
| 70 | }; |
| 71 | |
| 72 | class PeerConnectionWrapperForUsageHistogramTest; |
| 73 | typedef PeerConnectionWrapperForUsageHistogramTest* RawWrapperPtr; |
| 74 | |
| 75 | class ObserverForUsageHistogramTest : public MockPeerConnectionObserver { |
| 76 | public: |
| 77 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; |
| 78 | void PrepareToExchangeCandidates(RawWrapperPtr other) { |
| 79 | candidate_target_ = other; |
| 80 | } |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 81 | bool HaveDataChannel() { return last_datachannel_; } |
| 82 | |
| 83 | private: |
| 84 | RawWrapperPtr candidate_target_; // Note: Not thread-safe against deletions. |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | class PeerConnectionWrapperForUsageHistogramTest |
| 88 | : public PeerConnectionWrapper { |
| 89 | public: |
| 90 | using PeerConnectionWrapper::PeerConnectionWrapper; |
| 91 | |
| 92 | PeerConnection* GetInternalPeerConnection() { |
| 93 | auto* pci = |
| 94 | static_cast<PeerConnectionProxyWithInternal<PeerConnectionInterface>*>( |
| 95 | pc()); |
| 96 | return static_cast<PeerConnection*>(pci->internal()); |
| 97 | } |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 98 | |
| 99 | void PrepareToExchangeCandidates( |
| 100 | PeerConnectionWrapperForUsageHistogramTest* other) { |
| 101 | static_cast<ObserverForUsageHistogramTest*>(observer()) |
| 102 | ->PrepareToExchangeCandidates(other); |
| 103 | static_cast<ObserverForUsageHistogramTest*>(other->observer()) |
| 104 | ->PrepareToExchangeCandidates(this); |
| 105 | } |
| 106 | |
| 107 | bool IsConnected() { |
| 108 | return pc()->ice_connection_state() == |
| 109 | PeerConnectionInterface::kIceConnectionConnected || |
| 110 | pc()->ice_connection_state() == |
| 111 | PeerConnectionInterface::kIceConnectionCompleted; |
| 112 | } |
| 113 | |
| 114 | bool HaveDataChannel() { |
| 115 | return static_cast<ObserverForUsageHistogramTest*>(observer()) |
| 116 | ->HaveDataChannel(); |
| 117 | } |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 118 | void AddOrBufferIceCandidate(const webrtc::IceCandidateInterface* candidate) { |
| 119 | if (!pc()->AddIceCandidate(candidate)) { |
| 120 | std::string sdp; |
| 121 | EXPECT_TRUE(candidate->ToString(&sdp)); |
| 122 | std::unique_ptr<webrtc::IceCandidateInterface> candidate_copy( |
| 123 | CreateIceCandidate(candidate->sdp_mid(), candidate->sdp_mline_index(), |
| 124 | sdp, nullptr)); |
| 125 | buffered_candidates_.push_back(std::move(candidate_copy)); |
| 126 | } |
| 127 | } |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 128 | |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 129 | void AddBufferedIceCandidates() { |
| 130 | for (const auto& candidate : buffered_candidates_) { |
| 131 | EXPECT_TRUE(pc()->AddIceCandidate(candidate.get())); |
| 132 | } |
| 133 | buffered_candidates_.clear(); |
| 134 | } |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 135 | |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 136 | bool ConnectTo(PeerConnectionWrapperForUsageHistogramTest* callee) { |
| 137 | PrepareToExchangeCandidates(callee); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 138 | if (!ExchangeOfferAnswerWith(callee)) { |
| 139 | return false; |
| 140 | } |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 141 | AddBufferedIceCandidates(); |
| 142 | callee->AddBufferedIceCandidates(); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 143 | WAIT(IsConnected(), kDefaultTimeout); |
| 144 | WAIT(callee->IsConnected(), kDefaultTimeout); |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 145 | return IsConnected() && callee->IsConnected(); |
| 146 | } |
| 147 | |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 148 | bool GenerateOfferAndCollectCandidates() { |
| 149 | auto offer = CreateOffer(RTCOfferAnswerOptions()); |
| 150 | if (!offer) { |
| 151 | return false; |
| 152 | } |
| 153 | bool set_local_offer = |
| 154 | SetLocalDescription(CloneSessionDescription(offer.get())); |
| 155 | EXPECT_TRUE(set_local_offer); |
| 156 | if (!set_local_offer) { |
| 157 | return false; |
| 158 | } |
| 159 | EXPECT_TRUE_WAIT(observer()->ice_gathering_complete_, kDefaultTimeout); |
| 160 | return true; |
| 161 | } |
| 162 | |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 163 | private: |
| 164 | // Candidates that have been sent but not yet configured |
| 165 | std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> |
| 166 | buffered_candidates_; |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 167 | }; |
| 168 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 169 | void ObserverForUsageHistogramTest::OnIceCandidate( |
| 170 | const webrtc::IceCandidateInterface* candidate) { |
| 171 | if (candidate_target_) { |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 172 | this->candidate_target_->AddOrBufferIceCandidate(candidate); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 173 | } |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 174 | // If target is not set, ignore. This happens in one-ended unit tests. |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 177 | class PeerConnectionUsageHistogramTest : public ::testing::Test { |
| 178 | protected: |
| 179 | typedef std::unique_ptr<PeerConnectionWrapperForUsageHistogramTest> |
| 180 | WrapperPtr; |
| 181 | |
| 182 | PeerConnectionUsageHistogramTest() |
| 183 | : vss_(new rtc::VirtualSocketServer()), main_(vss_.get()) { |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 184 | webrtc::metrics::Reset(); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | WrapperPtr CreatePeerConnection() { |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 188 | return CreatePeerConnection(RTCConfiguration(), |
| 189 | PeerConnectionFactoryInterface::Options(), |
| 190 | nullptr, false); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 193 | WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { |
| 194 | return CreatePeerConnection( |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 195 | config, PeerConnectionFactoryInterface::Options(), nullptr, false); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 198 | WrapperPtr CreatePeerConnectionWithImmediateReport() { |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 199 | return CreatePeerConnection(RTCConfiguration(), |
| 200 | PeerConnectionFactoryInterface::Options(), |
| 201 | nullptr, true); |
| 202 | } |
| 203 | |
| 204 | WrapperPtr CreatePeerConnectionWithPrivateLocalAddresses() { |
| 205 | fake_network_manager_.reset(new rtc::FakeNetworkManager()); |
| 206 | fake_network_manager_->AddInterface(kDefaultLocalAddress); |
| 207 | fake_network_manager_->AddInterface(kPrivateLocalAddress); |
| 208 | std::unique_ptr<cricket::BasicPortAllocator> port_allocator( |
| 209 | new cricket::BasicPortAllocator(fake_network_manager_.get())); |
| 210 | return CreatePeerConnection(RTCConfiguration(), |
| 211 | PeerConnectionFactoryInterface::Options(), |
| 212 | std::move(port_allocator), false); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | WrapperPtr CreatePeerConnection( |
| 216 | const RTCConfiguration& config, |
| 217 | const PeerConnectionFactoryInterface::Options factory_options, |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 218 | std::unique_ptr<cricket::PortAllocator> allocator, |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 219 | bool immediate_report) { |
| 220 | rtc::scoped_refptr<PeerConnectionFactoryForUsageHistogramTest> pc_factory( |
| 221 | new PeerConnectionFactoryForUsageHistogramTest()); |
| 222 | pc_factory->SetOptions(factory_options); |
| 223 | RTC_CHECK(pc_factory->Initialize()); |
| 224 | if (immediate_report) { |
| 225 | pc_factory->ReturnHistogramVeryQuickly(); |
| 226 | } |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 227 | auto observer = absl::make_unique<ObserverForUsageHistogramTest>(); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 228 | auto pc = pc_factory->CreatePeerConnection(config, std::move(allocator), |
| 229 | nullptr, observer.get()); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 230 | if (!pc) { |
| 231 | return nullptr; |
| 232 | } |
| 233 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 234 | auto wrapper = |
| 235 | absl::make_unique<PeerConnectionWrapperForUsageHistogramTest>( |
| 236 | pc_factory, pc, std::move(observer)); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 237 | return wrapper; |
| 238 | } |
| 239 | |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 240 | std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_; |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 241 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 242 | rtc::AutoSocketServerThread main_; |
| 243 | }; |
| 244 | |
| 245 | TEST_F(PeerConnectionUsageHistogramTest, UsageFingerprintHistogramFromTimeout) { |
| 246 | auto pc = CreatePeerConnectionWithImmediateReport(); |
| 247 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 248 | int expected_fingerprint = MakeUsageFingerprint({}); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 249 | ASSERT_TRUE_WAIT( |
| 250 | 1u == webrtc::metrics::NumSamples("WebRTC.PeerConnection.UsagePattern"), |
| 251 | kDefaultTimeout); |
| 252 | EXPECT_EQ(1, webrtc::metrics::NumEvents("WebRTC.PeerConnection.UsagePattern", |
| 253 | expected_fingerprint)); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 256 | #ifndef WEBRTC_ANDROID |
| 257 | // These tests do not work on Android. Why is unclear. |
| 258 | // https://bugs.webrtc.org/9461 |
| 259 | |
| 260 | // Test getting the usage fingerprint for an audio/video connection. |
| 261 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintAudioVideo) { |
| 262 | auto caller = CreatePeerConnection(); |
| 263 | auto callee = CreatePeerConnection(); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 264 | caller->AddAudioTrack("audio"); |
| 265 | caller->AddVideoTrack("video"); |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 266 | ASSERT_TRUE(caller->ConnectTo(callee.get())); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 267 | caller->pc()->Close(); |
| 268 | callee->pc()->Close(); |
| 269 | int expected_fingerprint = MakeUsageFingerprint( |
| 270 | {PeerConnection::UsageEvent::AUDIO_ADDED, |
| 271 | PeerConnection::UsageEvent::VIDEO_ADDED, |
| 272 | PeerConnection::UsageEvent::SET_LOCAL_DESCRIPTION_CALLED, |
| 273 | PeerConnection::UsageEvent::SET_REMOTE_DESCRIPTION_CALLED, |
| 274 | PeerConnection::UsageEvent::CANDIDATE_COLLECTED, |
| 275 | PeerConnection::UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 276 | PeerConnection::UsageEvent::ICE_STATE_CONNECTED, |
| 277 | PeerConnection::UsageEvent::CLOSE_CALLED}); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 278 | // In this case, we may or may not have PRIVATE_CANDIDATE_COLLECTED, |
| 279 | // depending on the machine configuration. |
| 280 | EXPECT_EQ(2, |
| 281 | webrtc::metrics::NumSamples("WebRTC.PeerConnection.UsagePattern")); |
| 282 | EXPECT_TRUE( |
| 283 | webrtc::metrics::NumEvents("WebRTC.PeerConnection.UsagePattern", |
| 284 | expected_fingerprint) == 2 || |
| 285 | webrtc::metrics::NumEvents( |
| 286 | "WebRTC.PeerConnection.UsagePattern", |
| 287 | expected_fingerprint | |
| 288 | static_cast<int>( |
| 289 | PeerConnection::UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == |
| 290 | 2); |
| 291 | } |
| 292 | |
| 293 | // Test getting the usage fingerprint when there are no host candidates. |
| 294 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithNoHostCandidates) { |
| 295 | RTCConfiguration config; |
| 296 | config.type = PeerConnectionInterface::kNoHost; |
| 297 | auto caller = CreatePeerConnection(config); |
| 298 | auto callee = CreatePeerConnection(config); |
| 299 | caller->AddAudioTrack("audio"); |
| 300 | caller->AddVideoTrack("video"); |
| 301 | // Under some bot configurations, this will fail - presumably bots where |
| 302 | // no working non-host addresses exist. |
| 303 | if (!caller->ConnectTo(callee.get())) { |
| 304 | return; |
| 305 | } |
| 306 | // If we manage to connect, we should get this precise fingerprint. |
| 307 | caller->pc()->Close(); |
| 308 | callee->pc()->Close(); |
| 309 | int expected_fingerprint = MakeUsageFingerprint( |
| 310 | {PeerConnection::UsageEvent::AUDIO_ADDED, |
| 311 | PeerConnection::UsageEvent::VIDEO_ADDED, |
| 312 | PeerConnection::UsageEvent::SET_LOCAL_DESCRIPTION_CALLED, |
| 313 | PeerConnection::UsageEvent::SET_REMOTE_DESCRIPTION_CALLED, |
| 314 | PeerConnection::UsageEvent::CANDIDATE_COLLECTED, |
| 315 | PeerConnection::UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 316 | PeerConnection::UsageEvent::ICE_STATE_CONNECTED, |
| 317 | PeerConnection::UsageEvent::CLOSE_CALLED}); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 318 | EXPECT_EQ(2, |
| 319 | webrtc::metrics::NumSamples("WebRTC.PeerConnection.UsagePattern")); |
| 320 | EXPECT_EQ(2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.UsagePattern", |
| 321 | expected_fingerprint)); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | #ifdef HAVE_SCTP |
| 325 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintDataOnly) { |
| 326 | auto caller = CreatePeerConnection(); |
| 327 | auto callee = CreatePeerConnection(); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 328 | caller->CreateDataChannel("foodata"); |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 329 | ASSERT_TRUE(caller->ConnectTo(callee.get())); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 330 | ASSERT_TRUE_WAIT(callee->HaveDataChannel(), kDefaultTimeout); |
| 331 | caller->pc()->Close(); |
| 332 | callee->pc()->Close(); |
| 333 | int expected_fingerprint = MakeUsageFingerprint( |
| 334 | {PeerConnection::UsageEvent::DATA_ADDED, |
| 335 | PeerConnection::UsageEvent::SET_LOCAL_DESCRIPTION_CALLED, |
| 336 | PeerConnection::UsageEvent::SET_REMOTE_DESCRIPTION_CALLED, |
| 337 | PeerConnection::UsageEvent::CANDIDATE_COLLECTED, |
| 338 | PeerConnection::UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 339 | PeerConnection::UsageEvent::ICE_STATE_CONNECTED, |
| 340 | PeerConnection::UsageEvent::CLOSE_CALLED}); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 341 | EXPECT_EQ(2, |
| 342 | webrtc::metrics::NumSamples("WebRTC.PeerConnection.UsagePattern")); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 343 | EXPECT_TRUE( |
| 344 | webrtc::metrics::NumEvents("WebRTC.PeerConnection.UsagePattern", |
| 345 | expected_fingerprint) == 2 || |
| 346 | webrtc::metrics::NumEvents( |
| 347 | "WebRTC.PeerConnection.UsagePattern", |
| 348 | expected_fingerprint | |
| 349 | static_cast<int>( |
| 350 | PeerConnection::UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == |
| 351 | 2); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 352 | } |
| 353 | #endif // HAVE_SCTP |
| 354 | #endif // WEBRTC_ANDROID |
| 355 | |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 356 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintStunTurn) { |
| 357 | RTCConfiguration configuration; |
| 358 | PeerConnection::IceServer server; |
| 359 | server.urls = {"stun:dummy.stun.server/"}; |
| 360 | configuration.servers.push_back(server); |
| 361 | server.urls = {"turn:dummy.turn.server/"}; |
| 362 | server.username = "username"; |
| 363 | server.password = "password"; |
| 364 | configuration.servers.push_back(server); |
| 365 | auto caller = CreatePeerConnection(configuration); |
| 366 | ASSERT_TRUE(caller); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 367 | caller->pc()->Close(); |
| 368 | int expected_fingerprint = |
| 369 | MakeUsageFingerprint({PeerConnection::UsageEvent::STUN_SERVER_ADDED, |
| 370 | PeerConnection::UsageEvent::TURN_SERVER_ADDED, |
| 371 | PeerConnection::UsageEvent::CLOSE_CALLED}); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 372 | EXPECT_EQ(1, |
| 373 | webrtc::metrics::NumSamples("WebRTC.PeerConnection.UsagePattern")); |
| 374 | EXPECT_EQ(1, webrtc::metrics::NumEvents("WebRTC.PeerConnection.UsagePattern", |
| 375 | expected_fingerprint)); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintStunTurnInReconfiguration) { |
| 379 | RTCConfiguration configuration; |
| 380 | PeerConnection::IceServer server; |
| 381 | server.urls = {"stun:dummy.stun.server/"}; |
| 382 | configuration.servers.push_back(server); |
| 383 | server.urls = {"turn:dummy.turn.server/"}; |
| 384 | server.username = "username"; |
| 385 | server.password = "password"; |
| 386 | configuration.servers.push_back(server); |
| 387 | auto caller = CreatePeerConnection(); |
| 388 | ASSERT_TRUE(caller); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 389 | RTCError error; |
| 390 | caller->pc()->SetConfiguration(configuration, &error); |
| 391 | ASSERT_TRUE(error.ok()); |
| 392 | caller->pc()->Close(); |
| 393 | int expected_fingerprint = |
| 394 | MakeUsageFingerprint({PeerConnection::UsageEvent::STUN_SERVER_ADDED, |
| 395 | PeerConnection::UsageEvent::TURN_SERVER_ADDED, |
| 396 | PeerConnection::UsageEvent::CLOSE_CALLED}); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 397 | EXPECT_EQ(1, |
| 398 | webrtc::metrics::NumSamples("WebRTC.PeerConnection.UsagePattern")); |
| 399 | EXPECT_EQ(1, webrtc::metrics::NumEvents("WebRTC.PeerConnection.UsagePattern", |
| 400 | expected_fingerprint)); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 403 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithPrivateIP) { |
| 404 | auto caller = CreatePeerConnectionWithPrivateLocalAddresses(); |
| 405 | caller->AddAudioTrack("audio"); |
| 406 | ASSERT_TRUE(caller->GenerateOfferAndCollectCandidates()); |
| 407 | caller->pc()->Close(); |
| 408 | int expected_fingerprint = MakeUsageFingerprint( |
| 409 | {PeerConnection::UsageEvent::AUDIO_ADDED, |
| 410 | PeerConnection::UsageEvent::SET_LOCAL_DESCRIPTION_CALLED, |
| 411 | PeerConnection::UsageEvent::CANDIDATE_COLLECTED, |
| 412 | PeerConnection::UsageEvent::CLOSE_CALLED, |
| 413 | PeerConnection::UsageEvent::PRIVATE_CANDIDATE_COLLECTED}); |
| 414 | EXPECT_EQ(1, |
| 415 | webrtc::metrics::NumSamples("WebRTC.PeerConnection.UsagePattern")); |
| 416 | EXPECT_EQ(1, webrtc::metrics::NumEvents("WebRTC.PeerConnection.UsagePattern", |
| 417 | expected_fingerprint)); |
| 418 | } |
| 419 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 420 | } // namespace webrtc |