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

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

Issue 2020623002: Turning FakeDtlsIdentityStore into FakeRTCCertificateGenerator. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase with master Created 4 years, 6 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 | « webrtc/api/test/peerconnectiontestwrapper.cc ('k') | 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 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 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 <memory> 11 #include <memory>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "webrtc/api/audiotrack.h" 15 #include "webrtc/api/audiotrack.h"
16 #include "webrtc/api/fakemediacontroller.h" 16 #include "webrtc/api/fakemediacontroller.h"
17 #include "webrtc/api/fakemetricsobserver.h" 17 #include "webrtc/api/fakemetricsobserver.h"
18 #include "webrtc/api/jsepicecandidate.h" 18 #include "webrtc/api/jsepicecandidate.h"
19 #include "webrtc/api/jsepsessiondescription.h" 19 #include "webrtc/api/jsepsessiondescription.h"
20 #include "webrtc/api/peerconnection.h" 20 #include "webrtc/api/peerconnection.h"
21 #include "webrtc/api/sctputils.h" 21 #include "webrtc/api/sctputils.h"
22 #include "webrtc/api/test/fakedtlsidentitystore.h" 22 #include "webrtc/api/test/fakertccertificategenerator.h"
23 #include "webrtc/api/videotrack.h" 23 #include "webrtc/api/videotrack.h"
24 #include "webrtc/api/webrtcsession.h" 24 #include "webrtc/api/webrtcsession.h"
25 #include "webrtc/api/webrtcsessiondescriptionfactory.h" 25 #include "webrtc/api/webrtcsessiondescriptionfactory.h"
26 #include "webrtc/base/fakenetwork.h" 26 #include "webrtc/base/fakenetwork.h"
27 #include "webrtc/base/firewallsocketserver.h" 27 #include "webrtc/base/firewallsocketserver.h"
28 #include "webrtc/base/gunit.h" 28 #include "webrtc/base/gunit.h"
29 #include "webrtc/base/logging.h" 29 #include "webrtc/base/logging.h"
30 #include "webrtc/base/network.h" 30 #include "webrtc/base/network.h"
31 #include "webrtc/base/physicalsocketserver.h" 31 #include "webrtc/base/physicalsocketserver.h"
32 #include "webrtc/base/ssladapter.h" 32 #include "webrtc/base/ssladapter.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 allocator_->set_step_delay(cricket::kMinimumStepDelay); 369 allocator_->set_step_delay(cricket::kMinimumStepDelay);
370 } 370 }
371 371
372 void AddInterface(const SocketAddress& addr) { 372 void AddInterface(const SocketAddress& addr) {
373 network_manager_.AddInterface(addr); 373 network_manager_.AddInterface(addr);
374 } 374 }
375 void RemoveInterface(const SocketAddress& addr) { 375 void RemoveInterface(const SocketAddress& addr) {
376 network_manager_.RemoveInterface(addr); 376 network_manager_.RemoveInterface(addr);
377 } 377 }
378 378
379 // If |dtls_identity_store| != null or |rtc_configuration| contains 379 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
380 // |certificates| then DTLS will be enabled unless explicitly disabled by 380 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
381 // |rtc_configuration| options. When DTLS is enabled a certificate will be 381 // options. When DTLS is enabled a certificate will be used if provided,
382 // used if provided, otherwise one will be generated using the 382 // otherwise one will be generated using the |cert_generator|.
383 // |dtls_identity_store|.
384 void Init( 383 void Init(
385 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { 384 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
386 ASSERT_TRUE(session_.get() == NULL); 385 ASSERT_TRUE(session_.get() == NULL);
387 session_.reset(new WebRtcSessionForTest( 386 session_.reset(new WebRtcSessionForTest(
388 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(), 387 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
389 rtc::Thread::Current(), allocator_.get(), &observer_)); 388 rtc::Thread::Current(), allocator_.get(), &observer_));
390 session_->SignalDataChannelOpenMessage.connect( 389 session_->SignalDataChannelOpenMessage.connect(
391 this, &WebRtcSessionTest::OnDataChannelOpenMessage); 390 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
392 session_->GetOnDestroyedSignal()->connect( 391 session_->GetOnDestroyedSignal()->connect(
393 this, &WebRtcSessionTest::OnSessionDestroyed); 392 this, &WebRtcSessionTest::OnSessionDestroyed);
394 393
395 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, 394 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
396 observer_.ice_connection_state_); 395 observer_.ice_connection_state_);
397 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, 396 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
398 observer_.ice_gathering_state_); 397 observer_.ice_gathering_state_);
399 398
400 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator(
401 dtls_identity_store ? new webrtc::RTCCertificateGeneratorStoreWrapper(
402 std::move(dtls_identity_store)) : nullptr);
403 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), 399 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
404 configuration_)); 400 configuration_));
405 session_->set_metrics_observer(metrics_observer_); 401 session_->set_metrics_observer(metrics_observer_);
406 } 402 }
407 403
408 void OnDataChannelOpenMessage(const std::string& label, 404 void OnDataChannelOpenMessage(const std::string& label,
409 const InternalDataChannelInit& config) { 405 const InternalDataChannelInit& config) {
410 last_data_channel_label_ = label; 406 last_data_channel_label_ = label;
411 last_data_channel_config_ = config; 407 last_data_channel_config_ = config;
412 } 408 }
(...skipping 11 matching lines...) Expand all
424 void InitWithRtcpMuxPolicy( 420 void InitWithRtcpMuxPolicy(
425 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { 421 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
426 PeerConnectionInterface::RTCConfiguration configuration; 422 PeerConnectionInterface::RTCConfiguration configuration;
427 configuration_.rtcp_mux_policy = rtcp_mux_policy; 423 configuration_.rtcp_mux_policy = rtcp_mux_policy;
428 Init(); 424 Init();
429 } 425 }
430 426
431 // Successfully init with DTLS; with a certificate generated and supplied or 427 // Successfully init with DTLS; with a certificate generated and supplied or
432 // with a store that generates it for us. 428 // with a store that generates it for us.
433 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { 429 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
434 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store; 430 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
435 if (cert_gen_method == ALREADY_GENERATED) { 431 if (cert_gen_method == ALREADY_GENERATED) {
436 configuration_.certificates.push_back( 432 configuration_.certificates.push_back(
437 FakeDtlsIdentityStore::GenerateCertificate()); 433 FakeRTCCertificateGenerator::GenerateCertificate());
438 } else if (cert_gen_method == DTLS_IDENTITY_STORE) { 434 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
439 dtls_identity_store.reset(new FakeDtlsIdentityStore()); 435 cert_generator.reset(new FakeRTCCertificateGenerator());
440 dtls_identity_store->set_should_fail(false); 436 cert_generator->set_should_fail(false);
441 } else { 437 } else {
442 RTC_CHECK(false); 438 RTC_CHECK(false);
443 } 439 }
444 Init(std::move(dtls_identity_store)); 440 Init(std::move(cert_generator));
445 } 441 }
446 442
447 // Init with DTLS with a store that will fail to generate a certificate. 443 // Init with DTLS with a store that will fail to generate a certificate.
448 void InitWithDtlsIdentityGenFail() { 444 void InitWithDtlsIdentityGenFail() {
449 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( 445 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
450 new FakeDtlsIdentityStore()); 446 new FakeRTCCertificateGenerator());
451 dtls_identity_store->set_should_fail(true); 447 cert_generator->set_should_fail(true);
452 Init(std::move(dtls_identity_store)); 448 Init(std::move(cert_generator));
453 } 449 }
454 450
455 void InitWithDtmfCodec() { 451 void InitWithDtmfCodec() {
456 // Add kTelephoneEventCodec for dtmf test. 452 // Add kTelephoneEventCodec for dtmf test.
457 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, 453 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
458 0, 1); 454 0, 1);
459 std::vector<cricket::AudioCodec> codecs; 455 std::vector<cricket::AudioCodec> codecs;
460 codecs.push_back(kTelephoneEventCodec); 456 codecs.push_back(kTelephoneEventCodec);
461 media_engine_->SetAudioCodecs(codecs); 457 media_engine_->SetAudioCodecs(codecs);
462 desc_factory_->set_audio_codecs(codecs); 458 desc_factory_->set_audio_codecs(codecs);
(...skipping 3636 matching lines...) Expand 10 before | Expand all | Expand 10 after
4099 4095
4100 EXPECT_EQ("a", last_data_channel_label_); 4096 EXPECT_EQ("a", last_data_channel_label_);
4101 EXPECT_EQ(config.id, last_data_channel_config_.id); 4097 EXPECT_EQ(config.id, last_data_channel_config_.id);
4102 EXPECT_FALSE(last_data_channel_config_.negotiated); 4098 EXPECT_FALSE(last_data_channel_config_.negotiated);
4103 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker, 4099 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4104 last_data_channel_config_.open_handshake_role); 4100 last_data_channel_config_.open_handshake_role);
4105 } 4101 }
4106 4102
4107 TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) { 4103 TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
4108 rtc::scoped_refptr<rtc::RTCCertificate> certificate = 4104 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4109 FakeDtlsIdentityStore::GenerateCertificate(); 4105 FakeRTCCertificateGenerator::GenerateCertificate();
4110 4106
4111 configuration_.certificates.push_back(certificate); 4107 configuration_.certificates.push_back(certificate);
4112 Init(); 4108 Init();
4113 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); 4109 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4114 4110
4115 EXPECT_EQ(session_->certificate_for_testing(), certificate); 4111 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4116 } 4112 }
4117 4113
4118 // Verifies that CreateOffer succeeds when CreateOffer is called before async 4114 // Verifies that CreateOffer succeeds when CreateOffer is called before async
4119 // identity generation is finished (even if a certificate is provided this is 4115 // identity generation is finished (even if a certificate is provided this is
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
4420 } 4416 }
4421 4417
4422 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test 4418 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4423 // currently fails because upon disconnection and reconnection OnIceComplete is 4419 // currently fails because upon disconnection and reconnection OnIceComplete is
4424 // called more than once without returning to IceGatheringGathering. 4420 // called more than once without returning to IceGatheringGathering.
4425 4421
4426 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, 4422 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4427 WebRtcSessionTest, 4423 WebRtcSessionTest,
4428 testing::Values(ALREADY_GENERATED, 4424 testing::Values(ALREADY_GENERATED,
4429 DTLS_IDENTITY_STORE)); 4425 DTLS_IDENTITY_STORE));
OLDNEW
« no previous file with comments | « webrtc/api/test/peerconnectiontestwrapper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698