Index: webrtc/base/physicalsocketserver_unittest.cc |
diff --git a/webrtc/base/physicalsocketserver_unittest.cc b/webrtc/base/physicalsocketserver_unittest.cc |
index 37d412dc1fcf84e72a5448cbd9446fa8b7ee21dc..d0083bdcfcfc5771b8c1d3268febdf1a3434ff6b 100644 |
--- a/webrtc/base/physicalsocketserver_unittest.cc |
+++ b/webrtc/base/physicalsocketserver_unittest.cc |
@@ -14,6 +14,7 @@ |
#include "webrtc/base/gunit.h" |
#include "webrtc/base/logging.h" |
+#include "webrtc/base/networkmonitor.h" |
#include "webrtc/base/physicalsocketserver.h" |
#include "webrtc/base/socket_unittest.h" |
#include "webrtc/base/testutils.h" |
@@ -85,6 +86,18 @@ class FakePhysicalSocketServer : public PhysicalSocketServer { |
PhysicalSocketTest* test_; |
}; |
+class FakeNetworkBinder : public NetworkBinderInterface { |
+ public: |
+ NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override { |
+ return result_; |
+ } |
+ |
+ void set_result(NetworkBindingResult result) { result_ = result; } |
+ |
+ private: |
+ NetworkBindingResult result_ = NetworkBindingResult::SUCCESS; |
+}; |
+ |
class PhysicalSocketTest : public SocketTest { |
public: |
// Set flag to simluate failures when calling "::accept" on a AsyncSocket. |
@@ -415,6 +428,32 @@ TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6) { |
} |
#endif |
+// Verify that if the socket was unable to be bound to a real network interface |
+// (not loopback), Bind will return an error. |
+TEST_F(PhysicalSocketTest, |
+ BindFailsIfNetworkBinderFailsForNonLoopbackInterface) { |
+ FakeNetworkBinder fake_network_binder; |
+ server_->set_network_binder(&fake_network_binder); |
+ std::unique_ptr<AsyncSocket> socket( |
+ server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); |
+ fake_network_binder.set_result(NetworkBindingResult::FAILURE); |
+ EXPECT_EQ(-1, socket->Bind(SocketAddress("192.168.0.1", 0))); |
+ server_->set_network_binder(nullptr); |
+} |
+ |
+// For a loopback interface, failures to bind to the interface should be |
+// tolerated. |
+TEST_F(PhysicalSocketTest, |
+ BindSucceedsIfNetworkBinderFailsForLoopbackInterface) { |
+ FakeNetworkBinder fake_network_binder; |
+ server_->set_network_binder(&fake_network_binder); |
+ std::unique_ptr<AsyncSocket> socket( |
+ server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); |
+ fake_network_binder.set_result(NetworkBindingResult::FAILURE); |
+ EXPECT_EQ(0, socket->Bind(SocketAddress(kIPv4Loopback, 0))); |
+ server_->set_network_binder(nullptr); |
+} |
+ |
class PosixSignalDeliveryTest : public testing::Test { |
public: |
static void RecordSignal(int signum) { |