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 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 11 | #include <memory> |
| 12 | #include <set> |
| 13 | #include <string> |
| 14 | #include <utility> |
| 15 | #include <vector> |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 16 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 18 | #include "api/call/call_factory_interface.h" |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 19 | #include "api/jsep.h" |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 20 | #include "api/jsep_session_description.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 21 | #include "api/peer_connection_interface.h" |
| 22 | #include "api/peer_connection_proxy.h" |
| 23 | #include "api/rtc_error.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 24 | #include "api/scoped_refptr.h" |
Danil Chapovalov | 53d45ba | 2019-07-03 14:56:33 +0200 | [diff] [blame] | 25 | #include "api/task_queue/default_task_queue_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "media/base/fake_media_engine.h" |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 27 | #include "p2p/base/mock_async_resolver.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "p2p/base/port_allocator.h" |
| 29 | #include "p2p/client/basic_port_allocator.h" |
| 30 | #include "pc/peer_connection.h" |
| 31 | #include "pc/peer_connection_factory.h" |
| 32 | #include "pc/peer_connection_wrapper.h" |
| 33 | #include "pc/sdp_utils.h" |
| 34 | #include "pc/test/mock_peer_connection_observers.h" |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 35 | #include "pc/usage_pattern.h" |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 36 | #include "pc/webrtc_sdp.h" |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 37 | #include "rtc_base/arraysize.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 38 | #include "rtc_base/checks.h" |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 39 | #include "rtc_base/fake_mdns_responder.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 40 | #include "rtc_base/fake_network.h" |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 41 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 42 | #include "rtc_base/ref_counted_object.h" |
| 43 | #include "rtc_base/rtc_certificate_generator.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 44 | #include "rtc_base/socket_address.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 45 | #include "rtc_base/thread.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 46 | #include "rtc_base/virtual_socket_server.h" |
Mirko Bonadei | 17f4878 | 2018-09-28 08:51:10 +0200 | [diff] [blame] | 47 | #include "system_wrappers/include/metrics.h" |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 48 | #include "test/gmock.h" |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 49 | |
| 50 | namespace webrtc { |
| 51 | |
| 52 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 53 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 54 | using ::testing::NiceMock; |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 55 | using ::testing::Values; |
| 56 | |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 57 | static const char kUsagePatternMetric[] = "WebRTC.PeerConnection.UsagePattern"; |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 58 | static constexpr int kDefaultTimeout = 10000; |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 59 | static const rtc::SocketAddress kLocalAddrs[2] = { |
| 60 | rtc::SocketAddress("1.1.1.1", 0), rtc::SocketAddress("2.2.2.2", 0)}; |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 61 | static const rtc::SocketAddress kPrivateLocalAddress("10.1.1.1", 0); |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 62 | static const rtc::SocketAddress kPrivateIpv6LocalAddress("fd12:3456:789a:1::1", |
| 63 | 0); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 64 | |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 65 | int MakeUsageFingerprint(std::set<UsageEvent> events) { |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 66 | int signature = 0; |
| 67 | for (const auto it : events) { |
| 68 | signature |= static_cast<int>(it); |
| 69 | } |
| 70 | return signature; |
| 71 | } |
| 72 | |
| 73 | class PeerConnectionFactoryForUsageHistogramTest |
| 74 | : public rtc::RefCountedObject<PeerConnectionFactory> { |
| 75 | public: |
| 76 | PeerConnectionFactoryForUsageHistogramTest() |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 77 | : rtc::RefCountedObject<PeerConnectionFactory>([] { |
| 78 | PeerConnectionFactoryDependencies dependencies; |
| 79 | dependencies.network_thread = rtc::Thread::Current(); |
| 80 | dependencies.worker_thread = rtc::Thread::Current(); |
| 81 | dependencies.signaling_thread = rtc::Thread::Current(); |
Danil Chapovalov | 53d45ba | 2019-07-03 14:56:33 +0200 | [diff] [blame] | 82 | dependencies.task_queue_factory = CreateDefaultTaskQueueFactory(); |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 83 | dependencies.media_engine = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 84 | std::make_unique<cricket::FakeMediaEngine>(); |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 85 | dependencies.call_factory = CreateCallFactory(); |
| 86 | return dependencies; |
| 87 | }()) {} |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | class PeerConnectionWrapperForUsageHistogramTest; |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 91 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 92 | typedef PeerConnectionWrapperForUsageHistogramTest* RawWrapperPtr; |
| 93 | |
| 94 | class ObserverForUsageHistogramTest : public MockPeerConnectionObserver { |
| 95 | public: |
| 96 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 97 | |
| 98 | void OnInterestingUsage(int usage_pattern) override { |
| 99 | interesting_usage_detected_ = usage_pattern; |
| 100 | } |
| 101 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 102 | void PrepareToExchangeCandidates(RawWrapperPtr other) { |
| 103 | candidate_target_ = other; |
| 104 | } |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 105 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 106 | bool HaveDataChannel() { return last_datachannel_; } |
| 107 | |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 108 | absl::optional<int> interesting_usage_detected() { |
| 109 | return interesting_usage_detected_; |
| 110 | } |
| 111 | |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 112 | void ClearInterestingUsageDetector() { |
| 113 | interesting_usage_detected_ = absl::optional<int>(); |
| 114 | } |
| 115 | |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 116 | bool candidate_gathered() const { return candidate_gathered_; } |
| 117 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 118 | private: |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 119 | absl::optional<int> interesting_usage_detected_; |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 120 | bool candidate_gathered_ = false; |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 121 | RawWrapperPtr candidate_target_; // Note: Not thread-safe against deletions. |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | class PeerConnectionWrapperForUsageHistogramTest |
| 125 | : public PeerConnectionWrapper { |
| 126 | public: |
| 127 | using PeerConnectionWrapper::PeerConnectionWrapper; |
| 128 | |
| 129 | PeerConnection* GetInternalPeerConnection() { |
| 130 | auto* pci = |
| 131 | static_cast<PeerConnectionProxyWithInternal<PeerConnectionInterface>*>( |
| 132 | pc()); |
| 133 | return static_cast<PeerConnection*>(pci->internal()); |
| 134 | } |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 135 | |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 136 | // Override with different return type |
| 137 | ObserverForUsageHistogramTest* observer() { |
| 138 | return static_cast<ObserverForUsageHistogramTest*>( |
| 139 | PeerConnectionWrapper::observer()); |
| 140 | } |
| 141 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 142 | void PrepareToExchangeCandidates( |
| 143 | PeerConnectionWrapperForUsageHistogramTest* other) { |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 144 | observer()->PrepareToExchangeCandidates(other); |
| 145 | other->observer()->PrepareToExchangeCandidates(this); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | bool IsConnected() { |
| 149 | return pc()->ice_connection_state() == |
| 150 | PeerConnectionInterface::kIceConnectionConnected || |
| 151 | pc()->ice_connection_state() == |
| 152 | PeerConnectionInterface::kIceConnectionCompleted; |
| 153 | } |
| 154 | |
| 155 | bool HaveDataChannel() { |
| 156 | return static_cast<ObserverForUsageHistogramTest*>(observer()) |
| 157 | ->HaveDataChannel(); |
| 158 | } |
Qingsi Wang | 32913c1 | 2019-10-30 16:03:46 -0700 | [diff] [blame] | 159 | void BufferIceCandidate(const webrtc::IceCandidateInterface* candidate) { |
| 160 | std::string sdp; |
| 161 | EXPECT_TRUE(candidate->ToString(&sdp)); |
| 162 | std::unique_ptr<webrtc::IceCandidateInterface> candidate_copy( |
| 163 | CreateIceCandidate(candidate->sdp_mid(), candidate->sdp_mline_index(), |
| 164 | sdp, nullptr)); |
| 165 | buffered_candidates_.push_back(std::move(candidate_copy)); |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 166 | } |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 167 | |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 168 | void AddBufferedIceCandidates() { |
| 169 | for (const auto& candidate : buffered_candidates_) { |
| 170 | EXPECT_TRUE(pc()->AddIceCandidate(candidate.get())); |
| 171 | } |
| 172 | buffered_candidates_.clear(); |
| 173 | } |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 174 | |
Qingsi Wang | 32913c1 | 2019-10-30 16:03:46 -0700 | [diff] [blame] | 175 | // This method performs the following actions in sequence: |
| 176 | // 1. Exchange Offer and Answer. |
| 177 | // 2. Exchange ICE candidates after both caller and callee complete |
| 178 | // gathering. |
| 179 | // 3. Wait for ICE to connect. |
| 180 | // |
| 181 | // This guarantees a deterministic sequence of events and also rules out the |
| 182 | // occurrence of prflx candidates if the offer/answer signaling and the |
| 183 | // candidate trickling race in order. In case prflx candidates need to be |
| 184 | // simulated, see the approach used by tests below for that. |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 185 | bool ConnectTo(PeerConnectionWrapperForUsageHistogramTest* callee) { |
| 186 | PrepareToExchangeCandidates(callee); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 187 | if (!ExchangeOfferAnswerWith(callee)) { |
| 188 | return false; |
| 189 | } |
Qingsi Wang | 32913c1 | 2019-10-30 16:03:46 -0700 | [diff] [blame] | 190 | // Wait until the gathering completes before we signal the candidate. |
| 191 | WAIT(observer()->ice_gathering_complete_, kDefaultTimeout); |
| 192 | WAIT(callee->observer()->ice_gathering_complete_, kDefaultTimeout); |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 193 | AddBufferedIceCandidates(); |
| 194 | callee->AddBufferedIceCandidates(); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 195 | WAIT(IsConnected(), kDefaultTimeout); |
| 196 | WAIT(callee->IsConnected(), kDefaultTimeout); |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 197 | return IsConnected() && callee->IsConnected(); |
| 198 | } |
| 199 | |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 200 | bool GenerateOfferAndCollectCandidates() { |
| 201 | auto offer = CreateOffer(RTCOfferAnswerOptions()); |
| 202 | if (!offer) { |
| 203 | return false; |
| 204 | } |
| 205 | bool set_local_offer = |
| 206 | SetLocalDescription(CloneSessionDescription(offer.get())); |
| 207 | EXPECT_TRUE(set_local_offer); |
| 208 | if (!set_local_offer) { |
| 209 | return false; |
| 210 | } |
| 211 | EXPECT_TRUE_WAIT(observer()->ice_gathering_complete_, kDefaultTimeout); |
| 212 | return true; |
| 213 | } |
| 214 | |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 215 | webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { |
| 216 | return pc()->ice_gathering_state(); |
| 217 | } |
| 218 | |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 219 | private: |
| 220 | // Candidates that have been sent but not yet configured |
| 221 | std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> |
| 222 | buffered_candidates_; |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 223 | }; |
| 224 | |
Qingsi Wang | 32913c1 | 2019-10-30 16:03:46 -0700 | [diff] [blame] | 225 | // Buffers candidates until we add them via AddBufferedIceCandidates. |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 226 | void ObserverForUsageHistogramTest::OnIceCandidate( |
| 227 | const webrtc::IceCandidateInterface* candidate) { |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 228 | // 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] | 229 | if (candidate_target_) { |
Qingsi Wang | 32913c1 | 2019-10-30 16:03:46 -0700 | [diff] [blame] | 230 | this->candidate_target_->BufferIceCandidate(candidate); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 231 | } |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 232 | candidate_gathered_ = true; |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 233 | } |
| 234 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 235 | class PeerConnectionUsageHistogramTest : public ::testing::Test { |
| 236 | protected: |
| 237 | typedef std::unique_ptr<PeerConnectionWrapperForUsageHistogramTest> |
| 238 | WrapperPtr; |
| 239 | |
| 240 | PeerConnectionUsageHistogramTest() |
| 241 | : vss_(new rtc::VirtualSocketServer()), main_(vss_.get()) { |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 242 | webrtc::metrics::Reset(); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | WrapperPtr CreatePeerConnection() { |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 246 | return CreatePeerConnection( |
| 247 | RTCConfiguration(), PeerConnectionFactoryInterface::Options(), nullptr); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 250 | WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { |
| 251 | return CreatePeerConnection( |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 252 | config, PeerConnectionFactoryInterface::Options(), nullptr); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 255 | WrapperPtr CreatePeerConnectionWithMdns(const RTCConfiguration& config) { |
| 256 | auto resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 257 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 258 | |
| 259 | webrtc::PeerConnectionDependencies deps(nullptr /* observer_in */); |
| 260 | |
| 261 | auto fake_network = NewFakeNetwork(); |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 262 | fake_network->set_mdns_responder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 263 | std::make_unique<webrtc::FakeMdnsResponder>(rtc::Thread::Current())); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 264 | fake_network->AddInterface(NextLocalAddress()); |
| 265 | |
| 266 | std::unique_ptr<cricket::BasicPortAllocator> port_allocator( |
| 267 | new cricket::BasicPortAllocator(fake_network)); |
| 268 | |
| 269 | deps.async_resolver_factory = std::move(resolver_factory); |
| 270 | deps.allocator = std::move(port_allocator); |
| 271 | |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 272 | return CreatePeerConnection( |
| 273 | config, PeerConnectionFactoryInterface::Options(), std::move(deps)); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 276 | WrapperPtr CreatePeerConnectionWithImmediateReport() { |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 277 | RTCConfiguration configuration; |
| 278 | configuration.report_usage_pattern_delay_ms = 0; |
| 279 | return CreatePeerConnection( |
| 280 | configuration, PeerConnectionFactoryInterface::Options(), nullptr); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | WrapperPtr CreatePeerConnectionWithPrivateLocalAddresses() { |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 284 | auto* fake_network = NewFakeNetwork(); |
| 285 | fake_network->AddInterface(NextLocalAddress()); |
| 286 | fake_network->AddInterface(kPrivateLocalAddress); |
| 287 | |
| 288 | auto port_allocator = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 289 | std::make_unique<cricket::BasicPortAllocator>(fake_network); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 290 | return CreatePeerConnection(RTCConfiguration(), |
| 291 | PeerConnectionFactoryInterface::Options(), |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 292 | std::move(port_allocator)); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 295 | WrapperPtr CreatePeerConnectionWithPrivateIpv6LocalAddresses() { |
| 296 | auto* fake_network = NewFakeNetwork(); |
| 297 | fake_network->AddInterface(NextLocalAddress()); |
| 298 | fake_network->AddInterface(kPrivateIpv6LocalAddress); |
| 299 | |
| 300 | auto port_allocator = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 301 | std::make_unique<cricket::BasicPortAllocator>(fake_network); |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 302 | |
| 303 | return CreatePeerConnection(RTCConfiguration(), |
| 304 | PeerConnectionFactoryInterface::Options(), |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 305 | std::move(port_allocator)); |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 308 | WrapperPtr CreatePeerConnection( |
| 309 | const RTCConfiguration& config, |
| 310 | const PeerConnectionFactoryInterface::Options factory_options, |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 311 | std::unique_ptr<cricket::PortAllocator> allocator) { |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 312 | PeerConnectionDependencies deps(nullptr); |
| 313 | deps.allocator = std::move(allocator); |
| 314 | |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 315 | return CreatePeerConnection(config, factory_options, std::move(deps)); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | WrapperPtr CreatePeerConnection( |
| 319 | const RTCConfiguration& config, |
| 320 | const PeerConnectionFactoryInterface::Options factory_options, |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 321 | PeerConnectionDependencies deps) { |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 322 | rtc::scoped_refptr<PeerConnectionFactoryForUsageHistogramTest> pc_factory( |
| 323 | new PeerConnectionFactoryForUsageHistogramTest()); |
| 324 | pc_factory->SetOptions(factory_options); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 325 | |
| 326 | // If no allocator is provided, one will be created using a network manager |
| 327 | // that uses the host network. This doesn't work on all trybots. |
| 328 | if (!deps.allocator) { |
| 329 | auto fake_network = NewFakeNetwork(); |
| 330 | fake_network->AddInterface(NextLocalAddress()); |
| 331 | deps.allocator = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 332 | std::make_unique<cricket::BasicPortAllocator>(fake_network); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 335 | auto observer = std::make_unique<ObserverForUsageHistogramTest>(); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 336 | deps.observer = observer.get(); |
| 337 | |
| 338 | auto pc = pc_factory->CreatePeerConnection(config, std::move(deps)); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 339 | if (!pc) { |
| 340 | return nullptr; |
| 341 | } |
| 342 | |
Yves Gerey | 4e93329 | 2018-10-31 15:36:05 +0100 | [diff] [blame] | 343 | observer->SetPeerConnectionInterface(pc.get()); |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 344 | auto wrapper = std::make_unique<PeerConnectionWrapperForUsageHistogramTest>( |
| 345 | pc_factory, pc, std::move(observer)); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 346 | return wrapper; |
| 347 | } |
| 348 | |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 349 | int ObservedFingerprint() { |
| 350 | // This works correctly only if there is only one sample value |
| 351 | // that has been counted. |
| 352 | // Returns -1 for "not found". |
| 353 | return webrtc::metrics::MinSample(kUsagePatternMetric); |
| 354 | } |
| 355 | |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 356 | // The PeerConnection's port allocator is tied to the PeerConnection's |
| 357 | // lifetime and expects the underlying NetworkManager to outlive it. That |
| 358 | // prevents us from having the PeerConnectionWrapper own the fake network. |
| 359 | // Therefore, the test fixture will own all the fake networks even though |
| 360 | // tests should access the fake network through the PeerConnectionWrapper. |
| 361 | rtc::FakeNetworkManager* NewFakeNetwork() { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 362 | fake_networks_.emplace_back(std::make_unique<rtc::FakeNetworkManager>()); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 363 | return fake_networks_.back().get(); |
| 364 | } |
| 365 | |
| 366 | rtc::SocketAddress NextLocalAddress() { |
| 367 | RTC_DCHECK(next_local_address_ < (int)arraysize(kLocalAddrs)); |
| 368 | return kLocalAddrs[next_local_address_++]; |
| 369 | } |
| 370 | |
| 371 | std::vector<std::unique_ptr<rtc::FakeNetworkManager>> fake_networks_; |
| 372 | int next_local_address_ = 0; |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 373 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 374 | rtc::AutoSocketServerThread main_; |
| 375 | }; |
| 376 | |
| 377 | TEST_F(PeerConnectionUsageHistogramTest, UsageFingerprintHistogramFromTimeout) { |
| 378 | auto pc = CreatePeerConnectionWithImmediateReport(); |
| 379 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 380 | int expected_fingerprint = MakeUsageFingerprint({}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 381 | EXPECT_METRIC_EQ_WAIT(1, webrtc::metrics::NumSamples(kUsagePatternMetric), |
| 382 | kDefaultTimeout); |
| 383 | EXPECT_METRIC_EQ( |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 384 | 1, webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint)); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 387 | #ifndef WEBRTC_ANDROID |
| 388 | // These tests do not work on Android. Why is unclear. |
| 389 | // https://bugs.webrtc.org/9461 |
| 390 | |
| 391 | // Test getting the usage fingerprint for an audio/video connection. |
| 392 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintAudioVideo) { |
| 393 | auto caller = CreatePeerConnection(); |
| 394 | auto callee = CreatePeerConnection(); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 395 | caller->AddAudioTrack("audio"); |
| 396 | caller->AddVideoTrack("video"); |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 397 | ASSERT_TRUE(caller->ConnectTo(callee.get())); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 398 | caller->pc()->Close(); |
| 399 | callee->pc()->Close(); |
| 400 | int expected_fingerprint = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 401 | {UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED, |
| 402 | UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 403 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 404 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, |
| 405 | UsageEvent::ICE_STATE_CONNECTED, UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 406 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 407 | // In this case, we may or may not have PRIVATE_CANDIDATE_COLLECTED, |
| 408 | // depending on the machine configuration. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 409 | EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 410 | EXPECT_METRIC_TRUE( |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 411 | webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint) == |
| 412 | 2 || |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 413 | webrtc::metrics::NumEvents( |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 414 | kUsagePatternMetric, |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 415 | expected_fingerprint | |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 416 | static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == 2); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 419 | // Test getting the usage fingerprint when the caller collects an mDNS |
| 420 | // candidate. |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 421 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithMdnsCaller) { |
| 422 | RTCConfiguration config; |
| 423 | |
| 424 | // Enable hostname candidates with mDNS names. |
| 425 | auto caller = CreatePeerConnectionWithMdns(config); |
| 426 | auto callee = CreatePeerConnection(config); |
| 427 | |
| 428 | caller->AddAudioTrack("audio"); |
| 429 | caller->AddVideoTrack("video"); |
| 430 | ASSERT_TRUE(caller->ConnectTo(callee.get())); |
| 431 | caller->pc()->Close(); |
| 432 | callee->pc()->Close(); |
| 433 | |
| 434 | int expected_fingerprint_caller = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 435 | {UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED, |
| 436 | UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 437 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 438 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::MDNS_CANDIDATE_COLLECTED, |
| 439 | UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, UsageEvent::ICE_STATE_CONNECTED, |
| 440 | UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 441 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 442 | |
Qingsi Wang | cc46b10 | 2019-09-12 11:19:01 -0700 | [diff] [blame] | 443 | // Without a resolver, the callee cannot resolve the received mDNS candidate |
| 444 | // but can still connect with the caller via a prflx candidate. As a result, |
| 445 | // the bit for the direct connection should not be logged. |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 446 | int expected_fingerprint_callee = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 447 | {UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED, |
| 448 | UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 449 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 450 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, |
| 451 | UsageEvent::REMOTE_MDNS_CANDIDATE_ADDED, UsageEvent::ICE_STATE_CONNECTED, |
| 452 | UsageEvent::REMOTE_CANDIDATE_ADDED, UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 453 | EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 454 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 455 | expected_fingerprint_caller)); |
| 456 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 457 | expected_fingerprint_callee)); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 460 | // Test getting the usage fingerprint when the callee collects an mDNS |
| 461 | // candidate. |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 462 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithMdnsCallee) { |
| 463 | RTCConfiguration config; |
| 464 | |
| 465 | // Enable hostname candidates with mDNS names. |
| 466 | auto caller = CreatePeerConnection(config); |
| 467 | auto callee = CreatePeerConnectionWithMdns(config); |
| 468 | |
| 469 | caller->AddAudioTrack("audio"); |
| 470 | caller->AddVideoTrack("video"); |
| 471 | ASSERT_TRUE(caller->ConnectTo(callee.get())); |
| 472 | caller->pc()->Close(); |
| 473 | callee->pc()->Close(); |
| 474 | |
Qingsi Wang | cc46b10 | 2019-09-12 11:19:01 -0700 | [diff] [blame] | 475 | // Similar to the test above, the caller connects with the callee via a prflx |
| 476 | // candidate. |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 477 | int expected_fingerprint_caller = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 478 | {UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED, |
| 479 | UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 480 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 481 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, |
| 482 | UsageEvent::REMOTE_MDNS_CANDIDATE_ADDED, UsageEvent::ICE_STATE_CONNECTED, |
| 483 | UsageEvent::REMOTE_CANDIDATE_ADDED, UsageEvent::CLOSE_CALLED}); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 484 | |
| 485 | int expected_fingerprint_callee = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 486 | {UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED, |
| 487 | UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 488 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 489 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::MDNS_CANDIDATE_COLLECTED, |
| 490 | UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, UsageEvent::ICE_STATE_CONNECTED, |
| 491 | UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 492 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 493 | EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 494 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 495 | expected_fingerprint_caller)); |
| 496 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 497 | expected_fingerprint_callee)); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 500 | #ifdef HAVE_SCTP |
| 501 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintDataOnly) { |
| 502 | auto caller = CreatePeerConnection(); |
| 503 | auto callee = CreatePeerConnection(); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 504 | caller->CreateDataChannel("foodata"); |
Harald Alvestrand | 4238628 | 2018-07-12 07:56:05 +0200 | [diff] [blame] | 505 | ASSERT_TRUE(caller->ConnectTo(callee.get())); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 506 | ASSERT_TRUE_WAIT(callee->HaveDataChannel(), kDefaultTimeout); |
| 507 | caller->pc()->Close(); |
| 508 | callee->pc()->Close(); |
| 509 | int expected_fingerprint = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 510 | {UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 511 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 512 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, |
| 513 | UsageEvent::ICE_STATE_CONNECTED, UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 514 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 515 | EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 516 | EXPECT_METRIC_TRUE( |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 517 | webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint) == |
| 518 | 2 || |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 519 | webrtc::metrics::NumEvents( |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 520 | kUsagePatternMetric, |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 521 | expected_fingerprint | |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 522 | static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == 2); |
Harald Alvestrand | 183e09d | 2018-06-28 12:04:41 +0200 | [diff] [blame] | 523 | } |
| 524 | #endif // HAVE_SCTP |
| 525 | #endif // WEBRTC_ANDROID |
| 526 | |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 527 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintStunTurn) { |
| 528 | RTCConfiguration configuration; |
| 529 | PeerConnection::IceServer server; |
Harald Alvestrand | a3dd772 | 2020-11-27 08:05:42 +0000 | [diff] [blame^] | 530 | server.urls = {"stun:dummy.stun.server"}; |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 531 | configuration.servers.push_back(server); |
Harald Alvestrand | a3dd772 | 2020-11-27 08:05:42 +0000 | [diff] [blame^] | 532 | server.urls = {"turn:dummy.turn.server"}; |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 533 | server.username = "username"; |
| 534 | server.password = "password"; |
| 535 | configuration.servers.push_back(server); |
| 536 | auto caller = CreatePeerConnection(configuration); |
| 537 | ASSERT_TRUE(caller); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 538 | caller->pc()->Close(); |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 539 | int expected_fingerprint = MakeUsageFingerprint( |
| 540 | {UsageEvent::STUN_SERVER_ADDED, UsageEvent::TURN_SERVER_ADDED, |
| 541 | UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 542 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 543 | EXPECT_METRIC_EQ( |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 544 | 1, webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint)); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintStunTurnInReconfiguration) { |
| 548 | RTCConfiguration configuration; |
| 549 | PeerConnection::IceServer server; |
Harald Alvestrand | a3dd772 | 2020-11-27 08:05:42 +0000 | [diff] [blame^] | 550 | server.urls = {"stun:dummy.stun.server"}; |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 551 | configuration.servers.push_back(server); |
Harald Alvestrand | a3dd772 | 2020-11-27 08:05:42 +0000 | [diff] [blame^] | 552 | server.urls = {"turn:dummy.turn.server"}; |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 553 | server.username = "username"; |
| 554 | server.password = "password"; |
| 555 | configuration.servers.push_back(server); |
| 556 | auto caller = CreatePeerConnection(); |
| 557 | ASSERT_TRUE(caller); |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 558 | ASSERT_TRUE(caller->pc()->SetConfiguration(configuration).ok()); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 559 | caller->pc()->Close(); |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 560 | int expected_fingerprint = MakeUsageFingerprint( |
| 561 | {UsageEvent::STUN_SERVER_ADDED, UsageEvent::TURN_SERVER_ADDED, |
| 562 | UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 563 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 564 | EXPECT_METRIC_EQ( |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 565 | 1, webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint)); |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 566 | } |
| 567 | |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 568 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithPrivateIPCaller) { |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 569 | auto caller = CreatePeerConnectionWithPrivateLocalAddresses(); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 570 | auto callee = CreatePeerConnection(); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 571 | caller->AddAudioTrack("audio"); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 572 | ASSERT_TRUE(caller->ConnectTo(callee.get())); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 573 | caller->pc()->Close(); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 574 | callee->pc()->Close(); |
| 575 | |
| 576 | int expected_fingerprint_caller = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 577 | {UsageEvent::AUDIO_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 578 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 579 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::PRIVATE_CANDIDATE_COLLECTED, |
| 580 | UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, UsageEvent::ICE_STATE_CONNECTED, |
| 581 | UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 582 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 583 | |
| 584 | int expected_fingerprint_callee = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 585 | {UsageEvent::AUDIO_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 586 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 587 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, |
| 588 | UsageEvent::REMOTE_PRIVATE_CANDIDATE_ADDED, |
| 589 | UsageEvent::ICE_STATE_CONNECTED, UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 590 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 591 | EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 592 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 593 | expected_fingerprint_caller)); |
| 594 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 595 | expected_fingerprint_callee)); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 598 | TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithPrivateIpv6Callee) { |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 599 | auto caller = CreatePeerConnection(); |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 600 | auto callee = CreatePeerConnectionWithPrivateIpv6LocalAddresses(); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 601 | caller->AddAudioTrack("audio"); |
| 602 | ASSERT_TRUE(caller->ConnectTo(callee.get())); |
| 603 | caller->pc()->Close(); |
| 604 | callee->pc()->Close(); |
| 605 | |
| 606 | int expected_fingerprint_caller = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 607 | {UsageEvent::AUDIO_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 608 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 609 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, |
| 610 | UsageEvent::REMOTE_PRIVATE_CANDIDATE_ADDED, |
| 611 | UsageEvent::ICE_STATE_CONNECTED, UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 612 | UsageEvent::REMOTE_IPV6_CANDIDATE_ADDED, |
| 613 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Jeroen de Borst | af242c8 | 2019-04-24 13:13:48 -0700 | [diff] [blame] | 614 | |
| 615 | int expected_fingerprint_callee = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 616 | {UsageEvent::AUDIO_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 617 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 618 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::PRIVATE_CANDIDATE_COLLECTED, |
| 619 | UsageEvent::IPV6_CANDIDATE_COLLECTED, |
| 620 | UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, |
| 621 | UsageEvent::REMOTE_CANDIDATE_ADDED, UsageEvent::ICE_STATE_CONNECTED, |
| 622 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 623 | EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 624 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 625 | expected_fingerprint_caller)); |
| 626 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 627 | expected_fingerprint_callee)); |
Harald Alvestrand | 056d811 | 2018-07-16 19:18:58 +0200 | [diff] [blame] | 628 | } |
| 629 | |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 630 | #ifndef WEBRTC_ANDROID |
| 631 | #ifdef HAVE_SCTP |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 632 | // Test that the usage pattern bits for adding remote (private IPv6) candidates |
| 633 | // are set when the remote candidates are retrieved from the Offer SDP instead |
| 634 | // of trickled ICE messages. |
| 635 | TEST_F(PeerConnectionUsageHistogramTest, |
| 636 | AddRemoteCandidatesFromRemoteDescription) { |
| 637 | // We construct the following data-channel-only scenario. The caller collects |
| 638 | // IPv6 private local candidates and appends them in the Offer as in |
| 639 | // non-trickled sessions. The callee collects mDNS candidates that are not |
| 640 | // contained in the Answer as in Trickle ICE. Only the Offer and Answer are |
| 641 | // signaled and we expect a connection with prflx remote candidates at the |
| 642 | // caller side. |
| 643 | auto caller = CreatePeerConnectionWithPrivateIpv6LocalAddresses(); |
| 644 | auto callee = CreatePeerConnectionWithMdns(RTCConfiguration()); |
| 645 | caller->CreateDataChannel("test_channel"); |
| 646 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 647 | // Wait until the gathering completes so that the session description would |
| 648 | // have contained ICE candidates. |
| 649 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 650 | caller->ice_gathering_state(), kDefaultTimeout); |
| 651 | EXPECT_TRUE(caller->observer()->candidate_gathered()); |
| 652 | // Get the current offer that contains candidates and pass it to the callee. |
| 653 | // |
| 654 | // Note that we cannot use CloneSessionDescription on |cur_offer| to obtain an |
| 655 | // SDP with candidates. The method above does not strictly copy everything, in |
| 656 | // particular, not copying the ICE candidates. |
| 657 | // TODO(qingsi): Technically, this is a bug. Fix it. |
| 658 | auto cur_offer = caller->pc()->local_description(); |
| 659 | ASSERT_TRUE(cur_offer); |
| 660 | std::string sdp_with_candidates_str; |
| 661 | cur_offer->ToString(&sdp_with_candidates_str); |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 662 | auto offer = std::make_unique<JsepSessionDescription>(SdpType::kOffer); |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 663 | ASSERT_TRUE(SdpDeserialize(sdp_with_candidates_str, offer.get(), |
| 664 | nullptr /* error */)); |
| 665 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 666 | |
| 667 | // By default, the Answer created does not contain ICE candidates. |
| 668 | auto answer = callee->CreateAnswer(); |
| 669 | callee->SetLocalDescription(CloneSessionDescription(answer.get())); |
| 670 | caller->SetRemoteDescription(std::move(answer)); |
| 671 | EXPECT_TRUE_WAIT(caller->IsConnected(), kDefaultTimeout); |
| 672 | EXPECT_TRUE_WAIT(callee->IsConnected(), kDefaultTimeout); |
| 673 | // The callee needs to process the open message to have the data channel open. |
| 674 | EXPECT_TRUE_WAIT(callee->observer()->last_datachannel_ != nullptr, |
| 675 | kDefaultTimeout); |
| 676 | caller->pc()->Close(); |
| 677 | callee->pc()->Close(); |
| 678 | |
| 679 | // The caller should not have added any remote candidate either via |
Qingsi Wang | cc46b10 | 2019-09-12 11:19:01 -0700 | [diff] [blame] | 680 | // AddIceCandidate or from the remote description. Also, the caller connects |
| 681 | // with the callee via a prflx candidate and hence no direct connection bit |
| 682 | // should be set. |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 683 | int expected_fingerprint_caller = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 684 | {UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 685 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 686 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::PRIVATE_CANDIDATE_COLLECTED, |
| 687 | UsageEvent::IPV6_CANDIDATE_COLLECTED, UsageEvent::ICE_STATE_CONNECTED, |
| 688 | UsageEvent::CLOSE_CALLED}); |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 689 | |
| 690 | int expected_fingerprint_callee = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 691 | {UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 692 | UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED, |
| 693 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::MDNS_CANDIDATE_COLLECTED, |
| 694 | UsageEvent::REMOTE_CANDIDATE_ADDED, |
| 695 | UsageEvent::REMOTE_PRIVATE_CANDIDATE_ADDED, |
| 696 | UsageEvent::REMOTE_IPV6_CANDIDATE_ADDED, UsageEvent::ICE_STATE_CONNECTED, |
| 697 | UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 698 | EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 699 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 700 | expected_fingerprint_caller)); |
| 701 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric, |
| 702 | expected_fingerprint_callee)); |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 705 | TEST_F(PeerConnectionUsageHistogramTest, NotableUsageNoted) { |
| 706 | auto caller = CreatePeerConnection(); |
| 707 | caller->CreateDataChannel("foo"); |
| 708 | caller->GenerateOfferAndCollectCandidates(); |
| 709 | caller->pc()->Close(); |
| 710 | int expected_fingerprint = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 711 | {UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 712 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 713 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
| 714 | EXPECT_METRIC_TRUE( |
| 715 | expected_fingerprint == ObservedFingerprint() || |
| 716 | (expected_fingerprint | |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 717 | static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 718 | ObservedFingerprint()); |
| 719 | EXPECT_METRIC_EQ(absl::make_optional(ObservedFingerprint()), |
| 720 | caller->observer()->interesting_usage_detected()); |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 721 | } |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 722 | |
| 723 | TEST_F(PeerConnectionUsageHistogramTest, NotableUsageOnEventFiring) { |
| 724 | auto caller = CreatePeerConnection(); |
| 725 | caller->CreateDataChannel("foo"); |
| 726 | caller->GenerateOfferAndCollectCandidates(); |
| 727 | int expected_fingerprint = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 728 | {UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 729 | UsageEvent::CANDIDATE_COLLECTED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 730 | EXPECT_METRIC_EQ(0, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 731 | caller->GetInternalPeerConnection()->RequestUsagePatternReportForTesting(); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 732 | EXPECT_METRIC_EQ_WAIT(1, webrtc::metrics::NumSamples(kUsagePatternMetric), |
| 733 | kDefaultTimeout); |
| 734 | EXPECT_METRIC_TRUE( |
| 735 | expected_fingerprint == ObservedFingerprint() || |
| 736 | (expected_fingerprint | |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 737 | static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 738 | ObservedFingerprint()); |
| 739 | EXPECT_METRIC_EQ(absl::make_optional(ObservedFingerprint()), |
| 740 | caller->observer()->interesting_usage_detected()); |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | TEST_F(PeerConnectionUsageHistogramTest, |
| 744 | NoNotableUsageOnEventFiringAfterClose) { |
| 745 | auto caller = CreatePeerConnection(); |
| 746 | caller->CreateDataChannel("foo"); |
| 747 | caller->GenerateOfferAndCollectCandidates(); |
| 748 | int expected_fingerprint = MakeUsageFingerprint( |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 749 | {UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED, |
| 750 | UsageEvent::CANDIDATE_COLLECTED, UsageEvent::CLOSE_CALLED}); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 751 | EXPECT_METRIC_EQ(0, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 752 | caller->pc()->Close(); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 753 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumSamples(kUsagePatternMetric)); |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 754 | caller->GetInternalPeerConnection()->RequestUsagePatternReportForTesting(); |
| 755 | caller->observer()->ClearInterestingUsageDetector(); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 756 | EXPECT_METRIC_EQ_WAIT(2, webrtc::metrics::NumSamples(kUsagePatternMetric), |
| 757 | kDefaultTimeout); |
| 758 | EXPECT_METRIC_TRUE( |
| 759 | expected_fingerprint == ObservedFingerprint() || |
| 760 | (expected_fingerprint | |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 761 | static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 762 | ObservedFingerprint()); |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 763 | // After close, the usage-detection callback should NOT have been called. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 764 | EXPECT_METRIC_FALSE(caller->observer()->interesting_usage_detected()); |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 765 | } |
Harald Alvestrand | c0e9725 | 2018-07-26 10:39:55 +0200 | [diff] [blame] | 766 | #endif |
| 767 | #endif |
| 768 | |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 769 | } // namespace webrtc |