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

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

Issue 1284113003: Move the concept of multiple route into Network (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 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
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 #if defined(WEBRTC_WIN) 170 #if defined(WEBRTC_WIN)
171 closesocket(fd); 171 closesocket(fd);
172 #else 172 #else
173 close(fd); 173 close(fd);
174 #endif 174 #endif
175 } 175 }
176 delete (*it); 176 delete (*it);
177 } 177 }
178 } 178 }
179 179
180 // Test that UpdateNetworks succeeds. 180 // Test StartUpdating() and StopUpdating(). network_permission_state starts with
181 // UNKNOWN and changes to ALLOWED until no outstanding StartUpdating.
181 TEST_F(NetworkTest, TestUpdateNetworks) { 182 TEST_F(NetworkTest, TestUpdateNetworks) {
182 BasicNetworkManager manager; 183 BasicNetworkManager manager;
183 manager.SignalNetworksChanged.connect( 184 manager.SignalNetworksChanged.connect(
184 static_cast<NetworkTest*>(this), &NetworkTest::OnNetworksChanged); 185 static_cast<NetworkTest*>(this), &NetworkTest::OnNetworksChanged);
186 EXPECT_EQ(manager.network_permission_state(), NetworkManager::STATE_UNKNOWN);
185 manager.StartUpdating(); 187 manager.StartUpdating();
186 Thread::Current()->ProcessMessages(0); 188 Thread::Current()->ProcessMessages(0);
187 EXPECT_TRUE(callback_called_); 189 EXPECT_TRUE(callback_called_);
190 EXPECT_EQ(manager.network_permission_state(), NetworkManager::STATE_ALLOWED);
188 callback_called_ = false; 191 callback_called_ = false;
189 // Callback should be triggered immediately when StartUpdating 192 // Callback should be triggered immediately when StartUpdating
190 // is called, after network update signal is already sent. 193 // is called, after network update signal is already sent.
191 manager.StartUpdating(); 194 manager.StartUpdating();
192 EXPECT_TRUE(manager.started()); 195 EXPECT_TRUE(manager.started());
193 Thread::Current()->ProcessMessages(0); 196 Thread::Current()->ProcessMessages(0);
194 EXPECT_TRUE(callback_called_); 197 EXPECT_TRUE(callback_called_);
195 manager.StopUpdating(); 198 manager.StopUpdating();
199 EXPECT_EQ(manager.network_permission_state(), NetworkManager::STATE_ALLOWED);
196 EXPECT_TRUE(manager.started()); 200 EXPECT_TRUE(manager.started());
197 manager.StopUpdating(); 201 manager.StopUpdating();
202 EXPECT_EQ(manager.network_permission_state(), NetworkManager::STATE_UNKNOWN);
198 EXPECT_FALSE(manager.started()); 203 EXPECT_FALSE(manager.started());
199 manager.StopUpdating(); 204 manager.StopUpdating();
205 EXPECT_EQ(manager.network_permission_state(), NetworkManager::STATE_UNKNOWN);
200 EXPECT_FALSE(manager.started()); 206 EXPECT_FALSE(manager.started());
201 callback_called_ = false; 207 callback_called_ = false;
202 // Callback should be triggered immediately after StartUpdating is called 208 // Callback should be triggered immediately after StartUpdating is called
203 // when start_count_ is reset to 0. 209 // when start_count_ is reset to 0.
204 manager.StartUpdating(); 210 manager.StartUpdating();
205 Thread::Current()->ProcessMessages(0); 211 Thread::Current()->ProcessMessages(0);
212 EXPECT_EQ(manager.network_permission_state(), NetworkManager::STATE_ALLOWED);
206 EXPECT_TRUE(callback_called_); 213 EXPECT_TRUE(callback_called_);
207 } 214 }
208 215
209 // Verify that MergeNetworkList() merges network lists properly. 216 // Verify that MergeNetworkList() merges network lists properly.
210 TEST_F(NetworkTest, TestBasicMergeNetworkList) { 217 TEST_F(NetworkTest, TestBasicMergeNetworkList) {
211 Network ipv4_network1("test_eth0", "Test Network Adapter 1", 218 Network ipv4_network1("test_eth0", "Test Network Adapter 1",
212 IPAddress(0x12345600U), 24); 219 IPAddress(0x12345600U), 24);
213 Network ipv4_network2("test_eth1", "Test Network Adapter 2", 220 Network ipv4_network2("test_eth1", "Test Network Adapter 2",
214 IPAddress(0x00010000U), 16); 221 IPAddress(0x00010000U), 16);
215 ipv4_network1.AddIP(IPAddress(0x12345678)); 222 ipv4_network1.AddIP(IPAddress(0x12345678));
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 EXPECT_EQ(ipv6_network.GetBestIP(), static_cast<IPAddress>(ip)); 780 EXPECT_EQ(ipv6_network.GetBestIP(), static_cast<IPAddress>(ip));
774 781
775 // Add global dynamic temporary one. 782 // Add global dynamic temporary one.
776 ipstr = "2401:fa00:4:1000:be30:5bff:fee5:c6"; 783 ipstr = "2401:fa00:4:1000:be30:5bff:fee5:c6";
777 ASSERT_TRUE(IPFromString(ipstr, IPV6_ADDRESS_FLAG_TEMPORARY, &ip)); 784 ASSERT_TRUE(IPFromString(ipstr, IPV6_ADDRESS_FLAG_TEMPORARY, &ip));
778 ipv6_network.AddIP(ip); 785 ipv6_network.AddIP(ip);
779 EXPECT_EQ(ipv6_network.GetBestIP(), static_cast<IPAddress>(ip)); 786 EXPECT_EQ(ipv6_network.GetBestIP(), static_cast<IPAddress>(ip));
780 } 787 }
781 788
782 } // namespace rtc 789 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698