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.h" | 7 #include "base/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" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 virtual void SetUp() OVERRIDE { | 80 virtual void SetUp() OVERRIDE { |
81 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; | 81 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; |
82 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | 82 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) |
83 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | 83 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); |
84 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 84 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
85 mock_manager_client_ = | 85 mock_manager_client_ = |
86 mock_dbus_thread_manager->mock_shill_manager_client(); | 86 mock_dbus_thread_manager->mock_shill_manager_client(); |
87 mock_service_client_ = | 87 mock_service_client_ = |
88 mock_dbus_thread_manager->mock_shill_service_client(); | 88 mock_dbus_thread_manager->mock_shill_service_client(); |
89 | 89 |
90 // Initialize DBusThreadManager with a stub implementation. | 90 NetworkHandler::Initialize(); |
91 NetworkConfigurationHandler::Initialize(); | |
92 message_loop_.RunUntilIdle(); | 91 message_loop_.RunUntilIdle(); |
93 } | 92 } |
94 | 93 |
95 virtual void TearDown() OVERRIDE { | 94 virtual void TearDown() OVERRIDE { |
96 NetworkConfigurationHandler::Shutdown(); | 95 NetworkHandler::Shutdown(); |
97 DBusThreadManager::Shutdown(); | 96 DBusThreadManager::Shutdown(); |
98 } | 97 } |
99 | 98 |
100 // Handles responses for GetProperties method calls. | 99 // Handles responses for GetProperties method calls. |
101 void OnGetProperties( | 100 void OnGetProperties( |
102 const dbus::ObjectPath& path, | 101 const dbus::ObjectPath& path, |
103 const ShillClientHelper::DictionaryValueCallback& callback) { | 102 const ShillClientHelper::DictionaryValueCallback& callback) { |
104 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); | 103 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); |
105 } | 104 } |
106 | 105 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 dbus::ObjectPath(service_path), key, *networkNameValue, | 182 dbus::ObjectPath(service_path), key, *networkNameValue, |
184 base::Bind(&base::DoNothing), | 183 base::Bind(&base::DoNothing), |
185 base::Bind(&DBusErrorCallback)); | 184 base::Bind(&DBusErrorCallback)); |
186 message_loop_.RunUntilIdle(); | 185 message_loop_.RunUntilIdle(); |
187 | 186 |
188 ShillServiceClient::DictionaryValueCallback get_properties_callback; | 187 ShillServiceClient::DictionaryValueCallback get_properties_callback; |
189 EXPECT_CALL(*mock_service_client_, | 188 EXPECT_CALL(*mock_service_client_, |
190 GetProperties(_, _)).WillOnce( | 189 GetProperties(_, _)).WillOnce( |
191 Invoke(this, | 190 Invoke(this, |
192 &NetworkConfigurationHandlerTest::OnGetProperties)); | 191 &NetworkConfigurationHandlerTest::OnGetProperties)); |
193 NetworkConfigurationHandler::Get()->GetProperties( | 192 NetworkHandler::Get()->network_configuration_handler()->GetProperties( |
194 service_path, | 193 service_path, |
195 base::Bind(&DictionaryValueCallback, | 194 base::Bind(&DictionaryValueCallback, |
196 service_path, | 195 service_path, |
197 expected_json), | 196 expected_json), |
198 base::Bind(&ErrorCallback, false, service_path)); | 197 base::Bind(&ErrorCallback, false, service_path)); |
199 message_loop_.RunUntilIdle(); | 198 message_loop_.RunUntilIdle(); |
200 } | 199 } |
201 | 200 |
202 TEST_F(NetworkConfigurationHandlerTest, SetProperties) { | 201 TEST_F(NetworkConfigurationHandlerTest, SetProperties) { |
203 std::string service_path = "/service/1"; | 202 std::string service_path = "/service/1"; |
204 std::string networkName = "MyNetwork"; | 203 std::string networkName = "MyNetwork"; |
205 std::string key = "SSID"; | 204 std::string key = "SSID"; |
206 scoped_ptr<base::StringValue> networkNameValue( | 205 scoped_ptr<base::StringValue> networkNameValue( |
207 base::Value::CreateStringValue(networkName)); | 206 base::Value::CreateStringValue(networkName)); |
208 | 207 |
209 base::DictionaryValue value; | 208 base::DictionaryValue value; |
210 value.Set(key, base::Value::CreateStringValue(networkName)); | 209 value.Set(key, base::Value::CreateStringValue(networkName)); |
211 dictionary_value_result_ = &value; | 210 dictionary_value_result_ = &value; |
212 EXPECT_CALL(*mock_manager_client_, | 211 EXPECT_CALL(*mock_manager_client_, |
213 ConfigureService(_, _, _)).WillOnce( | 212 ConfigureService(_, _, _)).WillOnce( |
214 Invoke(this, | 213 Invoke(this, |
215 &NetworkConfigurationHandlerTest::OnSetProperties)); | 214 &NetworkConfigurationHandlerTest::OnSetProperties)); |
216 NetworkConfigurationHandler::Get()->SetProperties( | 215 NetworkHandler::Get()->network_configuration_handler()->SetProperties( |
217 service_path, | 216 service_path, |
218 value, | 217 value, |
219 base::Bind(&base::DoNothing), | 218 base::Bind(&base::DoNothing), |
220 base::Bind(&ErrorCallback, false, service_path)); | 219 base::Bind(&ErrorCallback, false, service_path)); |
221 message_loop_.RunUntilIdle(); | 220 message_loop_.RunUntilIdle(); |
222 } | 221 } |
223 | 222 |
224 TEST_F(NetworkConfigurationHandlerTest, ClearProperties) { | 223 TEST_F(NetworkConfigurationHandlerTest, ClearProperties) { |
225 std::string service_path = "/service/1"; | 224 std::string service_path = "/service/1"; |
226 std::string networkName = "MyNetwork"; | 225 std::string networkName = "MyNetwork"; |
227 std::string key = "SSID"; | 226 std::string key = "SSID"; |
228 scoped_ptr<base::StringValue> networkNameValue( | 227 scoped_ptr<base::StringValue> networkNameValue( |
229 base::Value::CreateStringValue(networkName)); | 228 base::Value::CreateStringValue(networkName)); |
230 | 229 |
231 // First set up a value to clear. | 230 // First set up a value to clear. |
232 base::DictionaryValue value; | 231 base::DictionaryValue value; |
233 value.Set(key, base::Value::CreateStringValue(networkName)); | 232 value.Set(key, base::Value::CreateStringValue(networkName)); |
234 dictionary_value_result_ = &value; | 233 dictionary_value_result_ = &value; |
235 EXPECT_CALL(*mock_manager_client_, | 234 EXPECT_CALL(*mock_manager_client_, |
236 ConfigureService(_, _, _)).WillOnce( | 235 ConfigureService(_, _, _)).WillOnce( |
237 Invoke(this, | 236 Invoke(this, |
238 &NetworkConfigurationHandlerTest::OnSetProperties)); | 237 &NetworkConfigurationHandlerTest::OnSetProperties)); |
239 NetworkConfigurationHandler::Get()->SetProperties( | 238 NetworkHandler::Get()->network_configuration_handler()->SetProperties( |
240 service_path, | 239 service_path, |
241 value, | 240 value, |
242 base::Bind(&base::DoNothing), | 241 base::Bind(&base::DoNothing), |
243 base::Bind(&ErrorCallback, false, service_path)); | 242 base::Bind(&ErrorCallback, false, service_path)); |
244 message_loop_.RunUntilIdle(); | 243 message_loop_.RunUntilIdle(); |
245 | 244 |
246 // Now clear it. | 245 // Now clear it. |
247 std::vector<std::string> values_to_clear; | 246 std::vector<std::string> values_to_clear; |
248 values_to_clear.push_back(key); | 247 values_to_clear.push_back(key); |
249 EXPECT_CALL(*mock_service_client_, | 248 EXPECT_CALL(*mock_service_client_, |
250 ClearProperties(_, _, _, _)).WillOnce( | 249 ClearProperties(_, _, _, _)).WillOnce( |
251 Invoke(this, | 250 Invoke(this, |
252 &NetworkConfigurationHandlerTest::OnClearProperties)); | 251 &NetworkConfigurationHandlerTest::OnClearProperties)); |
253 NetworkConfigurationHandler::Get()->ClearProperties( | 252 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( |
254 service_path, | 253 service_path, |
255 values_to_clear, | 254 values_to_clear, |
256 base::Bind(&base::DoNothing), | 255 base::Bind(&base::DoNothing), |
257 base::Bind(&ErrorCallback, false, service_path)); | 256 base::Bind(&ErrorCallback, false, service_path)); |
258 message_loop_.RunUntilIdle(); | 257 message_loop_.RunUntilIdle(); |
259 } | 258 } |
260 | 259 |
261 TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) { | 260 TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) { |
262 std::string service_path = "/service/1"; | 261 std::string service_path = "/service/1"; |
263 std::string networkName = "MyNetwork"; | 262 std::string networkName = "MyNetwork"; |
264 std::string key = "SSID"; | 263 std::string key = "SSID"; |
265 scoped_ptr<base::StringValue> networkNameValue( | 264 scoped_ptr<base::StringValue> networkNameValue( |
266 base::Value::CreateStringValue(networkName)); | 265 base::Value::CreateStringValue(networkName)); |
267 | 266 |
268 // First set up a value to clear. | 267 // First set up a value to clear. |
269 base::DictionaryValue value; | 268 base::DictionaryValue value; |
270 value.Set(key, base::Value::CreateStringValue(networkName)); | 269 value.Set(key, base::Value::CreateStringValue(networkName)); |
271 dictionary_value_result_ = &value; | 270 dictionary_value_result_ = &value; |
272 EXPECT_CALL(*mock_manager_client_, | 271 EXPECT_CALL(*mock_manager_client_, |
273 ConfigureService(_, _, _)).WillOnce( | 272 ConfigureService(_, _, _)).WillOnce( |
274 Invoke(this, | 273 Invoke(this, |
275 &NetworkConfigurationHandlerTest::OnSetProperties)); | 274 &NetworkConfigurationHandlerTest::OnSetProperties)); |
276 NetworkConfigurationHandler::Get()->SetProperties( | 275 NetworkHandler::Get()->network_configuration_handler()->SetProperties( |
277 service_path, | 276 service_path, |
278 value, | 277 value, |
279 base::Bind(&base::DoNothing), | 278 base::Bind(&base::DoNothing), |
280 base::Bind(&ErrorCallback, false, service_path)); | 279 base::Bind(&ErrorCallback, false, service_path)); |
281 message_loop_.RunUntilIdle(); | 280 message_loop_.RunUntilIdle(); |
282 | 281 |
283 // Now clear it. | 282 // Now clear it. |
284 std::vector<std::string> values_to_clear; | 283 std::vector<std::string> values_to_clear; |
285 values_to_clear.push_back(key); | 284 values_to_clear.push_back(key); |
286 EXPECT_CALL( | 285 EXPECT_CALL( |
287 *mock_service_client_, | 286 *mock_service_client_, |
288 ClearProperties(_, _, _, _)).WillOnce( | 287 ClearProperties(_, _, _, _)).WillOnce( |
289 Invoke(this, | 288 Invoke(this, |
290 &NetworkConfigurationHandlerTest::OnClearPropertiesError)); | 289 &NetworkConfigurationHandlerTest::OnClearPropertiesError)); |
291 NetworkConfigurationHandler::Get()->ClearProperties( | 290 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( |
292 service_path, | 291 service_path, |
293 values_to_clear, | 292 values_to_clear, |
294 base::Bind(&base::DoNothing), | 293 base::Bind(&base::DoNothing), |
295 base::Bind(&ErrorCallback, true, service_path)); | 294 base::Bind(&ErrorCallback, true, service_path)); |
296 message_loop_.RunUntilIdle(); | 295 message_loop_.RunUntilIdle(); |
297 } | 296 } |
298 | 297 |
299 TEST_F(NetworkConfigurationHandlerTest, Connect) { | 298 TEST_F(NetworkConfigurationHandlerTest, Connect) { |
300 std::string service_path = "/service/1"; | 299 std::string service_path = "/service/1"; |
301 | 300 |
302 EXPECT_CALL(*mock_service_client_, | 301 EXPECT_CALL(*mock_service_client_, |
303 Connect(_, _, _)).WillOnce( | 302 Connect(_, _, _)).WillOnce( |
304 Invoke(this, | 303 Invoke(this, |
305 &NetworkConfigurationHandlerTest::OnConnect)); | 304 &NetworkConfigurationHandlerTest::OnConnect)); |
306 NetworkConfigurationHandler::Get()->Connect( | 305 NetworkHandler::Get()->network_configuration_handler()->Connect( |
307 service_path, | 306 service_path, |
308 base::Bind(&base::DoNothing), | 307 base::Bind(&base::DoNothing), |
309 base::Bind(&ErrorCallback, false, service_path)); | 308 base::Bind(&ErrorCallback, false, service_path)); |
310 message_loop_.RunUntilIdle(); | 309 message_loop_.RunUntilIdle(); |
311 } | 310 } |
312 | 311 |
313 TEST_F(NetworkConfigurationHandlerTest, Disconnect) { | 312 TEST_F(NetworkConfigurationHandlerTest, Disconnect) { |
314 std::string service_path = "/service/1"; | 313 std::string service_path = "/service/1"; |
315 | 314 |
316 EXPECT_CALL(*mock_service_client_, | 315 EXPECT_CALL(*mock_service_client_, |
317 Disconnect(_, _, _)).WillOnce( | 316 Disconnect(_, _, _)).WillOnce( |
318 Invoke(this, | 317 Invoke(this, |
319 &NetworkConfigurationHandlerTest::OnDisconnect)); | 318 &NetworkConfigurationHandlerTest::OnDisconnect)); |
320 NetworkConfigurationHandler::Get()->Disconnect( | 319 NetworkHandler::Get()->network_configuration_handler()->Disconnect( |
321 service_path, | 320 service_path, |
322 base::Bind(&base::DoNothing), | 321 base::Bind(&base::DoNothing), |
323 base::Bind(&ErrorCallback, false, service_path)); | 322 base::Bind(&ErrorCallback, false, service_path)); |
324 message_loop_.RunUntilIdle(); | 323 message_loop_.RunUntilIdle(); |
325 } | 324 } |
326 | 325 |
327 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { | 326 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { |
328 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; | 327 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; |
329 std::string networkName = "MyNetwork"; | 328 std::string networkName = "MyNetwork"; |
330 std::string key = "SSID"; | 329 std::string key = "SSID"; |
331 scoped_ptr<base::StringValue> networkNameValue( | 330 scoped_ptr<base::StringValue> networkNameValue( |
332 base::Value::CreateStringValue(networkName)); | 331 base::Value::CreateStringValue(networkName)); |
333 base::DictionaryValue value; | 332 base::DictionaryValue value; |
334 value.Set(key, base::Value::CreateStringValue(networkName)); | 333 value.Set(key, base::Value::CreateStringValue(networkName)); |
335 | 334 |
336 EXPECT_CALL( | 335 EXPECT_CALL( |
337 *mock_manager_client_, | 336 *mock_manager_client_, |
338 GetService(_, _, _)).WillOnce( | 337 GetService(_, _, _)).WillOnce( |
339 Invoke(this, | 338 Invoke(this, |
340 &NetworkConfigurationHandlerTest::OnGetService)); | 339 &NetworkConfigurationHandlerTest::OnGetService)); |
341 NetworkConfigurationHandler::Get()->CreateConfiguration( | 340 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration( |
342 value, | 341 value, |
343 base::Bind(&StringResultCallback, std::string("/service/2")), | 342 base::Bind(&StringResultCallback, std::string("/service/2")), |
344 base::Bind(&ErrorCallback, false, std::string(""))); | 343 base::Bind(&ErrorCallback, false, std::string(""))); |
345 message_loop_.RunUntilIdle(); | 344 message_loop_.RunUntilIdle(); |
346 } | 345 } |
347 | 346 |
348 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) { | 347 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) { |
349 std::string service_path = "/service/1"; | 348 std::string service_path = "/service/1"; |
350 | 349 |
351 EXPECT_CALL( | 350 EXPECT_CALL( |
352 *mock_service_client_, | 351 *mock_service_client_, |
353 Remove(_, _, _)).WillOnce( | 352 Remove(_, _, _)).WillOnce( |
354 Invoke(this, | 353 Invoke(this, |
355 &NetworkConfigurationHandlerTest::OnRemove)); | 354 &NetworkConfigurationHandlerTest::OnRemove)); |
356 NetworkConfigurationHandler::Get()->RemoveConfiguration( | 355 NetworkHandler::Get()->network_configuration_handler()->RemoveConfiguration( |
357 service_path, | 356 service_path, |
358 base::Bind(&base::DoNothing), | 357 base::Bind(&base::DoNothing), |
359 base::Bind(&ErrorCallback, false, service_path)); | 358 base::Bind(&ErrorCallback, false, service_path)); |
360 message_loop_.RunUntilIdle(); | 359 message_loop_.RunUntilIdle(); |
361 } | 360 } |
362 | 361 |
363 } // namespace chromeos | 362 } // namespace chromeos |
OLD | NEW |