Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: net/base/network_interfaces_unittest.cc

Issue 1984133003: Remove Windows Vista/XP specific code from net/base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removing loading of methods from dll at runtime Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/base/network_interfaces_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "net/base/network_interfaces.h" 5 #include "net/base/network_interfaces.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 #include <string> 8 #include <string>
9 #include <unordered_set> 9 #include <unordered_set>
10 10
(...skipping 18 matching lines...) Expand all
29 #include <netinet/in_var.h> 29 #include <netinet/in_var.h>
30 #endif // !OS_IOS 30 #endif // !OS_IOS
31 #endif // OS_MACOSX 31 #endif // OS_MACOSX
32 #endif // !OS_NACL && !OS_WIN 32 #endif // !OS_NACL && !OS_WIN
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "url/gurl.h" 34 #include "url/gurl.h"
35 35
36 #if defined(OS_WIN) 36 #if defined(OS_WIN)
37 #include <iphlpapi.h> 37 #include <iphlpapi.h>
38 #include <objbase.h> 38 #include <objbase.h>
39 #include "base/win/windows_version.h"
40 #endif // OS_WIN 39 #endif // OS_WIN
41 40
42 #if !defined(OS_MACOSX) && !defined(OS_NACL) && !defined(OS_WIN) 41 #if !defined(OS_MACOSX) && !defined(OS_NACL) && !defined(OS_WIN)
43 #include "net/base/address_tracker_linux.h" 42 #include "net/base/address_tracker_linux.h"
44 #endif // !OS_MACOSX && !OS_NACL && !OS_WIN 43 #endif // !OS_MACOSX && !OS_NACL && !OS_WIN
45 44
46 #if defined(OS_WIN) 45 #if defined(OS_WIN)
47 #include "net/base/network_interfaces_win.h" 46 #include "net/base/network_interfaces_win.h"
48 #else // OS_WIN 47 #else // OS_WIN
49 #include "net/base/network_interfaces_posix.h" 48 #include "net/base/network_interfaces_posix.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 130
132 // Verify that the address is correct. 131 // Verify that the address is correct.
133 EXPECT_TRUE(it->address.IsValid()) << "Invalid address of size " 132 EXPECT_TRUE(it->address.IsValid()) << "Invalid address of size "
134 << it->address.size(); 133 << it->address.size();
135 EXPECT_FALSE(it->address.IsZero()); 134 EXPECT_FALSE(it->address.IsZero());
136 EXPECT_GT(it->prefix_length, 1u); 135 EXPECT_GT(it->prefix_length, 1u);
137 EXPECT_LE(it->prefix_length, it->address.size() * 8); 136 EXPECT_LE(it->prefix_length, it->address.size() * 8);
138 137
139 #if defined(OS_WIN) 138 #if defined(OS_WIN)
140 // On Windows |name| is NET_LUID. 139 // On Windows |name| is NET_LUID.
141 base::ScopedNativeLibrary phlpapi_lib(
142 base::FilePath(FILE_PATH_LITERAL("iphlpapi.dll")));
143 ASSERT_TRUE(phlpapi_lib.is_valid());
144 typedef NETIO_STATUS (WINAPI* ConvertInterfaceIndexToLuid)(NET_IFINDEX, 140 typedef NETIO_STATUS (WINAPI* ConvertInterfaceIndexToLuid)(NET_IFINDEX,
145 PNET_LUID); 141 PNET_LUID);
146 ConvertInterfaceIndexToLuid interface_to_luid =
147 reinterpret_cast<ConvertInterfaceIndexToLuid>(
148 phlpapi_lib.GetFunctionPointer("ConvertInterfaceIndexToLuid"));
149
150 typedef NETIO_STATUS (WINAPI* ConvertInterfaceLuidToGuid)(NET_LUID*, 142 typedef NETIO_STATUS (WINAPI* ConvertInterfaceLuidToGuid)(NET_LUID*,
151 GUID*); 143 GUID*);
mmenke 2016/05/18 17:54:03 Actually, you need to remove these two typedefs as
maksims (do not use this acc) 2016/05/19 05:58:31 Done. Thank you for explanations!
152 ConvertInterfaceLuidToGuid luid_to_guid =
153 reinterpret_cast<ConvertInterfaceLuidToGuid>(
154 phlpapi_lib.GetFunctionPointer("ConvertInterfaceLuidToGuid"));
155 144
156 if (interface_to_luid && luid_to_guid) { 145 NET_LUID luid;
157 NET_LUID luid; 146 EXPECT_EQ(static_cast<DWORD>(NO_ERROR),
158 EXPECT_EQ(static_cast<DWORD>(NO_ERROR), 147 ConvertInterfaceIndexToLuid(it->interface_index, &luid));
159 interface_to_luid(it->interface_index, &luid)); 148 GUID guid;
160 GUID guid; 149 EXPECT_EQ(static_cast<DWORD>(NO_ERROR),
161 EXPECT_EQ(static_cast<DWORD>(NO_ERROR), luid_to_guid(&luid, &guid)); 150 ConvertInterfaceLuidToGuid(&luid, &guid));
162 LPOLESTR name; 151 LPOLESTR name;
163 StringFromCLSID(guid, &name); 152 StringFromCLSID(guid, &name);
164 EXPECT_STREQ(base::UTF8ToWide(it->name).c_str(), name); 153 EXPECT_STREQ(base::UTF8ToWide(it->name).c_str(), name);
165 CoTaskMemFree(name); 154 CoTaskMemFree(name);
166 continue; 155
167 } else {
168 EXPECT_LT(base::win::GetVersion(), base::win::VERSION_VISTA);
169 EXPECT_LT(it->interface_index, 1u << 24u); // Must fit 0.x.x.x.
170 EXPECT_NE(it->interface_index, 0u); // 0 means to use default.
171 }
172 if (it->type == NetworkChangeNotifier::CONNECTION_WIFI) { 156 if (it->type == NetworkChangeNotifier::CONNECTION_WIFI) {
173 EXPECT_NE(WIFI_PHY_LAYER_PROTOCOL_NONE, GetWifiPHYLayerProtocol()); 157 EXPECT_NE(WIFI_PHY_LAYER_PROTOCOL_NONE, GetWifiPHYLayerProtocol());
174 } 158 }
175 #elif !defined(OS_ANDROID) 159 #elif !defined(OS_ANDROID)
176 char name[IF_NAMESIZE]; 160 char name[IF_NAMESIZE];
177 EXPECT_TRUE(if_indextoname(it->interface_index, name)); 161 EXPECT_TRUE(if_indextoname(it->interface_index, name));
178 EXPECT_STREQ(it->name.c_str(), name); 162 EXPECT_STREQ(it->name.c_str(), name);
179 #endif 163 #endif
180 } 164 }
181 } 165 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 adapter_address.FirstPrefix = &adapter_prefix; 467 adapter_address.FirstPrefix = &adapter_prefix;
484 468
485 // Address of offline links should be ignored. 469 // Address of offline links should be ignored.
486 ASSERT_TRUE(FillAdapterAddress( 470 ASSERT_TRUE(FillAdapterAddress(
487 &adapter_address /* adapter_address */, ifname_em1 /* ifname */, 471 &adapter_address /* adapter_address */, ifname_em1 /* ifname */,
488 ipv6_address /* ip_address */, ipv6_prefix /* ip_netmask */, 472 ipv6_address /* ip_address */, ipv6_prefix /* ip_netmask */,
489 addresses /* sock_addrs */)); 473 addresses /* sock_addrs */));
490 adapter_address.OperStatus = IfOperStatusDown; 474 adapter_address.OperStatus = IfOperStatusDown;
491 475
492 EXPECT_TRUE(internal::GetNetworkListImpl( 476 EXPECT_TRUE(internal::GetNetworkListImpl(
493 &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, true, &adapter_address)); 477 &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, true, &adapter_address));
mmenke 2016/05/18 17:54:03 All 7 of the "internal::GetNetworkListImpl" calls
maksims (do not use this acc) 2016/05/19 05:58:31 Done.
494 478
495 EXPECT_EQ(results.size(), 0ul); 479 EXPECT_EQ(results.size(), 0ul);
496 480
497 // Address on loopback interface should be trimmed out. 481 // Address on loopback interface should be trimmed out.
498 ASSERT_TRUE(FillAdapterAddress( 482 ASSERT_TRUE(FillAdapterAddress(
499 &adapter_address /* adapter_address */, ifname_em1 /* ifname */, 483 &adapter_address /* adapter_address */, ifname_em1 /* ifname */,
500 ipv6_local_address /* ip_address */, ipv6_prefix /* ip_netmask */, 484 ipv6_local_address /* ip_address */, ipv6_prefix /* ip_netmask */,
501 addresses /* sock_addrs */)); 485 addresses /* sock_addrs */));
502 adapter_address.IfType = IF_TYPE_SOFTWARE_LOOPBACK; 486 adapter_address.IfType = IF_TYPE_SOFTWARE_LOOPBACK;
503 487
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 // We can't check the result of GetHostName() directly, since the result 726 // We can't check the result of GetHostName() directly, since the result
743 // will differ across machines. Our goal here is to simply exercise the 727 // will differ across machines. Our goal here is to simply exercise the
744 // code path, and check that things "look about right". 728 // code path, and check that things "look about right".
745 std::string hostname = GetHostName(); 729 std::string hostname = GetHostName();
746 EXPECT_FALSE(hostname.empty()); 730 EXPECT_FALSE(hostname.empty());
747 } 731 }
748 732
749 } // namespace 733 } // namespace
750 734
751 } // namespace net 735 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/network_interfaces_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698