Always inject PacketSocketFactory in FakePortAllocator

This CL removes the use of the rtc::Thread::socketserver() method
in one place.

Bug: webrtc:13145
Change-Id: I1a1b2501450788263d5280c43e4328ade46f4146
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/263320
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Cr-Commit-Position: refs/heads/main@{#37340}
This commit is contained in:
Byoungchan Lee 2022-06-27 18:05:22 +09:00 committed by WebRTC LUCI CQ
parent fe053426e2
commit d58f526384
17 changed files with 172 additions and 89 deletions

View file

@ -186,6 +186,7 @@ if (rtc_include_tests) {
"../rtc_base",
"../rtc_base:net_helpers",
"../rtc_base:threading",
"../rtc_base/memory:always_valid_pointer",
"../test:scoped_key_value_config",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]

View file

@ -13,12 +13,14 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port_allocator.h"
#include "p2p/base/udp_port.h"
#include "rtc_base/memory/always_valid_pointer.h"
#include "rtc_base/net_helpers.h"
#include "rtc_base/thread.h"
#include "test/scoped_key_value_config.h"
@ -213,23 +215,13 @@ class FakePortAllocatorSession : public PortAllocatorSession {
class FakePortAllocator : public cricket::PortAllocator {
public:
// TODO(bugs.webrtc.org/13145): Require non-null `factory`.
FakePortAllocator(rtc::Thread* network_thread,
rtc::PacketSocketFactory* factory)
: network_thread_(network_thread), factory_(factory) {
if (factory_ == NULL) {
owned_factory_.reset(new rtc::BasicPacketSocketFactory(
network_thread_ ? network_thread_->socketserver() : nullptr));
factory_ = owned_factory_.get();
}
: FakePortAllocator(network_thread, factory, nullptr) {}
if (network_thread_ == nullptr) {
network_thread_ = rtc::Thread::Current();
Initialize();
return;
}
network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { Initialize(); });
}
FakePortAllocator(rtc::Thread* network_thread,
std::unique_ptr<rtc::PacketSocketFactory> factory)
: FakePortAllocator(network_thread, nullptr, std::move(factory)) {}
void SetNetworkIgnoreMask(int network_ignore_mask) override {}
@ -249,8 +241,8 @@ class FakePortAllocator : public cricket::PortAllocator {
absl::string_view ice_ufrag,
absl::string_view ice_pwd) override {
return new FakePortAllocatorSession(
this, network_thread_, factory_, std::string(content_name), component,
std::string(ice_ufrag), std::string(ice_pwd), field_trials_);
this, network_thread_, factory_.get(), std::string(content_name),
component, std::string(ice_ufrag), std::string(ice_pwd), field_trials_);
}
bool initialized() const { return initialized_; }
@ -264,10 +256,22 @@ class FakePortAllocator : public cricket::PortAllocator {
}
private:
FakePortAllocator(rtc::Thread* network_thread,
rtc::PacketSocketFactory* factory,
std::unique_ptr<rtc::PacketSocketFactory> owned_factory)
: network_thread_(network_thread),
factory_(std::move(owned_factory), factory) {
if (network_thread_ == nullptr) {
network_thread_ = rtc::Thread::Current();
Initialize();
return;
}
network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { Initialize(); });
}
webrtc::test::ScopedKeyValueConfig field_trials_;
rtc::Thread* network_thread_;
rtc::PacketSocketFactory* factory_;
std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_;
const webrtc::AlwaysValidPointerNoDefault<rtc::PacketSocketFactory> factory_;
bool mdns_obfuscation_enabled_ = false;
};

View file

@ -32,6 +32,7 @@
#include "rtc_base/firewall_socket_server.h"
#include "rtc_base/gunit.h"
#include "rtc_base/helpers.h"
#include "rtc_base/internal/default_socket_server.h"
#include "rtc_base/logging.h"
#include "rtc_base/mdns_responder_interface.h"
#include "rtc_base/nat_server.h"
@ -3387,7 +3388,10 @@ class P2PTransportChannelPingTest : public ::testing::Test,
public sigslot::has_slots<> {
public:
P2PTransportChannelPingTest()
: vss_(new rtc::VirtualSocketServer()), thread_(vss_.get()) {}
: vss_(std::make_unique<rtc::VirtualSocketServer>()),
packet_socket_factory_(
std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get())),
thread_(vss_.get()) {}
protected:
void PrepareChannel(P2PTransportChannel* ch) {
@ -3585,8 +3589,13 @@ class P2PTransportChannelPingTest : public ::testing::Test,
rtc::SocketServer* ss() const { return vss_.get(); }
rtc::PacketSocketFactory* packet_socket_factory() const {
return packet_socket_factory_.get();
}
private:
std::unique_ptr<rtc::VirtualSocketServer> vss_;
std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_;
rtc::AutoSocketServerThread thread_;
int selected_candidate_pair_switches_ = 0;
int last_sent_packet_id_ = -1;
@ -3597,7 +3606,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
};
TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("trigger checks", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -3621,7 +3630,7 @@ TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
}
TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("ping sufficiently", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -3649,7 +3658,7 @@ TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
int SCHEDULING_RANGE = 200;
int RTT_RANGE = 10;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("TestChannel", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -3740,7 +3749,7 @@ TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) {
rtc::ScopedFakeClock clock;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("TestChannel", 1, &pa);
ch.SetIceRole(ICEROLE_CONTROLLING);
ch.SetIceParameters(kIceParams[0]);
@ -3776,7 +3785,7 @@ TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) {
}
TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("trigger checks", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -3801,7 +3810,7 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
}
TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("Do not ping failed connections", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -3818,7 +3827,7 @@ TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) {
}
TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("state change", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -3839,7 +3848,7 @@ TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
// parameters arrive. If a remote candidate is added with the current ICE
// ufrag, its pwd and generation will be set properly.
TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("add candidate", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -3891,7 +3900,7 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
}
TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("connection resurrection", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -3944,7 +3953,7 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
rtc::ScopedFakeClock clock;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
// Default receiving timeout and checking receiving interval should not be too
@ -3973,7 +3982,7 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
// selected connection changes and SignalReadyToSend will be fired if the new
// selected connection is writable.
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4062,7 +4071,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
TEST_F(P2PTransportChannelPingTest, TestPingOnNomination) {
webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-IceFieldTrials/send_ping_on_nomination_ice_controlled:true/");
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("receiving state change", 1, &pa, &field_trials);
PrepareChannel(&ch);
ch.SetIceConfig(ch.config());
@ -4102,7 +4111,7 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnNomination) {
TEST_F(P2PTransportChannelPingTest, TestPingOnSwitch) {
webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-IceFieldTrials/send_ping_on_switch_ice_controlling:true/");
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("receiving state change", 1, &pa, &field_trials);
PrepareChannel(&ch);
ch.SetIceConfig(ch.config());
@ -4139,7 +4148,7 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSwitch) {
TEST_F(P2PTransportChannelPingTest, TestPingOnSelected) {
webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-IceFieldTrials/send_ping_on_selected_ice_controlling:true/");
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("receiving state change", 1, &pa, &field_trials);
PrepareChannel(&ch);
ch.SetIceConfig(ch.config());
@ -4167,7 +4176,7 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSelected) {
// also sends back a ping response and set the ICE pwd in the remote candidate
// appropriately.
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4244,7 +4253,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
// at which point the controlled side will select that connection as
// the "selected connection".
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4297,7 +4306,7 @@ TEST_F(P2PTransportChannelPingTest,
TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4346,7 +4355,7 @@ TEST_F(P2PTransportChannelPingTest,
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4386,7 +4395,7 @@ TEST_F(P2PTransportChannelPingTest,
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4432,7 +4441,7 @@ TEST_F(P2PTransportChannelPingTest, TestEstimatedDisconnectedTime) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4491,7 +4500,7 @@ TEST_F(P2PTransportChannelPingTest,
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4509,7 +4518,7 @@ TEST_F(P2PTransportChannelPingTest,
TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) {
rtc::ScopedFakeClock clock;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4550,7 +4559,7 @@ TEST_F(P2PTransportChannelPingTest,
// Test that if a new remote candidate has the same address and port with
// an old one, it will be used to create a new connection.
TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("candidate reuse", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -4590,7 +4599,7 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4626,7 +4635,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) {
rtc::ScopedFakeClock clock;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4650,7 +4659,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) {
TEST_F(P2PTransportChannelPingTest, TestGetState) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa);
EXPECT_EQ(webrtc::IceTransportState::kNew, ch.GetIceTransportState());
PrepareChannel(&ch);
@ -4691,7 +4700,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
@ -4741,7 +4750,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
// will all be deleted. We use Prune to simulate write_time_out.
TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
rtc::ScopedFakeClock clock;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.MaybeStartGathering();
@ -4773,7 +4782,7 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
// connection belonging to an old session becomes writable, it won't stop
// the current port allocator session.
TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE));
@ -4806,7 +4815,7 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
// These ports may still have connections that need a correct role, in case that
// the connections on it may still receive stun pings.
TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
// Starts with ICEROLE_CONTROLLING.
PrepareChannel(&ch);
@ -4831,7 +4840,7 @@ TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) {
// pings sent by those connections until they're replaced by newer-generation
// connections.
TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
// Starts with ICEROLE_CONTROLLING.
PrepareChannel(&ch);
@ -4855,7 +4864,7 @@ TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) {
rtc::ScopedFakeClock fake_clock;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
@ -4884,7 +4893,7 @@ TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) {
TEST_F(P2PTransportChannelPingTest, TestMaxOutstandingPingsFieldTrial) {
webrtc::test::ScopedKeyValueConfig field_trials(
"WebRTC-IceFieldTrials/max_outstanding_pings:3/");
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("max", 1, &pa, &field_trials);
ch.SetIceConfig(ch.config());
PrepareChannel(&ch);
@ -5145,8 +5154,11 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) {
// if the channel is not destroyed.
TEST(P2PTransportChannelResolverTest, HostnameCandidateIsResolved) {
ResolverFactoryFixture resolver_fixture;
rtc::AutoThread main_thread;
FakePortAllocator allocator(rtc::Thread::Current(), nullptr);
std::unique_ptr<rtc::SocketServer> socket_server =
rtc::CreateDefaultSocketServer();
rtc::AutoSocketServerThread main_thread(socket_server.get());
rtc::BasicPacketSocketFactory packet_socket_factory(socket_server.get());
FakePortAllocator allocator(rtc::Thread::Current(), &packet_socket_factory);
webrtc::IceTransportInit init;
init.set_port_allocator(&allocator);
init.set_async_dns_resolver_factory(&resolver_fixture);
@ -5984,7 +5996,7 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening0) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa, &field_trials);
PrepareChannel(&ch);
ch.SetIceConfig(ch.config());
@ -6008,7 +6020,7 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa, &field_trials);
PrepareChannel(&ch);
ch.SetIceConfig(ch.config());
@ -6032,7 +6044,7 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningPingReceived) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa, &field_trials);
PrepareChannel(&ch);
ch.SetIceConfig(ch.config());
@ -6059,7 +6071,7 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningBoth) {
rtc::ScopedFakeClock clock;
clock.AdvanceTime(webrtc::TimeDelta::Seconds(1));
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
P2PTransportChannel ch("test channel", 1, &pa, &field_trials);
PrepareChannel(&ch);
ch.SetIceConfig(ch.config());
@ -6078,9 +6090,12 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningBoth) {
}
TEST(P2PTransportChannel, InjectIceController) {
rtc::AutoThread main_thread_;
std::unique_ptr<rtc::SocketServer> socket_server =
rtc::CreateDefaultSocketServer();
rtc::AutoSocketServerThread main_thread(socket_server.get());
rtc::BasicPacketSocketFactory packet_socket_factory(socket_server.get());
MockIceControllerFactory factory;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), &packet_socket_factory);
EXPECT_CALL(factory, RecordIceControllerCreated()).Times(1);
webrtc::IceTransportInit init;
init.set_port_allocator(&pa);
@ -6133,7 +6148,7 @@ class ForgetLearnedStateControllerFactory
TEST_F(P2PTransportChannelPingTest, TestForgetLearnedState) {
ForgetLearnedStateControllerFactory factory;
FakePortAllocator pa(rtc::Thread::Current(), nullptr);
FakePortAllocator pa(rtc::Thread::Current(), packet_socket_factory());
webrtc::IceTransportInit init;
init.set_port_allocator(&pa);
init.set_ice_controller_factory(&factory);

View file

@ -28,10 +28,13 @@ static const char kTurnPassword[] = "test";
class PortAllocatorTest : public ::testing::Test, public sigslot::has_slots<> {
public:
PortAllocatorTest()
: vss_(new rtc::VirtualSocketServer()), main_(vss_.get()) {
allocator_.reset(
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
}
: vss_(std::make_unique<rtc::VirtualSocketServer>()),
main_(vss_.get()),
packet_socket_factory_(
std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get())),
allocator_(std::make_unique<cricket::FakePortAllocator>(
rtc::Thread::Current(),
packet_socket_factory_.get())) {}
protected:
void SetConfigurationWithPoolSize(int candidate_pool_size) {
@ -80,6 +83,7 @@ class PortAllocatorTest : public ::testing::Test, public sigslot::has_slots<> {
std::unique_ptr<rtc::VirtualSocketServer> vss_;
rtc::AutoSocketServerThread main_;
std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_;
std::unique_ptr<cricket::FakePortAllocator> allocator_;
rtc::SocketAddress stun_server_1{"11.11.11.11", 3478};
rtc::SocketAddress stun_server_2{"22.22.22.22", 3478};

View file

@ -48,11 +48,14 @@ class RegatheringControllerTest : public ::testing::Test,
public sigslot::has_slots<> {
public:
RegatheringControllerTest()
: vss_(new rtc::VirtualSocketServer()),
: vss_(std::make_unique<rtc::VirtualSocketServer>()),
thread_(vss_.get()),
ice_transport_(new cricket::MockIceTransport()),
allocator_(
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)) {
ice_transport_(std::make_unique<cricket::MockIceTransport>()),
packet_socket_factory_(
std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get())),
allocator_(std::make_unique<cricket::FakePortAllocator>(
rtc::Thread::Current(),
packet_socket_factory_.get())) {
BasicRegatheringController::Config regathering_config;
regathering_config.regather_on_failed_networks_interval = 0;
regathering_controller_.reset(new BasicRegatheringController(
@ -108,6 +111,7 @@ class RegatheringControllerTest : public ::testing::Test,
rtc::AutoSocketServerThread thread_;
std::unique_ptr<cricket::IceTransportInternal> ice_transport_;
std::unique_ptr<BasicRegatheringController> regathering_controller_;
std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_;
std::unique_ptr<cricket::PortAllocator> allocator_;
std::unique_ptr<cricket::PortAllocatorSession> allocator_session_;
std::map<cricket::IceRegatheringReason, int> count_;

View file

@ -18,13 +18,22 @@
#include "api/scoped_refptr.h"
#include "p2p/base/fake_ice_transport.h"
#include "p2p/base/fake_port_allocator.h"
#include "rtc_base/internal/default_socket_server.h"
#include "test/gtest.h"
namespace webrtc {
class IceTransportTest : public ::testing::Test {
protected:
IceTransportTest()
: socket_server_(rtc::CreateDefaultSocketServer()),
main_thread_(socket_server_.get()) {}
rtc::SocketServer* socket_server() const { return socket_server_.get(); }
private:
rtc::AutoThread main_thread_;
std::unique_ptr<rtc::SocketServer> socket_server_;
rtc::AutoSocketServerThread main_thread_;
};
TEST_F(IceTransportTest, CreateNonSelfDeletingTransport) {
@ -39,7 +48,9 @@ TEST_F(IceTransportTest, CreateNonSelfDeletingTransport) {
TEST_F(IceTransportTest, CreateSelfDeletingTransport) {
std::unique_ptr<cricket::FakePortAllocator> port_allocator(
std::make_unique<cricket::FakePortAllocator>(nullptr, nullptr));
std::make_unique<cricket::FakePortAllocator>(
nullptr,
std::make_unique<rtc::BasicPacketSocketFactory>(socket_server())));
IceTransportInit init;
init.set_port_allocator(port_allocator.get());
auto ice_transport = CreateIceTransport(std::move(init));

View file

@ -94,7 +94,8 @@ class PeerConnectionAdaptationIntegrationTest : public ::testing::Test {
const char* name) {
rtc::scoped_refptr<PeerConnectionTestWrapper> pc_wrapper =
rtc::make_ref_counted<PeerConnectionTestWrapper>(
name, network_thread_.get(), worker_thread_.get());
name, &virtual_socket_server_, network_thread_.get(),
worker_thread_.get());
PeerConnectionInterface::RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan;
EXPECT_TRUE(pc_wrapper->CreatePc(config, CreateBuiltinAudioEncoderFactory(),

View file

@ -96,7 +96,8 @@ class PeerConnectionCryptoBaseTest : public ::testing::Test {
const RTCConfiguration& config,
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_gen) {
auto fake_port_allocator = std::make_unique<cricket::FakePortAllocator>(
rtc::Thread::Current(), nullptr);
rtc::Thread::Current(),
std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get()));
auto observer = std::make_unique<MockPeerConnectionObserver>();
RTCConfiguration modified_config = config;
modified_config.sdp_semantics = sdp_semantics_;

View file

@ -86,9 +86,9 @@ class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>,
RTC_CHECK(network_thread_->Start());
RTC_CHECK(worker_thread_->Start());
caller_ = rtc::make_ref_counted<PeerConnectionTestWrapper>(
"caller", network_thread_.get(), worker_thread_.get());
"caller", &pss_, network_thread_.get(), worker_thread_.get());
callee_ = rtc::make_ref_counted<PeerConnectionTestWrapper>(
"callee", network_thread_.get(), worker_thread_.get());
"callee", &pss_, network_thread_.get(), worker_thread_.get());
webrtc::PeerConnectionInterface::IceServer ice_server;
ice_server.uri = "stun:stun.l.google.com:19302";
config_.servers.push_back(ice_server);

View file

@ -34,6 +34,7 @@
#include "pc/test/fake_video_track_source.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/gunit.h"
#include "rtc_base/internal/default_socket_server.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/time_utils.h"
@ -120,6 +121,12 @@ class MockNetworkManager : public rtc::NetworkManager {
} // namespace
class PeerConnectionFactoryTest : public ::testing::Test {
public:
PeerConnectionFactoryTest()
: socket_server_(rtc::CreateDefaultSocketServer()),
main_thread_(socket_server_.get()) {}
private:
void SetUp() {
#ifdef WEBRTC_ANDROID
webrtc::InitializeAndroidObjects();
@ -138,8 +145,10 @@ class PeerConnectionFactoryTest : public ::testing::Test {
nullptr /* audio_processing */);
ASSERT_TRUE(factory_.get() != NULL);
port_allocator_.reset(
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
packet_socket_factory_.reset(
new rtc::BasicPacketSocketFactory(socket_server_.get()));
port_allocator_.reset(new cricket::FakePortAllocator(
rtc::Thread::Current(), packet_socket_factory_.get()));
raw_port_allocator_ = port_allocator_.get();
}
@ -178,9 +187,11 @@ class PeerConnectionFactoryTest : public ::testing::Test {
EXPECT_GT(codec.clock_rate, 0);
}
rtc::AutoThread main_thread_;
std::unique_ptr<rtc::SocketServer> socket_server_;
rtc::AutoSocketServerThread main_thread_;
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_;
NullPeerConnectionObserver observer_;
std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_;
std::unique_ptr<cricket::FakePortAllocator> port_allocator_;
// Since the PC owns the port allocator after it's been initialized,
// this should only be used when known to be safe.

View file

@ -36,6 +36,7 @@
#include "pc/peer_connection_wrapper.h"
#include "pc/session_description.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/internal/default_socket_server.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/thread.h"
@ -55,7 +56,9 @@ class PeerConnectionHeaderExtensionTest
std::tuple<cricket::MediaType, SdpSemantics>> {
protected:
PeerConnectionHeaderExtensionTest()
: extensions_(
: socket_server_(rtc::CreateDefaultSocketServer()),
main_thread_(socket_server_.get()),
extensions_(
{RtpHeaderExtensionCapability("uri1",
1,
RtpTransceiverDirection::kStopped),
@ -96,7 +99,8 @@ class PeerConnectionHeaderExtensionTest
CreateModularPeerConnectionFactory(std::move(factory_dependencies));
auto fake_port_allocator = std::make_unique<cricket::FakePortAllocator>(
rtc::Thread::Current(), nullptr);
rtc::Thread::Current(),
std::make_unique<rtc::BasicPacketSocketFactory>(socket_server_.get()));
auto observer = std::make_unique<MockPeerConnectionObserver>();
PeerConnectionInterface::RTCConfiguration config;
if (semantics)
@ -111,7 +115,8 @@ class PeerConnectionHeaderExtensionTest
pc_factory, result.MoveValue(), std::move(observer));
}
rtc::AutoThread main_thread_;
std::unique_ptr<rtc::SocketServer> socket_server_;
rtc::AutoSocketServerThread main_thread_;
std::vector<RtpHeaderExtensionCapability> extensions_;
};

View file

@ -1405,6 +1405,11 @@ INSTANTIATE_TEST_SUITE_P(PeerConnectionIceTest,
SdpSemantics::kUnifiedPlan));
class PeerConnectionIceConfigTest : public ::testing::Test {
public:
PeerConnectionIceConfigTest()
: socket_server_(rtc::CreateDefaultSocketServer()),
main_thread_(socket_server_.get()) {}
protected:
void SetUp() override {
pc_factory_ = CreatePeerConnectionFactory(
@ -1415,8 +1420,11 @@ class PeerConnectionIceConfigTest : public ::testing::Test {
nullptr /* audio_processing */);
}
void CreatePeerConnection(const RTCConfiguration& config) {
packet_socket_factory_.reset(
new rtc::BasicPacketSocketFactory(socket_server_.get()));
std::unique_ptr<cricket::FakePortAllocator> port_allocator(
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
new cricket::FakePortAllocator(rtc::Thread::Current(),
packet_socket_factory_.get()));
port_allocator_ = port_allocator.get();
PeerConnectionDependencies pc_dependencies(&observer_);
pc_dependencies.allocator = std::move(port_allocator);
@ -1426,9 +1434,11 @@ class PeerConnectionIceConfigTest : public ::testing::Test {
pc_ = result.MoveValue();
}
rtc::AutoThread main_thread_;
std::unique_ptr<rtc::SocketServer> socket_server_;
rtc::AutoSocketServerThread main_thread_;
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_ = nullptr;
rtc::scoped_refptr<PeerConnectionInterface> pc_ = nullptr;
std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_;
cricket::FakePortAllocator* port_allocator_ = nullptr;
MockPeerConnectionObserver observer_;

View file

@ -728,7 +728,9 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
pc_ = nullptr;
}
std::unique_ptr<cricket::FakePortAllocator> port_allocator(
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
new cricket::FakePortAllocator(
rtc::Thread::Current(),
std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get())));
port_allocator_ = port_allocator.get();
// Create certificate generator unless DTLS constraint is explicitly set to
@ -1250,6 +1252,8 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
}
}
rtc::SocketServer* socket_server() const { return vss_.get(); }
std::unique_ptr<rtc::VirtualSocketServer> vss_;
rtc::AutoSocketServerThread main_;
rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
@ -1358,8 +1362,11 @@ TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
TEST_P(PeerConnectionInterfaceTest,
CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
// Create fake port allocator.
std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory(
new rtc::BasicPacketSocketFactory(socket_server()));
std::unique_ptr<cricket::FakePortAllocator> port_allocator(
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
new cricket::FakePortAllocator(rtc::Thread::Current(),
packet_socket_factory.get()));
cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
// Create RTCConfiguration with some network-related fields relevant to

View file

@ -137,7 +137,8 @@ class PeerConnectionMediaBaseTest : public ::testing::Test {
CreateModularPeerConnectionFactory(std::move(factory_dependencies));
auto fake_port_allocator = std::make_unique<cricket::FakePortAllocator>(
rtc::Thread::Current(), nullptr);
rtc::Thread::Current(),
std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get()));
auto observer = std::make_unique<MockPeerConnectionObserver>();
auto modified_config = config;
modified_config.sdp_semantics = sdp_semantics_;

View file

@ -111,9 +111,11 @@ class RTCStatsIntegrationTest : public ::testing::Test {
RTC_CHECK(worker_thread_->Start());
caller_ = rtc::make_ref_counted<PeerConnectionTestWrapper>(
"caller", network_thread_.get(), worker_thread_.get());
"caller", &virtual_socket_server_, network_thread_.get(),
worker_thread_.get());
callee_ = rtc::make_ref_counted<PeerConnectionTestWrapper>(
"callee", network_thread_.get(), worker_thread_.get());
"callee", &virtual_socket_server_, network_thread_.get(),
worker_thread_.get());
}
void StartCall() {

View file

@ -75,9 +75,11 @@ void PeerConnectionTestWrapper::Connect(PeerConnectionTestWrapper* caller,
PeerConnectionTestWrapper::PeerConnectionTestWrapper(
const std::string& name,
rtc::SocketServer* socket_server,
rtc::Thread* network_thread,
rtc::Thread* worker_thread)
: name_(name),
socket_server_(socket_server),
network_thread_(network_thread),
worker_thread_(worker_thread),
pending_negotiation_(false) {
@ -100,7 +102,9 @@ bool PeerConnectionTestWrapper::CreatePc(
rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory) {
std::unique_ptr<cricket::PortAllocator> port_allocator(
new cricket::FakePortAllocator(network_thread_, nullptr));
new cricket::FakePortAllocator(
network_thread_,
std::make_unique<rtc::BasicPacketSocketFactory>(socket_server_)));
RTC_DCHECK_RUN_ON(&pc_thread_checker_);

View file

@ -40,6 +40,7 @@ class PeerConnectionTestWrapper
PeerConnectionTestWrapper* callee);
PeerConnectionTestWrapper(const std::string& name,
rtc::SocketServer* socket_server,
rtc::Thread* network_thread,
rtc::Thread* worker_thread);
virtual ~PeerConnectionTestWrapper();
@ -116,6 +117,7 @@ class PeerConnectionTestWrapper
bool video);
std::string name_;
rtc::SocketServer* const socket_server_;
rtc::Thread* const network_thread_;
rtc::Thread* const worker_thread_;
webrtc::SequenceChecker pc_thread_checker_;