OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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. | |
4 | |
5 #include "content/renderer/p2p/ipc_network_manager.h" | |
6 #include "content/renderer/p2p/mock_socket_dispatcher.h" | |
7 #include "net/base/net_util.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace content { | |
11 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.
| |
12 | |
13 // 2 IPv6 addresses with only last digit different. | |
14 static const std::string kIPv6PublicAddrString1 = | |
15 "2401:fa00:4:1000:be30:5bff:fee5:c3"; | |
16 static const std::string kIPv6PublicAddrString2 = | |
17 "2401:fa00:4:1000:be30:5bff:fee5:c4"; | |
18 | |
19 class IpcNetworkManagerTest : public testing::Test { | |
20 public: | |
21 IpcNetworkManagerTest() { | |
22 socket_dispatcher_ = new MockP2PSocketDispatcher(); | |
23 mgr_ = new IpcNetworkManager(socket_dispatcher_); | |
24 } | |
25 | |
26 virtual ~IpcNetworkManagerTest() { | |
27 delete mgr_; | |
28 delete socket_dispatcher_; | |
29 } | |
30 | |
31 IpcNetworkManager* mgr_; | |
Sergey Ulanov
2014/09/10 18:05:32
protected:?
guoweis_webrtc
2014/09/10 19:56:32
Done.
| |
32 MockP2PSocketDispatcher* socket_dispatcher_; | |
33 | |
34 }; | |
35 | |
36 // Test overall logic of IpcNetworkManager on OnNetworkListChanged | |
37 // that it should group addresses with the same network key under | |
38 // single Network class. This also tests the logic inside | |
39 // IpcNetworkManager in addition to MergeNetworkList. | |
40 // TODO(guoweis): disable this test case for now until fix for webrtc | |
41 // issue 19249005 integrated into chromium | |
42 TEST_F(IpcNetworkManagerTest, DISABLED_TestMergeNetworkList) { | |
43 net::NetworkInterfaceList list; | |
44 net::IPAddressNumber ip_number; | |
45 std::vector<rtc::Network*> networks; | |
46 rtc::IPAddress ip_address; | |
47 | |
48 // Add 2 networks with the same prefix and prefix length. | |
49 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString1, &ip_number)); | |
50 list.push_back( | |
51 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.
| |
52 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, | |
53 ip_number, 64)); | |
54 | |
55 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString2, &ip_number)); | |
56 list.push_back( | |
57 net::NetworkInterface("em1", "em1", 0, | |
58 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, | |
59 ip_number, 64)); | |
60 | |
61 mgr_->OnNetworkListChanged(list); | |
62 mgr_->GetNetworks(&networks); | |
63 EXPECT_EQ(1uL, networks.size()); | |
64 EXPECT_EQ(2uL, networks[0]->GetIPs().size()); | |
65 | |
66 // Add another network with different prefix length, should result in | |
67 // a different network. | |
68 networks.clear(); | |
69 list.push_back( | |
70 net::NetworkInterface("em1", "em1", 0, | |
71 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, | |
72 ip_number, 48)); | |
73 | |
74 mgr_->OnNetworkListChanged(list); | |
75 | |
76 mgr_->GetNetworks(&networks); | |
77 | |
78 // Verify we have 2 networks now. | |
79 EXPECT_EQ(2uL, networks.size()); | |
80 // Verify the network with prefix length of 64 has 2 IP addresses. | |
81 EXPECT_EQ(64, networks[1]->prefix_length()); | |
82 EXPECT_EQ(2uL, networks[1]->GetIPs().size()); | |
83 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString1, &ip_address)); | |
84 EXPECT_EQ(networks[1]->GetIPs()[0], ip_address); | |
85 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address)); | |
86 EXPECT_EQ(networks[1]->GetIPs()[1], ip_address); | |
87 // Verify the network with prefix length of 48 has 2 IP addresses. | |
88 EXPECT_EQ(48, networks[0]->prefix_length()); | |
89 EXPECT_EQ(1uL, networks[0]->GetIPs().size()); | |
90 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address)); | |
91 EXPECT_EQ(networks[0]->GetIPs()[0], ip_address); | |
92 } | |
93 | |
94 } // namespace | |
95 } // namespace content | |
OLD | NEW |