Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / content / renderer / p2p / ipc_network_manager_unittest.cc
bloba833654b29057acc6d7c8c4916e6a3b1c4f05c43
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/ip_address_number.h"
9 #include "net/base/net_util.h"
10 #include "net/base/network_change_notifier.h"
11 #include "net/base/network_interfaces.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace content {
16 namespace {
18 class MockP2PSocketDispatcher : public NetworkListManager {
19 public:
20 void AddNetworkListObserver(
21 NetworkListObserver* network_list_observer) override {}
23 void RemoveNetworkListObserver(
24 NetworkListObserver* network_list_observer) override {}
26 ~MockP2PSocketDispatcher() override {}
29 } // namespace
31 // 2 IPv6 addresses with only last digit different.
32 static const char kIPv6PublicAddrString1[] =
33 "2401:fa00:4:1000:be30:5bff:fee5:c3";
34 static const char kIPv6PublicAddrString2[] =
35 "2401:fa00:4:1000:be30:5bff:fee5:c4";
37 class IpcNetworkManagerTest : public testing::Test {
38 public:
39 IpcNetworkManagerTest()
40 : network_list_manager_(new MockP2PSocketDispatcher()),
41 network_manager_(new IpcNetworkManager(network_list_manager_.get())) {}
43 protected:
44 scoped_ptr<MockP2PSocketDispatcher> network_list_manager_;
45 scoped_ptr<IpcNetworkManager> network_manager_;
48 // Test overall logic of IpcNetworkManager on OnNetworkListChanged
49 // that it should group addresses with the same network key under
50 // single Network class. This also tests the logic inside
51 // IpcNetworkManager in addition to MergeNetworkList.
52 // TODO(guoweis): disable this test case for now until fix for webrtc
53 // issue 19249005 integrated into chromium
54 TEST_F(IpcNetworkManagerTest, DISABLED_TestMergeNetworkList) {
55 net::NetworkInterfaceList list;
56 net::IPAddressNumber ip_number;
57 std::vector<rtc::Network*> networks;
58 rtc::IPAddress ip_address;
60 // Add 2 networks with the same prefix and prefix length.
61 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString1, &ip_number));
62 list.push_back(
63 net::NetworkInterface("em1",
64 "em1",
66 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
67 ip_number,
68 64,
69 net::IP_ADDRESS_ATTRIBUTE_NONE));
71 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString2, &ip_number));
72 list.push_back(
73 net::NetworkInterface("em1",
74 "em1",
76 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
77 ip_number,
78 64,
79 net::IP_ADDRESS_ATTRIBUTE_NONE));
81 network_manager_->OnNetworkListChanged(list);
82 network_manager_->GetNetworks(&networks);
83 EXPECT_EQ(1uL, networks.size());
84 EXPECT_EQ(2uL, networks[0]->GetIPs().size());
86 // Add another network with different prefix length, should result in
87 // a different network.
88 networks.clear();
89 list.push_back(
90 net::NetworkInterface("em1",
91 "em1",
93 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
94 ip_number,
95 48,
96 net::IP_ADDRESS_ATTRIBUTE_NONE));
98 network_manager_->OnNetworkListChanged(list);
100 network_manager_->GetNetworks(&networks);
102 // Verify we have 2 networks now.
103 EXPECT_EQ(2uL, networks.size());
104 // Verify the network with prefix length of 64 has 2 IP addresses.
105 EXPECT_EQ(64, networks[1]->prefix_length());
106 EXPECT_EQ(2uL, networks[1]->GetIPs().size());
107 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString1, &ip_address));
108 EXPECT_EQ(networks[1]->GetIPs()[0], ip_address);
109 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address));
110 EXPECT_EQ(networks[1]->GetIPs()[1], ip_address);
111 // Verify the network with prefix length of 48 has 2 IP addresses.
112 EXPECT_EQ(48, networks[0]->prefix_length());
113 EXPECT_EQ(1uL, networks[0]->GetIPs().size());
114 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address));
115 EXPECT_EQ(networks[0]->GetIPs()[0], ip_address);
118 } // namespace content