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

Side by Side Diff: webrtc/base/network_unittest.cc

Issue 2025573002: Use continual gathering to restore backup connections (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Merge Created 4 years, 5 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 | « webrtc/base/network.h ('k') | webrtc/p2p/base/fakeportallocator.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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } // namespace 60 } // namespace
61 61
62 class NetworkTest : public testing::Test, public sigslot::has_slots<> { 62 class NetworkTest : public testing::Test, public sigslot::has_slots<> {
63 public: 63 public:
64 NetworkTest() : callback_called_(false) {} 64 NetworkTest() : callback_called_(false) {}
65 65
66 void OnNetworksChanged() { 66 void OnNetworksChanged() {
67 callback_called_ = true; 67 callback_called_ = true;
68 } 68 }
69 69
70 void listenToNetworkInactive(BasicNetworkManager& network_manager) {
71 BasicNetworkManager::NetworkList networks;
72 network_manager.GetNetworks(&networks);
73 for (Network* network : networks) {
74 network->SignalInactive.connect(this, &NetworkTest::OnNetworkInactive);
75 }
76 }
77
78 void OnNetworkInactive(const Network* network) { num_networks_inactive_++; }
79
80 NetworkManager::Stats MergeNetworkList( 70 NetworkManager::Stats MergeNetworkList(
81 BasicNetworkManager& network_manager, 71 BasicNetworkManager& network_manager,
82 const NetworkManager::NetworkList& list, 72 const NetworkManager::NetworkList& list,
83 bool* changed) { 73 bool* changed) {
84 NetworkManager::Stats stats; 74 NetworkManager::Stats stats;
85 network_manager.MergeNetworkList(list, changed, &stats); 75 network_manager.MergeNetworkList(list, changed, &stats);
86 return stats; 76 return stats;
87 } 77 }
88 78
89 bool IsIgnoredNetwork(BasicNetworkManager& network_manager, 79 bool IsIgnoredNetwork(BasicNetworkManager& network_manager,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 delete if_addr->ifa_addr; 170 delete if_addr->ifa_addr;
181 delete if_addr->ifa_netmask; 171 delete if_addr->ifa_netmask;
182 delete if_addr; 172 delete if_addr;
183 if_addr = next_addr; 173 if_addr = next_addr;
184 } 174 }
185 } 175 }
186 #endif // defined(WEBRTC_POSIX) 176 #endif // defined(WEBRTC_POSIX)
187 177
188 protected: 178 protected:
189 bool callback_called_; 179 bool callback_called_;
190 // Number of networks that become inactive.
191 int num_networks_inactive_ = 0;
192 }; 180 };
193 181
194 class TestBasicNetworkManager : public BasicNetworkManager { 182 class TestBasicNetworkManager : public BasicNetworkManager {
195 public: 183 public:
196 using BasicNetworkManager::QueryDefaultLocalAddress; 184 using BasicNetworkManager::QueryDefaultLocalAddress;
197 using BasicNetworkManager::set_default_local_addresses; 185 using BasicNetworkManager::set_default_local_addresses;
198 }; 186 };
199 187
200 // Test that the Network ctor works properly. 188 // Test that the Network ctor works properly.
201 TEST_F(NetworkTest, TestNetworkConstruct) { 189 TEST_F(NetworkTest, TestNetworkConstruct) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 BasicNetworkManager manager; 303 BasicNetworkManager manager;
316 304
317 // Add ipv4_network1 to the list of networks. 305 // Add ipv4_network1 to the list of networks.
318 NetworkManager::NetworkList list; 306 NetworkManager::NetworkList list;
319 list.push_back(new Network(ipv4_network1)); 307 list.push_back(new Network(ipv4_network1));
320 bool changed; 308 bool changed;
321 NetworkManager::Stats stats = MergeNetworkList(manager, list, &changed); 309 NetworkManager::Stats stats = MergeNetworkList(manager, list, &changed);
322 EXPECT_TRUE(changed); 310 EXPECT_TRUE(changed);
323 EXPECT_EQ(stats.ipv6_network_count, 0); 311 EXPECT_EQ(stats.ipv6_network_count, 0);
324 EXPECT_EQ(stats.ipv4_network_count, 1); 312 EXPECT_EQ(stats.ipv4_network_count, 1);
325 listenToNetworkInactive(manager);
326 list.clear(); 313 list.clear();
327 314
328 manager.GetNetworks(&list); 315 manager.GetNetworks(&list);
329 EXPECT_EQ(1U, list.size()); 316 EXPECT_EQ(1U, list.size());
330 EXPECT_EQ(ipv4_network1.ToString(), list[0]->ToString()); 317 EXPECT_EQ(ipv4_network1.ToString(), list[0]->ToString());
331 Network* net1 = list[0]; 318 Network* net1 = list[0];
332 uint16_t net_id1 = net1->id(); 319 uint16_t net_id1 = net1->id();
333 EXPECT_EQ(1, net_id1); 320 EXPECT_EQ(1, net_id1);
334 list.clear(); 321 list.clear();
335 322
336 // Replace ipv4_network1 with ipv4_network2. 323 // Replace ipv4_network1 with ipv4_network2.
337 list.push_back(new Network(ipv4_network2)); 324 list.push_back(new Network(ipv4_network2));
338 stats = MergeNetworkList(manager, list, &changed); 325 stats = MergeNetworkList(manager, list, &changed);
339 EXPECT_TRUE(changed); 326 EXPECT_TRUE(changed);
340 EXPECT_EQ(stats.ipv6_network_count, 0); 327 EXPECT_EQ(stats.ipv6_network_count, 0);
341 EXPECT_EQ(stats.ipv4_network_count, 1); 328 EXPECT_EQ(stats.ipv4_network_count, 1);
342 EXPECT_EQ(1, num_networks_inactive_);
343 list.clear(); 329 list.clear();
344 num_networks_inactive_ = 0;
345 330
346 manager.GetNetworks(&list); 331 manager.GetNetworks(&list);
347 EXPECT_EQ(1U, list.size()); 332 EXPECT_EQ(1U, list.size());
348 EXPECT_EQ(ipv4_network2.ToString(), list[0]->ToString()); 333 EXPECT_EQ(ipv4_network2.ToString(), list[0]->ToString());
349 Network* net2 = list[0]; 334 Network* net2 = list[0];
350 uint16_t net_id2 = net2->id(); 335 uint16_t net_id2 = net2->id();
351 // Network id will increase. 336 // Network id will increase.
352 EXPECT_LT(net_id1, net_id2); 337 EXPECT_LT(net_id1, net_id2);
353 list.clear(); 338 list.clear();
354 339
355 // Add Network2 back. 340 // Add Network2 back.
356 list.push_back(new Network(ipv4_network1)); 341 list.push_back(new Network(ipv4_network1));
357 list.push_back(new Network(ipv4_network2)); 342 list.push_back(new Network(ipv4_network2));
358 stats = MergeNetworkList(manager, list, &changed); 343 stats = MergeNetworkList(manager, list, &changed);
359 EXPECT_TRUE(changed); 344 EXPECT_TRUE(changed);
360 EXPECT_EQ(stats.ipv6_network_count, 0); 345 EXPECT_EQ(stats.ipv6_network_count, 0);
361 EXPECT_EQ(stats.ipv4_network_count, 2); 346 EXPECT_EQ(stats.ipv4_network_count, 2);
362 EXPECT_EQ(0, num_networks_inactive_);
363 list.clear(); 347 list.clear();
364 348
365 // Verify that we get previous instances of Network objects. 349 // Verify that we get previous instances of Network objects.
366 manager.GetNetworks(&list); 350 manager.GetNetworks(&list);
367 EXPECT_EQ(2U, list.size()); 351 EXPECT_EQ(2U, list.size());
368 EXPECT_TRUE((net1 == list[0] && net2 == list[1]) || 352 EXPECT_TRUE((net1 == list[0] && net2 == list[1]) ||
369 (net1 == list[1] && net2 == list[0])); 353 (net1 == list[1] && net2 == list[0]));
370 EXPECT_TRUE((net_id1 == list[0]->id() && net_id2 == list[1]->id()) || 354 EXPECT_TRUE((net_id1 == list[0]->id() && net_id2 == list[1]->id()) ||
371 (net_id1 == list[1]->id() && net_id2 == list[0]->id())); 355 (net_id1 == list[1]->id() && net_id2 == list[0]->id()));
372 list.clear(); 356 list.clear();
373 357
374 // Call MergeNetworkList() again and verify that we don't get update 358 // Call MergeNetworkList() again and verify that we don't get update
375 // notification. 359 // notification.
376 list.push_back(new Network(ipv4_network2)); 360 list.push_back(new Network(ipv4_network2));
377 list.push_back(new Network(ipv4_network1)); 361 list.push_back(new Network(ipv4_network1));
378 stats = MergeNetworkList(manager, list, &changed); 362 stats = MergeNetworkList(manager, list, &changed);
379 EXPECT_FALSE(changed); 363 EXPECT_FALSE(changed);
380 EXPECT_EQ(stats.ipv6_network_count, 0); 364 EXPECT_EQ(stats.ipv6_network_count, 0);
381 EXPECT_EQ(stats.ipv4_network_count, 2); 365 EXPECT_EQ(stats.ipv4_network_count, 2);
382 EXPECT_EQ(0, num_networks_inactive_);
383 list.clear(); 366 list.clear();
384 367
385 // Verify that we get previous instances of Network objects. 368 // Verify that we get previous instances of Network objects.
386 manager.GetNetworks(&list); 369 manager.GetNetworks(&list);
387 EXPECT_EQ(2U, list.size()); 370 EXPECT_EQ(2U, list.size());
388 EXPECT_TRUE((net1 == list[0] && net2 == list[1]) || 371 EXPECT_TRUE((net1 == list[0] && net2 == list[1]) ||
389 (net1 == list[1] && net2 == list[0])); 372 (net1 == list[1] && net2 == list[0]));
390 EXPECT_TRUE((net_id1 == list[0]->id() && net_id2 == list[1]->id()) || 373 EXPECT_TRUE((net_id1 == list[0]->id() && net_id2 == list[1]->id()) ||
391 (net_id1 == list[1]->id() && net_id2 == list[0]->id())); 374 (net_id1 == list[1]->id() && net_id2 == list[0]->id()));
392 list.clear(); 375 list.clear();
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 // If the set default address is in a network, GetDefaultLocalAddress will 1138 // If the set default address is in a network, GetDefaultLocalAddress will
1156 // return the best IP in that network. 1139 // return the best IP in that network.
1157 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), ip2); 1140 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), ip2);
1158 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip)); 1141 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip));
1159 EXPECT_EQ(static_cast<IPAddress>(ip1), ip); 1142 EXPECT_EQ(static_cast<IPAddress>(ip1), ip);
1160 1143
1161 manager.StopUpdating(); 1144 manager.StopUpdating();
1162 } 1145 }
1163 1146
1164 } // namespace rtc 1147 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/network.h ('k') | webrtc/p2p/base/fakeportallocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698