| OLD | NEW |
| 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 Loading... |
| 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(kShillManagerClientStubCellular, |
| 223 network_state_handler_->FirstNetworkByType( |
| 224 NetworkTypePattern::Primitive( |
| 225 flimflam::kTypeCellular))->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::Primitive(flimflam::kTypeWimax), |
| 236 false, |
| 237 network_handler::ErrorCallback()); |
| 228 EXPECT_NE(NetworkStateHandler::TECHNOLOGY_ENABLED, | 238 EXPECT_NE(NetworkStateHandler::TECHNOLOGY_ENABLED, |
| 229 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 239 network_state_handler_->GetTechnologyState( |
| 240 NetworkTypePattern::Primitive(flimflam::kTypeWimax))); |
| 230 EXPECT_EQ(initial_changed_count + 1, test_observer_->manager_changed_count()); | 241 EXPECT_EQ(initial_changed_count + 1, test_observer_->manager_changed_count()); |
| 231 // Enable a technology. | 242 // Enable a technology. |
| 232 network_state_handler_->SetTechnologyEnabled( | 243 network_state_handler_->SetTechnologyEnabled( |
| 233 flimflam::kTypeWimax, true, network_handler::ErrorCallback()); | 244 NetworkTypePattern::Primitive(flimflam::kTypeWimax), |
| 245 true, |
| 246 network_handler::ErrorCallback()); |
| 234 // The technology state should immediately change to ENABLING and we should | 247 // The technology state should immediately change to ENABLING and we should |
| 235 // receive a manager changed callback. | 248 // receive a manager changed callback. |
| 236 EXPECT_EQ(initial_changed_count + 2, test_observer_->manager_changed_count()); | 249 EXPECT_EQ(initial_changed_count + 2, test_observer_->manager_changed_count()); |
| 237 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLING, | 250 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLING, |
| 238 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 251 network_state_handler_->GetTechnologyState( |
| 252 NetworkTypePattern::Primitive(flimflam::kTypeWimax))); |
| 239 message_loop_.RunUntilIdle(); | 253 message_loop_.RunUntilIdle(); |
| 240 // Ensure we receive 2 manager changed callbacks when the technology becomes | 254 // Ensure we receive 2 manager changed callbacks when the technology becomes |
| 241 // avalable and enabled. | 255 // avalable and enabled. |
| 242 EXPECT_EQ(initial_changed_count + 4, test_observer_->manager_changed_count()); | 256 EXPECT_EQ(initial_changed_count + 4, test_observer_->manager_changed_count()); |
| 243 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, | 257 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, |
| 244 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 258 network_state_handler_->GetTechnologyState( |
| 259 NetworkTypePattern::Primitive(flimflam::kTypeWimax))); |
| 245 } | 260 } |
| 246 | 261 |
| 247 TEST_F(NetworkStateHandlerTest, TechnologyState) { | 262 TEST_F(NetworkStateHandlerTest, TechnologyState) { |
| 248 ShillManagerClient::TestInterface* manager_test = | 263 ShillManagerClient::TestInterface* manager_test = |
| 249 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); | 264 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); |
| 250 manager_test->RemoveTechnology(flimflam::kTypeWimax); | 265 manager_test->RemoveTechnology(flimflam::kTypeWimax); |
| 251 message_loop_.RunUntilIdle(); | 266 message_loop_.RunUntilIdle(); |
| 252 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, | 267 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, |
| 253 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 268 network_state_handler_->GetTechnologyState( |
| 269 NetworkTypePattern::Primitive(flimflam::kTypeWimax))); |
| 254 | 270 |
| 255 manager_test->AddTechnology(flimflam::kTypeWimax, false); | 271 manager_test->AddTechnology(flimflam::kTypeWimax, false); |
| 256 message_loop_.RunUntilIdle(); | 272 message_loop_.RunUntilIdle(); |
| 257 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_AVAILABLE, | 273 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_AVAILABLE, |
| 258 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 274 network_state_handler_->GetTechnologyState( |
| 275 NetworkTypePattern::Primitive(flimflam::kTypeWimax))); |
| 259 | 276 |
| 260 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, true); | 277 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, true); |
| 261 message_loop_.RunUntilIdle(); | 278 message_loop_.RunUntilIdle(); |
| 262 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNINITIALIZED, | 279 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNINITIALIZED, |
| 263 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 280 network_state_handler_->GetTechnologyState( |
| 281 NetworkTypePattern::Primitive(flimflam::kTypeWimax))); |
| 264 | 282 |
| 265 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, false); | 283 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, false); |
| 266 network_state_handler_->SetTechnologyEnabled( | 284 network_state_handler_->SetTechnologyEnabled( |
| 267 flimflam::kTypeWimax, true, network_handler::ErrorCallback()); | 285 NetworkTypePattern::Primitive(flimflam::kTypeWimax), |
| 286 true, |
| 287 network_handler::ErrorCallback()); |
| 268 message_loop_.RunUntilIdle(); | 288 message_loop_.RunUntilIdle(); |
| 269 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, | 289 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, |
| 270 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 290 network_state_handler_->GetTechnologyState( |
| 291 NetworkTypePattern::Primitive(flimflam::kTypeWimax))); |
| 271 | 292 |
| 272 manager_test->RemoveTechnology(flimflam::kTypeWimax); | 293 manager_test->RemoveTechnology(flimflam::kTypeWimax); |
| 273 message_loop_.RunUntilIdle(); | 294 message_loop_.RunUntilIdle(); |
| 274 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, | 295 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, |
| 275 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 296 network_state_handler_->GetTechnologyState( |
| 297 NetworkTypePattern::Primitive(flimflam::kTypeWimax))); |
| 276 } | 298 } |
| 277 | 299 |
| 278 TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) { | 300 TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) { |
| 279 // Set a service property. | 301 // Set a service property. |
| 280 const std::string eth1 = kShillManagerClientStubDefaultService; | 302 const std::string eth1 = kShillManagerClientStubDefaultService; |
| 281 EXPECT_EQ("", network_state_handler_->GetNetworkState(eth1)->security()); | 303 EXPECT_EQ("", network_state_handler_->GetNetworkState(eth1)->security()); |
| 282 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth1)); | 304 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth1)); |
| 283 base::StringValue security_value("TestSecurity"); | 305 base::StringValue security_value("TestSecurity"); |
| 284 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 306 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 285 dbus::ObjectPath(eth1), | 307 dbus::ObjectPath(eth1), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // Other networks should have 2 updates (inital + request). | 413 // Other networks should have 2 updates (inital + request). |
| 392 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 414 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
| 393 kShillManagerClientStubDefaultService)); | 415 kShillManagerClientStubDefaultService)); |
| 394 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 416 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
| 395 kShillManagerClientStubWireless2)); | 417 kShillManagerClientStubWireless2)); |
| 396 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 418 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
| 397 kShillManagerClientStubCellular)); | 419 kShillManagerClientStubCellular)); |
| 398 } | 420 } |
| 399 | 421 |
| 400 } // namespace chromeos | 422 } // namespace chromeos |
| OLD | NEW |