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

Unified Diff: webrtc/base/physicalsocketserver_unittest.cc

Issue 2646863005: Fixing logic for using android_setsocknetwork() with bind(). (Closed)
Patch Set: Fixing tests for loopback IP change. Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/physicalsocketserver.cc ('k') | webrtc/base/socketserver.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « webrtc/base/physicalsocketserver.cc ('k') | webrtc/base/socketserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698