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

Side by Side Diff: chromeos/network/network_state_handler_unittest.cc

Issue 23712002: Cleanup network type matching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit test in Debug. Created 7 years, 3 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 | Annotate | Revision Log
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 "chromeos/network/network_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/shill_device_client.h" 16 #include "chromeos/dbus/shill_device_client.h"
17 #include "chromeos/dbus/shill_manager_client.h" 17 #include "chromeos/dbus/shill_manager_client.h"
18 #include "chromeos/dbus/shill_profile_client.h" 18 #include "chromeos/dbus/shill_profile_client.h"
19 #include "chromeos/dbus/shill_service_client.h" 19 #include "chromeos/dbus/shill_service_client.h"
20 #include "chromeos/network/network_state.h" 20 #include "chromeos/network/network_state.h"
21 #include "chromeos/network/network_state_handler_observer.h" 21 #include "chromeos/network/network_state_handler_observer.h"
22 #include "chromeos/network/shill_property_util.h"
22 #include "dbus/object_path.h" 23 #include "dbus/object_path.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "third_party/cros_system_api/dbus/service_constants.h" 25 #include "third_party/cros_system_api/dbus/service_constants.h"
25 26
26 namespace { 27 namespace {
27 28
28 void ErrorCallbackFunction(const std::string& error_name, 29 void ErrorCallbackFunction(const std::string& error_name,
29 const std::string& error_message) { 30 const std::string& error_message) {
30 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; 31 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message;
31 } 32 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 TEST_F(NetworkStateHandlerTest, NetworkStateHandlerStub) { 202 TEST_F(NetworkStateHandlerTest, NetworkStateHandlerStub) {
202 // Ensure that the network list is the expected size. 203 // Ensure that the network list is the expected size.
203 const size_t kNumShillManagerClientStubImplServices = 4; 204 const size_t kNumShillManagerClientStubImplServices = 4;
204 EXPECT_EQ(kNumShillManagerClientStubImplServices, 205 EXPECT_EQ(kNumShillManagerClientStubImplServices,
205 test_observer_->network_count()); 206 test_observer_->network_count());
206 // Ensure that the first stub network is the default network. 207 // Ensure that the first stub network is the default network.
207 EXPECT_EQ(kShillManagerClientStubDefaultService, 208 EXPECT_EQ(kShillManagerClientStubDefaultService,
208 test_observer_->default_network()); 209 test_observer_->default_network());
209 EXPECT_EQ(kShillManagerClientStubDefaultService, 210 EXPECT_EQ(kShillManagerClientStubDefaultService,
210 network_state_handler_->ConnectedNetworkByType( 211 network_state_handler_->ConnectedNetworkByType(
211 NetworkStateHandler::kMatchTypeDefault)->path()); 212 NetworkTypePattern::Default())->path());
212 EXPECT_EQ(kShillManagerClientStubDefaultService, 213 EXPECT_EQ(kShillManagerClientStubDefaultService,
213 network_state_handler_->ConnectedNetworkByType( 214 network_state_handler_->ConnectedNetworkByType(
214 flimflam::kTypeEthernet)->path()); 215 NetworkTypePattern::Ethernet())->path());
215 EXPECT_EQ(kShillManagerClientStubDefaultWireless, 216 EXPECT_EQ(kShillManagerClientStubDefaultWireless,
216 network_state_handler_->ConnectedNetworkByType( 217 network_state_handler_->ConnectedNetworkByType(
217 NetworkStateHandler::kMatchTypeWireless)->path()); 218 NetworkTypePattern::Wireless())->path());
219 EXPECT_EQ(kShillManagerClientStubCellular,
220 network_state_handler_->FirstNetworkByType(
221 NetworkTypePattern::Mobile())->path());
222 EXPECT_EQ(
223 kShillManagerClientStubCellular,
224 network_state_handler_->FirstNetworkByType(NetworkTypePattern::Cellular())
225 ->path());
218 EXPECT_EQ(flimflam::kStateOnline, 226 EXPECT_EQ(flimflam::kStateOnline,
219 test_observer_->default_network_connection_state()); 227 test_observer_->default_network_connection_state());
220 } 228 }
221 229
222 TEST_F(NetworkStateHandlerTest, TechnologyChanged) { 230 TEST_F(NetworkStateHandlerTest, TechnologyChanged) {
223 // There may be several manager changes during initialization. 231 // There may be several manager changes during initialization.
224 size_t initial_changed_count = test_observer_->manager_changed_count(); 232 size_t initial_changed_count = test_observer_->manager_changed_count();
225 // Disable a technology. 233 // Disable a technology.
226 network_state_handler_->SetTechnologyEnabled( 234 network_state_handler_->SetTechnologyEnabled(
227 flimflam::kTypeWimax, false, network_handler::ErrorCallback()); 235 NetworkTypePattern::Wimax(), false, network_handler::ErrorCallback());
228 EXPECT_NE(NetworkStateHandler::TECHNOLOGY_ENABLED, 236 EXPECT_NE(
229 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); 237 NetworkStateHandler::TECHNOLOGY_ENABLED,
238 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
230 EXPECT_EQ(initial_changed_count + 1, test_observer_->manager_changed_count()); 239 EXPECT_EQ(initial_changed_count + 1, test_observer_->manager_changed_count());
231 // Enable a technology. 240 // Enable a technology.
232 network_state_handler_->SetTechnologyEnabled( 241 network_state_handler_->SetTechnologyEnabled(
233 flimflam::kTypeWimax, true, network_handler::ErrorCallback()); 242 NetworkTypePattern::Wimax(), true, network_handler::ErrorCallback());
234 // The technology state should immediately change to ENABLING and we should 243 // The technology state should immediately change to ENABLING and we should
235 // receive a manager changed callback. 244 // receive a manager changed callback.
236 EXPECT_EQ(initial_changed_count + 2, test_observer_->manager_changed_count()); 245 EXPECT_EQ(initial_changed_count + 2, test_observer_->manager_changed_count());
237 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLING, 246 EXPECT_EQ(
238 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); 247 NetworkStateHandler::TECHNOLOGY_ENABLING,
248 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
239 message_loop_.RunUntilIdle(); 249 message_loop_.RunUntilIdle();
240 // Ensure we receive 2 manager changed callbacks when the technology becomes 250 // Ensure we receive 2 manager changed callbacks when the technology becomes
241 // avalable and enabled. 251 // avalable and enabled.
242 EXPECT_EQ(initial_changed_count + 4, test_observer_->manager_changed_count()); 252 EXPECT_EQ(initial_changed_count + 4, test_observer_->manager_changed_count());
243 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, 253 EXPECT_EQ(
244 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); 254 NetworkStateHandler::TECHNOLOGY_ENABLED,
255 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
245 } 256 }
246 257
247 TEST_F(NetworkStateHandlerTest, TechnologyState) { 258 TEST_F(NetworkStateHandlerTest, TechnologyState) {
248 ShillManagerClient::TestInterface* manager_test = 259 ShillManagerClient::TestInterface* manager_test =
249 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); 260 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
250 manager_test->RemoveTechnology(flimflam::kTypeWimax); 261 manager_test->RemoveTechnology(flimflam::kTypeWimax);
251 message_loop_.RunUntilIdle(); 262 message_loop_.RunUntilIdle();
252 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, 263 EXPECT_EQ(
253 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); 264 NetworkStateHandler::TECHNOLOGY_UNAVAILABLE,
265 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
254 266
255 manager_test->AddTechnology(flimflam::kTypeWimax, false); 267 manager_test->AddTechnology(flimflam::kTypeWimax, false);
256 message_loop_.RunUntilIdle(); 268 message_loop_.RunUntilIdle();
257 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_AVAILABLE, 269 EXPECT_EQ(
258 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); 270 NetworkStateHandler::TECHNOLOGY_AVAILABLE,
271 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
259 272
260 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, true); 273 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, true);
261 message_loop_.RunUntilIdle(); 274 message_loop_.RunUntilIdle();
262 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNINITIALIZED, 275 EXPECT_EQ(
263 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); 276 NetworkStateHandler::TECHNOLOGY_UNINITIALIZED,
277 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
264 278
265 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, false); 279 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, false);
266 network_state_handler_->SetTechnologyEnabled( 280 network_state_handler_->SetTechnologyEnabled(
267 flimflam::kTypeWimax, true, network_handler::ErrorCallback()); 281 NetworkTypePattern::Wimax(), true, network_handler::ErrorCallback());
268 message_loop_.RunUntilIdle(); 282 message_loop_.RunUntilIdle();
269 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, 283 EXPECT_EQ(
270 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); 284 NetworkStateHandler::TECHNOLOGY_ENABLED,
285 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
271 286
272 manager_test->RemoveTechnology(flimflam::kTypeWimax); 287 manager_test->RemoveTechnology(flimflam::kTypeWimax);
273 message_loop_.RunUntilIdle(); 288 message_loop_.RunUntilIdle();
274 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, 289 EXPECT_EQ(
275 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); 290 NetworkStateHandler::TECHNOLOGY_UNAVAILABLE,
291 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
276 } 292 }
277 293
278 TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) { 294 TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) {
279 // Set a service property. 295 // Set a service property.
280 const std::string eth1 = kShillManagerClientStubDefaultService; 296 const std::string eth1 = kShillManagerClientStubDefaultService;
281 EXPECT_EQ("", network_state_handler_->GetNetworkState(eth1)->security()); 297 EXPECT_EQ("", network_state_handler_->GetNetworkState(eth1)->security());
282 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth1)); 298 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth1));
283 base::StringValue security_value("TestSecurity"); 299 base::StringValue security_value("TestSecurity");
284 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 300 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
285 dbus::ObjectPath(eth1), 301 dbus::ObjectPath(eth1),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // Other networks should have 2 updates (inital + request). 407 // Other networks should have 2 updates (inital + request).
392 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( 408 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(
393 kShillManagerClientStubDefaultService)); 409 kShillManagerClientStubDefaultService));
394 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( 410 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(
395 kShillManagerClientStubWireless2)); 411 kShillManagerClientStubWireless2));
396 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( 412 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(
397 kShillManagerClientStubCellular)); 413 kShillManagerClientStubCellular));
398 } 414 }
399 415
400 } // namespace chromeos 416 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state_handler.cc ('k') | chromeos/network/shill_property_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698