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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2828223002: Delete method MessageQueue::set_socketserver (Closed)
Patch Set: Rebase. Created 3 years, 7 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/p2p/base/asyncstuntcpsocket_unittest.cc ('k') | webrtc/p2p/base/port.cc » ('j') | 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 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // form of connectivity to the other side. The test checks that the P2P 175 // form of connectivity to the other side. The test checks that the P2P
176 // negotiation successfully establishes connectivity within a certain time, 176 // negotiation successfully establishes connectivity within a certain time,
177 // and that the result is what we expect. 177 // and that the result is what we expect.
178 // Note that this class is a base class for use by other tests, who will provide 178 // Note that this class is a base class for use by other tests, who will provide
179 // specialized test behavior. 179 // specialized test behavior.
180 class P2PTransportChannelTestBase : public testing::Test, 180 class P2PTransportChannelTestBase : public testing::Test,
181 public rtc::MessageHandler, 181 public rtc::MessageHandler,
182 public sigslot::has_slots<> { 182 public sigslot::has_slots<> {
183 public: 183 public:
184 P2PTransportChannelTestBase() 184 P2PTransportChannelTestBase()
185 : main_(rtc::Thread::Current()), 185 : pss_(new rtc::PhysicalSocketServer),
186 pss_(new rtc::PhysicalSocketServer),
187 vss_(new rtc::VirtualSocketServer(pss_.get())), 186 vss_(new rtc::VirtualSocketServer(pss_.get())),
188 nss_(new rtc::NATSocketServer(vss_.get())), 187 nss_(new rtc::NATSocketServer(vss_.get())),
189 ss_(new rtc::FirewallSocketServer(nss_.get())), 188 ss_(new rtc::FirewallSocketServer(nss_.get())),
190 ss_scope_(ss_.get()), 189 main_(ss_.get()),
191 stun_server_(TestStunServer::Create(main_, kStunAddr)), 190 stun_server_(TestStunServer::Create(&main_, kStunAddr)),
192 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), 191 turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr),
193 socks_server1_(ss_.get(), 192 socks_server1_(ss_.get(),
194 kSocksProxyAddrs[0], 193 kSocksProxyAddrs[0],
195 ss_.get(), 194 ss_.get(),
196 kSocksProxyAddrs[0]), 195 kSocksProxyAddrs[0]),
197 socks_server2_(ss_.get(), 196 socks_server2_(ss_.get(),
198 kSocksProxyAddrs[1], 197 kSocksProxyAddrs[1],
199 ss_.get(), 198 ss_.get(),
200 kSocksProxyAddrs[1]), 199 kSocksProxyAddrs[1]),
201 force_relay_(false) { 200 force_relay_(false) {
202 ep1_.role_ = ICEROLE_CONTROLLING; 201 ep1_.role_ = ICEROLE_CONTROLLING;
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 688
690 // We pass the candidates directly to the other side. 689 // We pass the candidates directly to the other side.
691 void OnCandidateGathered(IceTransportInternal* ch, const Candidate& c) { 690 void OnCandidateGathered(IceTransportInternal* ch, const Candidate& c) {
692 if (force_relay_ && c.type() != RELAY_PORT_TYPE) 691 if (force_relay_ && c.type() != RELAY_PORT_TYPE)
693 return; 692 return;
694 693
695 if (GetEndpoint(ch)->save_candidates_) { 694 if (GetEndpoint(ch)->save_candidates_) {
696 GetEndpoint(ch)->saved_candidates_.push_back( 695 GetEndpoint(ch)->saved_candidates_.push_back(
697 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c))); 696 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c)));
698 } else { 697 } else {
699 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, 698 main_.Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES,
700 new CandidatesData(ch, c)); 699 new CandidatesData(ch, c));
701 } 700 }
702 } 701 }
703 void OnSelectedCandidatePairChanged( 702 void OnSelectedCandidatePairChanged(
704 IceTransportInternal* transport_channel, 703 IceTransportInternal* transport_channel,
705 CandidatePairInterface* selected_candidate_pair, 704 CandidatePairInterface* selected_candidate_pair,
706 int last_sent_packet_id, 705 int last_sent_packet_id,
707 bool ready_to_send) { 706 bool ready_to_send) {
708 // Do not count if it switches to nullptr. This may happen if all 707 // Do not count if it switches to nullptr. This may happen if all
709 // connections timed out. 708 // connections timed out.
710 if (selected_candidate_pair != nullptr) { 709 if (selected_candidate_pair != nullptr) {
711 ++selected_candidate_pair_switches_; 710 ++selected_candidate_pair_switches_;
712 } 711 }
713 } 712 }
714 713
715 int reset_selected_candidate_pair_switches() { 714 int reset_selected_candidate_pair_switches() {
716 int switches = selected_candidate_pair_switches_; 715 int switches = selected_candidate_pair_switches_;
717 selected_candidate_pair_switches_ = 0; 716 selected_candidate_pair_switches_ = 0;
718 return switches; 717 return switches;
719 } 718 }
720 719
721 void PauseCandidates(int endpoint) { 720 void PauseCandidates(int endpoint) {
722 GetEndpoint(endpoint)->save_candidates_ = true; 721 GetEndpoint(endpoint)->save_candidates_ = true;
723 } 722 }
724 723
725 void OnCandidatesRemoved(IceTransportInternal* ch, 724 void OnCandidatesRemoved(IceTransportInternal* ch,
726 const std::vector<Candidate>& candidates) { 725 const std::vector<Candidate>& candidates) {
727 // Candidate removals are not paused. 726 // Candidate removals are not paused.
728 CandidatesData* candidates_data = new CandidatesData(ch, candidates); 727 CandidatesData* candidates_data = new CandidatesData(ch, candidates);
729 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data); 728 main_.Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data);
730 } 729 }
731 730
732 // Tcp candidate verification has to be done when they are generated. 731 // Tcp candidate verification has to be done when they are generated.
733 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) { 732 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) {
734 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) { 733 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) {
735 for (auto& candidate : data->candidates) { 734 for (auto& candidate : data->candidates) {
736 EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME); 735 EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME);
737 EXPECT_EQ(candidate.tcptype(), tcptype); 736 EXPECT_EQ(candidate.tcptype(), tcptype);
738 if (candidate.tcptype() == TCPTYPE_ACTIVE_STR) { 737 if (candidate.tcptype() == TCPTYPE_ACTIVE_STR) {
739 EXPECT_EQ(candidate.address().port(), DISCARD_PORT); 738 EXPECT_EQ(candidate.address().port(), DISCARD_PORT);
740 } else if (candidate.tcptype() == TCPTYPE_PASSIVE_STR) { 739 } else if (candidate.tcptype() == TCPTYPE_PASSIVE_STR) {
741 EXPECT_NE(candidate.address().port(), DISCARD_PORT); 740 EXPECT_NE(candidate.address().port(), DISCARD_PORT);
742 } else { 741 } else {
743 FAIL() << "Unknown tcptype: " << candidate.tcptype(); 742 FAIL() << "Unknown tcptype: " << candidate.tcptype();
744 } 743 }
745 } 744 }
746 } 745 }
747 } 746 }
748 747
749 void ResumeCandidates(int endpoint) { 748 void ResumeCandidates(int endpoint) {
750 Endpoint* ed = GetEndpoint(endpoint); 749 Endpoint* ed = GetEndpoint(endpoint);
751 for (auto& candidate : ed->saved_candidates_) { 750 for (auto& candidate : ed->saved_candidates_) {
752 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, candidate.release()); 751 main_.Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, candidate.release());
753 } 752 }
754 ed->saved_candidates_.clear(); 753 ed->saved_candidates_.clear();
755 ed->save_candidates_ = false; 754 ed->save_candidates_ = false;
756 } 755 }
757 756
758 void OnMessage(rtc::Message* msg) { 757 void OnMessage(rtc::Message* msg) {
759 switch (msg->message_id) { 758 switch (msg->message_id) {
760 case MSG_ADD_CANDIDATES: { 759 case MSG_ADD_CANDIDATES: {
761 std::unique_ptr<CandidatesData> data( 760 std::unique_ptr<CandidatesData> data(
762 static_cast<CandidatesData*>(msg->pdata)); 761 static_cast<CandidatesData*>(msg->pdata));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 867
869 void ConnectSignalNominated(Connection* conn) { 868 void ConnectSignalNominated(Connection* conn) {
870 conn->SignalNominated.connect(this, 869 conn->SignalNominated.connect(this,
871 &P2PTransportChannelTestBase::OnNominated); 870 &P2PTransportChannelTestBase::OnNominated);
872 } 871 }
873 872
874 void OnNominated(Connection* conn) { nominated_ = true; } 873 void OnNominated(Connection* conn) { nominated_ = true; }
875 bool nominated() { return nominated_; } 874 bool nominated() { return nominated_; }
876 875
877 private: 876 private:
878 rtc::Thread* main_;
879 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 877 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
880 std::unique_ptr<rtc::VirtualSocketServer> vss_; 878 std::unique_ptr<rtc::VirtualSocketServer> vss_;
881 std::unique_ptr<rtc::NATSocketServer> nss_; 879 std::unique_ptr<rtc::NATSocketServer> nss_;
882 std::unique_ptr<rtc::FirewallSocketServer> ss_; 880 std::unique_ptr<rtc::FirewallSocketServer> ss_;
883 rtc::SocketServerScope ss_scope_; 881 rtc::AutoSocketServerThread main_;
884 std::unique_ptr<TestStunServer> stun_server_; 882 std::unique_ptr<TestStunServer> stun_server_;
885 TestTurnServer turn_server_; 883 TestTurnServer turn_server_;
886 rtc::SocksProxyServer socks_server1_; 884 rtc::SocksProxyServer socks_server1_;
887 rtc::SocksProxyServer socks_server2_; 885 rtc::SocksProxyServer socks_server2_;
888 Endpoint ep1_; 886 Endpoint ep1_;
889 Endpoint ep2_; 887 Endpoint ep2_;
890 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE; 888 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE;
891 bool force_relay_; 889 bool force_relay_;
892 int selected_candidate_pair_switches_ = 0; 890 int selected_candidate_pair_switches_ = 0;
893 891
(...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2927 } 2925 }
2928 2926
2929 // A collection of tests which tests a single P2PTransportChannel by sending 2927 // A collection of tests which tests a single P2PTransportChannel by sending
2930 // pings. 2928 // pings.
2931 class P2PTransportChannelPingTest : public testing::Test, 2929 class P2PTransportChannelPingTest : public testing::Test,
2932 public sigslot::has_slots<> { 2930 public sigslot::has_slots<> {
2933 public: 2931 public:
2934 P2PTransportChannelPingTest() 2932 P2PTransportChannelPingTest()
2935 : pss_(new rtc::PhysicalSocketServer), 2933 : pss_(new rtc::PhysicalSocketServer),
2936 vss_(new rtc::VirtualSocketServer(pss_.get())), 2934 vss_(new rtc::VirtualSocketServer(pss_.get())),
2937 ss_scope_(vss_.get()) {} 2935 thread_(vss_.get()) {}
2938 2936
2939 protected: 2937 protected:
2940 void PrepareChannel(P2PTransportChannel* ch) { 2938 void PrepareChannel(P2PTransportChannel* ch) {
2941 ch->SetIceRole(ICEROLE_CONTROLLING); 2939 ch->SetIceRole(ICEROLE_CONTROLLING);
2942 ch->SetIceParameters(kIceParams[0]); 2940 ch->SetIceParameters(kIceParams[0]);
2943 ch->SetRemoteIceParameters(kIceParams[1]); 2941 ch->SetRemoteIceParameters(kIceParams[1]);
2944 ch->SignalSelectedCandidatePairChanged.connect( 2942 ch->SignalSelectedCandidatePairChanged.connect(
2945 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); 2943 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged);
2946 ch->SignalReadyToSend.connect(this, 2944 ch->SignalReadyToSend.connect(this,
2947 &P2PTransportChannelPingTest::OnReadyToSend); 2945 &P2PTransportChannelPingTest::OnReadyToSend);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3077 IceTransportState channel_state() { return channel_state_; } 3075 IceTransportState channel_state() { return channel_state_; }
3078 int reset_selected_candidate_pair_switches() { 3076 int reset_selected_candidate_pair_switches() {
3079 int switches = selected_candidate_pair_switches_; 3077 int switches = selected_candidate_pair_switches_;
3080 selected_candidate_pair_switches_ = 0; 3078 selected_candidate_pair_switches_ = 0;
3081 return switches; 3079 return switches;
3082 } 3080 }
3083 3081
3084 private: 3082 private:
3085 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 3083 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
3086 std::unique_ptr<rtc::VirtualSocketServer> vss_; 3084 std::unique_ptr<rtc::VirtualSocketServer> vss_;
3087 rtc::SocketServerScope ss_scope_; 3085 rtc::AutoSocketServerThread thread_;
3088 CandidatePairInterface* last_selected_candidate_pair_ = nullptr; 3086 CandidatePairInterface* last_selected_candidate_pair_ = nullptr;
3089 int selected_candidate_pair_switches_ = 0; 3087 int selected_candidate_pair_switches_ = 0;
3090 int last_sent_packet_id_ = -1; 3088 int last_sent_packet_id_ = -1;
3091 bool channel_ready_to_send_ = false; 3089 bool channel_ready_to_send_ = false;
3092 IceTransportState channel_state_ = IceTransportState::STATE_INIT; 3090 IceTransportState channel_state_ = IceTransportState::STATE_INIT;
3093 }; 3091 };
3094 3092
3095 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { 3093 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
3096 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3094 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3097 P2PTransportChannel ch("trigger checks", 1, &pa); 3095 P2PTransportChannel ch("trigger checks", 1, &pa);
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after
4395 4393
4396 // TCP Relay/Relay is the next. 4394 // TCP Relay/Relay is the next.
4397 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4395 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
4398 TCP_PROTOCOL_NAME); 4396 TCP_PROTOCOL_NAME);
4399 4397
4400 // Finally, Local/Relay will be pinged. 4398 // Finally, Local/Relay will be pinged.
4401 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4399 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4402 } 4400 }
4403 4401
4404 } // namespace cricket { 4402 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/asyncstuntcpsocket_unittest.cc ('k') | webrtc/p2p/base/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698