• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2016 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <stdint.h>
12 #include <string.h>
13 
14 #include <memory>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
19 #include "absl/algorithm/container.h"
20 #include "absl/strings/match.h"
21 #include "api/audio_codecs/builtin_audio_decoder_factory.h"
22 #include "api/audio_codecs/builtin_audio_encoder_factory.h"
23 #include "api/audio_options.h"
24 #include "api/data_channel_interface.h"
25 #include "api/peer_connection_interface.h"
26 #include "api/rtp_receiver_interface.h"
27 #include "api/rtp_sender_interface.h"
28 #include "api/scoped_refptr.h"
29 #include "api/stats/rtc_stats.h"
30 #include "api/stats/rtc_stats_report.h"
31 #include "api/stats/rtcstats_objects.h"
32 #include "pc/rtc_stats_traversal.h"
33 #include "pc/test/peer_connection_test_wrapper.h"
34 #include "pc/test/rtc_stats_obtainer.h"
35 #include "rtc_base/checks.h"
36 #include "rtc_base/event_tracer.h"
37 #include "rtc_base/gunit.h"
38 #include "rtc_base/thread.h"
39 #include "rtc_base/trace_event.h"
40 #include "rtc_base/virtual_socket_server.h"
41 #include "test/gmock.h"
42 #include "test/gtest.h"
43 
44 using ::testing::Contains;
45 
46 namespace webrtc {
47 
48 namespace {
49 
50 const int64_t kGetStatsTimeoutMs = 10000;
51 
GetCategoryEnabledHandler(const char * name)52 const unsigned char* GetCategoryEnabledHandler(const char* name) {
53   if (strcmp("webrtc_stats", name) != 0) {
54     return reinterpret_cast<const unsigned char*>("");
55   }
56   return reinterpret_cast<const unsigned char*>(name);
57 }
58 
59 class RTCStatsReportTraceListener {
60  public:
SetUp()61   static void SetUp() {
62     if (!traced_report_)
63       traced_report_ = new RTCStatsReportTraceListener();
64     traced_report_->last_trace_ = "";
65     SetupEventTracer(&GetCategoryEnabledHandler,
66                      &RTCStatsReportTraceListener::AddTraceEventHandler);
67   }
68 
last_trace()69   static const std::string& last_trace() {
70     RTC_DCHECK(traced_report_);
71     return traced_report_->last_trace_;
72   }
73 
74  private:
AddTraceEventHandler(char phase,const unsigned char * category_enabled,const char * name,unsigned long long id,int num_args,const char ** arg_names,const unsigned char * arg_types,const unsigned long long * arg_values,unsigned char flags)75   static void AddTraceEventHandler(
76       char phase,
77       const unsigned char* category_enabled,
78       const char* name,
79       unsigned long long id,  // NOLINT(runtime/int)
80       int num_args,
81       const char** arg_names,
82       const unsigned char* arg_types,
83       const unsigned long long* arg_values,  // NOLINT(runtime/int)
84       unsigned char flags) {
85     RTC_DCHECK(traced_report_);
86     EXPECT_STREQ("webrtc_stats",
87                  reinterpret_cast<const char*>(category_enabled));
88     EXPECT_STREQ("webrtc_stats", name);
89     EXPECT_EQ(1, num_args);
90     EXPECT_STREQ("report", arg_names[0]);
91     EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]);
92 
93     traced_report_->last_trace_ = reinterpret_cast<const char*>(arg_values[0]);
94   }
95 
96   static RTCStatsReportTraceListener* traced_report_;
97   std::string last_trace_;
98 };
99 
100 RTCStatsReportTraceListener* RTCStatsReportTraceListener::traced_report_ =
101     nullptr;
102 
103 class RTCStatsIntegrationTest : public ::testing::Test {
104  public:
RTCStatsIntegrationTest()105   RTCStatsIntegrationTest()
106       : network_thread_(new rtc::Thread(&virtual_socket_server_)),
107         worker_thread_(rtc::Thread::Create()) {
108     RTCStatsReportTraceListener::SetUp();
109 
110     RTC_CHECK(network_thread_->Start());
111     RTC_CHECK(worker_thread_->Start());
112 
113     caller_ = rtc::make_ref_counted<PeerConnectionTestWrapper>(
114         "caller", &virtual_socket_server_, network_thread_.get(),
115         worker_thread_.get());
116     callee_ = rtc::make_ref_counted<PeerConnectionTestWrapper>(
117         "callee", &virtual_socket_server_, network_thread_.get(),
118         worker_thread_.get());
119   }
120 
StartCall()121   void StartCall() {
122     // Create PeerConnections and "connect" sigslots
123     PeerConnectionInterface::RTCConfiguration config;
124     config.sdp_semantics = SdpSemantics::kUnifiedPlan;
125     PeerConnectionInterface::IceServer ice_server;
126     ice_server.uri = "stun:1.1.1.1:3478";
127     config.servers.push_back(ice_server);
128     EXPECT_TRUE(caller_->CreatePc(config, CreateBuiltinAudioEncoderFactory(),
129                                   CreateBuiltinAudioDecoderFactory()));
130     EXPECT_TRUE(callee_->CreatePc(config, CreateBuiltinAudioEncoderFactory(),
131                                   CreateBuiltinAudioDecoderFactory()));
132     PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get());
133 
134     // Get user media for audio and video
135     caller_->GetAndAddUserMedia(true, cricket::AudioOptions(), true);
136     callee_->GetAndAddUserMedia(true, cricket::AudioOptions(), true);
137 
138     // Create data channels
139     DataChannelInit init;
140     caller_->CreateDataChannel("data", init);
141     callee_->CreateDataChannel("data", init);
142 
143     // Negotiate and wait for call to establish
144     caller_->CreateOffer(PeerConnectionInterface::RTCOfferAnswerOptions());
145     caller_->WaitForCallEstablished();
146     callee_->WaitForCallEstablished();
147   }
148 
GetStatsFromCaller()149   rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCaller() {
150     return GetStats(caller_->pc());
151   }
GetStatsFromCaller(rtc::scoped_refptr<RtpSenderInterface> selector)152   rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCaller(
153       rtc::scoped_refptr<RtpSenderInterface> selector) {
154     return GetStats(caller_->pc(), selector);
155   }
GetStatsFromCaller(rtc::scoped_refptr<RtpReceiverInterface> selector)156   rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCaller(
157       rtc::scoped_refptr<RtpReceiverInterface> selector) {
158     return GetStats(caller_->pc(), selector);
159   }
160 
GetStatsFromCallee()161   rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCallee() {
162     return GetStats(callee_->pc());
163   }
GetStatsFromCallee(rtc::scoped_refptr<RtpSenderInterface> selector)164   rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCallee(
165       rtc::scoped_refptr<RtpSenderInterface> selector) {
166     return GetStats(callee_->pc(), selector);
167   }
GetStatsFromCallee(rtc::scoped_refptr<RtpReceiverInterface> selector)168   rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCallee(
169       rtc::scoped_refptr<RtpReceiverInterface> selector) {
170     return GetStats(callee_->pc(), selector);
171   }
172 
173  protected:
GetStats(PeerConnectionInterface * pc)174   static rtc::scoped_refptr<const RTCStatsReport> GetStats(
175       PeerConnectionInterface* pc) {
176     rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
177         RTCStatsObtainer::Create();
178     pc->GetStats(stats_obtainer.get());
179     EXPECT_TRUE_WAIT(stats_obtainer->report() != nullptr, kGetStatsTimeoutMs);
180     return stats_obtainer->report();
181   }
182 
183   template <typename T>
GetStats(PeerConnectionInterface * pc,rtc::scoped_refptr<T> selector)184   static rtc::scoped_refptr<const RTCStatsReport> GetStats(
185       PeerConnectionInterface* pc,
186       rtc::scoped_refptr<T> selector) {
187     rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
188         RTCStatsObtainer::Create();
189     pc->GetStats(selector, stats_obtainer);
190     EXPECT_TRUE_WAIT(stats_obtainer->report() != nullptr, kGetStatsTimeoutMs);
191     return stats_obtainer->report();
192   }
193 
194   // `network_thread_` uses `virtual_socket_server_` so they must be
195   // constructed/destructed in the correct order.
196   rtc::VirtualSocketServer virtual_socket_server_;
197   std::unique_ptr<rtc::Thread> network_thread_;
198   std::unique_ptr<rtc::Thread> worker_thread_;
199   rtc::scoped_refptr<PeerConnectionTestWrapper> caller_;
200   rtc::scoped_refptr<PeerConnectionTestWrapper> callee_;
201 };
202 
203 class RTCStatsVerifier {
204  public:
RTCStatsVerifier(const RTCStatsReport * report,const RTCStats * stats)205   RTCStatsVerifier(const RTCStatsReport* report, const RTCStats* stats)
206       : report_(report), stats_(stats), all_tests_successful_(true) {
207     RTC_CHECK(report_);
208     RTC_CHECK(stats_);
209     for (const RTCStatsMemberInterface* member : stats_->Members()) {
210       untested_members_.insert(member);
211     }
212   }
213 
MarkMemberTested(const RTCStatsMemberInterface & member,bool test_successful)214   void MarkMemberTested(const RTCStatsMemberInterface& member,
215                         bool test_successful) {
216     untested_members_.erase(&member);
217     all_tests_successful_ &= test_successful;
218   }
219 
TestMemberIsDefined(const RTCStatsMemberInterface & member)220   void TestMemberIsDefined(const RTCStatsMemberInterface& member) {
221     EXPECT_TRUE(member.is_defined())
222         << stats_->type() << "." << member.name() << "[" << stats_->id()
223         << "] was undefined.";
224     MarkMemberTested(member, member.is_defined());
225   }
226 
TestMemberIsUndefined(const RTCStatsMemberInterface & member)227   void TestMemberIsUndefined(const RTCStatsMemberInterface& member) {
228     EXPECT_FALSE(member.is_defined())
229         << stats_->type() << "." << member.name() << "[" << stats_->id()
230         << "] was defined (" << member.ValueToString() << ").";
231     MarkMemberTested(member, !member.is_defined());
232   }
233 
234   template <typename T>
TestMemberIsPositive(const RTCStatsMemberInterface & member)235   void TestMemberIsPositive(const RTCStatsMemberInterface& member) {
236     EXPECT_TRUE(member.is_defined())
237         << stats_->type() << "." << member.name() << "[" << stats_->id()
238         << "] was undefined.";
239     if (!member.is_defined()) {
240       MarkMemberTested(member, false);
241       return;
242     }
243     bool is_positive = *member.cast_to<RTCStatsMember<T>>() > T(0);
244     EXPECT_TRUE(is_positive)
245         << stats_->type() << "." << member.name() << "[" << stats_->id()
246         << "] was not positive (" << member.ValueToString() << ").";
247     MarkMemberTested(member, is_positive);
248   }
249 
250   template <typename T>
TestMemberIsNonNegative(const RTCStatsMemberInterface & member)251   void TestMemberIsNonNegative(const RTCStatsMemberInterface& member) {
252     EXPECT_TRUE(member.is_defined())
253         << stats_->type() << "." << member.name() << "[" << stats_->id()
254         << "] was undefined.";
255     if (!member.is_defined()) {
256       MarkMemberTested(member, false);
257       return;
258     }
259     bool is_non_negative = *member.cast_to<RTCStatsMember<T>>() >= T(0);
260     EXPECT_TRUE(is_non_negative)
261         << stats_->type() << "." << member.name() << "[" << stats_->id()
262         << "] was not non-negative (" << member.ValueToString() << ").";
263     MarkMemberTested(member, is_non_negative);
264   }
265 
TestMemberIsIDReference(const RTCStatsMemberInterface & member,const char * expected_type)266   void TestMemberIsIDReference(const RTCStatsMemberInterface& member,
267                                const char* expected_type) {
268     TestMemberIsIDReference(member, expected_type, false);
269   }
270 
TestMemberIsOptionalIDReference(const RTCStatsMemberInterface & member,const char * expected_type)271   void TestMemberIsOptionalIDReference(const RTCStatsMemberInterface& member,
272                                        const char* expected_type) {
273     TestMemberIsIDReference(member, expected_type, true);
274   }
275 
ExpectAllMembersSuccessfullyTested()276   bool ExpectAllMembersSuccessfullyTested() {
277     if (untested_members_.empty())
278       return all_tests_successful_;
279     for (const RTCStatsMemberInterface* member : untested_members_) {
280       EXPECT_TRUE(false) << stats_->type() << "." << member->name() << "["
281                          << stats_->id() << "] was not tested.";
282     }
283     return false;
284   }
285 
286  private:
TestMemberIsIDReference(const RTCStatsMemberInterface & member,const char * expected_type,bool optional)287   void TestMemberIsIDReference(const RTCStatsMemberInterface& member,
288                                const char* expected_type,
289                                bool optional) {
290     if (optional && !member.is_defined()) {
291       MarkMemberTested(member, true);
292       return;
293     }
294     bool valid_reference = false;
295     if (member.is_defined()) {
296       if (member.type() == RTCStatsMemberInterface::kString) {
297         // A single ID.
298         const RTCStatsMember<std::string>& id =
299             member.cast_to<RTCStatsMember<std::string>>();
300         const RTCStats* referenced_stats = report_->Get(*id);
301         valid_reference =
302             referenced_stats && referenced_stats->type() == expected_type;
303       } else if (member.type() == RTCStatsMemberInterface::kSequenceString) {
304         // A vector of IDs.
305         valid_reference = true;
306         const RTCStatsMember<std::vector<std::string>>& ids =
307             member.cast_to<RTCStatsMember<std::vector<std::string>>>();
308         for (const std::string& id : *ids) {
309           const RTCStats* referenced_stats = report_->Get(id);
310           if (!referenced_stats || referenced_stats->type() != expected_type) {
311             valid_reference = false;
312             break;
313           }
314         }
315       }
316     }
317     EXPECT_TRUE(valid_reference)
318         << stats_->type() << "." << member.name()
319         << " is not a reference to an "
320            "existing dictionary of type "
321         << expected_type << " (value: "
322         << (member.is_defined() ? member.ValueToString() : "null") << ").";
323     MarkMemberTested(member, valid_reference);
324   }
325 
326   rtc::scoped_refptr<const RTCStatsReport> report_;
327   const RTCStats* stats_;
328   std::set<const RTCStatsMemberInterface*> untested_members_;
329   bool all_tests_successful_;
330 };
331 
332 class RTCStatsReportVerifier {
333  public:
StatsTypes()334   static std::set<const char*> StatsTypes() {
335     std::set<const char*> stats_types;
336     stats_types.insert(RTCCertificateStats::kType);
337     stats_types.insert(RTCCodecStats::kType);
338     stats_types.insert(RTCDataChannelStats::kType);
339     stats_types.insert(RTCIceCandidatePairStats::kType);
340     stats_types.insert(RTCLocalIceCandidateStats::kType);
341     stats_types.insert(RTCRemoteIceCandidateStats::kType);
342     stats_types.insert(DEPRECATED_RTCMediaStreamStats::kType);
343     stats_types.insert(DEPRECATED_RTCMediaStreamTrackStats::kType);
344     stats_types.insert(RTCPeerConnectionStats::kType);
345     stats_types.insert(RTCInboundRTPStreamStats::kType);
346     stats_types.insert(RTCOutboundRTPStreamStats::kType);
347     stats_types.insert(RTCTransportStats::kType);
348     return stats_types;
349   }
350 
RTCStatsReportVerifier(const RTCStatsReport * report)351   explicit RTCStatsReportVerifier(const RTCStatsReport* report)
352       : report_(report) {}
353 
VerifyReport(std::vector<const char * > allowed_missing_stats)354   void VerifyReport(std::vector<const char*> allowed_missing_stats) {
355     std::set<const char*> missing_stats = StatsTypes();
356     bool verify_successful = true;
357     std::vector<const RTCTransportStats*> transport_stats =
358         report_->GetStatsOfType<RTCTransportStats>();
359     EXPECT_EQ(transport_stats.size(), 1U);
360     std::string selected_candidate_pair_id =
361         *transport_stats[0]->selected_candidate_pair_id;
362     for (const RTCStats& stats : *report_) {
363       missing_stats.erase(stats.type());
364       if (stats.type() == RTCCertificateStats::kType) {
365         verify_successful &=
366             VerifyRTCCertificateStats(stats.cast_to<RTCCertificateStats>());
367       } else if (stats.type() == RTCCodecStats::kType) {
368         verify_successful &=
369             VerifyRTCCodecStats(stats.cast_to<RTCCodecStats>());
370       } else if (stats.type() == RTCDataChannelStats::kType) {
371         verify_successful &=
372             VerifyRTCDataChannelStats(stats.cast_to<RTCDataChannelStats>());
373       } else if (stats.type() == RTCIceCandidatePairStats::kType) {
374         verify_successful &= VerifyRTCIceCandidatePairStats(
375             stats.cast_to<RTCIceCandidatePairStats>(),
376             stats.id() == selected_candidate_pair_id);
377       } else if (stats.type() == RTCLocalIceCandidateStats::kType) {
378         verify_successful &= VerifyRTCLocalIceCandidateStats(
379             stats.cast_to<RTCLocalIceCandidateStats>());
380       } else if (stats.type() == RTCRemoteIceCandidateStats::kType) {
381         verify_successful &= VerifyRTCRemoteIceCandidateStats(
382             stats.cast_to<RTCRemoteIceCandidateStats>());
383       } else if (stats.type() == DEPRECATED_RTCMediaStreamStats::kType) {
384         verify_successful &= DEPRECATED_VerifyRTCMediaStreamStats(
385             stats.cast_to<DEPRECATED_RTCMediaStreamStats>());
386       } else if (stats.type() == DEPRECATED_RTCMediaStreamTrackStats::kType) {
387         verify_successful &= VerLegacyifyRTCMediaStreamTrackStats(
388             stats.cast_to<DEPRECATED_RTCMediaStreamTrackStats>());
389       } else if (stats.type() == RTCPeerConnectionStats::kType) {
390         verify_successful &= VerifyRTCPeerConnectionStats(
391             stats.cast_to<RTCPeerConnectionStats>());
392       } else if (stats.type() == RTCInboundRTPStreamStats::kType) {
393         verify_successful &= VerifyRTCInboundRTPStreamStats(
394             stats.cast_to<RTCInboundRTPStreamStats>());
395       } else if (stats.type() == RTCOutboundRTPStreamStats::kType) {
396         verify_successful &= VerifyRTCOutboundRTPStreamStats(
397             stats.cast_to<RTCOutboundRTPStreamStats>());
398       } else if (stats.type() == RTCRemoteInboundRtpStreamStats::kType) {
399         verify_successful &= VerifyRTCRemoteInboundRtpStreamStats(
400             stats.cast_to<RTCRemoteInboundRtpStreamStats>());
401       } else if (stats.type() == RTCRemoteOutboundRtpStreamStats::kType) {
402         verify_successful &= VerifyRTCRemoteOutboundRTPStreamStats(
403             stats.cast_to<RTCRemoteOutboundRtpStreamStats>());
404       } else if (stats.type() == RTCAudioSourceStats::kType) {
405         // RTCAudioSourceStats::kType and RTCVideoSourceStats::kType both have
406         // the value "media-source", but they are distinguishable with pointer
407         // equality (==). In JavaScript they would be distinguished with `kind`.
408         verify_successful &=
409             VerifyRTCAudioSourceStats(stats.cast_to<RTCAudioSourceStats>());
410       } else if (stats.type() == RTCVideoSourceStats::kType) {
411         // RTCAudioSourceStats::kType and RTCVideoSourceStats::kType both have
412         // the value "media-source", but they are distinguishable with pointer
413         // equality (==). In JavaScript they would be distinguished with `kind`.
414         verify_successful &=
415             VerifyRTCVideoSourceStats(stats.cast_to<RTCVideoSourceStats>());
416       } else if (stats.type() == RTCTransportStats::kType) {
417         verify_successful &=
418             VerifyRTCTransportStats(stats.cast_to<RTCTransportStats>());
419       } else {
420         EXPECT_TRUE(false) << "Unrecognized stats type: " << stats.type();
421         verify_successful = false;
422       }
423     }
424     for (const char* missing : missing_stats) {
425       if (!absl::c_linear_search(allowed_missing_stats, missing)) {
426         verify_successful = false;
427         EXPECT_TRUE(false) << "Missing expected stats type: " << missing;
428       }
429     }
430     EXPECT_TRUE(verify_successful)
431         << "One or more problems with the stats. This is the report:\n"
432         << report_->ToJson();
433   }
434 
VerifyRTCCertificateStats(const RTCCertificateStats & certificate)435   bool VerifyRTCCertificateStats(const RTCCertificateStats& certificate) {
436     RTCStatsVerifier verifier(report_.get(), &certificate);
437     verifier.TestMemberIsDefined(certificate.fingerprint);
438     verifier.TestMemberIsDefined(certificate.fingerprint_algorithm);
439     verifier.TestMemberIsDefined(certificate.base64_certificate);
440     verifier.TestMemberIsOptionalIDReference(certificate.issuer_certificate_id,
441                                              RTCCertificateStats::kType);
442     return verifier.ExpectAllMembersSuccessfullyTested();
443   }
444 
VerifyRTCCodecStats(const RTCCodecStats & codec)445   bool VerifyRTCCodecStats(const RTCCodecStats& codec) {
446     RTCStatsVerifier verifier(report_.get(), &codec);
447     verifier.TestMemberIsIDReference(codec.transport_id,
448                                      RTCTransportStats::kType);
449     verifier.TestMemberIsDefined(codec.payload_type);
450     verifier.TestMemberIsDefined(codec.mime_type);
451     verifier.TestMemberIsPositive<uint32_t>(codec.clock_rate);
452 
453     if (codec.mime_type->rfind("audio", 0) == 0)
454       verifier.TestMemberIsPositive<uint32_t>(codec.channels);
455     else
456       verifier.TestMemberIsUndefined(codec.channels);
457 
458     // sdp_fmtp_line is an optional field.
459     verifier.MarkMemberTested(codec.sdp_fmtp_line, true);
460     return verifier.ExpectAllMembersSuccessfullyTested();
461   }
462 
VerifyRTCDataChannelStats(const RTCDataChannelStats & data_channel)463   bool VerifyRTCDataChannelStats(const RTCDataChannelStats& data_channel) {
464     RTCStatsVerifier verifier(report_.get(), &data_channel);
465     verifier.TestMemberIsDefined(data_channel.label);
466     verifier.TestMemberIsDefined(data_channel.protocol);
467     verifier.TestMemberIsDefined(data_channel.data_channel_identifier);
468     verifier.TestMemberIsDefined(data_channel.state);
469     verifier.TestMemberIsNonNegative<uint32_t>(data_channel.messages_sent);
470     verifier.TestMemberIsNonNegative<uint64_t>(data_channel.bytes_sent);
471     verifier.TestMemberIsNonNegative<uint32_t>(data_channel.messages_received);
472     verifier.TestMemberIsNonNegative<uint64_t>(data_channel.bytes_received);
473     return verifier.ExpectAllMembersSuccessfullyTested();
474   }
475 
VerifyRTCIceCandidatePairStats(const RTCIceCandidatePairStats & candidate_pair,bool is_selected_pair)476   bool VerifyRTCIceCandidatePairStats(
477       const RTCIceCandidatePairStats& candidate_pair,
478       bool is_selected_pair) {
479     RTCStatsVerifier verifier(report_.get(), &candidate_pair);
480     verifier.TestMemberIsIDReference(candidate_pair.transport_id,
481                                      RTCTransportStats::kType);
482     verifier.TestMemberIsIDReference(candidate_pair.local_candidate_id,
483                                      RTCLocalIceCandidateStats::kType);
484     verifier.TestMemberIsIDReference(candidate_pair.remote_candidate_id,
485                                      RTCRemoteIceCandidateStats::kType);
486     verifier.TestMemberIsDefined(candidate_pair.state);
487     verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.priority);
488     verifier.TestMemberIsDefined(candidate_pair.nominated);
489     verifier.TestMemberIsDefined(candidate_pair.writable);
490     verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.packets_sent);
491     verifier.TestMemberIsNonNegative<uint64_t>(
492         candidate_pair.packets_discarded_on_send);
493     verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.packets_received);
494     verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.bytes_sent);
495     verifier.TestMemberIsNonNegative<uint64_t>(
496         candidate_pair.bytes_discarded_on_send);
497     verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.bytes_received);
498     verifier.TestMemberIsNonNegative<double>(
499         candidate_pair.total_round_trip_time);
500     verifier.TestMemberIsNonNegative<double>(
501         candidate_pair.current_round_trip_time);
502     if (is_selected_pair) {
503       verifier.TestMemberIsNonNegative<double>(
504           candidate_pair.available_outgoing_bitrate);
505       // A pair should be nominated in order to be selected.
506       EXPECT_TRUE(*candidate_pair.nominated);
507     } else {
508       verifier.TestMemberIsUndefined(candidate_pair.available_outgoing_bitrate);
509     }
510     verifier.TestMemberIsUndefined(candidate_pair.available_incoming_bitrate);
511     verifier.TestMemberIsNonNegative<uint64_t>(
512         candidate_pair.requests_received);
513     verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.requests_sent);
514     verifier.TestMemberIsNonNegative<uint64_t>(
515         candidate_pair.responses_received);
516     verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.responses_sent);
517     verifier.TestMemberIsNonNegative<uint64_t>(
518         candidate_pair.consent_requests_sent);
519     verifier.TestMemberIsDefined(candidate_pair.last_packet_received_timestamp);
520     verifier.TestMemberIsDefined(candidate_pair.last_packet_sent_timestamp);
521 
522     return verifier.ExpectAllMembersSuccessfullyTested();
523   }
524 
VerifyRTCIceCandidateStats(const RTCIceCandidateStats & candidate)525   bool VerifyRTCIceCandidateStats(const RTCIceCandidateStats& candidate) {
526     RTCStatsVerifier verifier(report_.get(), &candidate);
527     verifier.TestMemberIsIDReference(candidate.transport_id,
528                                      RTCTransportStats::kType);
529     verifier.TestMemberIsDefined(candidate.is_remote);
530     if (*candidate.is_remote) {
531       verifier.TestMemberIsUndefined(candidate.network_type);
532       verifier.TestMemberIsUndefined(candidate.network_adapter_type);
533       verifier.TestMemberIsUndefined(candidate.vpn);
534     } else {
535       verifier.TestMemberIsDefined(candidate.network_type);
536       verifier.TestMemberIsDefined(candidate.network_adapter_type);
537       verifier.TestMemberIsDefined(candidate.vpn);
538     }
539     verifier.TestMemberIsDefined(candidate.ip);
540     verifier.TestMemberIsDefined(candidate.address);
541     verifier.TestMemberIsNonNegative<int32_t>(candidate.port);
542     verifier.TestMemberIsDefined(candidate.protocol);
543     verifier.TestMemberIsDefined(candidate.candidate_type);
544     verifier.TestMemberIsNonNegative<int32_t>(candidate.priority);
545     verifier.TestMemberIsUndefined(candidate.url);
546     verifier.TestMemberIsUndefined(candidate.relay_protocol);
547     verifier.TestMemberIsDefined(candidate.foundation);
548     verifier.TestMemberIsUndefined(candidate.related_address);
549     verifier.TestMemberIsUndefined(candidate.related_port);
550     verifier.TestMemberIsDefined(candidate.username_fragment);
551     verifier.TestMemberIsUndefined(candidate.tcp_type);
552     return verifier.ExpectAllMembersSuccessfullyTested();
553   }
554 
VerifyRTCLocalIceCandidateStats(const RTCLocalIceCandidateStats & local_candidate)555   bool VerifyRTCLocalIceCandidateStats(
556       const RTCLocalIceCandidateStats& local_candidate) {
557     return VerifyRTCIceCandidateStats(local_candidate);
558   }
559 
VerifyRTCRemoteIceCandidateStats(const RTCRemoteIceCandidateStats & remote_candidate)560   bool VerifyRTCRemoteIceCandidateStats(
561       const RTCRemoteIceCandidateStats& remote_candidate) {
562     return VerifyRTCIceCandidateStats(remote_candidate);
563   }
564 
DEPRECATED_VerifyRTCMediaStreamStats(const DEPRECATED_RTCMediaStreamStats & media_stream)565   bool DEPRECATED_VerifyRTCMediaStreamStats(
566       const DEPRECATED_RTCMediaStreamStats& media_stream) {
567     RTCStatsVerifier verifier(report_.get(), &media_stream);
568     verifier.TestMemberIsDefined(media_stream.stream_identifier);
569     verifier.TestMemberIsIDReference(
570         media_stream.track_ids, DEPRECATED_RTCMediaStreamTrackStats::kType);
571     return verifier.ExpectAllMembersSuccessfullyTested();
572   }
573 
VerLegacyifyRTCMediaStreamTrackStats(const DEPRECATED_RTCMediaStreamTrackStats & media_stream_track)574   bool VerLegacyifyRTCMediaStreamTrackStats(
575       const DEPRECATED_RTCMediaStreamTrackStats& media_stream_track) {
576     RTCStatsVerifier verifier(report_.get(), &media_stream_track);
577     verifier.TestMemberIsDefined(media_stream_track.track_identifier);
578     verifier.TestMemberIsDefined(media_stream_track.remote_source);
579     verifier.TestMemberIsDefined(media_stream_track.ended);
580     verifier.TestMemberIsDefined(media_stream_track.detached);
581     verifier.TestMemberIsDefined(media_stream_track.kind);
582     RTC_DCHECK(media_stream_track.remote_source.is_defined());
583     // Video or audio media stream track?
584     if (*media_stream_track.kind == RTCMediaStreamTrackKind::kVideo) {
585       // The type of the referenced media source depends on kind.
586       if (*media_stream_track.remote_source) {
587         verifier.TestMemberIsUndefined(media_stream_track.media_source_id);
588         verifier.TestMemberIsNonNegative<double>(
589             media_stream_track.jitter_buffer_delay);
590         verifier.TestMemberIsNonNegative<uint64_t>(
591             media_stream_track.jitter_buffer_emitted_count);
592         verifier.TestMemberIsUndefined(media_stream_track.frames_sent);
593         verifier.TestMemberIsUndefined(media_stream_track.huge_frames_sent);
594         verifier.TestMemberIsNonNegative<uint32_t>(
595             media_stream_track.frames_received);
596         verifier.TestMemberIsNonNegative<uint32_t>(
597             media_stream_track.frames_decoded);
598         verifier.TestMemberIsNonNegative<uint32_t>(
599             media_stream_track.frames_dropped);
600       } else {
601         verifier.TestMemberIsIDReference(media_stream_track.media_source_id,
602                                          RTCVideoSourceStats::kType);
603         // Local tracks have no jitter buffer.
604         verifier.TestMemberIsUndefined(media_stream_track.jitter_buffer_delay);
605         verifier.TestMemberIsUndefined(
606             media_stream_track.jitter_buffer_emitted_count);
607         verifier.TestMemberIsNonNegative<uint32_t>(
608             media_stream_track.frames_sent);
609         verifier.TestMemberIsNonNegative<uint32_t>(
610             media_stream_track.huge_frames_sent);
611         verifier.TestMemberIsUndefined(media_stream_track.frames_received);
612         verifier.TestMemberIsUndefined(media_stream_track.frames_decoded);
613         verifier.TestMemberIsUndefined(media_stream_track.frames_dropped);
614       }
615       // Video-only members
616       verifier.TestMemberIsNonNegative<uint32_t>(
617           media_stream_track.frame_width);
618       verifier.TestMemberIsNonNegative<uint32_t>(
619           media_stream_track.frame_height);
620       // Audio-only members should be undefined
621       verifier.TestMemberIsUndefined(media_stream_track.audio_level);
622       verifier.TestMemberIsUndefined(media_stream_track.echo_return_loss);
623       verifier.TestMemberIsUndefined(
624           media_stream_track.echo_return_loss_enhancement);
625       verifier.TestMemberIsUndefined(media_stream_track.total_audio_energy);
626       verifier.TestMemberIsUndefined(media_stream_track.total_samples_duration);
627       verifier.TestMemberIsUndefined(media_stream_track.total_samples_received);
628       verifier.TestMemberIsUndefined(media_stream_track.concealed_samples);
629       verifier.TestMemberIsUndefined(
630           media_stream_track.silent_concealed_samples);
631       verifier.TestMemberIsUndefined(media_stream_track.concealment_events);
632       verifier.TestMemberIsUndefined(
633           media_stream_track.inserted_samples_for_deceleration);
634       verifier.TestMemberIsUndefined(
635           media_stream_track.removed_samples_for_acceleration);
636     } else {
637       RTC_DCHECK_EQ(*media_stream_track.kind, RTCMediaStreamTrackKind::kAudio);
638       // The type of the referenced media source depends on kind.
639       if (*media_stream_track.remote_source) {
640         // Remote tracks don't have media source stats.
641         verifier.TestMemberIsUndefined(media_stream_track.media_source_id);
642         verifier.TestMemberIsNonNegative<double>(
643             media_stream_track.jitter_buffer_delay);
644         verifier.TestMemberIsNonNegative<uint64_t>(
645             media_stream_track.jitter_buffer_emitted_count);
646         verifier.TestMemberIsPositive<double>(media_stream_track.audio_level);
647         verifier.TestMemberIsPositive<double>(
648             media_stream_track.total_audio_energy);
649         verifier.TestMemberIsPositive<uint64_t>(
650             media_stream_track.total_samples_received);
651         verifier.TestMemberIsPositive<double>(
652             media_stream_track.total_samples_duration);
653         verifier.TestMemberIsNonNegative<uint64_t>(
654             media_stream_track.concealed_samples);
655         verifier.TestMemberIsNonNegative<uint64_t>(
656             media_stream_track.silent_concealed_samples);
657         verifier.TestMemberIsNonNegative<uint64_t>(
658             media_stream_track.concealment_events);
659         verifier.TestMemberIsNonNegative<uint64_t>(
660             media_stream_track.inserted_samples_for_deceleration);
661         verifier.TestMemberIsNonNegative<uint64_t>(
662             media_stream_track.removed_samples_for_acceleration);
663       } else {
664         verifier.TestMemberIsIDReference(media_stream_track.media_source_id,
665                                          RTCAudioSourceStats::kType);
666         // Local audio tracks have no jitter buffer.
667         verifier.TestMemberIsUndefined(media_stream_track.jitter_buffer_delay);
668         verifier.TestMemberIsUndefined(
669             media_stream_track.jitter_buffer_emitted_count);
670         verifier.TestMemberIsUndefined(media_stream_track.audio_level);
671         verifier.TestMemberIsUndefined(media_stream_track.total_audio_energy);
672         verifier.TestMemberIsUndefined(
673             media_stream_track.total_samples_received);
674         verifier.TestMemberIsUndefined(
675             media_stream_track.total_samples_duration);
676         verifier.TestMemberIsUndefined(media_stream_track.concealed_samples);
677         verifier.TestMemberIsUndefined(
678             media_stream_track.silent_concealed_samples);
679         verifier.TestMemberIsUndefined(media_stream_track.concealment_events);
680         verifier.TestMemberIsUndefined(
681             media_stream_track.inserted_samples_for_deceleration);
682         verifier.TestMemberIsUndefined(
683             media_stream_track.removed_samples_for_acceleration);
684       }
685       // Video-only members should be undefined
686       verifier.TestMemberIsUndefined(media_stream_track.frame_width);
687       verifier.TestMemberIsUndefined(media_stream_track.frame_height);
688       verifier.TestMemberIsUndefined(media_stream_track.frames_sent);
689       verifier.TestMemberIsUndefined(media_stream_track.huge_frames_sent);
690       verifier.TestMemberIsUndefined(media_stream_track.frames_received);
691       verifier.TestMemberIsUndefined(media_stream_track.frames_decoded);
692       verifier.TestMemberIsUndefined(media_stream_track.frames_dropped);
693       // Audio-only members
694       // TODO(hbos): `echo_return_loss` and `echo_return_loss_enhancement` are
695       // flaky on msan bot (sometimes defined, sometimes undefined). Should the
696       // test run until available or is there a way to have it always be
697       // defined? crbug.com/627816
698       verifier.MarkMemberTested(media_stream_track.echo_return_loss, true);
699       verifier.MarkMemberTested(media_stream_track.echo_return_loss_enhancement,
700                                 true);
701     }
702     return verifier.ExpectAllMembersSuccessfullyTested();
703   }
704 
VerifyRTCPeerConnectionStats(const RTCPeerConnectionStats & peer_connection)705   bool VerifyRTCPeerConnectionStats(
706       const RTCPeerConnectionStats& peer_connection) {
707     RTCStatsVerifier verifier(report_.get(), &peer_connection);
708     verifier.TestMemberIsNonNegative<uint32_t>(
709         peer_connection.data_channels_opened);
710     verifier.TestMemberIsNonNegative<uint32_t>(
711         peer_connection.data_channels_closed);
712     return verifier.ExpectAllMembersSuccessfullyTested();
713   }
714 
VerifyRTCRTPStreamStats(const RTCRTPStreamStats & stream,RTCStatsVerifier & verifier)715   void VerifyRTCRTPStreamStats(const RTCRTPStreamStats& stream,
716                                RTCStatsVerifier& verifier) {
717     verifier.TestMemberIsDefined(stream.ssrc);
718     verifier.TestMemberIsDefined(stream.kind);
719     // Some legacy metrics are only defined for some of the RTP types in the
720     // hierarcy.
721     if (stream.type() == RTCInboundRTPStreamStats::kType ||
722         stream.type() == RTCOutboundRTPStreamStats::kType) {
723       verifier.TestMemberIsDefined(stream.media_type);
724       verifier.TestMemberIsIDReference(
725           stream.track_id, DEPRECATED_RTCMediaStreamTrackStats::kType);
726     } else {
727       verifier.TestMemberIsUndefined(stream.media_type);
728       verifier.TestMemberIsUndefined(stream.track_id);
729     }
730     verifier.TestMemberIsIDReference(stream.transport_id,
731                                      RTCTransportStats::kType);
732     verifier.TestMemberIsIDReference(stream.codec_id, RTCCodecStats::kType);
733   }
734 
VerifyRTCSentRTPStreamStats(const RTCSentRtpStreamStats & sent_stream,RTCStatsVerifier & verifier)735   void VerifyRTCSentRTPStreamStats(const RTCSentRtpStreamStats& sent_stream,
736                                    RTCStatsVerifier& verifier) {
737     VerifyRTCRTPStreamStats(sent_stream, verifier);
738     verifier.TestMemberIsDefined(sent_stream.packets_sent);
739     verifier.TestMemberIsDefined(sent_stream.bytes_sent);
740   }
741 
VerifyRTCInboundRTPStreamStats(const RTCInboundRTPStreamStats & inbound_stream)742   bool VerifyRTCInboundRTPStreamStats(
743       const RTCInboundRTPStreamStats& inbound_stream) {
744     RTCStatsVerifier verifier(report_.get(), &inbound_stream);
745     VerifyRTCReceivedRtpStreamStats(inbound_stream, verifier);
746     verifier.TestMemberIsOptionalIDReference(
747         inbound_stream.remote_id, RTCRemoteOutboundRtpStreamStats::kType);
748     verifier.TestMemberIsDefined(inbound_stream.mid);
749     verifier.TestMemberIsDefined(inbound_stream.track_identifier);
750     if (inbound_stream.kind.is_defined() && *inbound_stream.kind == "video") {
751       verifier.TestMemberIsNonNegative<uint64_t>(inbound_stream.qp_sum);
752       verifier.TestMemberIsDefined(inbound_stream.decoder_implementation);
753       verifier.TestMemberIsDefined(inbound_stream.power_efficient_decoder);
754       EXPECT_EQ(inbound_stream.power_efficient_decoder.exposure_criteria(),
755                 StatExposureCriteria::kHardwareCapability);
756     } else {
757       verifier.TestMemberIsUndefined(inbound_stream.qp_sum);
758       verifier.TestMemberIsUndefined(inbound_stream.decoder_implementation);
759       verifier.TestMemberIsUndefined(inbound_stream.power_efficient_decoder);
760       EXPECT_EQ(inbound_stream.power_efficient_decoder.exposure_criteria(),
761                 StatExposureCriteria::kHardwareCapability);
762     }
763     verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.packets_received);
764     if (inbound_stream.kind.is_defined() && *inbound_stream.kind == "audio") {
765       verifier.TestMemberIsNonNegative<uint64_t>(
766           inbound_stream.packets_discarded);
767       verifier.TestMemberIsNonNegative<uint64_t>(
768           inbound_stream.fec_packets_received);
769       verifier.TestMemberIsNonNegative<uint64_t>(
770           inbound_stream.fec_packets_discarded);
771     } else {
772       verifier.TestMemberIsUndefined(inbound_stream.packets_discarded);
773       verifier.TestMemberIsUndefined(inbound_stream.fec_packets_received);
774       verifier.TestMemberIsUndefined(inbound_stream.fec_packets_discarded);
775     }
776     verifier.TestMemberIsNonNegative<uint64_t>(inbound_stream.bytes_received);
777     verifier.TestMemberIsNonNegative<uint64_t>(
778         inbound_stream.header_bytes_received);
779     verifier.TestMemberIsDefined(inbound_stream.last_packet_received_timestamp);
780     if (inbound_stream.frames_received.ValueOrDefault(0) > 0) {
781       verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.frame_width);
782       verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.frame_height);
783     } else {
784       verifier.TestMemberIsUndefined(inbound_stream.frame_width);
785       verifier.TestMemberIsUndefined(inbound_stream.frame_height);
786     }
787     if (inbound_stream.frames_per_second.is_defined()) {
788       verifier.TestMemberIsNonNegative<double>(
789           inbound_stream.frames_per_second);
790     } else {
791       verifier.TestMemberIsUndefined(inbound_stream.frames_per_second);
792     }
793     verifier.TestMemberIsNonNegative<double>(
794         inbound_stream.jitter_buffer_delay);
795     verifier.TestMemberIsNonNegative<uint64_t>(
796         inbound_stream.jitter_buffer_emitted_count);
797     if (inbound_stream.kind.is_defined() && *inbound_stream.kind == "video") {
798       verifier.TestMemberIsUndefined(inbound_stream.total_samples_received);
799       verifier.TestMemberIsUndefined(inbound_stream.concealed_samples);
800       verifier.TestMemberIsUndefined(inbound_stream.silent_concealed_samples);
801       verifier.TestMemberIsUndefined(inbound_stream.concealment_events);
802       verifier.TestMemberIsUndefined(
803           inbound_stream.inserted_samples_for_deceleration);
804       verifier.TestMemberIsUndefined(
805           inbound_stream.removed_samples_for_acceleration);
806       verifier.TestMemberIsUndefined(inbound_stream.jitter_buffer_target_delay);
807       verifier.TestMemberIsUndefined(
808           inbound_stream.jitter_buffer_minimum_delay);
809       verifier.TestMemberIsUndefined(inbound_stream.audio_level);
810       verifier.TestMemberIsUndefined(inbound_stream.total_audio_energy);
811       verifier.TestMemberIsUndefined(inbound_stream.total_samples_duration);
812       verifier.TestMemberIsNonNegative<int32_t>(inbound_stream.frames_received);
813       verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.fir_count);
814       verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.pli_count);
815       verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.nack_count);
816     } else {
817       verifier.TestMemberIsUndefined(inbound_stream.fir_count);
818       verifier.TestMemberIsUndefined(inbound_stream.pli_count);
819       verifier.TestMemberIsUndefined(inbound_stream.nack_count);
820       verifier.TestMemberIsPositive<uint64_t>(
821           inbound_stream.total_samples_received);
822       verifier.TestMemberIsNonNegative<uint64_t>(
823           inbound_stream.concealed_samples);
824       verifier.TestMemberIsNonNegative<uint64_t>(
825           inbound_stream.silent_concealed_samples);
826       verifier.TestMemberIsNonNegative<uint64_t>(
827           inbound_stream.concealment_events);
828       verifier.TestMemberIsNonNegative<uint64_t>(
829           inbound_stream.inserted_samples_for_deceleration);
830       verifier.TestMemberIsNonNegative<uint64_t>(
831           inbound_stream.removed_samples_for_acceleration);
832       verifier.TestMemberIsNonNegative<double>(
833           inbound_stream.jitter_buffer_target_delay);
834       verifier.TestMemberIsNonNegative<double>(
835           inbound_stream.jitter_buffer_minimum_delay);
836       verifier.TestMemberIsPositive<double>(inbound_stream.audio_level);
837       verifier.TestMemberIsPositive<double>(inbound_stream.total_audio_energy);
838       verifier.TestMemberIsPositive<double>(
839           inbound_stream.total_samples_duration);
840       verifier.TestMemberIsUndefined(inbound_stream.frames_received);
841     }
842     // Test runtime too short to get an estimate (at least two RTCP sender
843     // reports need to be received).
844     verifier.MarkMemberTested(inbound_stream.estimated_playout_timestamp, true);
845     if (inbound_stream.kind.is_defined() && *inbound_stream.kind == "video") {
846       verifier.TestMemberIsDefined(inbound_stream.frames_decoded);
847       verifier.TestMemberIsDefined(inbound_stream.key_frames_decoded);
848       verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.frames_dropped);
849       verifier.TestMemberIsNonNegative<double>(
850           inbound_stream.total_decode_time);
851       verifier.TestMemberIsNonNegative<double>(
852           inbound_stream.total_processing_delay);
853       verifier.TestMemberIsNonNegative<double>(
854           inbound_stream.total_assembly_time);
855       verifier.TestMemberIsDefined(
856           inbound_stream.frames_assembled_from_multiple_packets);
857       verifier.TestMemberIsNonNegative<double>(
858           inbound_stream.total_inter_frame_delay);
859       verifier.TestMemberIsNonNegative<double>(
860           inbound_stream.total_squared_inter_frame_delay);
861       verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.pause_count);
862       verifier.TestMemberIsNonNegative<double>(
863           inbound_stream.total_pauses_duration);
864       verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.freeze_count);
865       verifier.TestMemberIsNonNegative<double>(
866           inbound_stream.total_freezes_duration);
867       // The integration test is not set up to test screen share; don't require
868       // this to be present.
869       verifier.MarkMemberTested(inbound_stream.content_type, true);
870       verifier.TestMemberIsUndefined(inbound_stream.jitter_buffer_flushes);
871       verifier.TestMemberIsUndefined(
872           inbound_stream.delayed_packet_outage_samples);
873       verifier.TestMemberIsUndefined(
874           inbound_stream.relative_packet_arrival_delay);
875       verifier.TestMemberIsUndefined(inbound_stream.interruption_count);
876       verifier.TestMemberIsUndefined(
877           inbound_stream.total_interruption_duration);
878       verifier.TestMemberIsNonNegative<double>(
879           inbound_stream.min_playout_delay);
880       verifier.TestMemberIsDefined(inbound_stream.goog_timing_frame_info);
881     } else {
882       verifier.TestMemberIsUndefined(inbound_stream.frames_decoded);
883       verifier.TestMemberIsUndefined(inbound_stream.key_frames_decoded);
884       verifier.TestMemberIsUndefined(inbound_stream.frames_dropped);
885       verifier.TestMemberIsUndefined(inbound_stream.total_decode_time);
886       verifier.TestMemberIsUndefined(inbound_stream.total_processing_delay);
887       verifier.TestMemberIsUndefined(inbound_stream.total_assembly_time);
888       verifier.TestMemberIsUndefined(
889           inbound_stream.frames_assembled_from_multiple_packets);
890       verifier.TestMemberIsUndefined(inbound_stream.total_inter_frame_delay);
891       verifier.TestMemberIsUndefined(
892           inbound_stream.total_squared_inter_frame_delay);
893       verifier.TestMemberIsUndefined(inbound_stream.pause_count);
894       verifier.TestMemberIsUndefined(inbound_stream.total_pauses_duration);
895       verifier.TestMemberIsUndefined(inbound_stream.freeze_count);
896       verifier.TestMemberIsUndefined(inbound_stream.total_freezes_duration);
897       verifier.TestMemberIsUndefined(inbound_stream.content_type);
898       verifier.TestMemberIsNonNegative<uint64_t>(
899           inbound_stream.jitter_buffer_flushes);
900       verifier.TestMemberIsNonNegative<uint64_t>(
901           inbound_stream.delayed_packet_outage_samples);
902       verifier.TestMemberIsNonNegative<double>(
903           inbound_stream.relative_packet_arrival_delay);
904       verifier.TestMemberIsNonNegative<uint32_t>(
905           inbound_stream.interruption_count);
906       verifier.TestMemberIsNonNegative<double>(
907           inbound_stream.total_interruption_duration);
908       verifier.TestMemberIsUndefined(inbound_stream.min_playout_delay);
909       verifier.TestMemberIsUndefined(inbound_stream.goog_timing_frame_info);
910     }
911     return verifier.ExpectAllMembersSuccessfullyTested();
912   }
913 
VerifyRTCOutboundRTPStreamStats(const RTCOutboundRTPStreamStats & outbound_stream)914   bool VerifyRTCOutboundRTPStreamStats(
915       const RTCOutboundRTPStreamStats& outbound_stream) {
916     RTCStatsVerifier verifier(report_.get(), &outbound_stream);
917     VerifyRTCRTPStreamStats(outbound_stream, verifier);
918     verifier.TestMemberIsDefined(outbound_stream.mid);
919     verifier.TestMemberIsDefined(outbound_stream.active);
920     if (outbound_stream.kind.is_defined() && *outbound_stream.kind == "video") {
921       verifier.TestMemberIsIDReference(outbound_stream.media_source_id,
922                                        RTCVideoSourceStats::kType);
923       verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.fir_count);
924       verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.pli_count);
925       if (*outbound_stream.frames_encoded > 0) {
926         verifier.TestMemberIsNonNegative<uint64_t>(outbound_stream.qp_sum);
927       } else {
928         verifier.TestMemberIsUndefined(outbound_stream.qp_sum);
929       }
930     } else {
931       verifier.TestMemberIsUndefined(outbound_stream.fir_count);
932       verifier.TestMemberIsUndefined(outbound_stream.pli_count);
933       verifier.TestMemberIsIDReference(outbound_stream.media_source_id,
934                                        RTCAudioSourceStats::kType);
935       verifier.TestMemberIsUndefined(outbound_stream.qp_sum);
936     }
937     verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.nack_count);
938     verifier.TestMemberIsOptionalIDReference(
939         outbound_stream.remote_id, RTCRemoteInboundRtpStreamStats::kType);
940     verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.packets_sent);
941     verifier.TestMemberIsNonNegative<double>(
942         outbound_stream.total_packet_send_delay);
943     verifier.TestMemberIsNonNegative<uint64_t>(
944         outbound_stream.retransmitted_packets_sent);
945     verifier.TestMemberIsNonNegative<uint64_t>(outbound_stream.bytes_sent);
946     verifier.TestMemberIsNonNegative<uint64_t>(
947         outbound_stream.header_bytes_sent);
948     verifier.TestMemberIsNonNegative<uint64_t>(
949         outbound_stream.retransmitted_bytes_sent);
950     verifier.TestMemberIsNonNegative<double>(outbound_stream.target_bitrate);
951     if (outbound_stream.kind.is_defined() && *outbound_stream.kind == "video") {
952       verifier.TestMemberIsDefined(outbound_stream.frames_encoded);
953       verifier.TestMemberIsDefined(outbound_stream.key_frames_encoded);
954       verifier.TestMemberIsNonNegative<double>(
955           outbound_stream.total_encode_time);
956       verifier.TestMemberIsNonNegative<uint64_t>(
957           outbound_stream.total_encoded_bytes_target);
958       verifier.TestMemberIsDefined(outbound_stream.quality_limitation_reason);
959       verifier.TestMemberIsDefined(
960           outbound_stream.quality_limitation_durations);
961       verifier.TestMemberIsNonNegative<uint32_t>(
962           outbound_stream.quality_limitation_resolution_changes);
963       // The integration test is not set up to test screen share; don't require
964       // this to be present.
965       verifier.MarkMemberTested(outbound_stream.content_type, true);
966       verifier.TestMemberIsDefined(outbound_stream.encoder_implementation);
967       verifier.TestMemberIsDefined(outbound_stream.power_efficient_encoder);
968       EXPECT_EQ(outbound_stream.power_efficient_encoder.exposure_criteria(),
969                 StatExposureCriteria::kHardwareCapability);
970       // Unless an implementation-specific amount of time has passed and at
971       // least one frame has been encoded, undefined is reported. Because it
972       // is hard to tell what is the case here, we treat FPS as optional.
973       // TODO(hbos): Update the tests to run until all implemented metrics
974       // should be populated.
975       if (outbound_stream.frames_per_second.is_defined()) {
976         verifier.TestMemberIsNonNegative<double>(
977             outbound_stream.frames_per_second);
978       } else {
979         verifier.TestMemberIsUndefined(outbound_stream.frames_per_second);
980       }
981       verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.frame_height);
982       verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.frame_width);
983       verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.frames_sent);
984       verifier.TestMemberIsNonNegative<uint32_t>(
985           outbound_stream.huge_frames_sent);
986       verifier.MarkMemberTested(outbound_stream.rid, true);
987     } else {
988       verifier.TestMemberIsUndefined(outbound_stream.frames_encoded);
989       verifier.TestMemberIsUndefined(outbound_stream.key_frames_encoded);
990       verifier.TestMemberIsUndefined(outbound_stream.total_encode_time);
991       verifier.TestMemberIsUndefined(
992           outbound_stream.total_encoded_bytes_target);
993       verifier.TestMemberIsUndefined(outbound_stream.quality_limitation_reason);
994       verifier.TestMemberIsUndefined(
995           outbound_stream.quality_limitation_durations);
996       verifier.TestMemberIsUndefined(
997           outbound_stream.quality_limitation_resolution_changes);
998       verifier.TestMemberIsUndefined(outbound_stream.content_type);
999       // TODO(hbos): Implement for audio as well.
1000       verifier.TestMemberIsUndefined(outbound_stream.encoder_implementation);
1001       verifier.TestMemberIsUndefined(outbound_stream.power_efficient_encoder);
1002       verifier.TestMemberIsUndefined(outbound_stream.rid);
1003       verifier.TestMemberIsUndefined(outbound_stream.frames_per_second);
1004       verifier.TestMemberIsUndefined(outbound_stream.frame_height);
1005       verifier.TestMemberIsUndefined(outbound_stream.frame_width);
1006       verifier.TestMemberIsUndefined(outbound_stream.frames_sent);
1007       verifier.TestMemberIsUndefined(outbound_stream.huge_frames_sent);
1008     }
1009     return verifier.ExpectAllMembersSuccessfullyTested();
1010   }
1011 
VerifyRTCReceivedRtpStreamStats(const RTCReceivedRtpStreamStats & received_rtp,RTCStatsVerifier & verifier)1012   void VerifyRTCReceivedRtpStreamStats(
1013       const RTCReceivedRtpStreamStats& received_rtp,
1014       RTCStatsVerifier& verifier) {
1015     VerifyRTCRTPStreamStats(received_rtp, verifier);
1016     verifier.TestMemberIsNonNegative<double>(received_rtp.jitter);
1017     verifier.TestMemberIsDefined(received_rtp.packets_lost);
1018   }
1019 
VerifyRTCRemoteInboundRtpStreamStats(const RTCRemoteInboundRtpStreamStats & remote_inbound_stream)1020   bool VerifyRTCRemoteInboundRtpStreamStats(
1021       const RTCRemoteInboundRtpStreamStats& remote_inbound_stream) {
1022     RTCStatsVerifier verifier(report_.get(), &remote_inbound_stream);
1023     VerifyRTCReceivedRtpStreamStats(remote_inbound_stream, verifier);
1024     verifier.TestMemberIsDefined(remote_inbound_stream.fraction_lost);
1025     verifier.TestMemberIsIDReference(remote_inbound_stream.local_id,
1026                                      RTCOutboundRTPStreamStats::kType);
1027     verifier.TestMemberIsNonNegative<double>(
1028         remote_inbound_stream.round_trip_time);
1029     verifier.TestMemberIsNonNegative<double>(
1030         remote_inbound_stream.total_round_trip_time);
1031     verifier.TestMemberIsNonNegative<int32_t>(
1032         remote_inbound_stream.round_trip_time_measurements);
1033     return verifier.ExpectAllMembersSuccessfullyTested();
1034   }
1035 
VerifyRTCRemoteOutboundRTPStreamStats(const RTCRemoteOutboundRtpStreamStats & remote_outbound_stream)1036   bool VerifyRTCRemoteOutboundRTPStreamStats(
1037       const RTCRemoteOutboundRtpStreamStats& remote_outbound_stream) {
1038     RTCStatsVerifier verifier(report_.get(), &remote_outbound_stream);
1039     VerifyRTCRTPStreamStats(remote_outbound_stream, verifier);
1040     VerifyRTCSentRTPStreamStats(remote_outbound_stream, verifier);
1041     verifier.TestMemberIsIDReference(remote_outbound_stream.local_id,
1042                                      RTCOutboundRTPStreamStats::kType);
1043     verifier.TestMemberIsNonNegative<double>(
1044         remote_outbound_stream.remote_timestamp);
1045     verifier.TestMemberIsDefined(remote_outbound_stream.reports_sent);
1046     return verifier.ExpectAllMembersSuccessfullyTested();
1047   }
1048 
VerifyRTCMediaSourceStats(const RTCMediaSourceStats & media_source,RTCStatsVerifier * verifier)1049   void VerifyRTCMediaSourceStats(const RTCMediaSourceStats& media_source,
1050                                  RTCStatsVerifier* verifier) {
1051     verifier->TestMemberIsDefined(media_source.track_identifier);
1052     verifier->TestMemberIsDefined(media_source.kind);
1053     if (media_source.kind.is_defined()) {
1054       EXPECT_TRUE((*media_source.kind == "audio" &&
1055                    media_source.type() == RTCAudioSourceStats::kType) ||
1056                   (*media_source.kind == "video" &&
1057                    media_source.type() == RTCVideoSourceStats::kType));
1058     }
1059   }
1060 
VerifyRTCAudioSourceStats(const RTCAudioSourceStats & audio_source)1061   bool VerifyRTCAudioSourceStats(const RTCAudioSourceStats& audio_source) {
1062     RTCStatsVerifier verifier(report_.get(), &audio_source);
1063     VerifyRTCMediaSourceStats(audio_source, &verifier);
1064     // Audio level, unlike audio energy, only gets updated at a certain
1065     // frequency, so we don't require that one to be positive to avoid a race
1066     // (https://crbug.com/webrtc/10962).
1067     verifier.TestMemberIsNonNegative<double>(audio_source.audio_level);
1068     verifier.TestMemberIsPositive<double>(audio_source.total_audio_energy);
1069     verifier.TestMemberIsPositive<double>(audio_source.total_samples_duration);
1070     // TODO(hbos): `echo_return_loss` and `echo_return_loss_enhancement` are
1071     // flaky on msan bot (sometimes defined, sometimes undefined). Should the
1072     // test run until available or is there a way to have it always be
1073     // defined? crbug.com/627816
1074     verifier.MarkMemberTested(audio_source.echo_return_loss, true);
1075     verifier.MarkMemberTested(audio_source.echo_return_loss_enhancement, true);
1076     return verifier.ExpectAllMembersSuccessfullyTested();
1077   }
1078 
VerifyRTCVideoSourceStats(const RTCVideoSourceStats & video_source)1079   bool VerifyRTCVideoSourceStats(const RTCVideoSourceStats& video_source) {
1080     RTCStatsVerifier verifier(report_.get(), &video_source);
1081     VerifyRTCMediaSourceStats(video_source, &verifier);
1082     // TODO(hbos): This integration test uses fakes that doesn't support
1083     // VideoTrackSourceInterface::Stats. When this is fixed we should
1084     // TestMemberIsNonNegative<uint32_t>() for `width` and `height` instead to
1085     // reflect real code.
1086     verifier.TestMemberIsUndefined(video_source.width);
1087     verifier.TestMemberIsUndefined(video_source.height);
1088     verifier.TestMemberIsNonNegative<uint32_t>(video_source.frames);
1089     verifier.TestMemberIsNonNegative<double>(video_source.frames_per_second);
1090     return verifier.ExpectAllMembersSuccessfullyTested();
1091   }
1092 
VerifyRTCTransportStats(const RTCTransportStats & transport)1093   bool VerifyRTCTransportStats(const RTCTransportStats& transport) {
1094     RTCStatsVerifier verifier(report_.get(), &transport);
1095     verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_sent);
1096     verifier.TestMemberIsNonNegative<uint64_t>(transport.packets_sent);
1097     verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_received);
1098     verifier.TestMemberIsNonNegative<uint64_t>(transport.packets_received);
1099     verifier.TestMemberIsOptionalIDReference(transport.rtcp_transport_stats_id,
1100                                              RTCTransportStats::kType);
1101     verifier.TestMemberIsDefined(transport.dtls_state);
1102     verifier.TestMemberIsIDReference(transport.selected_candidate_pair_id,
1103                                      RTCIceCandidatePairStats::kType);
1104     verifier.TestMemberIsIDReference(transport.local_certificate_id,
1105                                      RTCCertificateStats::kType);
1106     verifier.TestMemberIsIDReference(transport.remote_certificate_id,
1107                                      RTCCertificateStats::kType);
1108     verifier.TestMemberIsDefined(transport.tls_version);
1109     verifier.TestMemberIsDefined(transport.dtls_cipher);
1110     verifier.TestMemberIsDefined(transport.dtls_role);
1111     verifier.TestMemberIsDefined(transport.srtp_cipher);
1112     verifier.TestMemberIsPositive<uint32_t>(
1113         transport.selected_candidate_pair_changes);
1114     verifier.TestMemberIsDefined(transport.ice_role);
1115     verifier.TestMemberIsDefined(transport.ice_local_username_fragment);
1116     verifier.TestMemberIsDefined(transport.ice_state);
1117     return verifier.ExpectAllMembersSuccessfullyTested();
1118   }
1119 
1120  private:
1121   rtc::scoped_refptr<const RTCStatsReport> report_;
1122 };
1123 
1124 #ifdef WEBRTC_HAVE_SCTP
TEST_F(RTCStatsIntegrationTest,GetStatsFromCaller)1125 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) {
1126   StartCall();
1127 
1128   rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller();
1129   RTCStatsReportVerifier(report.get()).VerifyReport({});
1130 
1131 #if RTC_TRACE_EVENTS_ENABLED
1132   EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
1133 #endif
1134 }
1135 
TEST_F(RTCStatsIntegrationTest,GetStatsFromCallee)1136 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
1137   StartCall();
1138 
1139   rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
1140   RTCStatsReportVerifier(report.get()).VerifyReport({});
1141 
1142 #if RTC_TRACE_EVENTS_ENABLED
1143   EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
1144 #endif
1145 }
1146 
1147 // These tests exercise the integration of the stats selection algorithm inside
1148 // of PeerConnection. See rtcstatstraveral_unittest.cc for more detailed stats
1149 // traversal tests on particular stats graphs.
TEST_F(RTCStatsIntegrationTest,GetStatsWithSenderSelector)1150 TEST_F(RTCStatsIntegrationTest, GetStatsWithSenderSelector) {
1151   StartCall();
1152   ASSERT_FALSE(caller_->pc()->GetSenders().empty());
1153   rtc::scoped_refptr<const RTCStatsReport> report =
1154       GetStatsFromCaller(caller_->pc()->GetSenders()[0]);
1155   std::vector<const char*> allowed_missing_stats = {
1156       // TODO(hbos): Include RTC[Audio/Video]ReceiverStats when implemented.
1157       // TODO(hbos): Include RTCRemoteOutboundRtpStreamStats when implemented.
1158       // TODO(hbos): Include RTCRtpContributingSourceStats when implemented.
1159       RTCInboundRTPStreamStats::kType,
1160       RTCPeerConnectionStats::kType,
1161       DEPRECATED_RTCMediaStreamStats::kType,
1162       RTCDataChannelStats::kType,
1163   };
1164   RTCStatsReportVerifier(report.get()).VerifyReport(allowed_missing_stats);
1165   EXPECT_TRUE(report->size());
1166 }
1167 
TEST_F(RTCStatsIntegrationTest,GetStatsWithReceiverSelector)1168 TEST_F(RTCStatsIntegrationTest, GetStatsWithReceiverSelector) {
1169   StartCall();
1170 
1171   ASSERT_FALSE(caller_->pc()->GetReceivers().empty());
1172   rtc::scoped_refptr<const RTCStatsReport> report =
1173       GetStatsFromCaller(caller_->pc()->GetReceivers()[0]);
1174   std::vector<const char*> allowed_missing_stats = {
1175       // TODO(hbos): Include RTC[Audio/Video]SenderStats when implemented.
1176       // TODO(hbos): Include RTCRemoteInboundRtpStreamStats when implemented.
1177       // TODO(hbos): Include RTCRtpContributingSourceStats when implemented.
1178       RTCOutboundRTPStreamStats::kType,
1179       RTCPeerConnectionStats::kType,
1180       DEPRECATED_RTCMediaStreamStats::kType,
1181       RTCDataChannelStats::kType,
1182   };
1183   RTCStatsReportVerifier(report.get()).VerifyReport(allowed_missing_stats);
1184   EXPECT_TRUE(report->size());
1185 }
1186 
TEST_F(RTCStatsIntegrationTest,GetStatsWithInvalidSenderSelector)1187 TEST_F(RTCStatsIntegrationTest, GetStatsWithInvalidSenderSelector) {
1188   StartCall();
1189 
1190   ASSERT_FALSE(callee_->pc()->GetSenders().empty());
1191   // The selector is invalid for the caller because it belongs to the callee.
1192   auto invalid_selector = callee_->pc()->GetSenders()[0];
1193   rtc::scoped_refptr<const RTCStatsReport> report =
1194       GetStatsFromCaller(invalid_selector);
1195   EXPECT_FALSE(report->size());
1196 }
1197 
TEST_F(RTCStatsIntegrationTest,GetStatsWithInvalidReceiverSelector)1198 TEST_F(RTCStatsIntegrationTest, GetStatsWithInvalidReceiverSelector) {
1199   StartCall();
1200 
1201   ASSERT_FALSE(callee_->pc()->GetReceivers().empty());
1202   // The selector is invalid for the caller because it belongs to the callee.
1203   auto invalid_selector = callee_->pc()->GetReceivers()[0];
1204   rtc::scoped_refptr<const RTCStatsReport> report =
1205       GetStatsFromCaller(invalid_selector);
1206   EXPECT_FALSE(report->size());
1207 }
1208 
1209 // TODO(bugs.webrtc.org/10041) For now this is equivalent to the following
1210 // test GetsStatsWhileClosingPeerConnection, because pc() is closed by
1211 // PeerConnectionTestWrapper. See: bugs.webrtc.org/9847
TEST_F(RTCStatsIntegrationTest,DISABLED_GetStatsWhileDestroyingPeerConnection)1212 TEST_F(RTCStatsIntegrationTest,
1213        DISABLED_GetStatsWhileDestroyingPeerConnection) {
1214   StartCall();
1215 
1216   rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
1217       RTCStatsObtainer::Create();
1218   caller_->pc()->GetStats(stats_obtainer.get());
1219   // This will destroy the peer connection.
1220   caller_ = nullptr;
1221   // Any pending stats requests should have completed in the act of destroying
1222   // the peer connection.
1223   ASSERT_TRUE(stats_obtainer->report());
1224 #if RTC_TRACE_EVENTS_ENABLED
1225   EXPECT_EQ(stats_obtainer->report()->ToJson(),
1226             RTCStatsReportTraceListener::last_trace());
1227 #endif
1228 }
1229 
TEST_F(RTCStatsIntegrationTest,GetsStatsWhileClosingPeerConnection)1230 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileClosingPeerConnection) {
1231   StartCall();
1232 
1233   rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
1234       RTCStatsObtainer::Create();
1235   caller_->pc()->GetStats(stats_obtainer.get());
1236   caller_->pc()->Close();
1237 
1238   ASSERT_TRUE(stats_obtainer->report());
1239 #if RTC_TRACE_EVENTS_ENABLED
1240   EXPECT_EQ(stats_obtainer->report()->ToJson(),
1241             RTCStatsReportTraceListener::last_trace());
1242 #endif
1243 }
1244 
1245 // GetStatsReferencedIds() is optimized to recognize what is or isn't a
1246 // referenced ID based on dictionary type information and knowing what members
1247 // are used as references, as opposed to iterating all members to find the ones
1248 // with the "Id" or "Ids" suffix. As such, GetStatsReferencedIds() is tested as
1249 // an integration test instead of a unit test in order to guard against adding
1250 // new references and forgetting to update GetStatsReferencedIds().
TEST_F(RTCStatsIntegrationTest,GetStatsReferencedIds)1251 TEST_F(RTCStatsIntegrationTest, GetStatsReferencedIds) {
1252   StartCall();
1253 
1254   rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
1255   for (const RTCStats& stats : *report) {
1256     // Find all references by looking at all string members with the "Id" or
1257     // "Ids" suffix.
1258     std::set<const std::string*> expected_ids;
1259     for (const auto* member : stats.Members()) {
1260       if (!member->is_defined())
1261         continue;
1262       if (member->type() == RTCStatsMemberInterface::kString) {
1263         if (absl::EndsWith(member->name(), "Id")) {
1264           const auto& id = member->cast_to<const RTCStatsMember<std::string>>();
1265           expected_ids.insert(&(*id));
1266         }
1267       } else if (member->type() == RTCStatsMemberInterface::kSequenceString) {
1268         if (absl::EndsWith(member->name(), "Ids")) {
1269           const auto& ids =
1270               member->cast_to<const RTCStatsMember<std::vector<std::string>>>();
1271           for (const std::string& id : *ids)
1272             expected_ids.insert(&id);
1273         }
1274       }
1275     }
1276 
1277     std::vector<const std::string*> neighbor_ids = GetStatsReferencedIds(stats);
1278     EXPECT_EQ(neighbor_ids.size(), expected_ids.size());
1279     for (const std::string* neighbor_id : neighbor_ids) {
1280       EXPECT_THAT(expected_ids, Contains(neighbor_id));
1281     }
1282     for (const std::string* expected_id : expected_ids) {
1283       EXPECT_THAT(neighbor_ids, Contains(expected_id));
1284     }
1285   }
1286 }
1287 
TEST_F(RTCStatsIntegrationTest,GetStatsContainsNoDuplicateMembers)1288 TEST_F(RTCStatsIntegrationTest, GetStatsContainsNoDuplicateMembers) {
1289   StartCall();
1290 
1291   rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
1292   for (const RTCStats& stats : *report) {
1293     std::set<std::string> member_names;
1294     for (const auto* member : stats.Members()) {
1295       EXPECT_TRUE(member_names.find(member->name()) == member_names.end())
1296           << member->name() << " is a duplicate!";
1297       member_names.insert(member->name());
1298     }
1299   }
1300 }
1301 #endif  // WEBRTC_HAVE_SCTP
1302 
1303 }  // namespace
1304 
1305 }  // namespace webrtc
1306