Chromium Code Reviews| Index: content/renderer/p2p/ipc_network_manager_unittest.cc |
| diff --git a/content/renderer/p2p/ipc_network_manager_unittest.cc b/content/renderer/p2p/ipc_network_manager_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f165a9256d78324c274a7b79c4fb368896d94aa2 |
| --- /dev/null |
| +++ b/content/renderer/p2p/ipc_network_manager_unittest.cc |
| @@ -0,0 +1,95 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/p2p/ipc_network_manager.h" |
| +#include "content/renderer/p2p/mock_socket_dispatcher.h" |
| +#include "net/base/net_util.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace content { |
| +namespace { |
|
Sergey Ulanov
2014/09/10 18:05:32
nit: tests don't need to be in the anonymous names
guoweis_webrtc
2014/09/10 19:56:32
Done.
|
| + |
| +// 2 IPv6 addresses with only last digit different. |
| +static const std::string kIPv6PublicAddrString1 = |
| + "2401:fa00:4:1000:be30:5bff:fee5:c3"; |
| +static const std::string kIPv6PublicAddrString2 = |
| + "2401:fa00:4:1000:be30:5bff:fee5:c4"; |
| + |
| +class IpcNetworkManagerTest : public testing::Test { |
| + public: |
| + IpcNetworkManagerTest() { |
| + socket_dispatcher_ = new MockP2PSocketDispatcher(); |
| + mgr_ = new IpcNetworkManager(socket_dispatcher_); |
| + } |
| + |
| + virtual ~IpcNetworkManagerTest() { |
| + delete mgr_; |
| + delete socket_dispatcher_; |
| + } |
| + |
| + IpcNetworkManager* mgr_; |
|
Sergey Ulanov
2014/09/10 18:05:32
protected:?
guoweis_webrtc
2014/09/10 19:56:32
Done.
|
| + MockP2PSocketDispatcher* socket_dispatcher_; |
| + |
| +}; |
| + |
| +// Test overall logic of IpcNetworkManager on OnNetworkListChanged |
| +// that it should group addresses with the same network key under |
| +// single Network class. This also tests the logic inside |
| +// IpcNetworkManager in addition to MergeNetworkList. |
| +// TODO(guoweis): disable this test case for now until fix for webrtc |
| +// issue 19249005 integrated into chromium |
| +TEST_F(IpcNetworkManagerTest, DISABLED_TestMergeNetworkList) { |
| + net::NetworkInterfaceList list; |
| + net::IPAddressNumber ip_number; |
| + std::vector<rtc::Network*> networks; |
| + rtc::IPAddress ip_address; |
| + |
| + // Add 2 networks with the same prefix and prefix length. |
| + EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString1, &ip_number)); |
| + list.push_back( |
| + net::NetworkInterface("em1", "em1", 0, |
|
Sergey Ulanov
2014/09/10 18:05:32
nit: 4 space indentation relative to the previous
guoweis_webrtc
2014/09/10 19:56:32
Done.
|
| + net::NetworkChangeNotifier::CONNECTION_UNKNOWN, |
| + ip_number, 64)); |
| + |
| + EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString2, &ip_number)); |
| + list.push_back( |
| + net::NetworkInterface("em1", "em1", 0, |
| + net::NetworkChangeNotifier::CONNECTION_UNKNOWN, |
| + ip_number, 64)); |
| + |
| + mgr_->OnNetworkListChanged(list); |
| + mgr_->GetNetworks(&networks); |
| + EXPECT_EQ(1uL, networks.size()); |
| + EXPECT_EQ(2uL, networks[0]->GetIPs().size()); |
| + |
| + // Add another network with different prefix length, should result in |
| + // a different network. |
| + networks.clear(); |
| + list.push_back( |
| + net::NetworkInterface("em1", "em1", 0, |
| + net::NetworkChangeNotifier::CONNECTION_UNKNOWN, |
| + ip_number, 48)); |
| + |
| + mgr_->OnNetworkListChanged(list); |
| + |
| + mgr_->GetNetworks(&networks); |
| + |
| + // Verify we have 2 networks now. |
| + EXPECT_EQ(2uL, networks.size()); |
| + // Verify the network with prefix length of 64 has 2 IP addresses. |
| + EXPECT_EQ(64, networks[1]->prefix_length()); |
| + EXPECT_EQ(2uL, networks[1]->GetIPs().size()); |
| + EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString1, &ip_address)); |
| + EXPECT_EQ(networks[1]->GetIPs()[0], ip_address); |
| + EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address)); |
| + EXPECT_EQ(networks[1]->GetIPs()[1], ip_address); |
| + // Verify the network with prefix length of 48 has 2 IP addresses. |
| + EXPECT_EQ(48, networks[0]->prefix_length()); |
| + EXPECT_EQ(1uL, networks[0]->GetIPs().size()); |
| + EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address)); |
| + EXPECT_EQ(networks[0]->GetIPs()[0], ip_address); |
| +} |
| + |
| +} // namespace |
| +} // namespace content |