Chromium Code Reviews| Index: webrtc/api/peerconnection_unittest.cc |
| diff --git a/webrtc/api/peerconnection_unittest.cc b/webrtc/api/peerconnection_unittest.cc |
| index 4a544c48256cca9cae27ae1c852eed54f56adf7c..afb8b9236321563998abd08cd54c4546f81dcbb3 100644 |
| --- a/webrtc/api/peerconnection_unittest.cc |
| +++ b/webrtc/api/peerconnection_unittest.cc |
| @@ -155,9 +155,11 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| const std::string& id, |
| const MediaConstraintsInterface* constraints, |
| const PeerConnectionFactory::Options* options, |
| - rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { |
| + rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, |
| + bool prefer_constraint_apis) { |
| PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); |
| - if (!client->Init(constraints, options, std::move(dtls_identity_store))) { |
| + if (!client->Init(constraints, options, std::move(dtls_identity_store), |
| + prefer_constraint_apis)) { |
| delete client; |
| return nullptr; |
| } |
| @@ -172,8 +174,19 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
| : nullptr); |
| - return CreateClientWithDtlsIdentityStore(id, constraints, options, |
| - std::move(dtls_identity_store)); |
| + return CreateClientWithDtlsIdentityStore( |
| + id, constraints, options, std::move(dtls_identity_store), true); |
| + } |
| + |
| + static PeerConnectionTestClient* CreateClientPreferNoConstraints( |
| + const std::string& id, |
| + const PeerConnectionFactory::Options* options) { |
| + rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
| + rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
| + : nullptr); |
| + |
| + return CreateClientWithDtlsIdentityStore( |
| + id, nullptr, options, std::move(dtls_identity_store), false); |
| } |
| ~PeerConnectionTestClient() { |
| @@ -337,6 +350,7 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| void IceRestart() { |
| session_description_constraints_.SetMandatoryIceRestart(true); |
| + session_description_options_.ice_restart = true; |
| SetExpectIceRestart(true); |
| } |
| @@ -357,12 +371,14 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| if (audio && can_receive_audio()) |
| return; |
| session_description_constraints_.SetMandatoryReceiveAudio(audio); |
| + session_description_options_.offer_to_receive_audio = audio ? 1 : 0; |
| } |
| void SetReceiveVideo(bool video) { |
| if (video && can_receive_video()) |
| return; |
| session_description_constraints_.SetMandatoryReceiveVideo(video); |
| + session_description_options_.offer_to_receive_video = video ? 1 : 0; |
| } |
| void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; } |
| @@ -373,22 +389,34 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| bool can_receive_audio() { |
| bool value; |
| - if (webrtc::FindConstraint(&session_description_constraints_, |
| - MediaConstraintsInterface::kOfferToReceiveAudio, |
| - &value, nullptr)) { |
| - return value; |
| + if (prefer_constraint_apis_) { |
| + if (webrtc::FindConstraint( |
| + &session_description_constraints_, |
| + MediaConstraintsInterface::kOfferToReceiveAudio, &value, |
| + nullptr)) { |
| + return value; |
| + } |
| + return true; |
| } |
| - return true; |
| + return session_description_options_.offer_to_receive_audio > 0 || |
| + session_description_options_.offer_to_receive_audio == |
| + PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined; |
| } |
| bool can_receive_video() { |
| bool value; |
| - if (webrtc::FindConstraint(&session_description_constraints_, |
| - MediaConstraintsInterface::kOfferToReceiveVideo, |
| - &value, nullptr)) { |
| - return value; |
| + if (prefer_constraint_apis_) { |
| + if (webrtc::FindConstraint( |
| + &session_description_constraints_, |
| + MediaConstraintsInterface::kOfferToReceiveVideo, &value, |
| + nullptr)) { |
| + return value; |
| + } |
| + return true; |
| } |
| - return true; |
| + return session_description_options_.offer_to_receive_audio > 0 || |
|
perkj_webrtc
2016/03/10 15:35:24
video
hta-webrtc
2016/03/10 16:22:05
Ouch. Makes me feel I should write tests for my te
|
| + session_description_options_.offer_to_receive_audio == |
|
perkj_webrtc
2016/03/10 15:35:24
video
hta-webrtc
2016/03/10 16:22:05
Done.
|
| + PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined; |
| } |
| void OnDataChannel(DataChannelInterface* data_channel) override { |
| @@ -745,9 +773,15 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| bool Init( |
| const MediaConstraintsInterface* constraints, |
| const PeerConnectionFactory::Options* options, |
| - rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { |
| + rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, |
| + bool prefer_constraint_apis) { |
| EXPECT_TRUE(!peer_connection_); |
| EXPECT_TRUE(!peer_connection_factory_); |
| + if (!prefer_constraint_apis) { |
| + EXPECT_TRUE(!constraints); |
| + } |
| + prefer_constraint_apis_ = prefer_constraint_apis; |
| + |
| rtc::scoped_ptr<cricket::PortAllocator> port_allocator( |
| new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
| @@ -819,10 +853,18 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| rtc::scoped_refptr<MockCreateSessionDescriptionObserver> |
| observer(new rtc::RefCountedObject< |
| MockCreateSessionDescriptionObserver>()); |
| - if (offer) { |
| - pc()->CreateOffer(observer, &session_description_constraints_); |
| + if (prefer_constraint_apis_) { |
| + if (offer) { |
| + pc()->CreateOffer(observer, &session_description_constraints_); |
| + } else { |
| + pc()->CreateAnswer(observer, &session_description_constraints_); |
| + } |
| } else { |
| - pc()->CreateAnswer(observer, &session_description_constraints_); |
| + if (offer) { |
| + pc()->CreateOffer(observer, session_description_options_); |
| + } else { |
| + pc()->CreateAnswer(observer, session_description_options_); |
| + } |
| } |
| EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs); |
| *desc = observer->release_desc(); |
| @@ -895,6 +937,7 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
| peer_connection_factory_; |
| + bool prefer_constraint_apis_ = true; |
| bool auto_add_stream_ = true; |
| typedef std::pair<std::string, std::string> IceUfragPwdPair; |
| @@ -924,6 +967,7 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
| std::vector<cricket::VideoCapturer*> video_capturers_; |
| webrtc::FakeConstraints session_description_constraints_; |
| + PeerConnectionInterface::RTCOfferAnswerOptions session_description_options_; |
|
perkj_webrtc
2016/03/10 15:35:24
suggest change name to match the type. what about
hta-webrtc
2016/03/10 16:22:05
Good idea. The "session_description" moniker was n
|
| bool remove_msid_ = false; // True if MSID should be removed in received SDP. |
| bool remove_bundle_ = |
| false; // True if bundle should be removed in received SDP. |
| @@ -1033,6 +1077,22 @@ class P2PTestConductor : public testing::Test { |
| nullptr); |
| } |
| + bool CreateTestClientsThatPreferNoConstraints() { |
| + initiating_client_.reset( |
| + PeerConnectionTestClient::CreateClientPreferNoConstraints("Caller: ", |
| + nullptr)); |
| + receiving_client_.reset( |
| + PeerConnectionTestClient::CreateClientPreferNoConstraints("Callee: ", |
| + nullptr)); |
| + if (!initiating_client_ || !receiving_client_) { |
| + return false; |
| + } |
| + // Remember the choice for possible later resets of the clients. |
| + prefer_constraint_apis_ = false; |
| + SetSignalingReceivers(); |
| + return true; |
| + } |
| + |
| void SetSignalingReceivers() { |
| initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
| receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
| @@ -1141,7 +1201,7 @@ class P2PTestConductor : public testing::Test { |
| // Make sure the new client is using a different certificate. |
| return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( |
| "New Peer: ", &setup_constraints, nullptr, |
| - std::move(dtls_identity_store)); |
| + std::move(dtls_identity_store), prefer_constraint_apis_); |
| } |
| void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
| @@ -1186,6 +1246,7 @@ class P2PTestConductor : public testing::Test { |
| rtc::SocketServerScope ss_scope_; |
| rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_; |
| rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_; |
| + bool prefer_constraint_apis_ = true; |
| }; |
| // Disable for TSan v2, see |
| @@ -1252,6 +1313,12 @@ TEST_F(P2PTestConductor, OneWayMediaCall) { |
| LocalP2PTest(); |
| } |
| +TEST_F(P2PTestConductor, OneWayMediaCallWithoutConstraints) { |
| + ASSERT_TRUE(CreateTestClientsThatPreferNoConstraints()); |
| + receiving_client()->set_auto_add_stream(false); |
| + LocalP2PTest(); |
| +} |
| + |
| // This test sets up a audio call initially and then upgrades to audio/video, |
| // using DTLS. |
| TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) { |