| 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 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 MediaControllerInterface::Create(cricket::MediaConfig(), | 52 MediaControllerInterface::Create(cricket::MediaConfig(), |
| 53 worker_thread_, | 53 worker_thread_, |
| 54 channel_manager_.get())), | 54 channel_manager_.get())), |
| 55 session_(media_controller_.get()), | 55 session_(media_controller_.get()), |
| 56 pc_() { | 56 pc_() { |
| 57 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); | 57 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); |
| 58 EXPECT_CALL(pc_, sctp_data_channels()).WillRepeatedly( | 58 EXPECT_CALL(pc_, sctp_data_channels()).WillRepeatedly( |
| 59 ReturnRef(data_channels_)); | 59 ReturnRef(data_channels_)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 rtc::ScopedFakeClock& fake_clock() { return fake_clock_; } |
| 62 MockWebRtcSession& session() { return session_; } | 63 MockWebRtcSession& session() { return session_; } |
| 63 MockPeerConnection& pc() { return pc_; } | 64 MockPeerConnection& pc() { return pc_; } |
| 64 std::vector<rtc::scoped_refptr<DataChannel>>& data_channels() { | 65 std::vector<rtc::scoped_refptr<DataChannel>>& data_channels() { |
| 65 return data_channels_; | 66 return data_channels_; |
| 66 } | 67 } |
| 67 | 68 |
| 68 // SetSessionDescriptionObserver overrides. | 69 // SetSessionDescriptionObserver overrides. |
| 69 void OnSuccess() override {} | 70 void OnSuccess() override {} |
| 70 void OnFailure(const std::string& error) override { | 71 void OnFailure(const std::string& error) override { |
| 71 RTC_NOTREACHED() << error; | 72 RTC_NOTREACHED() << error; |
| 72 } | 73 } |
| 73 | 74 |
| 74 private: | 75 private: |
| 76 rtc::ScopedFakeClock fake_clock_; |
| 75 rtc::Thread* const worker_thread_; | 77 rtc::Thread* const worker_thread_; |
| 76 rtc::Thread* const network_thread_; | 78 rtc::Thread* const network_thread_; |
| 77 std::unique_ptr<cricket::ChannelManager> channel_manager_; | 79 std::unique_ptr<cricket::ChannelManager> channel_manager_; |
| 78 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_; | 80 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_; |
| 79 MockWebRtcSession session_; | 81 MockWebRtcSession session_; |
| 80 MockPeerConnection pc_; | 82 MockPeerConnection pc_; |
| 81 | 83 |
| 82 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; | 84 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; |
| 83 }; | 85 }; |
| 84 | 86 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 collector_->GetStatsReport(StatsCallback::Create(&b)); | 273 collector_->GetStatsReport(StatsCallback::Create(&b)); |
| 272 collector_->GetStatsReport(StatsCallback::Create(&c)); | 274 collector_->GetStatsReport(StatsCallback::Create(&c)); |
| 273 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); | 275 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); |
| 274 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); | 276 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); |
| 275 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); | 277 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); |
| 276 EXPECT_EQ(a.get(), b.get()); | 278 EXPECT_EQ(a.get(), b.get()); |
| 277 EXPECT_EQ(b.get(), c.get()); | 279 EXPECT_EQ(b.get(), c.get()); |
| 278 } | 280 } |
| 279 | 281 |
| 280 TEST_F(RTCStatsCollectorTest, CachedStatsReports) { | 282 TEST_F(RTCStatsCollectorTest, CachedStatsReports) { |
| 281 rtc::ScopedFakeClock fake_clock; | |
| 282 // Caching should ensure |a| and |b| are the same report. | 283 // Caching should ensure |a| and |b| are the same report. |
| 283 rtc::scoped_refptr<const RTCStatsReport> a = GetStatsReport(); | 284 rtc::scoped_refptr<const RTCStatsReport> a = GetStatsReport(); |
| 284 rtc::scoped_refptr<const RTCStatsReport> b = GetStatsReport(); | 285 rtc::scoped_refptr<const RTCStatsReport> b = GetStatsReport(); |
| 285 EXPECT_EQ(a.get(), b.get()); | 286 EXPECT_EQ(a.get(), b.get()); |
| 286 // Invalidate cache by clearing it. | 287 // Invalidate cache by clearing it. |
| 287 collector_->ClearCachedStatsReport(); | 288 collector_->ClearCachedStatsReport(); |
| 288 rtc::scoped_refptr<const RTCStatsReport> c = GetStatsReport(); | 289 rtc::scoped_refptr<const RTCStatsReport> c = GetStatsReport(); |
| 289 EXPECT_NE(b.get(), c.get()); | 290 EXPECT_NE(b.get(), c.get()); |
| 290 // Invalidate cache by advancing time. | 291 // Invalidate cache by advancing time. |
| 291 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); | 292 test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); |
| 292 rtc::scoped_refptr<const RTCStatsReport> d = GetStatsReport(); | 293 rtc::scoped_refptr<const RTCStatsReport> d = GetStatsReport(); |
| 293 EXPECT_TRUE(d); | 294 EXPECT_TRUE(d); |
| 294 EXPECT_NE(c.get(), d.get()); | 295 EXPECT_NE(c.get(), d.get()); |
| 295 } | 296 } |
| 296 | 297 |
| 297 TEST_F(RTCStatsCollectorTest, MultipleCallbacksWithInvalidatedCacheInBetween) { | 298 TEST_F(RTCStatsCollectorTest, MultipleCallbacksWithInvalidatedCacheInBetween) { |
| 298 rtc::ScopedFakeClock fake_clock; | |
| 299 rtc::scoped_refptr<const RTCStatsReport> a; | 299 rtc::scoped_refptr<const RTCStatsReport> a; |
| 300 rtc::scoped_refptr<const RTCStatsReport> b; | 300 rtc::scoped_refptr<const RTCStatsReport> b; |
| 301 rtc::scoped_refptr<const RTCStatsReport> c; | 301 rtc::scoped_refptr<const RTCStatsReport> c; |
| 302 collector_->GetStatsReport(StatsCallback::Create(&a)); | 302 collector_->GetStatsReport(StatsCallback::Create(&a)); |
| 303 collector_->GetStatsReport(StatsCallback::Create(&b)); | 303 collector_->GetStatsReport(StatsCallback::Create(&b)); |
| 304 // Cache is invalidated after 50 ms. | 304 // Cache is invalidated after 50 ms. |
| 305 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); | 305 test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); |
| 306 collector_->GetStatsReport(StatsCallback::Create(&c)); | 306 collector_->GetStatsReport(StatsCallback::Create(&c)); |
| 307 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); | 307 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); |
| 308 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); | 308 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); |
| 309 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); | 309 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); |
| 310 EXPECT_EQ(a.get(), b.get()); | 310 EXPECT_EQ(a.get(), b.get()); |
| 311 // The act of doing |AdvanceTime| processes all messages. If this was not the | 311 // The act of doing |AdvanceTime| processes all messages. If this was not the |
| 312 // case we might not require |c| to be fresher than |b|. | 312 // case we might not require |c| to be fresher than |b|. |
| 313 EXPECT_NE(c.get(), b.get()); | 313 EXPECT_NE(c.get(), b.get()); |
| 314 } | 314 } |
| 315 | 315 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 374 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
| 375 }; | 375 }; |
| 376 | 376 |
| 377 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 377 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
| 378 collector_->VerifyThreadUsageAndResultsMerging(); | 378 collector_->VerifyThreadUsageAndResultsMerging(); |
| 379 } | 379 } |
| 380 | 380 |
| 381 } // namespace | 381 } // namespace |
| 382 | 382 |
| 383 } // namespace webrtc | 383 } // namespace webrtc |
| OLD | NEW |