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