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

Unified Diff: talk/app/webrtc/webrtcsession_unittest.cc

Issue 1269843005: Added DtlsCertificate, a ref counted object owning an SSLIdentity (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: webrtcsession_unittest cleanup Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: talk/app/webrtc/webrtcsession_unittest.cc
diff --git a/talk/app/webrtc/webrtcsession_unittest.cc b/talk/app/webrtc/webrtcsession_unittest.cc
index de10bc40a8b432ba79a248d4a55b112f29f0d2e0..acc10f3c08bc2e67657bdc4327a12c23e30a6537 100644
--- a/talk/app/webrtc/webrtcsession_unittest.cc
+++ b/talk/app/webrtc/webrtcsession_unittest.cc
@@ -26,6 +26,7 @@
*/
#include "talk/app/webrtc/audiotrack.h"
+#include "talk/app/webrtc/dtlscertificate.h"
#include "talk/app/webrtc/fakemetricsobserver.h"
#include "talk/app/webrtc/jsepicecandidate.h"
#include "talk/app/webrtc/jsepsessiondescription.h"
@@ -358,7 +359,7 @@ class WebRtcSessionTest : public testing::Test {
}
void Init(
- DTLSIdentityServiceInterface* identity_service,
+ rtc::scoped_refptr<webrtc::DtlsCertificate> certificate,
const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
ASSERT_TRUE(session_.get() == NULL);
session_.reset(new WebRtcSessionForTest(
@@ -373,7 +374,7 @@ class WebRtcSessionTest : public testing::Test {
observer_.ice_gathering_state_);
EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
- identity_service, rtc_configuration));
+ certificate, rtc_configuration));
session_->set_metrics_observer(metrics_observer_);
}
@@ -403,11 +404,9 @@ class WebRtcSessionTest : public testing::Test {
Init(NULL, configuration);
}
- void InitWithDtls(bool identity_request_should_fail = false) {
- FakeIdentityService* identity_service = new FakeIdentityService();
- identity_service->set_should_fail(identity_request_should_fail);
+ void InitWithCertificate() {
PeerConnectionInterface::RTCConfiguration configuration;
- Init(identity_service, configuration);
+ Init(FakeIdentityService::GenerateCertificate(), configuration);
}
void InitWithDtmfCodec() {
@@ -1182,8 +1181,8 @@ class WebRtcSessionTest : public testing::Test {
}
void VerifyMultipleAsyncCreateDescription(
- bool success, CreateSessionDescriptionRequest::Type type) {
- InitWithDtls(!success);
+ CreateSessionDescriptionRequest::Type type) {
+ InitWithCertificate();
SetFactoryDtlsSrtp();
if (type == CreateSessionDescriptionRequest::kAnswer) {
cricket::MediaSessionOptions options;
@@ -1206,17 +1205,10 @@ class WebRtcSessionTest : public testing::Test {
}
}
- WebRtcSessionCreateSDPObserverForTest::State expected_state =
- success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
- WebRtcSessionCreateSDPObserverForTest::kFailed;
-
for (int i = 0; i < kNumber; ++i) {
- EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
- if (success) {
- EXPECT_TRUE(observers[i]->description() != NULL);
- } else {
- EXPECT_TRUE(observers[i]->description() == NULL);
- }
+ EXPECT_EQ_WAIT(WebRtcSessionCreateSDPObserverForTest::kSucceeded,
+ observers[i]->state(), 1000);
+ EXPECT_TRUE(observers[i]->description() != NULL);
}
}
@@ -1258,8 +1250,8 @@ class WebRtcSessionTest : public testing::Test {
rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
};
-TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
- InitWithDtls();
+TEST_F(WebRtcSessionTest, TestInitializeWithCertificate) {
+ InitWithCertificate();
// SDES is disabled when DTLS is on.
EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
}
@@ -1569,7 +1561,7 @@ TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mediastream_signaling_.SendAudioVideoStream1();
- InitWithDtls();
+ InitWithCertificate();
SetFactoryDtlsSrtp();
cricket::MediaSessionOptions options;
options.recv_video = true;
@@ -1598,7 +1590,7 @@ TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mediastream_signaling_.SendAudioVideoStream1();
- InitWithDtls();
+ InitWithCertificate();
SetFactoryDtlsSrtp();
// Verify that we get a crypto fingerprint in the answer.
@@ -1627,7 +1619,7 @@ TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
// we will fail to set the remote description.
TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
cricket::MediaSessionOptions options;
options.recv_video = true;
options.bundle_enabled = true;
@@ -1651,7 +1643,7 @@ TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
// a DTLS fingerprint when DTLS is required.
TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
SessionDescriptionInterface* offer = NULL;
SessionDescriptionInterface* answer = NULL;
CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
@@ -1669,7 +1661,7 @@ TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
// Enable both SDES and DTLS, so that offer won't be outright rejected as a
// result of using the "UDP/TLS/RTP/SAVPF" profile.
- InitWithDtls();
+ InitWithCertificate();
session_->SetSdesPolicy(cricket::SEC_ENABLED);
SessionDescriptionInterface* offer = CreateOffer();
cricket::MediaSessionOptions options;
@@ -1689,7 +1681,7 @@ TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
mediastream_signaling_.SendAudioVideoStream1();
options_.disable_encryption = true;
- InitWithDtls();
+ InitWithCertificate();
// Verify that we get a crypto fingerprint in the answer.
SessionDescriptionInterface* offer = CreateOffer();
@@ -1717,7 +1709,7 @@ TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
// offer without SDES or DTLS when encryption is disabled.
TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
options_.disable_encryption = true;
- InitWithDtls();
+ InitWithCertificate();
cricket::MediaSessionOptions options;
options.recv_video = true;
@@ -3418,7 +3410,7 @@ TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
options_.disable_sctp_data_channels = false;
- InitWithDtls();
+ InitWithCertificate();
SetLocalDescriptionWithDataChannel();
EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
@@ -3427,7 +3419,7 @@ TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
@@ -3437,7 +3429,7 @@ TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
SetFactoryDtlsSrtp();
- InitWithDtls();
+ InitWithCertificate();
// Create remote offer with SCTP.
cricket::MediaSessionOptions options;
@@ -3457,7 +3449,7 @@ TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
constraints_.reset(new FakeConstraints());
constraints_->AddOptional(
webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
- InitWithDtls();
+ InitWithCertificate();
SetLocalDescriptionWithDataChannel();
EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
@@ -3466,7 +3458,7 @@ TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
SetLocalDescriptionWithDataChannel();
EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
@@ -3475,7 +3467,7 @@ TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
options_.disable_sctp_data_channels = true;
- InitWithDtls();
+ InitWithCertificate();
SetLocalDescriptionWithDataChannel();
EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
@@ -3486,7 +3478,7 @@ TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
const int new_send_port = 9998;
const int new_recv_port = 7775;
- InitWithDtls();
+ InitWithCertificate();
SetFactoryDtlsSrtp();
// By default, don't actually add the codecs to desc_factory_; they don't
@@ -3539,9 +3531,9 @@ TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
// identity generation is finished.
TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
- EXPECT_TRUE(session_->waiting_for_identity());
+ EXPECT_TRUE(session_->waiting_for_certificate());
mediastream_signaling_.SendAudioVideoStream1();
rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
@@ -3554,7 +3546,7 @@ TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
// identity generation is finished.
TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
SetFactoryDtlsSrtp();
cricket::MediaSessionOptions options;
@@ -3574,42 +3566,21 @@ TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
// identity generation is finished.
TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
- EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
+ EXPECT_TRUE_WAIT(!session_->waiting_for_certificate(), 1000);
rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
EXPECT_TRUE(offer != NULL);
}
-// Verifies that CreateOffer fails when CreateOffer is called after async
-// identity generation fails.
-TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
- MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls(true);
-
- EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
-
- rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
- EXPECT_TRUE(offer == NULL);
-}
-
// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
// before async identity generation is finished.
TEST_F(WebRtcSessionTest,
TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
VerifyMultipleAsyncCreateDescription(
- true, CreateSessionDescriptionRequest::kOffer);
-}
-
-// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
-// before async identity generation fails.
-TEST_F(WebRtcSessionTest,
- TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
- MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- VerifyMultipleAsyncCreateDescription(
- false, CreateSessionDescriptionRequest::kOffer);
+ CreateSessionDescriptionRequest::kOffer);
}
// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
@@ -3618,16 +3589,7 @@ TEST_F(WebRtcSessionTest,
TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
VerifyMultipleAsyncCreateDescription(
- true, CreateSessionDescriptionRequest::kAnswer);
-}
-
-// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
-// before async identity generation fails.
-TEST_F(WebRtcSessionTest,
- TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
- MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- VerifyMultipleAsyncCreateDescription(
- false, CreateSessionDescriptionRequest::kAnswer);
+ CreateSessionDescriptionRequest::kAnswer);
}
// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
@@ -3730,7 +3692,7 @@ TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
// new remote SDP.
TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
SetFactoryDtlsSrtp();
mediastream_signaling_.UseOptionsAudioOnly();
@@ -3760,7 +3722,7 @@ TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
// from the remote SDP.
TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
- InitWithDtls();
+ InitWithCertificate();
SetFactoryDtlsSrtp();
mediastream_signaling_.UseOptionsAudioOnly();

Powered by Google App Engine
This is Rietveld 408576698