Chromium Code Reviews| Index: talk/app/webrtc/peerconnection_unittest.cc |
| diff --git a/talk/app/webrtc/peerconnection_unittest.cc b/talk/app/webrtc/peerconnection_unittest.cc |
| index 9ce6c5e7585645f56e6d2a2cef52988370ce39d9..9cd0d5b29a31a4878f42c7ba322c31447ba7772b 100644 |
| --- a/talk/app/webrtc/peerconnection_unittest.cc |
| +++ b/talk/app/webrtc/peerconnection_unittest.cc |
| @@ -145,18 +145,26 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| public SignalingMessageReceiver, |
| public ObserverInterface { |
| public: |
| - static PeerConnectionTestClient* CreateClient( |
| + static PeerConnectionTestClient* CreateClientWithKeySpecified( |
| const std::string& id, |
| const MediaConstraintsInterface* constraints, |
| - const PeerConnectionFactory::Options* options) { |
| + const PeerConnectionFactory::Options* options, |
| + bool use_alternate_key) { |
|
juberti
2015/12/02 00:29:43
Instead of using a magic bool value, it seems like
guoweis_webrtc
2015/12/02 18:44:15
Will do.
guoweis_webrtc
2015/12/03 22:59:41
Done.
|
| PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); |
| - if (!client->Init(constraints, options)) { |
| + if (!client->Init(constraints, options, use_alternate_key)) { |
| delete client; |
| return nullptr; |
| } |
| return client; |
| } |
| + static PeerConnectionTestClient* CreateClient( |
| + const std::string& id, |
| + const MediaConstraintsInterface* constraints, |
| + const PeerConnectionFactory::Options* options) { |
| + return CreateClientWithKeySpecified(id, constraints, options, false); |
| + } |
| + |
| ~PeerConnectionTestClient() { |
| while (!fake_video_renderers_.empty()) { |
| RenderMap::iterator it = fake_video_renderers_.begin(); |
| @@ -705,7 +713,8 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} |
| bool Init(const MediaConstraintsInterface* constraints, |
| - const PeerConnectionFactory::Options* options) { |
| + const PeerConnectionFactory::Options* options, |
| + bool use_alternate_key) { |
| EXPECT_TRUE(!peer_connection_); |
| EXPECT_TRUE(!peer_connection_factory_); |
| allocator_factory_ = webrtc::FakePortAllocatorFactory::Create(); |
| @@ -730,22 +739,29 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| peer_connection_factory_->SetOptions(*options); |
| } |
| peer_connection_ = CreatePeerConnection(allocator_factory_.get(), |
| - constraints); |
| + constraints, use_alternate_key); |
| return peer_connection_.get() != nullptr; |
| } |
| rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
| webrtc::PortAllocatorFactoryInterface* factory, |
| - const MediaConstraintsInterface* constraints) { |
| + const MediaConstraintsInterface* constraints, |
| + bool use_alternate_key) { |
| // CreatePeerConnection with IceServers. |
| webrtc::PeerConnectionInterface::IceServers ice_servers; |
| webrtc::PeerConnectionInterface::IceServer ice_server; |
| ice_server.uri = "stun:stun.l.google.com:19302"; |
| ice_servers.push_back(ice_server); |
| - rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store( |
| + rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
| rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
| : nullptr); |
| + |
| + if (use_alternate_key) { |
| + dtls_identity_store->use_alternate_key(); |
| + } else { |
| + dtls_identity_store->use_original_key(); |
| + } |
| return peer_connection_factory_->CreatePeerConnection( |
| ice_servers, constraints, factory, dtls_identity_store.Pass(), this); |
| } |
| @@ -979,6 +995,11 @@ class MAYBE_JsepPeerConnectionP2PTestClient : public testing::Test { |
| nullptr); |
| } |
| + void SetSignalingReceivers() { |
| + initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
| + receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
| + } |
| + |
| bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
| PeerConnectionFactory::Options* init_options, |
| MediaConstraintsInterface* recv_constraints, |
| @@ -990,8 +1011,7 @@ class MAYBE_JsepPeerConnectionP2PTestClient : public testing::Test { |
| if (!initiating_client_ || !receiving_client_) { |
| return false; |
| } |
| - initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
| - receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
| + SetSignalingReceivers(); |
| return true; |
| } |
| @@ -1068,6 +1088,26 @@ class MAYBE_JsepPeerConnectionP2PTestClient : public testing::Test { |
| kMaxWaitForFramesMs); |
| } |
| + void SetupAndVerifyDtlsCall() { |
| + MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| + FakeConstraints setup_constraints; |
| + setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| + true); |
| + ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| + LocalP2PTest(); |
| + VerifyRenderedSize(640, 480); |
| + } |
| + |
| + PeerConnectionTestClient* CreateDtlsClientWithAlternateKey() { |
| + FakeConstraints setup_constraints; |
| + setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| + true); |
| + |
| + // Make sure the new client is using a different certificate. |
| + return PeerConnectionTestClient::CreateClientWithKeySpecified( |
| + "New Peer: ", &setup_constraints, nullptr, true); |
| + } |
| + |
| void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
| // Messages may get lost on the unreliable DataChannel, so we send multiple |
| // times to avoid test flakiness. |
| @@ -1081,10 +1121,29 @@ class MAYBE_JsepPeerConnectionP2PTestClient : public testing::Test { |
| PeerConnectionTestClient* initializing_client() { |
| return initiating_client_.get(); |
| } |
| + |
| + // Set the |initiating_client_| to the |client| passed in and return the |
| + // original |initiating_client_|. |
| + PeerConnectionTestClient* set_initializing_client( |
| + PeerConnectionTestClient* client) { |
| + PeerConnectionTestClient* old = initiating_client_.release(); |
| + initiating_client_.reset(client); |
| + return old; |
| + } |
| + |
| PeerConnectionTestClient* receiving_client() { |
| return receiving_client_.get(); |
| } |
| + // Set the |receiving_client_| to the |client| passed in and return the |
| + // original |receiving_client_|. |
| + PeerConnectionTestClient* set_receiving_client( |
| + PeerConnectionTestClient* client) { |
| + PeerConnectionTestClient* old = receiving_client_.release(); |
| + receiving_client_.reset(client); |
| + return old; |
| + } |
| + |
| private: |
| rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; |
| @@ -1146,13 +1205,7 @@ TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTest1280By720) { |
| // This test sets up a call between two endpoints that are configured to use |
| // DTLS key agreement. As a result, DTLS is negotiated and used for transport. |
| TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestDtls) { |
| - MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| - FakeConstraints setup_constraints; |
| - setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| - true); |
| - ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| - LocalP2PTest(); |
| - VerifyRenderedSize(640, 480); |
| + SetupAndVerifyDtlsCall(); |
| } |
| // This test sets up a audio call initially and then upgrades to audio/video, |
| @@ -1169,6 +1222,40 @@ TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestDtlsRenegotiate) { |
| receiving_client()->Negotiate(); |
| } |
| +// This test sets up a call transfer to a new caller with a different DTLS |
| +// fingerprint. |
| +TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestDtlsTransferCallee) { |
| + MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| + SetupAndVerifyDtlsCall(); |
| + |
| + // Keeping the original peer around which will still send packets to the |
| + // receiving client. These SRTP packets will be dropped. |
| + rtc::scoped_ptr<PeerConnectionTestClient> original_peer( |
| + set_initializing_client(CreateDtlsClientWithAlternateKey())); |
| + |
| + SetSignalingReceivers(); |
| + receiving_client()->SetExpectIceRestart(true); |
| + LocalP2PTest(); |
| + VerifyRenderedSize(640, 480); |
| +} |
| + |
| +// This test sets up a call transfer to a new callee with a different DTLS |
| +// fingerprint. |
| +TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestDtlsTransferCaller) { |
| + MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| + SetupAndVerifyDtlsCall(); |
| + |
| + // Keeping the original peer around which will still send packets to the |
| + // receiving client. These SRTP packets will be dropped. |
| + rtc::scoped_ptr<PeerConnectionTestClient> original_peer( |
| + set_receiving_client(CreateDtlsClientWithAlternateKey())); |
| + |
| + SetSignalingReceivers(); |
| + initializing_client()->IceRestart(); |
| + LocalP2PTest(); |
| + VerifyRenderedSize(640, 480); |
| +} |
| + |
| // This test sets up a call between two endpoints that are configured to use |
| // DTLS key agreement. The offerer don't support SDES. As a result, DTLS is |
| // negotiated and used for transport. |