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

Unified Diff: webrtc/base/virtualsocket_unittest.cc

Issue 1274013002: Bug 4865: Enable connectivity when the remote peer is on public internet. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 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 | « no previous file | webrtc/base/virtualsocketserver.h » ('j') | webrtc/base/virtualsocketserver.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/virtualsocket_unittest.cc
diff --git a/webrtc/base/virtualsocket_unittest.cc b/webrtc/base/virtualsocket_unittest.cc
index e9d57f8f305ac285a0a4fb3a5854877f970c4427..5cb80e8a88e6f4f8d3e7609f95579bbcaa5b91a8 100644
--- a/webrtc/base/virtualsocket_unittest.cc
+++ b/webrtc/base/virtualsocket_unittest.cc
@@ -149,6 +149,49 @@ class VirtualSocketServerTest : public testing::Test {
}
}
+ // Test a client can bind to the any address, and all sent packets will have
+ // the default route as the source address. Also, it can receive packets sent
+ // to the default route.
+ void TestDefaultRoute(const IPAddress& default_route) {
+ ss_->SetDefaultRoute(default_route);
+
+ // Create client1 bound to the any address.
+ AsyncSocket* socket =
+ ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM);
+ socket->Bind(EmptySocketAddressWithFamily(default_route.family()));
+ SocketAddress client1_any_addr = socket->GetLocalAddress();
+ EXPECT_TRUE(client1_any_addr.IsAnyIP());
+ TestClient* client1 = new TestClient(new AsyncUDPSocket(socket));
+
+ // Create client2 bound to the default route.
+ AsyncSocket* socket2 =
+ ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM);
+ socket2->Bind(SocketAddress(default_route, 0));
+ SocketAddress client2_addr = socket2->GetLocalAddress();
+ EXPECT_FALSE(client2_addr.IsAnyIP());
+ TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2));
+
+ // Client1 sends to client2, client2 should see the default route as
+ // client1's address.
+ SocketAddress client1_addr;
+ EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr));
+ EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr));
+ EXPECT_EQ(client1_addr,
+ SocketAddress(default_route, client1_any_addr.port()));
+
+ // Client2 can send back to client1's default route address.
+ EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr));
+ EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr));
+
+ // Client2 also can send to client1's any address. This is to document the
+ // current behavior. In reality, this should fail as the any address
+ // shouldn't be the destination.
pthatcher1 2015/08/07 21:28:19 Can we just remove the current behavior, or do we
guoweis_webrtc 2015/08/13 14:17:28 Done.
+ SocketAddress client2_addr_new;
+ EXPECT_EQ(3, client2->SendTo("foo", 3, client1_any_addr));
+ EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr_new));
+ EXPECT_EQ(client2_addr_new, client2_addr);
+ }
+
void BasicTest(const SocketAddress& initial_addr) {
AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(),
SOCK_DGRAM);
@@ -791,6 +834,18 @@ TEST_F(VirtualSocketServerTest, basic_v6) {
BasicTest(ipv6_test_addr);
}
+TEST_F(VirtualSocketServerTest, TestDefaultRoute_v4) {
+ IPAddress ipv4_default_addr(0x01020304);
+ TestDefaultRoute(ipv4_default_addr);
+}
+
+TEST_F(VirtualSocketServerTest, TestDefaultRoute_v6) {
+ IPAddress ipv6_default_addr;
+ EXPECT_TRUE(
+ IPFromString("2401:fa00:4:1000:be30:5bff:fee5:c3", &ipv6_default_addr));
+ TestDefaultRoute(ipv6_default_addr);
+}
+
TEST_F(VirtualSocketServerTest, connect_v4) {
ConnectTest(kIPv4AnyAddress);
}
« no previous file with comments | « no previous file | webrtc/base/virtualsocketserver.h » ('j') | webrtc/base/virtualsocketserver.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698