| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "content/renderer/p2p/ipc_network_manager.h" | 6 #include "content/renderer/p2p/ipc_network_manager.h" |
| 7 #include "content/renderer/p2p/network_list_manager.h" | 7 #include "content/renderer/p2p/network_list_manager.h" |
| 8 #include "net/base/ip_address_number.h" | 8 #include "net/base/ip_address.h" |
| 9 #include "net/base/network_change_notifier.h" | 9 #include "net/base/network_change_notifier.h" |
| 10 #include "net/base/network_interfaces.h" | 10 #include "net/base/network_interfaces.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 class MockP2PSocketDispatcher : public NetworkListManager { | 17 class MockP2PSocketDispatcher : public NetworkListManager { |
| 18 public: | 18 public: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // Test overall logic of IpcNetworkManager on OnNetworkListChanged | 48 // Test overall logic of IpcNetworkManager on OnNetworkListChanged |
| 49 // that it should group addresses with the same network key under | 49 // that it should group addresses with the same network key under |
| 50 // single Network class. This also tests the logic inside | 50 // single Network class. This also tests the logic inside |
| 51 // IpcNetworkManager in addition to MergeNetworkList. | 51 // IpcNetworkManager in addition to MergeNetworkList. |
| 52 // TODO(guoweis): disable this test case for now until fix for webrtc | 52 // TODO(guoweis): disable this test case for now until fix for webrtc |
| 53 // issue 19249005 integrated into chromium | 53 // issue 19249005 integrated into chromium |
| 54 TEST_F(IpcNetworkManagerTest, TestMergeNetworkList) { | 54 TEST_F(IpcNetworkManagerTest, TestMergeNetworkList) { |
| 55 net::NetworkInterfaceList list; | 55 net::NetworkInterfaceList list; |
| 56 net::IPAddressNumber ip_number; | 56 net::IPAddress ip; |
| 57 std::vector<rtc::Network*> networks; | 57 std::vector<rtc::Network*> networks; |
| 58 rtc::IPAddress ip_address; | 58 rtc::IPAddress ip_address; |
| 59 | 59 |
| 60 // Add 2 networks with the same prefix and prefix length. | 60 // Add 2 networks with the same prefix and prefix length. |
| 61 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString1, &ip_number)); | 61 EXPECT_TRUE(ip.AssignFromIPLiteral(kIPv6PublicAddrString1)); |
| 62 list.push_back( | 62 list.push_back(net::NetworkInterface( |
| 63 net::NetworkInterface("em1", | 63 "em1", "em1", 0, net::NetworkChangeNotifier::CONNECTION_UNKNOWN, ip, 64, |
| 64 "em1", | 64 net::IP_ADDRESS_ATTRIBUTE_NONE)); |
| 65 0, | |
| 66 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, | |
| 67 ip_number, | |
| 68 64, | |
| 69 net::IP_ADDRESS_ATTRIBUTE_NONE)); | |
| 70 | 65 |
| 71 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString2, &ip_number)); | 66 EXPECT_TRUE(ip.AssignFromIPLiteral(kIPv6PublicAddrString2)); |
| 72 list.push_back( | 67 list.push_back(net::NetworkInterface( |
| 73 net::NetworkInterface("em1", | 68 "em1", "em1", 0, net::NetworkChangeNotifier::CONNECTION_UNKNOWN, ip, 64, |
| 74 "em1", | 69 net::IP_ADDRESS_ATTRIBUTE_NONE)); |
| 75 0, | |
| 76 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, | |
| 77 ip_number, | |
| 78 64, | |
| 79 net::IP_ADDRESS_ATTRIBUTE_NONE)); | |
| 80 | 70 |
| 81 network_manager_->OnNetworkListChanged(list, net::IPAddressNumber(), | 71 network_manager_->OnNetworkListChanged(list, net::IPAddress(), |
| 82 net::IPAddressNumber()); | 72 net::IPAddress()); |
| 83 network_manager_->GetNetworks(&networks); | 73 network_manager_->GetNetworks(&networks); |
| 84 EXPECT_EQ(1uL, networks.size()); | 74 EXPECT_EQ(1uL, networks.size()); |
| 85 EXPECT_EQ(2uL, networks[0]->GetIPs().size()); | 75 EXPECT_EQ(2uL, networks[0]->GetIPs().size()); |
| 86 | 76 |
| 87 // Add another network with different prefix length, should result in | 77 // Add another network with different prefix length, should result in |
| 88 // a different network. | 78 // a different network. |
| 89 networks.clear(); | 79 networks.clear(); |
| 90 list.push_back( | 80 list.push_back(net::NetworkInterface( |
| 91 net::NetworkInterface("em1", | 81 "em1", "em1", 0, net::NetworkChangeNotifier::CONNECTION_UNKNOWN, ip, 48, |
| 92 "em1", | 82 net::IP_ADDRESS_ATTRIBUTE_NONE)); |
| 93 0, | |
| 94 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, | |
| 95 ip_number, | |
| 96 48, | |
| 97 net::IP_ADDRESS_ATTRIBUTE_NONE)); | |
| 98 | 83 |
| 99 // Push an unknown address as the default address. | 84 // Push an unknown address as the default address. |
| 100 EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv4MappedAddrString, &ip_number)); | 85 EXPECT_TRUE(ip.AssignFromIPLiteral(kIPv4MappedAddrString)); |
| 101 network_manager_->OnNetworkListChanged(list, net::IPAddressNumber(), | 86 network_manager_->OnNetworkListChanged(list, net::IPAddress(), ip); |
| 102 ip_number); | |
| 103 | 87 |
| 104 // The unknown default address should be ignored. | 88 // The unknown default address should be ignored. |
| 105 EXPECT_FALSE(network_manager_->GetDefaultLocalAddress(AF_INET6, &ip_address)); | 89 EXPECT_FALSE(network_manager_->GetDefaultLocalAddress(AF_INET6, &ip_address)); |
| 106 | 90 |
| 107 network_manager_->GetNetworks(&networks); | 91 network_manager_->GetNetworks(&networks); |
| 108 | 92 |
| 109 // Verify we have 2 networks now. | 93 // Verify we have 2 networks now. |
| 110 EXPECT_EQ(2uL, networks.size()); | 94 EXPECT_EQ(2uL, networks.size()); |
| 111 // Verify the network with prefix length of 64 has 2 IP addresses. | 95 // Verify the network with prefix length of 64 has 2 IP addresses. |
| 112 EXPECT_EQ(64, networks[1]->prefix_length()); | 96 EXPECT_EQ(64, networks[1]->prefix_length()); |
| 113 EXPECT_EQ(2uL, networks[1]->GetIPs().size()); | 97 EXPECT_EQ(2uL, networks[1]->GetIPs().size()); |
| 114 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString1, &ip_address)); | 98 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString1, &ip_address)); |
| 115 EXPECT_EQ(networks[1]->GetIPs()[0], ip_address); | 99 EXPECT_EQ(networks[1]->GetIPs()[0], ip_address); |
| 116 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address)); | 100 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address)); |
| 117 EXPECT_EQ(networks[1]->GetIPs()[1], ip_address); | 101 EXPECT_EQ(networks[1]->GetIPs()[1], ip_address); |
| 118 // Verify the network with prefix length of 48 has 2 IP addresses. | 102 // Verify the network with prefix length of 48 has 2 IP addresses. |
| 119 EXPECT_EQ(48, networks[0]->prefix_length()); | 103 EXPECT_EQ(48, networks[0]->prefix_length()); |
| 120 EXPECT_EQ(1uL, networks[0]->GetIPs().size()); | 104 EXPECT_EQ(1uL, networks[0]->GetIPs().size()); |
| 121 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address)); | 105 EXPECT_TRUE(rtc::IPFromString(kIPv6PublicAddrString2, &ip_address)); |
| 122 EXPECT_EQ(networks[0]->GetIPs()[0], ip_address); | 106 EXPECT_EQ(networks[0]->GetIPs()[0], ip_address); |
| 123 } | 107 } |
| 124 | 108 |
| 125 } // namespace content | 109 } // namespace content |
| OLD | NEW |