| 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/fake_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_stub_helper.h" | 15 #include "chromeos/dbus/shill_stub_helper.h" |
| 16 #include "chromeos/network/network_configuration_handler.h" | 16 #include "chromeos/network/network_configuration_handler.h" |
| 17 #include "chromeos/network/network_state.h" | 17 #include "chromeos/network/network_state.h" |
| 18 #include "chromeos/network/network_state_handler.h" | 18 #include "chromeos/network/network_state_handler.h" |
| 19 #include "chromeos/network/network_state_handler_observer.h" | 19 #include "chromeos/network/network_state_handler_observer.h" |
| 20 #include "chromeos/network/shill_property_util.h" | 20 #include "chromeos/network/shill_property_util.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 24 | 24 |
| 25 using ::testing::_; | 25 using ::testing::_; |
| 26 using ::testing::AnyNumber; |
| 26 using ::testing::Invoke; | 27 using ::testing::Invoke; |
| 27 using ::testing::Pointee; | 28 using ::testing::Pointee; |
| 28 using ::testing::Return; | 29 using ::testing::Return; |
| 29 using ::testing::SaveArg; | 30 using ::testing::SaveArg; |
| 30 using ::testing::StrEq; | 31 using ::testing::StrEq; |
| 31 | 32 |
| 32 // Matcher to match base::Value. | 33 // Matcher to match base::Value. |
| 33 MATCHER_P(IsEqualTo, value, "") { return arg.Equals(value); } | 34 MATCHER_P(IsEqualTo, value, "") { return arg.Equals(value); } |
| 34 | 35 |
| 35 namespace chromeos { | 36 namespace chromeos { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 class NetworkConfigurationHandlerTest : public testing::Test { | 92 class NetworkConfigurationHandlerTest : public testing::Test { |
| 92 public: | 93 public: |
| 93 NetworkConfigurationHandlerTest() | 94 NetworkConfigurationHandlerTest() |
| 94 : mock_manager_client_(NULL), | 95 : mock_manager_client_(NULL), |
| 95 mock_profile_client_(NULL), | 96 mock_profile_client_(NULL), |
| 96 mock_service_client_(NULL), | 97 mock_service_client_(NULL), |
| 97 dictionary_value_result_(NULL) {} | 98 dictionary_value_result_(NULL) {} |
| 98 virtual ~NetworkConfigurationHandlerTest() {} | 99 virtual ~NetworkConfigurationHandlerTest() {} |
| 99 | 100 |
| 100 virtual void SetUp() OVERRIDE { | 101 virtual void SetUp() OVERRIDE { |
| 101 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; | 102 FakeDBusThreadManager* dbus_thread_manager = new FakeDBusThreadManager; |
| 102 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | 103 mock_manager_client_ = new MockShillManagerClient(); |
| 103 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | 104 mock_profile_client_ = new MockShillProfileClient(); |
| 104 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 105 mock_service_client_ = new MockShillServiceClient(); |
| 105 mock_manager_client_ = | 106 dbus_thread_manager->SetShillManagerClient( |
| 106 mock_dbus_thread_manager->mock_shill_manager_client(); | 107 scoped_ptr<ShillManagerClient>(mock_manager_client_).Pass()); |
| 107 mock_profile_client_ = | 108 dbus_thread_manager->SetShillProfileClient( |
| 108 mock_dbus_thread_manager->mock_shill_profile_client(); | 109 scoped_ptr<ShillProfileClient>(mock_profile_client_).Pass()); |
| 109 mock_service_client_ = | 110 dbus_thread_manager->SetShillServiceClient( |
| 110 mock_dbus_thread_manager->mock_shill_service_client(); | 111 scoped_ptr<ShillServiceClient>(mock_service_client_).Pass()); |
| 112 |
| 113 EXPECT_CALL(*mock_service_client_, GetProperties(_, _)) |
| 114 .Times(AnyNumber()); |
| 115 EXPECT_CALL(*mock_manager_client_, GetProperties(_)) |
| 116 .Times(AnyNumber()); |
| 117 EXPECT_CALL(*mock_manager_client_, AddPropertyChangedObserver(_)) |
| 118 .Times(AnyNumber()); |
| 119 EXPECT_CALL(*mock_manager_client_, RemovePropertyChangedObserver(_)) |
| 120 .Times(AnyNumber()); |
| 121 |
| 122 DBusThreadManager::InitializeForTesting(dbus_thread_manager); |
| 111 | 123 |
| 112 network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); | 124 network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); |
| 113 network_configuration_handler_.reset(new NetworkConfigurationHandler()); | 125 network_configuration_handler_.reset(new NetworkConfigurationHandler()); |
| 114 network_configuration_handler_->Init(network_state_handler_.get()); | 126 network_configuration_handler_->Init(network_state_handler_.get()); |
| 115 message_loop_.RunUntilIdle(); | 127 message_loop_.RunUntilIdle(); |
| 116 } | 128 } |
| 117 | 129 |
| 118 virtual void TearDown() OVERRIDE { | 130 virtual void TearDown() OVERRIDE { |
| 119 network_configuration_handler_.reset(); | 131 network_configuration_handler_.reset(); |
| 120 network_state_handler_.reset(); | 132 network_state_handler_.reset(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 std::string key = "SSID"; | 218 std::string key = "SSID"; |
| 207 scoped_ptr<base::StringValue> networkNameValue( | 219 scoped_ptr<base::StringValue> networkNameValue( |
| 208 base::Value::CreateStringValue(networkName)); | 220 base::Value::CreateStringValue(networkName)); |
| 209 | 221 |
| 210 base::DictionaryValue value; | 222 base::DictionaryValue value; |
| 211 value.Set(key, base::Value::CreateStringValue(networkName)); | 223 value.Set(key, base::Value::CreateStringValue(networkName)); |
| 212 dictionary_value_result_ = &value; | 224 dictionary_value_result_ = &value; |
| 213 EXPECT_CALL(*mock_service_client_, | 225 EXPECT_CALL(*mock_service_client_, |
| 214 SetProperty(dbus::ObjectPath(service_path), key, | 226 SetProperty(dbus::ObjectPath(service_path), key, |
| 215 IsEqualTo(networkNameValue.get()), _, _)).Times(1); | 227 IsEqualTo(networkNameValue.get()), _, _)).Times(1); |
| 216 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 228 mock_service_client_->SetProperty(dbus::ObjectPath(service_path), |
| 217 dbus::ObjectPath(service_path), key, *networkNameValue, | 229 key, |
| 218 base::Bind(&base::DoNothing), | 230 *networkNameValue, |
| 219 base::Bind(&DBusErrorCallback)); | 231 base::Bind(&base::DoNothing), |
| 232 base::Bind(&DBusErrorCallback)); |
| 220 message_loop_.RunUntilIdle(); | 233 message_loop_.RunUntilIdle(); |
| 221 | 234 |
| 222 ShillServiceClient::DictionaryValueCallback get_properties_callback; | 235 ShillServiceClient::DictionaryValueCallback get_properties_callback; |
| 223 EXPECT_CALL(*mock_service_client_, | 236 EXPECT_CALL(*mock_service_client_, |
| 224 GetProperties(_, _)).WillOnce( | 237 GetProperties(_, _)).WillOnce( |
| 225 Invoke(this, | 238 Invoke(this, |
| 226 &NetworkConfigurationHandlerTest::OnGetProperties)); | 239 &NetworkConfigurationHandlerTest::OnGetProperties)); |
| 227 network_configuration_handler_->GetProperties( | 240 network_configuration_handler_->GetProperties( |
| 228 service_path, | 241 service_path, |
| 229 base::Bind(&DictionaryValueCallback, | 242 base::Bind(&DictionaryValueCallback, |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 create_service_path_, shill::kGuidProperty, &guid)); | 617 create_service_path_, shill::kGuidProperty, &guid)); |
| 605 EXPECT_EQ(service_path, guid); | 618 EXPECT_EQ(service_path, guid); |
| 606 | 619 |
| 607 std::string actual_profile; | 620 std::string actual_profile; |
| 608 EXPECT_TRUE(GetServiceStringProperty( | 621 EXPECT_TRUE(GetServiceStringProperty( |
| 609 create_service_path_, shill::kProfileProperty, &actual_profile)); | 622 create_service_path_, shill::kProfileProperty, &actual_profile)); |
| 610 EXPECT_EQ(shill_stub_helper::kSharedProfilePath, actual_profile); | 623 EXPECT_EQ(shill_stub_helper::kSharedProfilePath, actual_profile); |
| 611 } | 624 } |
| 612 | 625 |
| 613 } // namespace chromeos | 626 } // namespace chromeos |
| OLD | NEW |