| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/managed_network_configuration_handler.h" | 5 #include "chromeos/network/managed_network_configuration_handler.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 12 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/mock_shill_manager_client.h" | 13 #include "chromeos/dbus/mock_shill_manager_client.h" |
| 14 #include "chromeos/dbus/mock_shill_profile_client.h" | 14 #include "chromeos/dbus/mock_shill_profile_client.h" |
| 15 #include "chromeos/dbus/mock_shill_service_client.h" | 15 #include "chromeos/dbus/mock_shill_service_client.h" |
| 16 #include "chromeos/dbus/shill_profile_client_stub.h" | 16 #include "chromeos/dbus/shill_profile_client_stub.h" |
| 17 #include "chromeos/network/network_configuration_handler.h" | 17 #include "chromeos/network/network_configuration_handler.h" |
| 18 #include "chromeos/network/network_profile_handler_stub.h" | 18 #include "chromeos/network/network_profile_handler.h" |
| 19 #include "chromeos/network/onc/onc_test_utils.h" | 19 #include "chromeos/network/onc/onc_test_utils.h" |
| 20 #include "chromeos/network/onc/onc_utils.h" | 20 #include "chromeos/network/onc/onc_utils.h" |
| 21 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 25 | 25 |
| 26 using ::testing::AnyNumber; |
| 26 using ::testing::Invoke; | 27 using ::testing::Invoke; |
| 27 using ::testing::Mock; | 28 using ::testing::Mock; |
| 28 using ::testing::Pointee; | 29 using ::testing::Pointee; |
| 29 using ::testing::Return; | 30 using ::testing::Return; |
| 30 using ::testing::SaveArg; | 31 using ::testing::SaveArg; |
| 31 using ::testing::StrEq; | 32 using ::testing::StrEq; |
| 32 using ::testing::StrictMock; | 33 using ::testing::StrictMock; |
| 33 using ::testing::_; | 34 using ::testing::_; |
| 34 | 35 |
| 35 namespace test_utils = ::chromeos::onc::test_utils; | 36 namespace test_utils = ::chromeos::onc::test_utils; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 entries->GetDictionaryWithoutPathExpansion(entry_path, &entry); | 123 entries->GetDictionaryWithoutPathExpansion(entry_path, &entry); |
| 123 ASSERT_TRUE(entry); | 124 ASSERT_TRUE(entry); |
| 124 callback.Run(*entry); | 125 callback.Run(*entry); |
| 125 } | 126 } |
| 126 | 127 |
| 127 protected: | 128 protected: |
| 128 base::DictionaryValue profile_entries_; | 129 base::DictionaryValue profile_entries_; |
| 129 std::map<std::string, std::string> profile_to_user_; | 130 std::map<std::string, std::string> profile_to_user_; |
| 130 }; | 131 }; |
| 131 | 132 |
| 133 class TestNetworkProfileHandler : public NetworkProfileHandler { |
| 134 public: |
| 135 TestNetworkProfileHandler() {} |
| 136 virtual ~TestNetworkProfileHandler() {} |
| 137 |
| 138 void AddProfileForTest(const NetworkProfile& profile) { |
| 139 AddProfile(profile); |
| 140 } |
| 141 |
| 142 private: |
| 143 DISALLOW_COPY_AND_ASSIGN(TestNetworkProfileHandler); |
| 144 }; |
| 145 |
| 132 } // namespace | 146 } // namespace |
| 133 | 147 |
| 134 class ManagedNetworkConfigurationHandlerTest : public testing::Test { | 148 class ManagedNetworkConfigurationHandlerTest : public testing::Test { |
| 135 public: | 149 public: |
| 136 ManagedNetworkConfigurationHandlerTest() { | 150 ManagedNetworkConfigurationHandlerTest() { |
| 137 } | 151 } |
| 138 | 152 |
| 139 virtual ~ManagedNetworkConfigurationHandlerTest() { | 153 virtual ~ManagedNetworkConfigurationHandlerTest() { |
| 140 } | 154 } |
| 141 | 155 |
| 142 virtual void SetUp() OVERRIDE { | 156 virtual void SetUp() OVERRIDE { |
| 143 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; | 157 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; |
| 144 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) | 158 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) |
| 145 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); | 159 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); |
| 146 DBusThreadManager::InitializeForTesting(dbus_thread_manager); | 160 DBusThreadManager::InitializeForTesting(dbus_thread_manager); |
| 147 | 161 |
| 162 SetNetworkConfigurationHandlerExpectations(); |
| 163 |
| 148 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) | 164 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) |
| 149 .WillRepeatedly(Return(&mock_manager_client_)); | 165 .WillRepeatedly(Return(&mock_manager_client_)); |
| 150 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) | 166 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) |
| 151 .WillRepeatedly(Return(&mock_service_client_)); | 167 .WillRepeatedly(Return(&mock_service_client_)); |
| 152 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) | 168 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) |
| 153 .WillRepeatedly(Return(&mock_profile_client_)); | 169 .WillRepeatedly(Return(&mock_profile_client_)); |
| 154 | 170 |
| 155 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) | 171 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) |
| 156 .WillByDefault(Invoke(&profiles_stub_, | 172 .WillByDefault(Invoke(&profiles_stub_, |
| 157 &ShillProfileTestClient::GetProperties)); | 173 &ShillProfileTestClient::GetProperties)); |
| 158 | 174 |
| 159 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) | 175 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) |
| 160 .WillByDefault(Invoke(&profiles_stub_, | 176 .WillByDefault(Invoke(&profiles_stub_, |
| 161 &ShillProfileTestClient::GetEntry)); | 177 &ShillProfileTestClient::GetEntry)); |
| 162 | 178 |
| 163 NetworkConfigurationHandler::Initialize(); | 179 network_profile_handler_.reset(new TestNetworkProfileHandler()); |
| 164 ManagedNetworkConfigurationHandler::Initialize(&stub_profile_handler_); | 180 network_configuration_handler_.reset( |
| 181 NetworkConfigurationHandler::InitializeForTest( |
| 182 NULL /* no NetworkStateHandler */)); |
| 183 managed_network_configuration_handler_.reset( |
| 184 new ManagedNetworkConfigurationHandler()); |
| 185 managed_network_configuration_handler_->Init( |
| 186 NULL /* no NetworkStateHandler */, |
| 187 network_profile_handler_.get(), |
| 188 network_configuration_handler_.get()); |
| 189 |
| 165 message_loop_.RunUntilIdle(); | 190 message_loop_.RunUntilIdle(); |
| 166 } | 191 } |
| 167 | 192 |
| 168 virtual void TearDown() OVERRIDE { | 193 virtual void TearDown() OVERRIDE { |
| 169 ManagedNetworkConfigurationHandler::Shutdown(); | 194 managed_network_configuration_handler_.reset(); |
| 170 NetworkConfigurationHandler::Shutdown(); | 195 network_configuration_handler_.reset(); |
| 196 network_profile_handler_.reset(); |
| 171 DBusThreadManager::Shutdown(); | 197 DBusThreadManager::Shutdown(); |
| 172 } | 198 } |
| 173 | 199 |
| 174 void VerifyAndClearExpectations() { | 200 void VerifyAndClearExpectations() { |
| 175 Mock::VerifyAndClearExpectations(&mock_manager_client_); | 201 Mock::VerifyAndClearExpectations(&mock_manager_client_); |
| 176 Mock::VerifyAndClearExpectations(&mock_service_client_); | 202 Mock::VerifyAndClearExpectations(&mock_service_client_); |
| 177 Mock::VerifyAndClearExpectations(&mock_profile_client_); | 203 Mock::VerifyAndClearExpectations(&mock_profile_client_); |
| 204 SetNetworkConfigurationHandlerExpectations(); |
| 178 } | 205 } |
| 179 | 206 |
| 180 void InitializeStandardProfiles() { | 207 void InitializeStandardProfiles() { |
| 181 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); | 208 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); |
| 182 stub_profile_handler_.AddProfile(NetworkProfile(kUser1ProfilePath, kUser1)); | 209 network_profile_handler_-> |
| 183 stub_profile_handler_.AddProfile( | 210 AddProfileForTest(NetworkProfile(kUser1ProfilePath, kUser1)); |
| 184 NetworkProfile(kSharedProfilePath, std::string())); | 211 network_profile_handler_-> |
| 212 AddProfileForTest(NetworkProfile(kSharedProfilePath, std::string())); |
| 185 } | 213 } |
| 186 | 214 |
| 187 void SetUpEntry(const std::string& path_to_shill_json, | 215 void SetUpEntry(const std::string& path_to_shill_json, |
| 188 const std::string& profile_path, | 216 const std::string& profile_path, |
| 189 const std::string& entry_path) { | 217 const std::string& entry_path) { |
| 190 scoped_ptr<base::DictionaryValue> entry = | 218 scoped_ptr<base::DictionaryValue> entry = |
| 191 test_utils::ReadTestDictionary(path_to_shill_json); | 219 test_utils::ReadTestDictionary(path_to_shill_json); |
| 192 profiles_stub_.AddEntry(profile_path, entry_path, *entry); | 220 profiles_stub_.AddEntry(profile_path, entry_path, *entry); |
| 193 } | 221 } |
| 194 | 222 |
| 195 void SetPolicy(onc::ONCSource onc_source, | 223 void SetPolicy(onc::ONCSource onc_source, |
| 196 const std::string& userhash, | 224 const std::string& userhash, |
| 197 const std::string& path_to_onc) { | 225 const std::string& path_to_onc) { |
| 198 scoped_ptr<base::DictionaryValue> policy; | 226 scoped_ptr<base::DictionaryValue> policy; |
| 199 if (path_to_onc.empty()) | 227 if (path_to_onc.empty()) |
| 200 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); | 228 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); |
| 201 else | 229 else |
| 202 policy = test_utils::ReadTestDictionary(path_to_onc); | 230 policy = test_utils::ReadTestDictionary(path_to_onc); |
| 203 | 231 |
| 204 base::ListValue* network_configs = NULL; | 232 base::ListValue* network_configs = NULL; |
| 205 policy->GetListWithoutPathExpansion( | 233 policy->GetListWithoutPathExpansion( |
| 206 onc::toplevel_config::kNetworkConfigurations, &network_configs); | 234 onc::toplevel_config::kNetworkConfigurations, &network_configs); |
| 207 | 235 |
| 208 managed_handler()->SetPolicy( | 236 managed_handler()->SetPolicy( |
| 209 onc::ONC_SOURCE_USER_POLICY, userhash, *network_configs); | 237 onc::ONC_SOURCE_USER_POLICY, userhash, *network_configs); |
| 210 } | 238 } |
| 211 | 239 |
| 240 void SetNetworkConfigurationHandlerExpectations() { |
| 241 // These calls occur in NetworkConfigurationHandler. |
| 242 EXPECT_CALL(mock_manager_client_, GetProperties(_)).Times(AnyNumber()); |
| 243 EXPECT_CALL(mock_manager_client_, |
| 244 AddPropertyChangedObserver(_)).Times(AnyNumber()); |
| 245 EXPECT_CALL(mock_manager_client_, |
| 246 RemovePropertyChangedObserver(_)).Times(AnyNumber()); |
| 247 } |
| 248 |
| 212 ManagedNetworkConfigurationHandler* managed_handler() { | 249 ManagedNetworkConfigurationHandler* managed_handler() { |
| 213 return ManagedNetworkConfigurationHandler::Get(); | 250 return managed_network_configuration_handler_.get(); |
| 214 } | 251 } |
| 215 | 252 |
| 216 protected: | 253 protected: |
| 217 StrictMock<MockShillManagerClient> mock_manager_client_; | 254 StrictMock<MockShillManagerClient> mock_manager_client_; |
| 218 StrictMock<MockShillServiceClient> mock_service_client_; | 255 StrictMock<MockShillServiceClient> mock_service_client_; |
| 219 StrictMock<MockShillProfileClient> mock_profile_client_; | 256 StrictMock<MockShillProfileClient> mock_profile_client_; |
| 220 NetworkProfileHandlerStub stub_profile_handler_; | |
| 221 ShillProfileTestClient profiles_stub_; | 257 ShillProfileTestClient profiles_stub_; |
| 258 scoped_ptr<TestNetworkProfileHandler> network_profile_handler_; |
| 259 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_; |
| 260 scoped_ptr<ManagedNetworkConfigurationHandler> |
| 261 managed_network_configuration_handler_; |
| 222 MessageLoop message_loop_; | 262 MessageLoop message_loop_; |
| 223 | 263 |
| 224 private: | 264 private: |
| 225 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); | 265 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); |
| 226 }; | 266 }; |
| 227 | 267 |
| 228 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { | 268 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { |
| 229 InitializeStandardProfiles(); | 269 InitializeStandardProfiles(); |
| 230 message_loop_.RunUntilIdle(); | 270 message_loop_.RunUntilIdle(); |
| 231 } | 271 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 ConfigureServiceForProfile( | 466 ConfigureServiceForProfile( |
| 427 dbus::ObjectPath(kUser1ProfilePath), | 467 dbus::ObjectPath(kUser1ProfilePath), |
| 428 IsEqualTo(expected_shill_properties.get()), | 468 IsEqualTo(expected_shill_properties.get()), |
| 429 _, _)); | 469 _, _)); |
| 430 | 470 |
| 431 InitializeStandardProfiles(); | 471 InitializeStandardProfiles(); |
| 432 message_loop_.RunUntilIdle(); | 472 message_loop_.RunUntilIdle(); |
| 433 } | 473 } |
| 434 | 474 |
| 435 } // namespace chromeos | 475 } // namespace chromeos |
| OLD | NEW |