| 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/thread_checker.h" |
| 28 #include "webrtc/base/timedelta.h" | 28 #include "webrtc/base/timedelta.h" |
| 29 #include "webrtc/base/timeutils.h" | 29 #include "webrtc/base/timeutils.h" |
| 30 #include "webrtc/base/timing.h" | |
| 31 #include "webrtc/media/base/fakemediaengine.h" | 30 #include "webrtc/media/base/fakemediaengine.h" |
| 32 | 31 |
| 33 using testing::Return; | 32 using testing::Return; |
| 34 using testing::ReturnRef; | 33 using testing::ReturnRef; |
| 35 | 34 |
| 36 namespace webrtc { | 35 namespace webrtc { |
| 37 | 36 |
| 38 namespace { | 37 namespace { |
| 39 | 38 |
| 40 const int64_t kGetStatsReportTimeoutMs = 1000; | 39 const int64_t kGetStatsReportTimeoutMs = 1000; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); | 306 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); |
| 308 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); | 307 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); |
| 309 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); | 308 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); |
| 310 EXPECT_EQ(a.get(), b.get()); | 309 EXPECT_EQ(a.get(), b.get()); |
| 311 // The act of doing |AdvanceTime| processes all messages. If this was not the | 310 // 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|. | 311 // case we might not require |c| to be fresher than |b|. |
| 313 EXPECT_NE(c.get(), b.get()); | 312 EXPECT_NE(c.get(), b.get()); |
| 314 } | 313 } |
| 315 | 314 |
| 316 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { | 315 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
| 317 int64_t before = static_cast<int64_t>( | 316 int64_t before = rtc::TimeUTCMicros(); |
| 318 rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec); | |
| 319 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 317 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 320 int64_t after = static_cast<int64_t>( | 318 int64_t after = rtc::TimeUTCMicros(); |
| 321 rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec); | |
| 322 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), | 319 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), |
| 323 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; | 320 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; |
| 324 const RTCStats* stats = report->Get("RTCPeerConnection"); | 321 const RTCStats* stats = report->Get("RTCPeerConnection"); |
| 325 EXPECT_TRUE(stats); | 322 EXPECT_TRUE(stats); |
| 326 EXPECT_LE(before, stats->timestamp_us()); | 323 EXPECT_LE(before, stats->timestamp_us()); |
| 327 EXPECT_LE(stats->timestamp_us(), after); | 324 EXPECT_LE(stats->timestamp_us(), after); |
| 328 { | 325 { |
| 329 // Expected stats with no data channels | 326 // Expected stats with no data channels |
| 330 const RTCPeerConnectionStats& pcstats = | 327 const RTCPeerConnectionStats& pcstats = |
| 331 stats->cast_to<RTCPeerConnectionStats>(); | 328 stats->cast_to<RTCPeerConnectionStats>(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 371 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
| 375 }; | 372 }; |
| 376 | 373 |
| 377 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 374 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
| 378 collector_->VerifyThreadUsageAndResultsMerging(); | 375 collector_->VerifyThreadUsageAndResultsMerging(); |
| 379 } | 376 } |
| 380 | 377 |
| 381 } // namespace | 378 } // namespace |
| 382 | 379 |
| 383 } // namespace webrtc | 380 } // namespace webrtc |
| OLD | NEW |