Chromium Code Reviews| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 | 139 |
| 139 virtual ~ManagedNetworkConfigurationHandlerTest() { | 140 virtual ~ManagedNetworkConfigurationHandlerTest() { |
| 140 } | 141 } |
| 141 | 142 |
| 142 virtual void SetUp() OVERRIDE { | 143 virtual void SetUp() OVERRIDE { |
| 143 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; | 144 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; |
| 144 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) | 145 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) |
| 145 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); | 146 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); |
| 146 DBusThreadManager::InitializeForTesting(dbus_thread_manager); | 147 DBusThreadManager::InitializeForTesting(dbus_thread_manager); |
| 147 | 148 |
| 149 SetShillManagerClientExpectations(); | |
| 150 | |
| 148 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) | 151 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) |
| 149 .WillRepeatedly(Return(&mock_manager_client_)); | 152 .WillRepeatedly(Return(&mock_manager_client_)); |
| 150 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) | 153 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) |
| 151 .WillRepeatedly(Return(&mock_service_client_)); | 154 .WillRepeatedly(Return(&mock_service_client_)); |
| 152 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) | 155 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) |
| 153 .WillRepeatedly(Return(&mock_profile_client_)); | 156 .WillRepeatedly(Return(&mock_profile_client_)); |
| 154 | 157 |
| 155 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) | 158 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) |
| 156 .WillByDefault(Invoke(&profiles_stub_, | 159 .WillByDefault(Invoke(&profiles_stub_, |
| 157 &ShillProfileTestClient::GetProperties)); | 160 &ShillProfileTestClient::GetProperties)); |
| 158 | 161 |
| 159 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) | 162 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) |
| 160 .WillByDefault(Invoke(&profiles_stub_, | 163 .WillByDefault(Invoke(&profiles_stub_, |
| 161 &ShillProfileTestClient::GetEntry)); | 164 &ShillProfileTestClient::GetEntry)); |
| 162 | 165 |
| 163 NetworkConfigurationHandler::Initialize(); | 166 NetworkHandler::Initialize(); |
|
pneubeck (no reviews)
2013/05/13 09:17:06
This is one of the implications of your change tha
gauravsh
2013/05/13 23:30:12
I agree with this concern. Having recently dealt w
stevenjb
2013/05/13 23:49:35
See meta comment.
| |
| 164 ManagedNetworkConfigurationHandler::Initialize(&stub_profile_handler_); | |
| 165 message_loop_.RunUntilIdle(); | 167 message_loop_.RunUntilIdle(); |
| 166 } | 168 } |
| 167 | 169 |
| 168 virtual void TearDown() OVERRIDE { | 170 virtual void TearDown() OVERRIDE { |
| 169 ManagedNetworkConfigurationHandler::Shutdown(); | 171 NetworkHandler::Shutdown(); |
| 170 NetworkConfigurationHandler::Shutdown(); | |
| 171 DBusThreadManager::Shutdown(); | 172 DBusThreadManager::Shutdown(); |
| 172 } | 173 } |
| 173 | 174 |
| 174 void VerifyAndClearExpectations() { | 175 void VerifyAndClearExpectations() { |
| 175 Mock::VerifyAndClearExpectations(&mock_manager_client_); | 176 Mock::VerifyAndClearExpectations(&mock_manager_client_); |
| 176 Mock::VerifyAndClearExpectations(&mock_service_client_); | 177 Mock::VerifyAndClearExpectations(&mock_service_client_); |
| 177 Mock::VerifyAndClearExpectations(&mock_profile_client_); | 178 Mock::VerifyAndClearExpectations(&mock_profile_client_); |
| 179 SetShillManagerClientExpectations(); | |
| 178 } | 180 } |
| 179 | 181 |
| 180 void InitializeStandardProfiles() { | 182 void InitializeStandardProfiles() { |
| 181 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); | 183 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); |
| 182 stub_profile_handler_.AddProfile(NetworkProfile(kUser1ProfilePath, kUser1)); | 184 NetworkHandler::Get()->network_profile_handler()-> |
| 183 stub_profile_handler_.AddProfile( | 185 AddProfileForTest(NetworkProfile(kUser1ProfilePath, kUser1)); |
|
pneubeck (no reviews)
2013/05/13 09:17:06
I don't see the improvement here.
Ok, for now it d
stevenjb
2013/05/13 23:49:35
See meta comment.
| |
| 184 NetworkProfile(kSharedProfilePath, std::string())); | 186 NetworkHandler::Get()->network_profile_handler()-> |
| 187 AddProfileForTest(NetworkProfile(kSharedProfilePath, std::string())); | |
| 185 } | 188 } |
| 186 | 189 |
| 187 void SetUpEntry(const std::string& path_to_shill_json, | 190 void SetUpEntry(const std::string& path_to_shill_json, |
| 188 const std::string& profile_path, | 191 const std::string& profile_path, |
| 189 const std::string& entry_path) { | 192 const std::string& entry_path) { |
| 190 scoped_ptr<base::DictionaryValue> entry = | 193 scoped_ptr<base::DictionaryValue> entry = |
| 191 test_utils::ReadTestDictionary(path_to_shill_json); | 194 test_utils::ReadTestDictionary(path_to_shill_json); |
| 192 profiles_stub_.AddEntry(profile_path, entry_path, *entry); | 195 profiles_stub_.AddEntry(profile_path, entry_path, *entry); |
| 193 } | 196 } |
| 194 | 197 |
| 195 void SetPolicy(onc::ONCSource onc_source, | 198 void SetPolicy(onc::ONCSource onc_source, |
| 196 const std::string& userhash, | 199 const std::string& userhash, |
| 197 const std::string& path_to_onc) { | 200 const std::string& path_to_onc) { |
| 198 scoped_ptr<base::DictionaryValue> policy; | 201 scoped_ptr<base::DictionaryValue> policy; |
| 199 if (path_to_onc.empty()) | 202 if (path_to_onc.empty()) |
| 200 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); | 203 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); |
| 201 else | 204 else |
| 202 policy = test_utils::ReadTestDictionary(path_to_onc); | 205 policy = test_utils::ReadTestDictionary(path_to_onc); |
| 203 | 206 |
| 204 base::ListValue* network_configs = NULL; | 207 base::ListValue* network_configs = NULL; |
| 205 policy->GetListWithoutPathExpansion( | 208 policy->GetListWithoutPathExpansion( |
| 206 onc::toplevel_config::kNetworkConfigurations, &network_configs); | 209 onc::toplevel_config::kNetworkConfigurations, &network_configs); |
| 207 | 210 |
| 208 managed_handler()->SetPolicy( | 211 managed_handler()->SetPolicy( |
| 209 onc::ONC_SOURCE_USER_POLICY, userhash, *network_configs); | 212 onc::ONC_SOURCE_USER_POLICY, userhash, *network_configs); |
| 210 } | 213 } |
| 211 | 214 |
| 215 void SetShillManagerClientExpectations() { | |
| 216 EXPECT_CALL(mock_manager_client_, GetProperties(_)).Times(AnyNumber()); | |
|
pneubeck (no reviews)
2013/05/13 09:17:06
Are these necessary because of calls from the othe
stevenjb
2013/05/13 23:49:35
Yes. See meta comment.
| |
| 217 EXPECT_CALL(mock_manager_client_, | |
| 218 AddPropertyChangedObserver(_)).Times(AnyNumber()); | |
| 219 EXPECT_CALL(mock_manager_client_, | |
| 220 RemovePropertyChangedObserver(_)).Times(AnyNumber()); | |
| 221 } | |
| 222 | |
| 212 ManagedNetworkConfigurationHandler* managed_handler() { | 223 ManagedNetworkConfigurationHandler* managed_handler() { |
| 213 return ManagedNetworkConfigurationHandler::Get(); | 224 return NetworkHandler::Get()->managed_network_configuration_handler(); |
| 214 } | 225 } |
| 215 | 226 |
| 216 protected: | 227 protected: |
| 217 StrictMock<MockShillManagerClient> mock_manager_client_; | 228 StrictMock<MockShillManagerClient> mock_manager_client_; |
| 218 StrictMock<MockShillServiceClient> mock_service_client_; | 229 StrictMock<MockShillServiceClient> mock_service_client_; |
| 219 StrictMock<MockShillProfileClient> mock_profile_client_; | 230 StrictMock<MockShillProfileClient> mock_profile_client_; |
| 220 NetworkProfileHandlerStub stub_profile_handler_; | |
| 221 ShillProfileTestClient profiles_stub_; | 231 ShillProfileTestClient profiles_stub_; |
| 222 MessageLoop message_loop_; | 232 MessageLoop message_loop_; |
| 223 | 233 |
| 224 private: | 234 private: |
| 225 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); | 235 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); |
| 226 }; | 236 }; |
| 227 | 237 |
| 228 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { | 238 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { |
| 229 InitializeStandardProfiles(); | 239 InitializeStandardProfiles(); |
| 230 message_loop_.RunUntilIdle(); | 240 message_loop_.RunUntilIdle(); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 ConfigureServiceForProfile( | 436 ConfigureServiceForProfile( |
| 427 dbus::ObjectPath(kUser1ProfilePath), | 437 dbus::ObjectPath(kUser1ProfilePath), |
| 428 IsEqualTo(expected_shill_properties.get()), | 438 IsEqualTo(expected_shill_properties.get()), |
| 429 _, _)); | 439 _, _)); |
| 430 | 440 |
| 431 InitializeStandardProfiles(); | 441 InitializeStandardProfiles(); |
| 432 message_loop_.RunUntilIdle(); | 442 message_loop_.RunUntilIdle(); |
| 433 } | 443 } |
| 434 | 444 |
| 435 } // namespace chromeos | 445 } // namespace chromeos |
| OLD | NEW |