Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/stats/rtcstatscollector.h" | 11 #include "webrtc/stats/rtcstatscollector.h" |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/api/jsepsessiondescription.h" | 17 #include "webrtc/api/jsepsessiondescription.h" |
| 18 #include "webrtc/api/rtcstats_objects.h" | 18 #include "webrtc/api/rtcstats_objects.h" |
| 19 #include "webrtc/api/rtcstatsreport.h" | 19 #include "webrtc/api/rtcstatsreport.h" |
| 20 #include "webrtc/api/test/mock_datachannel.h" | 20 #include "webrtc/api/test/mock_datachannel.h" |
| 21 #include "webrtc/api/test/mock_peerconnection.h" | 21 #include "webrtc/api/test/mock_peerconnection.h" |
| 22 #include "webrtc/api/test/mock_webrtcsession.h" | 22 #include "webrtc/api/test/mock_webrtcsession.h" |
| 23 #include "webrtc/base/checks.h" | 23 #include "webrtc/base/checks.h" |
| 24 #include "webrtc/base/fakeclock.h" | 24 #include "webrtc/base/fakeclock.h" |
| 25 #include "webrtc/base/gunit.h" | 25 #include "webrtc/base/gunit.h" |
| 26 #include "webrtc/base/logging.h" | 26 #include "webrtc/base/logging.h" |
| 27 #include "webrtc/base/thread_checker.h" | |
| 27 #include "webrtc/base/timedelta.h" | 28 #include "webrtc/base/timedelta.h" |
| 28 #include "webrtc/base/timeutils.h" | 29 #include "webrtc/base/timeutils.h" |
| 29 #include "webrtc/base/timing.h" | 30 #include "webrtc/base/timing.h" |
| 30 #include "webrtc/media/base/fakemediaengine.h" | 31 #include "webrtc/media/base/fakemediaengine.h" |
| 31 | 32 |
| 32 using testing::Return; | 33 using testing::Return; |
| 33 using testing::ReturnRef; | 34 using testing::ReturnRef; |
| 34 | 35 |
| 35 namespace webrtc { | 36 namespace webrtc { |
| 36 | 37 |
| 37 class RTCStatsCollectorTester : public SetSessionDescriptionObserver { | 38 namespace { |
| 39 | |
| 40 const int64_t kGetStatsReportTimeoutMs = 1000; | |
| 41 | |
| 42 class RTCStatsCollectorTestHelper : public SetSessionDescriptionObserver { | |
| 38 public: | 43 public: |
| 39 RTCStatsCollectorTester() | 44 RTCStatsCollectorTestHelper() |
| 40 : worker_thread_(rtc::Thread::Current()), | 45 : worker_thread_(rtc::Thread::Current()), |
| 41 network_thread_(rtc::Thread::Current()), | 46 network_thread_(rtc::Thread::Current()), |
| 42 channel_manager_(new cricket::ChannelManager( | 47 channel_manager_(new cricket::ChannelManager( |
| 43 new cricket::FakeMediaEngine(), | 48 new cricket::FakeMediaEngine(), |
| 44 worker_thread_, | 49 worker_thread_, |
| 45 network_thread_)), | 50 network_thread_)), |
| 46 media_controller_( | 51 media_controller_( |
| 47 MediaControllerInterface::Create(cricket::MediaConfig(), | 52 MediaControllerInterface::Create(cricket::MediaConfig(), |
| 48 worker_thread_, | 53 worker_thread_, |
| 49 channel_manager_.get())), | 54 channel_manager_.get())), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 70 rtc::Thread* const worker_thread_; | 75 rtc::Thread* const worker_thread_; |
| 71 rtc::Thread* const network_thread_; | 76 rtc::Thread* const network_thread_; |
| 72 std::unique_ptr<cricket::ChannelManager> channel_manager_; | 77 std::unique_ptr<cricket::ChannelManager> channel_manager_; |
| 73 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_; | 78 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_; |
| 74 MockWebRtcSession session_; | 79 MockWebRtcSession session_; |
| 75 MockPeerConnection pc_; | 80 MockPeerConnection pc_; |
| 76 | 81 |
| 77 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; | 82 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; |
| 78 }; | 83 }; |
| 79 | 84 |
| 85 class RTCTestStats : public RTCStats { | |
| 86 public: | |
| 87 RTCTestStats(const std::string& id, int64_t timestamp_us) | |
| 88 : RTCStats(id, timestamp_us), | |
| 89 dummy_stat("dummyStat") {} | |
| 90 | |
| 91 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats, | |
| 92 &dummy_stat); | |
| 93 | |
| 94 RTCStatsMember<int32_t> dummy_stat; | |
| 95 }; | |
| 96 | |
| 97 const char RTCTestStats::kType[] = "test-stats"; | |
| 98 | |
| 99 // Overrides the stats collection to verify thread usage and that the resulting | |
| 100 // partial reports are merged. | |
| 101 class FakeRTCStatsCollector : public RTCStatsCollector, | |
| 102 public RTCStatsCollectorCallback { | |
| 103 public: | |
| 104 static rtc::scoped_refptr<FakeRTCStatsCollector> Create( | |
| 105 PeerConnection* pc, | |
| 106 int64_t cache_lifetime_us) { | |
| 107 return rtc::scoped_refptr<FakeRTCStatsCollector>( | |
| 108 new rtc::RefCountedObject<FakeRTCStatsCollector>( | |
| 109 pc, cache_lifetime_us)); | |
| 110 } | |
| 111 | |
| 112 // RTCStatsCollectorCallback implementation. | |
| 113 void OnStatsDelivered( | |
| 114 const rtc::scoped_refptr<const RTCStatsReport>& report) override { | |
| 115 EXPECT_TRUE(signaling_thread_->IsCurrent()); | |
| 116 rtc::CritScope cs(&lock_); | |
| 117 delivered_report_ = report; | |
| 118 } | |
| 119 | |
| 120 void VerifyThreadUsageAndResultsMerging() { | |
| 121 GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback>(this)); | |
| 122 EXPECT_TRUE_WAIT(HasVerifiedResults(), kGetStatsReportTimeoutMs); | |
| 123 } | |
| 124 | |
| 125 bool HasVerifiedResults() { | |
| 126 EXPECT_TRUE(signaling_thread_->IsCurrent()); | |
| 127 rtc::CritScope cs(&lock_); | |
| 128 if (!delivered_report_) | |
| 129 return false; | |
| 130 EXPECT_EQ(produced_on_signaling_thread_, 1); | |
| 131 EXPECT_EQ(produced_on_worker_thread_, 1); | |
| 132 EXPECT_EQ(produced_on_network_thread_, 1); | |
| 133 | |
| 134 EXPECT_TRUE(delivered_report_->Get("SignalingThreadStats")); | |
| 135 EXPECT_TRUE(delivered_report_->Get("WorkerThreadStats")); | |
| 136 EXPECT_TRUE(delivered_report_->Get("NetworkThreadStats")); | |
| 137 | |
| 138 produced_on_signaling_thread_ = 0; | |
| 139 produced_on_worker_thread_ = 0; | |
| 140 produced_on_network_thread_ = 0; | |
| 141 delivered_report_ = nullptr; | |
| 142 return true; | |
| 143 } | |
| 144 | |
| 145 protected: | |
| 146 FakeRTCStatsCollector( | |
| 147 PeerConnection* pc, | |
| 148 int64_t cache_lifetime) | |
| 149 : RTCStatsCollector(pc, cache_lifetime), | |
| 150 signaling_thread_(pc->session()->signaling_thread()), | |
| 151 worker_thread_(pc->session()->worker_thread()), | |
| 152 network_thread_(pc->session()->network_thread()) { | |
| 153 } | |
| 154 | |
| 155 void ProducePartialResultsOnSignalingThread(int64_t timestamp_us) override { | |
| 156 EXPECT_TRUE(signaling_thread_->IsCurrent()); | |
| 157 { | |
| 158 rtc::CritScope cs(&lock_); | |
| 159 EXPECT_FALSE(delivered_report_); | |
| 160 ++produced_on_signaling_thread_; | |
| 161 } | |
| 162 | |
| 163 rtc::scoped_refptr<RTCStatsReport> signaling_report = | |
| 164 RTCStatsReport::Create(); | |
| 165 signaling_report->AddStats(std::unique_ptr<const RTCStats>( | |
| 166 new RTCTestStats("SignalingThreadStats", timestamp_us))); | |
| 167 AddPartialResults(signaling_report); | |
| 168 } | |
| 169 void ProducePartialResultsOnWorkerThread(int64_t timestamp_us) override { | |
| 170 EXPECT_TRUE(worker_thread_->IsCurrent()); | |
| 171 { | |
| 172 rtc::CritScope cs(&lock_); | |
| 173 EXPECT_FALSE(delivered_report_); | |
| 174 ++produced_on_worker_thread_; | |
| 175 } | |
| 176 | |
| 177 rtc::scoped_refptr<RTCStatsReport> worker_report = RTCStatsReport::Create(); | |
| 178 worker_report->AddStats(std::unique_ptr<const RTCStats>( | |
| 179 new RTCTestStats("WorkerThreadStats", timestamp_us))); | |
| 180 AddPartialResults(worker_report); | |
| 181 } | |
| 182 void ProducePartialResultsOnNetworkThread(int64_t timestamp_us) override { | |
| 183 EXPECT_TRUE(network_thread_->IsCurrent()); | |
| 184 { | |
| 185 rtc::CritScope cs(&lock_); | |
| 186 EXPECT_FALSE(delivered_report_); | |
| 187 ++produced_on_network_thread_; | |
| 188 } | |
| 189 | |
| 190 rtc::scoped_refptr<RTCStatsReport> network_report = | |
| 191 RTCStatsReport::Create(); | |
| 192 network_report->AddStats(std::unique_ptr<const RTCStats>( | |
| 193 new RTCTestStats("NetworkThreadStats", timestamp_us))); | |
| 194 AddPartialResults(network_report); | |
| 195 } | |
| 196 | |
| 197 private: | |
| 198 rtc::Thread* const signaling_thread_; | |
| 199 rtc::Thread* const worker_thread_; | |
| 200 rtc::Thread* const network_thread_; | |
| 201 | |
| 202 rtc::CriticalSection lock_; | |
| 203 rtc::scoped_refptr<const RTCStatsReport> delivered_report_; | |
| 204 int produced_on_signaling_thread_ = 0; | |
| 205 int produced_on_worker_thread_ = 0; | |
| 206 int produced_on_network_thread_ = 0; | |
| 207 }; | |
| 208 | |
| 209 class StatsCallback : public RTCStatsCollectorCallback { | |
| 210 public: | |
| 211 static rtc::scoped_refptr<StatsCallback> Create( | |
| 212 rtc::scoped_refptr<const RTCStatsReport>* report_ptr = nullptr) { | |
| 213 return rtc::scoped_refptr<StatsCallback>( | |
| 214 new rtc::RefCountedObject<StatsCallback>(report_ptr)); | |
| 215 } | |
| 216 | |
| 217 void OnStatsDelivered( | |
| 218 const rtc::scoped_refptr<const RTCStatsReport>& report) override { | |
| 219 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | |
| 220 report_ = report; | |
| 221 if (report_ptr_) | |
| 222 *report_ptr_ = report_; | |
| 223 } | |
| 224 | |
| 225 rtc::scoped_refptr<const RTCStatsReport> report() const { | |
| 226 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | |
| 227 return report_; | |
| 228 } | |
| 229 | |
| 230 protected: | |
| 231 explicit StatsCallback(rtc::scoped_refptr<const RTCStatsReport>* report_ptr) | |
| 232 : report_ptr_(report_ptr) {} | |
| 233 | |
| 234 private: | |
| 235 rtc::ThreadChecker thread_checker_; | |
| 236 rtc::scoped_refptr<const RTCStatsReport> report_; | |
| 237 rtc::scoped_refptr<const RTCStatsReport>* report_ptr_; | |
| 238 }; | |
| 239 | |
| 240 } // namespace | |
|
hta-webrtc
2016/09/02 08:47:13
It's good practice to leave the tests in the anony
hbos
2016/09/02 09:18:30
Done.
| |
| 241 | |
| 80 class RTCStatsCollectorTest : public testing::Test { | 242 class RTCStatsCollectorTest : public testing::Test { |
| 81 public: | 243 public: |
| 82 RTCStatsCollectorTest() | 244 RTCStatsCollectorTest() |
| 83 : test_(new rtc::RefCountedObject<RTCStatsCollectorTester>()), | 245 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), |
| 84 collector_(&test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec) { | 246 collector_(RTCStatsCollector::Create( |
| 247 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { | |
| 248 } | |
| 249 | |
| 250 rtc::scoped_refptr<const RTCStatsReport> GetStatsReport() { | |
| 251 rtc::scoped_refptr<StatsCallback> callback = StatsCallback::Create(); | |
| 252 collector_->GetStatsReport(callback); | |
| 253 EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs); | |
| 254 return callback->report(); | |
| 85 } | 255 } |
| 86 | 256 |
| 87 protected: | 257 protected: |
| 88 rtc::scoped_refptr<RTCStatsCollectorTester> test_; | 258 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; |
| 89 RTCStatsCollector collector_; | 259 rtc::scoped_refptr<RTCStatsCollector> collector_; |
| 90 }; | 260 }; |
| 91 | 261 |
| 92 TEST_F(RTCStatsCollectorTest, CachedStatsReport) { | 262 TEST_F(RTCStatsCollectorTest, SingleCallback) { |
| 263 rtc::scoped_refptr<const RTCStatsReport> result; | |
| 264 collector_->GetStatsReport(StatsCallback::Create(&result)); | |
| 265 EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs); | |
| 266 } | |
| 267 | |
| 268 TEST_F(RTCStatsCollectorTest, MultipleCallbacks) { | |
| 269 rtc::scoped_refptr<const RTCStatsReport> a; | |
| 270 rtc::scoped_refptr<const RTCStatsReport> b; | |
| 271 rtc::scoped_refptr<const RTCStatsReport> c; | |
| 272 collector_->GetStatsReport(StatsCallback::Create(&a)); | |
| 273 collector_->GetStatsReport(StatsCallback::Create(&b)); | |
| 274 collector_->GetStatsReport(StatsCallback::Create(&c)); | |
| 275 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); | |
| 276 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); | |
| 277 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); | |
| 278 EXPECT_EQ(a.get(), b.get()); | |
| 279 EXPECT_EQ(b.get(), c.get()); | |
| 280 } | |
| 281 | |
| 282 TEST_F(RTCStatsCollectorTest, CachedStatsReports) { | |
| 93 rtc::ScopedFakeClock fake_clock; | 283 rtc::ScopedFakeClock fake_clock; |
| 94 // Caching should ensure |a| and |b| are the same report. | 284 // Caching should ensure |a| and |b| are the same report. |
| 95 rtc::scoped_refptr<const RTCStatsReport> a = collector_.GetStatsReport(); | 285 rtc::scoped_refptr<const RTCStatsReport> a = GetStatsReport(); |
| 96 rtc::scoped_refptr<const RTCStatsReport> b = collector_.GetStatsReport(); | 286 rtc::scoped_refptr<const RTCStatsReport> b = GetStatsReport(); |
| 97 EXPECT_TRUE(a); | |
| 98 EXPECT_EQ(a.get(), b.get()); | 287 EXPECT_EQ(a.get(), b.get()); |
| 99 // Invalidate cache by clearing it. | 288 // Invalidate cache by clearing it. |
| 100 collector_.ClearCachedStatsReport(); | 289 collector_->ClearCachedStatsReport(); |
| 101 rtc::scoped_refptr<const RTCStatsReport> c = collector_.GetStatsReport(); | 290 rtc::scoped_refptr<const RTCStatsReport> c = GetStatsReport(); |
| 102 EXPECT_TRUE(c); | |
| 103 EXPECT_NE(b.get(), c.get()); | 291 EXPECT_NE(b.get(), c.get()); |
| 104 // Invalidate cache by advancing time. | 292 // Invalidate cache by advancing time. |
| 105 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); | 293 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); |
| 106 rtc::scoped_refptr<const RTCStatsReport> d = collector_.GetStatsReport(); | 294 rtc::scoped_refptr<const RTCStatsReport> d = GetStatsReport(); |
| 107 EXPECT_TRUE(d); | 295 EXPECT_TRUE(d); |
| 108 EXPECT_NE(c.get(), d.get()); | 296 EXPECT_NE(c.get(), d.get()); |
| 109 } | 297 } |
| 110 | 298 |
| 299 TEST_F(RTCStatsCollectorTest, MultipleCallbacksWithInvalidatedCacheInBetween) { | |
| 300 rtc::ScopedFakeClock fake_clock; | |
| 301 rtc::scoped_refptr<const RTCStatsReport> a; | |
| 302 rtc::scoped_refptr<const RTCStatsReport> b; | |
| 303 rtc::scoped_refptr<const RTCStatsReport> c; | |
| 304 collector_->GetStatsReport(StatsCallback::Create(&a)); | |
| 305 collector_->GetStatsReport(StatsCallback::Create(&b)); | |
| 306 // Cache is invalidated after 50 ms. | |
| 307 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); | |
| 308 collector_->GetStatsReport(StatsCallback::Create(&c)); | |
| 309 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); | |
| 310 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); | |
| 311 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); | |
| 312 EXPECT_EQ(a.get(), b.get()); | |
| 313 // The act of doing |AdvanceTime| processes all messages. If this was not the | |
| 314 // case we might not require |c| to be fresher than |b|. | |
| 315 EXPECT_NE(c.get(), b.get()); | |
| 316 } | |
| 317 | |
| 111 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { | 318 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
| 112 int64_t before = static_cast<int64_t>( | 319 int64_t before = static_cast<int64_t>( |
| 113 rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec); | 320 rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec); |
| 114 rtc::scoped_refptr<const RTCStatsReport> report = collector_.GetStatsReport(); | 321 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 115 int64_t after = static_cast<int64_t>( | 322 int64_t after = static_cast<int64_t>( |
| 116 rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec); | 323 rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec); |
| 117 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), | 324 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), |
| 118 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; | 325 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; |
| 119 const RTCStats* stats = report->Get("RTCPeerConnection"); | 326 const RTCStats* stats = report->Get("RTCPeerConnection"); |
| 120 EXPECT_TRUE(stats); | 327 EXPECT_TRUE(stats); |
| 121 EXPECT_LE(before, stats->timestamp_us()); | 328 EXPECT_LE(before, stats->timestamp_us()); |
| 122 EXPECT_LE(stats->timestamp_us(), after); | 329 EXPECT_LE(stats->timestamp_us(), after); |
| 123 { | 330 { |
| 124 // Expected stats with no data channels | 331 // Expected stats with no data channels |
| 125 const RTCPeerConnectionStats& pcstats = | 332 const RTCPeerConnectionStats& pcstats = |
| 126 stats->cast_to<RTCPeerConnectionStats>(); | 333 stats->cast_to<RTCPeerConnectionStats>(); |
| 127 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(0)); | 334 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(0)); |
| 128 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(0)); | 335 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(0)); |
| 129 } | 336 } |
| 130 | 337 |
| 131 test_->data_channels().push_back( | 338 test_->data_channels().push_back( |
| 132 new MockDataChannel(DataChannelInterface::kConnecting)); | 339 new MockDataChannel(DataChannelInterface::kConnecting)); |
| 133 test_->data_channels().push_back( | 340 test_->data_channels().push_back( |
| 134 new MockDataChannel(DataChannelInterface::kOpen)); | 341 new MockDataChannel(DataChannelInterface::kOpen)); |
| 135 test_->data_channels().push_back( | 342 test_->data_channels().push_back( |
| 136 new MockDataChannel(DataChannelInterface::kClosing)); | 343 new MockDataChannel(DataChannelInterface::kClosing)); |
| 137 test_->data_channels().push_back( | 344 test_->data_channels().push_back( |
| 138 new MockDataChannel(DataChannelInterface::kClosed)); | 345 new MockDataChannel(DataChannelInterface::kClosed)); |
| 139 | 346 |
| 140 collector_.ClearCachedStatsReport(); | 347 collector_->ClearCachedStatsReport(); |
| 141 report = collector_.GetStatsReport(); | 348 report = GetStatsReport(); |
| 142 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), | 349 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), |
| 143 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; | 350 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; |
| 144 stats = report->Get("RTCPeerConnection"); | 351 stats = report->Get("RTCPeerConnection"); |
| 145 EXPECT_TRUE(stats); | 352 EXPECT_TRUE(stats); |
| 146 { | 353 { |
| 147 // Expected stats with the above four data channels | 354 // Expected stats with the above four data channels |
| 148 // TODO(hbos): When the |RTCPeerConnectionStats| is the number of data | 355 // TODO(hbos): When the |RTCPeerConnectionStats| is the number of data |
| 149 // channels that have been opened and closed, not the numbers currently | 356 // channels that have been opened and closed, not the numbers currently |
| 150 // open/closed, we would expect opened >= closed and (opened - closed) to be | 357 // open/closed, we would expect opened >= closed and (opened - closed) to be |
| 151 // the number currently open. crbug.com/636818. | 358 // the number currently open. crbug.com/636818. |
| 152 const RTCPeerConnectionStats& pcstats = | 359 const RTCPeerConnectionStats& pcstats = |
| 153 stats->cast_to<RTCPeerConnectionStats>(); | 360 stats->cast_to<RTCPeerConnectionStats>(); |
| 154 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(1)); | 361 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(1)); |
| 155 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(3)); | 362 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(3)); |
| 156 } | 363 } |
| 157 } | 364 } |
| 158 | 365 |
| 366 class RTCStatsCollectorTestWithFakeCollector : public testing::Test { | |
| 367 public: | |
| 368 RTCStatsCollectorTestWithFakeCollector() | |
| 369 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), | |
| 370 collector_(FakeRTCStatsCollector::Create( | |
| 371 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { | |
| 372 } | |
| 373 | |
| 374 protected: | |
| 375 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; | |
| 376 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | |
| 377 }; | |
| 378 | |
| 379 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | |
| 380 collector_->VerifyThreadUsageAndResultsMerging(); | |
| 381 } | |
| 382 | |
| 159 } // namespace webrtc | 383 } // namespace webrtc |
| OLD | NEW |