| Index: webrtc/base/virtualsocket_unittest.cc
|
| diff --git a/webrtc/base/virtualsocket_unittest.cc b/webrtc/base/virtualsocket_unittest.cc
|
| index e9d57f8f305ac285a0a4fb3a5854877f970c4427..a656691b50f7a46cbfcf868dfd7dbe65c6437d68 100644
|
| --- a/webrtc/base/virtualsocket_unittest.cc
|
| +++ b/webrtc/base/virtualsocket_unittest.cc
|
| @@ -149,6 +149,41 @@ 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));
|
| + }
|
| +
|
| void BasicTest(const SocketAddress& initial_addr) {
|
| AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(),
|
| SOCK_DGRAM);
|
| @@ -791,6 +826,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);
|
| }
|
|
|