Replace FINAL and OVERRIDE with their C++11 counterparts in content/renderer
[chromium-blink-merge.git] / content / renderer / p2p / ipc_network_manager_unittest.cc
blob9fdd4567cb472a24a9595f8d81202bf3d4b02bd4
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "content/renderer/p2p/ipc_network_manager.h"
7 #include "content/renderer/p2p/network_list_manager.h"
8 #include "net/base/net_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace content {
13 namespace {
15 class MockP2PSocketDispatcher : public NetworkListManager {
16 public:
17 virtual void AddNetworkListObserver(
18 NetworkListObserver* network_list_observer) override {}
20 virtual void RemoveNetworkListObserver(
21 NetworkListObserver* network_list_observer) override {}
23 virtual ~MockP2PSocketDispatcher() {}
26 } // namespace
28 // 2 IPv6 addresses with only last digit different.
29 static const char kIPv6PublicAddrString1[] =
30 "2401:fa00:4:1000:be30:5bff:fee5:c3";
31 static const char kIPv6PublicAddrString2[] =
32 "2401:fa00:4:1000:be30:5bff:fee5:c4";
34 class IpcNetworkManagerTest : public testing::Test {
35 public:
36 IpcNetworkManagerTest()
37 : network_list_manager_(new MockP2PSocketDispatcher()),
38 network_manager_(new IpcNetworkManager(network_list_manager_.get())) {}
40 protected:
41 scoped_ptr<MockP2PSocketDispatcher> network_list_manager_;
42 scoped_ptr<IpcNetworkManager> network_manager_;
45 // Test overall logic of IpcNetworkManager on OnNetworkListChanged
46 // that it should group addresses with the same network key under
47 // single Network class. This also tests the logic inside
48 // IpcNetworkManager in addition to MergeNetworkList.
49 // TODO(guoweis): disable this test case for now until fix for webrtc
50 // issue 19249005 integrated into chromium
51 TEST_F(IpcNetworkManagerTest, DISABLED_TestMergeNetworkList) {
52 net::NetworkInterfaceList list;
53 net::IPAddressNumber ip_number;
54 std::vector<rtc::Network*> networks;
55 rtc::IPAddress ip_address;
57 // Add 2 networks with the same prefix and prefix length.
58 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString1, &ip_number));
59 list.push_back(
60 net::NetworkInterface("em1",
61 "em1",
63 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
64 ip_number,
65 64,
66 net::IP_ADDRESS_ATTRIBUTE_NONE));
68 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString2, &ip_number));
69 list.push_back(
70 net::NetworkInterface("em1",
71 "em1",
73 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
74 ip_number,
75 64,
76 net::IP_ADDRESS_ATTRIBUTE_NONE));
78 network_manager_->OnNetworkListChanged(list);
79 network_manager_->GetNetworks(&networks);
80 EXPECT_EQ(1uL, networks.size());
81 EXPECT_EQ(2uL, networks[0]->GetIPs().size());
83 // Add another network with different prefix length, should result in
84 // a different network.
85 networks.clear();
86 list.push_back(
87 net::NetworkInterface("em1",
88 "em1",
90 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
91 ip_number,
92 48,
93 net::IP_ADDRESS_ATTRIBUTE_NONE));
95 network_manager_->OnNetworkListChanged(list);
97 network_manager_->GetNetworks(&networks);
99 // Verify we have 2 networks now.
100 EXPECT_EQ(2uL, networks.size());
101 // Verify the network with prefix length of 64 has 2 IP addresses.
102 EXPECT_EQ(64, networks[1]->prefix_length());
103 EXPECT_EQ(2uL, networks[1]->GetIPs().size());
104 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString1, &ip_address));
105 EXPECT_EQ(networks[1]->GetIPs()[0], ip_address);
106 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address));
107 EXPECT_EQ(networks[1]->GetIPs()[1], ip_address);
108 // Verify the network with prefix length of 48 has 2 IP addresses.
109 EXPECT_EQ(48, networks[0]->prefix_length());
110 EXPECT_EQ(1uL, networks[0]->GetIPs().size());
111 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address));
112 EXPECT_EQ(networks[0]->GetIPs()[0], ip_address);
115 } // namespace content