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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 const std::string& service_path, | 43 const std::string& service_path, |
44 const base::DictionaryValue& dictionary) { | 44 const base::DictionaryValue& dictionary) { |
45 std::string dict_str = PrettyJson(dictionary); | 45 std::string dict_str = PrettyJson(dictionary); |
46 EXPECT_EQ(expected_json, dict_str); | 46 EXPECT_EQ(expected_json, dict_str); |
47 EXPECT_EQ(expected_id, service_path); | 47 EXPECT_EQ(expected_id, service_path); |
48 } | 48 } |
49 | 49 |
50 void ErrorCallback(bool error_expected, | 50 void ErrorCallback(bool error_expected, |
51 const std::string& expected_id, | 51 const std::string& expected_id, |
52 const std::string& error_name, | 52 const std::string& error_name, |
53 const scoped_ptr<base::DictionaryValue> error_data) { | 53 scoped_ptr<base::DictionaryValue> error_data) { |
54 EXPECT_TRUE(error_expected) << "Unexpected error: " << error_name | 54 EXPECT_TRUE(error_expected) << "Unexpected error: " << error_name |
55 << " with associated data: \n" | 55 << " with associated data: \n" |
56 << PrettyJson(*error_data); | 56 << PrettyJson(*error_data); |
57 } | 57 } |
58 | 58 |
59 void StringResultCallback(const std::string& expected_result, | 59 void StringResultCallback(const std::string& expected_result, |
60 const std::string& result) { | 60 const std::string& result) { |
61 EXPECT_EQ(expected_result, result); | 61 EXPECT_EQ(expected_result, result); |
62 } | 62 } |
63 | 63 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 void OnClearPropertiesError( | 127 void OnClearPropertiesError( |
128 const dbus::ObjectPath& service_path, | 128 const dbus::ObjectPath& service_path, |
129 const std::vector<std::string>& names, | 129 const std::vector<std::string>& names, |
130 const ShillClientHelper::ListValueCallback& callback, | 130 const ShillClientHelper::ListValueCallback& callback, |
131 const ShillClientHelper::ErrorCallback& error_callback) { | 131 const ShillClientHelper::ErrorCallback& error_callback) { |
132 base::ListValue result; | 132 base::ListValue result; |
133 result.AppendBoolean(false); | 133 result.AppendBoolean(false); |
134 callback.Run(result); | 134 callback.Run(result); |
135 } | 135 } |
136 | 136 |
137 void OnConnect(const dbus::ObjectPath& service_path, | |
138 const base::Closure& callback, | |
139 const ShillClientHelper::ErrorCallback& error_callback) { | |
140 callback.Run(); | |
141 } | |
142 | |
143 void OnDisconnect(const dbus::ObjectPath& service_path, | |
144 const base::Closure& callback, | |
145 const ShillClientHelper::ErrorCallback& error_callback) { | |
146 callback.Run(); | |
147 } | |
148 | |
149 void OnGetService(const base::DictionaryValue& properties, | 137 void OnGetService(const base::DictionaryValue& properties, |
150 const ObjectPathCallback& callback, | 138 const ObjectPathCallback& callback, |
151 const ShillClientHelper::ErrorCallback& error_callback) { | 139 const ShillClientHelper::ErrorCallback& error_callback) { |
152 callback.Run(dbus::ObjectPath("/service/2")); | 140 callback.Run(dbus::ObjectPath("/service/2")); |
153 } | 141 } |
154 | 142 |
155 void OnRemove(const dbus::ObjectPath& service_path, | 143 void OnRemove(const dbus::ObjectPath& service_path, |
156 const base::Closure& callback, | 144 const base::Closure& callback, |
157 const ShillClientHelper::ErrorCallback& error_callback) { | 145 const ShillClientHelper::ErrorCallback& error_callback) { |
158 callback.Run(); | 146 callback.Run(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 Invoke(this, | 277 Invoke(this, |
290 &NetworkConfigurationHandlerTest::OnClearPropertiesError)); | 278 &NetworkConfigurationHandlerTest::OnClearPropertiesError)); |
291 NetworkConfigurationHandler::Get()->ClearProperties( | 279 NetworkConfigurationHandler::Get()->ClearProperties( |
292 service_path, | 280 service_path, |
293 values_to_clear, | 281 values_to_clear, |
294 base::Bind(&base::DoNothing), | 282 base::Bind(&base::DoNothing), |
295 base::Bind(&ErrorCallback, true, service_path)); | 283 base::Bind(&ErrorCallback, true, service_path)); |
296 message_loop_.RunUntilIdle(); | 284 message_loop_.RunUntilIdle(); |
297 } | 285 } |
298 | 286 |
299 TEST_F(NetworkConfigurationHandlerTest, Connect) { | |
300 std::string service_path = "/service/1"; | |
301 | |
302 EXPECT_CALL(*mock_service_client_, | |
303 Connect(_, _, _)).WillOnce( | |
304 Invoke(this, | |
305 &NetworkConfigurationHandlerTest::OnConnect)); | |
306 NetworkConfigurationHandler::Get()->Connect( | |
307 service_path, | |
308 base::Bind(&base::DoNothing), | |
309 base::Bind(&ErrorCallback, false, service_path)); | |
310 message_loop_.RunUntilIdle(); | |
311 } | |
312 | |
313 TEST_F(NetworkConfigurationHandlerTest, Disconnect) { | |
314 std::string service_path = "/service/1"; | |
315 | |
316 EXPECT_CALL(*mock_service_client_, | |
317 Disconnect(_, _, _)).WillOnce( | |
318 Invoke(this, | |
319 &NetworkConfigurationHandlerTest::OnDisconnect)); | |
320 NetworkConfigurationHandler::Get()->Disconnect( | |
321 service_path, | |
322 base::Bind(&base::DoNothing), | |
323 base::Bind(&ErrorCallback, false, service_path)); | |
324 message_loop_.RunUntilIdle(); | |
325 } | |
326 | |
327 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { | 287 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { |
328 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; | 288 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; |
329 std::string networkName = "MyNetwork"; | 289 std::string networkName = "MyNetwork"; |
330 std::string key = "SSID"; | 290 std::string key = "SSID"; |
331 scoped_ptr<base::StringValue> networkNameValue( | 291 scoped_ptr<base::StringValue> networkNameValue( |
332 base::Value::CreateStringValue(networkName)); | 292 base::Value::CreateStringValue(networkName)); |
333 base::DictionaryValue value; | 293 base::DictionaryValue value; |
334 value.Set(key, base::Value::CreateStringValue(networkName)); | 294 value.Set(key, base::Value::CreateStringValue(networkName)); |
335 | 295 |
336 EXPECT_CALL( | 296 EXPECT_CALL( |
(...skipping 17 matching lines...) Expand all Loading... |
354 Invoke(this, | 314 Invoke(this, |
355 &NetworkConfigurationHandlerTest::OnRemove)); | 315 &NetworkConfigurationHandlerTest::OnRemove)); |
356 NetworkConfigurationHandler::Get()->RemoveConfiguration( | 316 NetworkConfigurationHandler::Get()->RemoveConfiguration( |
357 service_path, | 317 service_path, |
358 base::Bind(&base::DoNothing), | 318 base::Bind(&base::DoNothing), |
359 base::Bind(&ErrorCallback, false, service_path)); | 319 base::Bind(&ErrorCallback, false, service_path)); |
360 message_loop_.RunUntilIdle(); | 320 message_loop_.RunUntilIdle(); |
361 } | 321 } |
362 | 322 |
363 } // namespace chromeos | 323 } // namespace chromeos |
OLD | NEW |