Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / renderer / p2p / ipc_network_manager_unittest.cc
blobc5c2ff37af80dc479a28b040cab1c9c56c720068
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 "testing/gtest/include/gtest/gtest.h"
13 namespace content {
15 namespace {
17 class MockP2PSocketDispatcher : public NetworkListManager {
18 public:
19 void AddNetworkListObserver(
20 NetworkListObserver* network_list_observer) override {}
22 void RemoveNetworkListObserver(
23 NetworkListObserver* network_list_observer) override {}
25 ~MockP2PSocketDispatcher() override {}
28 } // namespace
30 // 2 IPv6 addresses with only last digit different.
31 static const char kIPv6PublicAddrString1[] =
32 "2401:fa00:4:1000:be30:5bff:fee5:c3";
33 static const char kIPv6PublicAddrString2[] =
34 "2401:fa00:4:1000:be30:5bff:fee5:c4";
36 class IpcNetworkManagerTest : public testing::Test {
37 public:
38 IpcNetworkManagerTest()
39 : network_list_manager_(new MockP2PSocketDispatcher()),
40 network_manager_(new IpcNetworkManager(network_list_manager_.get())) {}
42 protected:
43 scoped_ptr<MockP2PSocketDispatcher> network_list_manager_;
44 scoped_ptr<IpcNetworkManager> network_manager_;
47 // Test overall logic of IpcNetworkManager on OnNetworkListChanged
48 // that it should group addresses with the same network key under
49 // single Network class. This also tests the logic inside
50 // IpcNetworkManager in addition to MergeNetworkList.
51 // TODO(guoweis): disable this test case for now until fix for webrtc
52 // issue 19249005 integrated into chromium
53 TEST_F(IpcNetworkManagerTest, DISABLED_TestMergeNetworkList) {
54 net::NetworkInterfaceList list;
55 net::IPAddressNumber ip_number;
56 std::vector<rtc::Network*> networks;
57 rtc::IPAddress ip_address;
59 // Add 2 networks with the same prefix and prefix length.
60 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString1, &ip_number));
61 list.push_back(
62 net::NetworkInterface("em1",
63 "em1",
65 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
66 ip_number,
67 64,
68 net::IP_ADDRESS_ATTRIBUTE_NONE));
70 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString2, &ip_number));
71 list.push_back(
72 net::NetworkInterface("em1",
73 "em1",
75 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
76 ip_number,
77 64,
78 net::IP_ADDRESS_ATTRIBUTE_NONE));
80 network_manager_->OnNetworkListChanged(list);
81 network_manager_->GetNetworks(&networks);
82 EXPECT_EQ(1uL, networks.size());
83 EXPECT_EQ(2uL, networks[0]->GetIPs().size());
85 // Add another network with different prefix length, should result in
86 // a different network.
87 networks.clear();
88 list.push_back(
89 net::NetworkInterface("em1",
90 "em1",
92 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
93 ip_number,
94 48,
95 net::IP_ADDRESS_ATTRIBUTE_NONE));
97 network_manager_->OnNetworkListChanged(list);
99 network_manager_->GetNetworks(&networks);
101 // Verify we have 2 networks now.
102 EXPECT_EQ(2uL, networks.size());
103 // Verify the network with prefix length of 64 has 2 IP addresses.
104 EXPECT_EQ(64, networks[1]->prefix_length());
105 EXPECT_EQ(2uL, networks[1]->GetIPs().size());
106 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString1, &ip_address));
107 EXPECT_EQ(networks[1]->GetIPs()[0], ip_address);
108 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address));
109 EXPECT_EQ(networks[1]->GetIPs()[1], ip_address);
110 // Verify the network with prefix length of 48 has 2 IP addresses.
111 EXPECT_EQ(48, networks[0]->prefix_length());
112 EXPECT_EQ(1uL, networks[0]->GetIPs().size());
113 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address));
114 EXPECT_EQ(networks[0]->GetIPs()[0], ip_address);
117 } // namespace content