Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: webrtc/api/rtcstatscollector_unittest.cc

Issue 2594553003: RTCStatsCollectorTest: ExpectReportContainsCertificateInfo /w EXPECT_EQ (Closed)
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 EXPECT_EQ(*candidate_stats->protocol, candidate.protocol()); 511 EXPECT_EQ(*candidate_stats->protocol, candidate.protocol());
512 EXPECT_EQ(*candidate_stats->candidate_type, 512 EXPECT_EQ(*candidate_stats->candidate_type,
513 CandidateTypeToRTCIceCandidateTypeForTesting(candidate.type())); 513 CandidateTypeToRTCIceCandidateTypeForTesting(candidate.type()));
514 EXPECT_EQ(*candidate_stats->priority, 514 EXPECT_EQ(*candidate_stats->priority,
515 static_cast<int32_t>(candidate.priority())); 515 static_cast<int32_t>(candidate.priority()));
516 // TODO(hbos): Define candidate_stats->url. crbug.com/632723 516 // TODO(hbos): Define candidate_stats->url. crbug.com/632723
517 EXPECT_FALSE(candidate_stats->url.is_defined()); 517 EXPECT_FALSE(candidate_stats->url.is_defined());
518 return candidate_stats; 518 return candidate_stats;
519 } 519 }
520 520
521 void ExpectReportContainsCertificateInfo(
522 const rtc::scoped_refptr<const RTCStatsReport>& report,
523 const CertificateInfo& cert_info) {
524 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) {
525 const RTCStats* stats = report->Get(
526 "RTCCertificate_" + cert_info.fingerprints[i]);
527 ASSERT_TRUE(stats);
528 const RTCCertificateStats& cert_stats =
529 stats->cast_to<const RTCCertificateStats>();
530 EXPECT_EQ(*cert_stats.fingerprint, cert_info.fingerprints[i]);
531 EXPECT_EQ(*cert_stats.fingerprint_algorithm, "sha-1");
532 EXPECT_EQ(*cert_stats.base64_certificate, cert_info.pems[i]);
533 if (i + 1 < cert_info.fingerprints.size()) {
534 EXPECT_EQ(*cert_stats.issuer_certificate_id,
535 "RTCCertificate_" + cert_info.fingerprints[i + 1]);
536 } else {
537 EXPECT_FALSE(cert_stats.issuer_certificate_id.is_defined());
538 }
539 }
540 }
541
542 void ExpectReportContainsDataChannel( 521 void ExpectReportContainsDataChannel(
543 const rtc::scoped_refptr<const RTCStatsReport>& report, 522 const rtc::scoped_refptr<const RTCStatsReport>& report,
544 const DataChannel& data_channel) { 523 const DataChannel& data_channel) {
545 const RTCStats* stats = report->Get("RTCDataChannel_" + 524 const RTCStats* stats = report->Get("RTCDataChannel_" +
546 rtc::ToString<>(data_channel.id())); 525 rtc::ToString<>(data_channel.id()));
547 EXPECT_TRUE(stats); 526 EXPECT_TRUE(stats);
548 const RTCDataChannelStats& data_channel_stats = 527 const RTCDataChannelStats& data_channel_stats =
549 stats->cast_to<const RTCDataChannelStats>(); 528 stats->cast_to<const RTCDataChannelStats>();
550 EXPECT_EQ(*data_channel_stats.label, data_channel.label()); 529 EXPECT_EQ(*data_channel_stats.label, data_channel.label());
551 EXPECT_EQ(*data_channel_stats.protocol, data_channel.protocol()); 530 EXPECT_EQ(*data_channel_stats.protocol, data_channel.protocol());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 })); 624 }));
646 EXPECT_CALL(test_->session(), 625 EXPECT_CALL(test_->session(),
647 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke( 626 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke(
648 [this, &remote_certinfo](const std::string& transport_name) { 627 [this, &remote_certinfo](const std::string& transport_name) {
649 if (transport_name == "transport") 628 if (transport_name == "transport")
650 return remote_certinfo->certificate->ssl_certificate().GetReference(); 629 return remote_certinfo->certificate->ssl_certificate().GetReference();
651 return static_cast<rtc::SSLCertificate*>(nullptr); 630 return static_cast<rtc::SSLCertificate*>(nullptr);
652 })); 631 }));
653 632
654 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); 633 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
655 ExpectReportContainsCertificateInfo(report, *local_certinfo.get()); 634
656 ExpectReportContainsCertificateInfo(report, *remote_certinfo.get()); 635 RTCCertificateStats expected_local_certificate(
636 "RTCCertificate_" + local_certinfo->fingerprints[0],
637 report->timestamp_us());
638 expected_local_certificate.fingerprint = local_certinfo->fingerprints[0];
639 expected_local_certificate.fingerprint_algorithm = "sha-1";
640 expected_local_certificate.base64_certificate = local_certinfo->pems[0];
641 ASSERT(report->Get(expected_local_certificate.id()));
Taylor Brandstetter 2016/12/20 19:49:49 Should this use ASSERT_TRUE, so it's a gtest asser
hbos 2016/12/21 09:59:11 Ah, yes!
642 EXPECT_EQ(expected_local_certificate,
643 report->Get(expected_local_certificate.id())->cast_to<
644 RTCCertificateStats>());
Taylor Brandstetter 2016/12/20 19:49:49 Each of these blocks of code is effectively the sa
hbos 2016/12/21 09:59:11 Yeah that makes sense :) Done.
645
646 RTCCertificateStats expected_remote_certificate(
647 "RTCCertificate_" + remote_certinfo->fingerprints[0],
648 report->timestamp_us());
649 expected_remote_certificate.fingerprint = remote_certinfo->fingerprints[0];
650 expected_remote_certificate.fingerprint_algorithm = "sha-1";
651 expected_remote_certificate.base64_certificate = remote_certinfo->pems[0];
652 ASSERT(report->Get(expected_remote_certificate.id()));
653 EXPECT_EQ(expected_remote_certificate,
654 report->Get(expected_remote_certificate.id())->cast_to<
655 RTCCertificateStats>());
657 } 656 }
658 657
659 TEST_F(RTCStatsCollectorTest, CollectRTCCodecStats) { 658 TEST_F(RTCStatsCollectorTest, CollectRTCCodecStats) {
660 MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel(); 659 MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel();
661 cricket::VoiceChannel voice_channel( 660 cricket::VoiceChannel voice_channel(
662 test_->worker_thread(), test_->network_thread(), test_->media_engine(), 661 test_->worker_thread(), test_->network_thread(), test_->media_engine(),
663 voice_media_channel, nullptr, "VoiceContentName", kDefaultRtcpEnabled, 662 voice_media_channel, nullptr, "VoiceContentName", kDefaultRtcpEnabled,
664 kDefaultSrtpRequired); 663 kDefaultSrtpRequired);
665 664
666 MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel(); 665 MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 .GetReference(); 823 .GetReference();
825 } 824 }
826 if (transport_name == "video") { 825 if (transport_name == "video") {
827 return video_remote_certinfo->certificate->ssl_certificate() 826 return video_remote_certinfo->certificate->ssl_certificate()
828 .GetReference(); 827 .GetReference();
829 } 828 }
830 return static_cast<rtc::SSLCertificate*>(nullptr); 829 return static_cast<rtc::SSLCertificate*>(nullptr);
831 })); 830 }));
832 831
833 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); 832 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
834 ExpectReportContainsCertificateInfo(report, *audio_local_certinfo.get()); 833
835 ExpectReportContainsCertificateInfo(report, *audio_remote_certinfo.get()); 834 RTCCertificateStats expected_local_audio_certificate(
836 ExpectReportContainsCertificateInfo(report, *video_local_certinfo.get()); 835 "RTCCertificate_" + audio_local_certinfo->fingerprints[0],
837 ExpectReportContainsCertificateInfo(report, *video_remote_certinfo.get()); 836 report->timestamp_us());
837 expected_local_audio_certificate.fingerprint =
838 audio_local_certinfo->fingerprints[0];
839 expected_local_audio_certificate.fingerprint_algorithm = "sha-1";
840 expected_local_audio_certificate.base64_certificate =
841 audio_local_certinfo->pems[0];
842 ASSERT(report->Get(expected_local_audio_certificate.id()));
843 EXPECT_EQ(expected_local_audio_certificate,
844 report->Get(expected_local_audio_certificate.id())->cast_to<
845 RTCCertificateStats>());
846
847 RTCCertificateStats expected_remote_audio_certificate(
848 "RTCCertificate_" + audio_remote_certinfo->fingerprints[0],
849 report->timestamp_us());
850 expected_remote_audio_certificate.fingerprint =
851 audio_remote_certinfo->fingerprints[0];
852 expected_remote_audio_certificate.fingerprint_algorithm = "sha-1";
853 expected_remote_audio_certificate.base64_certificate =
854 audio_remote_certinfo->pems[0];
855 ASSERT(report->Get(expected_remote_audio_certificate.id()));
856 EXPECT_EQ(expected_remote_audio_certificate,
857 report->Get(expected_remote_audio_certificate.id())->cast_to<
858 RTCCertificateStats>());
859
860 RTCCertificateStats expected_local_video_certificate(
861 "RTCCertificate_" + video_local_certinfo->fingerprints[0],
862 report->timestamp_us());
863 expected_local_video_certificate.fingerprint =
864 video_local_certinfo->fingerprints[0];
865 expected_local_video_certificate.fingerprint_algorithm = "sha-1";
866 expected_local_video_certificate.base64_certificate =
867 video_local_certinfo->pems[0];
868 ASSERT(report->Get(expected_local_video_certificate.id()));
869 EXPECT_EQ(expected_local_video_certificate,
870 report->Get(expected_local_video_certificate.id())->cast_to<
871 RTCCertificateStats>());
872
873 RTCCertificateStats expected_remote_video_certificate(
874 "RTCCertificate_" + video_remote_certinfo->fingerprints[0],
875 report->timestamp_us());
876 expected_remote_video_certificate.fingerprint =
877 video_remote_certinfo->fingerprints[0];
878 expected_remote_video_certificate.fingerprint_algorithm = "sha-1";
879 expected_remote_video_certificate.base64_certificate =
880 video_remote_certinfo->pems[0];
881 ASSERT(report->Get(expected_remote_video_certificate.id()));
882 EXPECT_EQ(expected_remote_video_certificate,
883 report->Get(expected_remote_video_certificate.id())->cast_to<
884 RTCCertificateStats>());
838 } 885 }
839 886
840 TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsChain) { 887 TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsChain) {
841 std::vector<std::string> local_ders; 888 std::vector<std::string> local_ders;
842 local_ders.push_back("(local) this"); 889 local_ders.push_back("(local) this");
843 local_ders.push_back("(local) is"); 890 local_ders.push_back("(local) is");
844 local_ders.push_back("(local) a"); 891 local_ders.push_back("(local) a");
845 local_ders.push_back("(local) chain"); 892 local_ders.push_back("(local) chain");
846 std::unique_ptr<CertificateInfo> local_certinfo = 893 std::unique_ptr<CertificateInfo> local_certinfo =
847 CreateFakeCertificateAndInfoFromDers(local_ders); 894 CreateFakeCertificateAndInfoFromDers(local_ders);
(...skipping 23 matching lines...) Expand all
871 })); 918 }));
872 EXPECT_CALL(test_->session(), 919 EXPECT_CALL(test_->session(),
873 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke( 920 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke(
874 [this, &remote_certinfo](const std::string& transport_name) { 921 [this, &remote_certinfo](const std::string& transport_name) {
875 if (transport_name == "transport") 922 if (transport_name == "transport")
876 return remote_certinfo->certificate->ssl_certificate().GetReference(); 923 return remote_certinfo->certificate->ssl_certificate().GetReference();
877 return static_cast<rtc::SSLCertificate*>(nullptr); 924 return static_cast<rtc::SSLCertificate*>(nullptr);
878 })); 925 }));
879 926
880 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); 927 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
881 ExpectReportContainsCertificateInfo(report, *local_certinfo.get()); 928
882 ExpectReportContainsCertificateInfo(report, *remote_certinfo.get()); 929 for (size_t i = 0; i < local_certinfo->fingerprints.size(); ++i) {
930 RTCCertificateStats expected_local_certificate(
931 "RTCCertificate_" + local_certinfo->fingerprints[i],
932 report->timestamp_us());
933 expected_local_certificate.fingerprint =
934 local_certinfo->fingerprints[i];
935 expected_local_certificate.fingerprint_algorithm = "sha-1";
936 expected_local_certificate.base64_certificate =
937 local_certinfo->pems[i];
938 if (i + 1 < local_certinfo->fingerprints.size()) {
939 expected_local_certificate.issuer_certificate_id =
940 "RTCCertificate_" + local_certinfo->fingerprints[i + 1];
941 }
942 ASSERT(report->Get(expected_local_certificate.id()));
943 EXPECT_EQ(expected_local_certificate,
944 report->Get(expected_local_certificate.id())->cast_to<
945 RTCCertificateStats>());
946 }
947
948 for (size_t i = 0; i < remote_certinfo->fingerprints.size(); ++i) {
949 RTCCertificateStats expected_remote_certificate(
950 "RTCCertificate_" + remote_certinfo->fingerprints[i],
951 report->timestamp_us());
952 expected_remote_certificate.fingerprint =
953 remote_certinfo->fingerprints[i];
954 expected_remote_certificate.fingerprint_algorithm = "sha-1";
955 expected_remote_certificate.base64_certificate =
956 remote_certinfo->pems[i];
957 if (i + 1 < remote_certinfo->fingerprints.size()) {
958 expected_remote_certificate.issuer_certificate_id =
959 "RTCCertificate_" + remote_certinfo->fingerprints[i + 1];
960 }
961 ASSERT(report->Get(expected_remote_certificate.id()));
962 EXPECT_EQ(expected_remote_certificate,
963 report->Get(expected_remote_certificate.id())->cast_to<
964 RTCCertificateStats>());
965 }
883 } 966 }
884 967
885 TEST_F(RTCStatsCollectorTest, CollectRTCDataChannelStats) { 968 TEST_F(RTCStatsCollectorTest, CollectRTCDataChannelStats) {
886 test_->data_channels().push_back( 969 test_->data_channels().push_back(
887 new MockDataChannel(0, DataChannelInterface::kConnecting)); 970 new MockDataChannel(0, DataChannelInterface::kConnecting));
888 test_->data_channels().push_back( 971 test_->data_channels().push_back(
889 new MockDataChannel(1, DataChannelInterface::kOpen)); 972 new MockDataChannel(1, DataChannelInterface::kOpen));
890 test_->data_channels().push_back( 973 test_->data_channels().push_back(
891 new MockDataChannel(2, DataChannelInterface::kClosing)); 974 new MockDataChannel(2, DataChannelInterface::kClosing));
892 test_->data_channels().push_back( 975 test_->data_channels().push_back(
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; 1990 rtc::scoped_refptr<FakeRTCStatsCollector> collector_;
1908 }; 1991 };
1909 1992
1910 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { 1993 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) {
1911 collector_->VerifyThreadUsageAndResultsMerging(); 1994 collector_->VerifyThreadUsageAndResultsMerging();
1912 } 1995 }
1913 1996
1914 } // namespace 1997 } // namespace
1915 1998
1916 } // namespace webrtc 1999 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698