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_profile_handler.h" |
18 #include "chromeos/network/network_profile_handler_stub.h" | |
19 #include "chromeos/network/onc/onc_test_utils.h" | 18 #include "chromeos/network/onc/onc_test_utils.h" |
20 #include "chromeos/network/onc/onc_utils.h" | 19 #include "chromeos/network/onc/onc_utils.h" |
21 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
25 | 24 |
| 25 using ::testing::AnyNumber; |
26 using ::testing::Invoke; | 26 using ::testing::Invoke; |
27 using ::testing::Mock; | 27 using ::testing::Mock; |
28 using ::testing::Pointee; | 28 using ::testing::Pointee; |
29 using ::testing::Return; | 29 using ::testing::Return; |
30 using ::testing::SaveArg; | 30 using ::testing::SaveArg; |
31 using ::testing::StrEq; | 31 using ::testing::StrEq; |
32 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
33 using ::testing::_; | 33 using ::testing::_; |
34 | 34 |
35 namespace test_utils = ::chromeos::onc::test_utils; | 35 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); | 122 entries->GetDictionaryWithoutPathExpansion(entry_path, &entry); |
123 ASSERT_TRUE(entry); | 123 ASSERT_TRUE(entry); |
124 callback.Run(*entry); | 124 callback.Run(*entry); |
125 } | 125 } |
126 | 126 |
127 protected: | 127 protected: |
128 base::DictionaryValue profile_entries_; | 128 base::DictionaryValue profile_entries_; |
129 std::map<std::string, std::string> profile_to_user_; | 129 std::map<std::string, std::string> profile_to_user_; |
130 }; | 130 }; |
131 | 131 |
| 132 class TestNetworkProfileHandler : public NetworkProfileHandler { |
| 133 public: |
| 134 TestNetworkProfileHandler() {} |
| 135 ~TestNetworkProfileHandler() {} |
| 136 |
| 137 void AddProfileForTest(const NetworkProfile& profile) { |
| 138 AddProfile(profile); |
| 139 } |
| 140 |
| 141 private: |
| 142 DISALLOW_COPY_AND_ASSIGN(TestNetworkProfileHandler); |
| 143 }; |
| 144 |
132 } // namespace | 145 } // namespace |
133 | 146 |
134 class ManagedNetworkConfigurationHandlerTest : public testing::Test { | 147 class ManagedNetworkConfigurationHandlerTest : public testing::Test { |
135 public: | 148 public: |
136 ManagedNetworkConfigurationHandlerTest() { | 149 ManagedNetworkConfigurationHandlerTest() { |
137 } | 150 } |
138 | 151 |
139 virtual ~ManagedNetworkConfigurationHandlerTest() { | 152 virtual ~ManagedNetworkConfigurationHandlerTest() { |
140 } | 153 } |
141 | 154 |
(...skipping 11 matching lines...) Expand all Loading... |
153 .WillRepeatedly(Return(&mock_profile_client_)); | 166 .WillRepeatedly(Return(&mock_profile_client_)); |
154 | 167 |
155 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) | 168 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) |
156 .WillByDefault(Invoke(&profiles_stub_, | 169 .WillByDefault(Invoke(&profiles_stub_, |
157 &ShillProfileTestClient::GetProperties)); | 170 &ShillProfileTestClient::GetProperties)); |
158 | 171 |
159 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) | 172 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) |
160 .WillByDefault(Invoke(&profiles_stub_, | 173 .WillByDefault(Invoke(&profiles_stub_, |
161 &ShillProfileTestClient::GetEntry)); | 174 &ShillProfileTestClient::GetEntry)); |
162 | 175 |
163 NetworkConfigurationHandler::Initialize(); | 176 network_profile_handler_.reset(new TestNetworkProfileHandler()); |
164 ManagedNetworkConfigurationHandler::Initialize(&stub_profile_handler_); | 177 managed_network_configuration_handler_.reset( |
| 178 new ManagedNetworkConfigurationHandler()); |
| 179 managed_network_configuration_handler_->Init( |
| 180 NULL /* no NetworkStateHandler */, |
| 181 network_profile_handler_.get(), |
| 182 NULL /* no NetworkConfigurationHandler */); |
| 183 |
165 message_loop_.RunUntilIdle(); | 184 message_loop_.RunUntilIdle(); |
166 } | 185 } |
167 | 186 |
168 virtual void TearDown() OVERRIDE { | 187 virtual void TearDown() OVERRIDE { |
169 ManagedNetworkConfigurationHandler::Shutdown(); | 188 managed_network_configuration_handler_.reset(); |
170 NetworkConfigurationHandler::Shutdown(); | 189 network_profile_handler_.reset(); |
171 DBusThreadManager::Shutdown(); | 190 DBusThreadManager::Shutdown(); |
172 } | 191 } |
173 | 192 |
174 void VerifyAndClearExpectations() { | 193 void VerifyAndClearExpectations() { |
175 Mock::VerifyAndClearExpectations(&mock_manager_client_); | 194 Mock::VerifyAndClearExpectations(&mock_manager_client_); |
176 Mock::VerifyAndClearExpectations(&mock_service_client_); | 195 Mock::VerifyAndClearExpectations(&mock_service_client_); |
177 Mock::VerifyAndClearExpectations(&mock_profile_client_); | 196 Mock::VerifyAndClearExpectations(&mock_profile_client_); |
178 } | 197 } |
179 | 198 |
180 void InitializeStandardProfiles() { | 199 void InitializeStandardProfiles() { |
181 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); | 200 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); |
182 stub_profile_handler_.AddProfile(NetworkProfile(kUser1ProfilePath, kUser1)); | 201 network_profile_handler_-> |
183 stub_profile_handler_.AddProfile( | 202 AddProfileForTest(NetworkProfile(kUser1ProfilePath, kUser1)); |
184 NetworkProfile(kSharedProfilePath, std::string())); | 203 network_profile_handler_-> |
| 204 AddProfileForTest(NetworkProfile(kSharedProfilePath, std::string())); |
185 } | 205 } |
186 | 206 |
187 void SetUpEntry(const std::string& path_to_shill_json, | 207 void SetUpEntry(const std::string& path_to_shill_json, |
188 const std::string& profile_path, | 208 const std::string& profile_path, |
189 const std::string& entry_path) { | 209 const std::string& entry_path) { |
190 scoped_ptr<base::DictionaryValue> entry = | 210 scoped_ptr<base::DictionaryValue> entry = |
191 test_utils::ReadTestDictionary(path_to_shill_json); | 211 test_utils::ReadTestDictionary(path_to_shill_json); |
192 profiles_stub_.AddEntry(profile_path, entry_path, *entry); | 212 profiles_stub_.AddEntry(profile_path, entry_path, *entry); |
193 } | 213 } |
194 | 214 |
195 void SetPolicy(onc::ONCSource onc_source, | 215 void SetPolicy(onc::ONCSource onc_source, |
196 const std::string& userhash, | 216 const std::string& userhash, |
197 const std::string& path_to_onc) { | 217 const std::string& path_to_onc) { |
198 scoped_ptr<base::DictionaryValue> policy; | 218 scoped_ptr<base::DictionaryValue> policy; |
199 if (path_to_onc.empty()) | 219 if (path_to_onc.empty()) |
200 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); | 220 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); |
201 else | 221 else |
202 policy = test_utils::ReadTestDictionary(path_to_onc); | 222 policy = test_utils::ReadTestDictionary(path_to_onc); |
203 | 223 |
204 base::ListValue* network_configs = NULL; | 224 base::ListValue* network_configs = NULL; |
205 policy->GetListWithoutPathExpansion( | 225 policy->GetListWithoutPathExpansion( |
206 onc::toplevel_config::kNetworkConfigurations, &network_configs); | 226 onc::toplevel_config::kNetworkConfigurations, &network_configs); |
207 | 227 |
208 managed_handler()->SetPolicy( | 228 managed_handler()->SetPolicy( |
209 onc::ONC_SOURCE_USER_POLICY, userhash, *network_configs); | 229 onc::ONC_SOURCE_USER_POLICY, userhash, *network_configs); |
210 } | 230 } |
211 | 231 |
212 ManagedNetworkConfigurationHandler* managed_handler() { | 232 ManagedNetworkConfigurationHandler* managed_handler() { |
213 return ManagedNetworkConfigurationHandler::Get(); | 233 return managed_network_configuration_handler_.get(); |
214 } | 234 } |
215 | 235 |
216 protected: | 236 protected: |
217 StrictMock<MockShillManagerClient> mock_manager_client_; | 237 StrictMock<MockShillManagerClient> mock_manager_client_; |
218 StrictMock<MockShillServiceClient> mock_service_client_; | 238 StrictMock<MockShillServiceClient> mock_service_client_; |
219 StrictMock<MockShillProfileClient> mock_profile_client_; | 239 StrictMock<MockShillProfileClient> mock_profile_client_; |
220 NetworkProfileHandlerStub stub_profile_handler_; | |
221 ShillProfileTestClient profiles_stub_; | 240 ShillProfileTestClient profiles_stub_; |
| 241 scoped_ptr<TestNetworkProfileHandler> network_profile_handler_; |
| 242 scoped_ptr<ManagedNetworkConfigurationHandler> |
| 243 managed_network_configuration_handler_; |
222 MessageLoop message_loop_; | 244 MessageLoop message_loop_; |
223 | 245 |
224 private: | 246 private: |
225 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); | 247 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); |
226 }; | 248 }; |
227 | 249 |
228 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { | 250 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { |
229 InitializeStandardProfiles(); | 251 InitializeStandardProfiles(); |
230 message_loop_.RunUntilIdle(); | 252 message_loop_.RunUntilIdle(); |
231 } | 253 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 ConfigureServiceForProfile( | 448 ConfigureServiceForProfile( |
427 dbus::ObjectPath(kUser1ProfilePath), | 449 dbus::ObjectPath(kUser1ProfilePath), |
428 IsEqualTo(expected_shill_properties.get()), | 450 IsEqualTo(expected_shill_properties.get()), |
429 _, _)); | 451 _, _)); |
430 | 452 |
431 InitializeStandardProfiles(); | 453 InitializeStandardProfiles(); |
432 message_loop_.RunUntilIdle(); | 454 message_loop_.RunUntilIdle(); |
433 } | 455 } |
434 | 456 |
435 } // namespace chromeos | 457 } // namespace chromeos |
OLD | NEW |