| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 11 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 12 #include "chromeos/dbus/mock_shill_manager_client.h" | 12 #include "chromeos/dbus/mock_shill_manager_client.h" |
| 13 #include "chromeos/dbus/mock_shill_profile_client.h" | 13 #include "chromeos/dbus/mock_shill_profile_client.h" |
| 14 #include "chromeos/dbus/mock_shill_service_client.h" | 14 #include "chromeos/dbus/mock_shill_service_client.h" |
| 15 #include "chromeos/dbus/shill_profile_client_stub.h" |
| 15 #include "chromeos/network/network_configuration_handler.h" | 16 #include "chromeos/network/network_configuration_handler.h" |
| 16 #include "chromeos/network/network_state.h" | 17 #include "chromeos/network/network_state.h" |
| 17 #include "chromeos/network/network_state_handler.h" | 18 #include "chromeos/network/network_state_handler.h" |
| 18 #include "chromeos/network/network_state_handler_observer.h" | 19 #include "chromeos/network/network_state_handler_observer.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 22 | 23 |
| 23 using ::testing::_; | 24 using ::testing::_; |
| 24 using ::testing::Invoke; | 25 using ::testing::Invoke; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void OnClearPropertiesError( | 151 void OnClearPropertiesError( |
| 151 const dbus::ObjectPath& service_path, | 152 const dbus::ObjectPath& service_path, |
| 152 const std::vector<std::string>& names, | 153 const std::vector<std::string>& names, |
| 153 const ShillClientHelper::ListValueCallback& callback, | 154 const ShillClientHelper::ListValueCallback& callback, |
| 154 const ShillClientHelper::ErrorCallback& error_callback) { | 155 const ShillClientHelper::ErrorCallback& error_callback) { |
| 155 base::ListValue result; | 156 base::ListValue result; |
| 156 result.AppendBoolean(false); | 157 result.AppendBoolean(false); |
| 157 callback.Run(result); | 158 callback.Run(result); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void OnConfigureService(const base::DictionaryValue& properties, | 161 void OnConfigureService( |
| 161 const ObjectPathCallback& callback, | 162 const dbus::ObjectPath& profile_path, |
| 162 const ShillClientHelper::ErrorCallback& error_callback) { | 163 const base::DictionaryValue& properties, |
| 164 const ObjectPathCallback& callback, |
| 165 const ShillClientHelper::ErrorCallback& error_callback) { |
| 163 callback.Run(dbus::ObjectPath("/service/2")); | 166 callback.Run(dbus::ObjectPath("/service/2")); |
| 164 } | 167 } |
| 165 | 168 |
| 166 void OnGetLoadableProfileEntries( | 169 void OnGetLoadableProfileEntries( |
| 167 const dbus::ObjectPath& service_path, | 170 const dbus::ObjectPath& service_path, |
| 168 const ShillClientHelper::DictionaryValueCallback& callback) { | 171 const ShillClientHelper::DictionaryValueCallback& callback) { |
| 169 base::DictionaryValue entries; | 172 base::DictionaryValue entries; |
| 170 entries.SetString("profile1", "entry1"); | 173 entries.SetString("profile1", "entry1"); |
| 171 entries.SetString("profile2", "entry2"); | 174 entries.SetString("profile2", "entry2"); |
| 172 callback.Run(DBUS_METHOD_CALL_SUCCESS, entries); | 175 callback.Run(DBUS_METHOD_CALL_SUCCESS, entries); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 &NetworkConfigurationHandlerTest::OnClearPropertiesError)); | 323 &NetworkConfigurationHandlerTest::OnClearPropertiesError)); |
| 321 network_configuration_handler_->ClearProperties( | 324 network_configuration_handler_->ClearProperties( |
| 322 service_path, | 325 service_path, |
| 323 values_to_clear, | 326 values_to_clear, |
| 324 base::Bind(&base::DoNothing), | 327 base::Bind(&base::DoNothing), |
| 325 base::Bind(&ErrorCallback, true, service_path)); | 328 base::Bind(&ErrorCallback, true, service_path)); |
| 326 message_loop_.RunUntilIdle(); | 329 message_loop_.RunUntilIdle(); |
| 327 } | 330 } |
| 328 | 331 |
| 329 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { | 332 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { |
| 330 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; | |
| 331 std::string networkName = "MyNetwork"; | 333 std::string networkName = "MyNetwork"; |
| 332 std::string key = "SSID"; | 334 std::string key = "SSID"; |
| 335 std::string profile = "profile path"; |
| 333 scoped_ptr<base::StringValue> networkNameValue( | 336 scoped_ptr<base::StringValue> networkNameValue( |
| 334 base::Value::CreateStringValue(networkName)); | 337 base::Value::CreateStringValue(networkName)); |
| 335 base::DictionaryValue value; | 338 base::DictionaryValue value; |
| 336 value.Set(key, base::Value::CreateStringValue(networkName)); | 339 value.SetWithoutPathExpansion(flimflam::kSSIDProperty, |
| 340 base::Value::CreateStringValue(networkName)); |
| 341 value.SetWithoutPathExpansion(flimflam::kProfileProperty, |
| 342 base::Value::CreateStringValue(profile)); |
| 337 | 343 |
| 338 EXPECT_CALL( | 344 EXPECT_CALL(*mock_manager_client_, |
| 339 *mock_manager_client_, | 345 ConfigureServiceForProfile(dbus::ObjectPath(profile), _, _, _)) |
| 340 ConfigureService(_, _, _)).WillOnce( | 346 .WillOnce( |
| 341 Invoke(this, | 347 Invoke(this, &NetworkConfigurationHandlerTest::OnConfigureService)); |
| 342 &NetworkConfigurationHandlerTest::OnConfigureService)); | |
| 343 network_configuration_handler_->CreateConfiguration( | 348 network_configuration_handler_->CreateConfiguration( |
| 344 value, | 349 value, |
| 345 base::Bind(&StringResultCallback, std::string("/service/2")), | 350 base::Bind(&StringResultCallback, std::string("/service/2")), |
| 346 base::Bind(&ErrorCallback, false, std::string(""))); | 351 base::Bind(&ErrorCallback, false, std::string(""))); |
| 347 message_loop_.RunUntilIdle(); | 352 message_loop_.RunUntilIdle(); |
| 348 } | 353 } |
| 349 | 354 |
| 350 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) { | 355 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) { |
| 351 std::string service_path = "/service/1"; | 356 std::string service_path = "/service/1"; |
| 352 | 357 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 properties.SetStringWithoutPathExpansion( | 584 properties.SetStringWithoutPathExpansion( |
| 580 flimflam::kSSIDProperty, service_path); | 585 flimflam::kSSIDProperty, service_path); |
| 581 properties.SetStringWithoutPathExpansion( | 586 properties.SetStringWithoutPathExpansion( |
| 582 flimflam::kNameProperty, service_path); | 587 flimflam::kNameProperty, service_path); |
| 583 properties.SetStringWithoutPathExpansion( | 588 properties.SetStringWithoutPathExpansion( |
| 584 flimflam::kGuidProperty, service_path); | 589 flimflam::kGuidProperty, service_path); |
| 585 properties.SetStringWithoutPathExpansion( | 590 properties.SetStringWithoutPathExpansion( |
| 586 flimflam::kTypeProperty, flimflam::kTypeWifi); | 591 flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 587 properties.SetStringWithoutPathExpansion( | 592 properties.SetStringWithoutPathExpansion( |
| 588 flimflam::kStateProperty, flimflam::kStateIdle); | 593 flimflam::kStateProperty, flimflam::kStateIdle); |
| 594 properties.SetStringWithoutPathExpansion( |
| 595 flimflam::kProfileProperty, ShillProfileClientStub::kSharedProfilePath); |
| 589 | 596 |
| 590 network_configuration_handler_->CreateConfiguration( | 597 network_configuration_handler_->CreateConfiguration( |
| 591 properties, | 598 properties, |
| 592 base::Bind( | 599 base::Bind( |
| 593 &NetworkConfigurationHandlerStubTest::CreateConfigurationCallback, | 600 &NetworkConfigurationHandlerStubTest::CreateConfigurationCallback, |
| 594 base::Unretained(this)), | 601 base::Unretained(this)), |
| 595 base::Bind(&ErrorCallback, false, service_path)); | 602 base::Bind(&ErrorCallback, false, service_path)); |
| 596 message_loop_.RunUntilIdle(); | 603 message_loop_.RunUntilIdle(); |
| 597 | 604 |
| 598 EXPECT_FALSE(create_service_path_.empty()); | 605 EXPECT_FALSE(create_service_path_.empty()); |
| 606 |
| 599 std::string ssid; | 607 std::string ssid; |
| 600 EXPECT_TRUE(GetServiceStringProperty( | 608 EXPECT_TRUE(GetServiceStringProperty( |
| 601 create_service_path_, flimflam::kSSIDProperty, &ssid)); | 609 create_service_path_, flimflam::kSSIDProperty, &ssid)); |
| 610 std::string actual_profile; |
| 602 EXPECT_EQ(service_path, ssid); | 611 EXPECT_EQ(service_path, ssid); |
| 612 |
| 613 EXPECT_TRUE(GetServiceStringProperty( |
| 614 create_service_path_, flimflam::kProfileProperty, &actual_profile)); |
| 615 EXPECT_EQ(ShillProfileClientStub::kSharedProfilePath, actual_profile); |
| 603 } | 616 } |
| 604 | 617 |
| 605 } // namespace chromeos | 618 } // namespace chromeos |
| OLD | NEW |