| 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 "chromeos/dbus/gsm_sms_client.h" | 5 #include "chromeos/dbus/gsm_sms_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "dbus/message.h" | 15 #include "dbus/message.h" |
| 15 #include "dbus/mock_bus.h" | 16 #include "dbus/mock_bus.h" |
| 16 #include "dbus/mock_object_proxy.h" | 17 #include "dbus/mock_object_proxy.h" |
| 17 #include "dbus/object_path.h" | 18 #include "dbus/object_path.h" |
| 18 #include "dbus/values_util.h" | 19 #include "dbus/values_util.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 const uint32_t kIndex = 42; | 201 const uint32_t kIndex = 42; |
| 201 const bool kComplete = true; | 202 const bool kComplete = true; |
| 202 MockSmsReceivedHandler handler; | 203 MockSmsReceivedHandler handler; |
| 203 EXPECT_CALL(handler, Run(kIndex, kComplete)).Times(1); | 204 EXPECT_CALL(handler, Run(kIndex, kComplete)).Times(1); |
| 204 // Set handler. | 205 // Set handler. |
| 205 client_->SetSmsReceivedHandler(kServiceName, dbus::ObjectPath(kObjectPath), | 206 client_->SetSmsReceivedHandler(kServiceName, dbus::ObjectPath(kObjectPath), |
| 206 base::Bind(&MockSmsReceivedHandler::Run, | 207 base::Bind(&MockSmsReceivedHandler::Run, |
| 207 base::Unretained(&handler))); | 208 base::Unretained(&handler))); |
| 208 | 209 |
| 209 // Run the message loop to run the signal connection result callback. | 210 // Run the message loop to run the signal connection result callback. |
| 210 message_loop_.RunUntilIdle(); | 211 base::RunLoop().RunUntilIdle(); |
| 211 | 212 |
| 212 // Send signal. | 213 // Send signal. |
| 213 dbus::Signal signal(modemmanager::kModemManagerSMSInterface, | 214 dbus::Signal signal(modemmanager::kModemManagerSMSInterface, |
| 214 modemmanager::kSMSReceivedSignal); | 215 modemmanager::kSMSReceivedSignal); |
| 215 dbus::MessageWriter writer(&signal); | 216 dbus::MessageWriter writer(&signal); |
| 216 writer.AppendUint32(kIndex); | 217 writer.AppendUint32(kIndex); |
| 217 writer.AppendBool(kComplete); | 218 writer.AppendBool(kComplete); |
| 218 ASSERT_FALSE(sms_received_callback_.is_null()); | 219 ASSERT_FALSE(sms_received_callback_.is_null()); |
| 219 sms_received_callback_.Run(&signal); | 220 sms_received_callback_.Run(&signal); |
| 220 // Reset handler. | 221 // Reset handler. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 233 EXPECT_CALL(callback, Run()).Times(1); | 234 EXPECT_CALL(callback, Run()).Times(1); |
| 234 // Create response. | 235 // Create response. |
| 235 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 236 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 236 response_ = response.get(); | 237 response_ = response.get(); |
| 237 // Call Delete. | 238 // Call Delete. |
| 238 client_->Delete(kServiceName, dbus::ObjectPath(kObjectPath), kIndex, | 239 client_->Delete(kServiceName, dbus::ObjectPath(kObjectPath), kIndex, |
| 239 base::Bind(&MockDeleteCallback::Run, | 240 base::Bind(&MockDeleteCallback::Run, |
| 240 base::Unretained(&callback))); | 241 base::Unretained(&callback))); |
| 241 | 242 |
| 242 // Run the message loop. | 243 // Run the message loop. |
| 243 message_loop_.RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
| 244 } | 245 } |
| 245 | 246 |
| 246 TEST_F(GsmSMSClientTest, Get) { | 247 TEST_F(GsmSMSClientTest, Get) { |
| 247 // Set expectations. | 248 // Set expectations. |
| 248 const uint32_t kIndex = 42; | 249 const uint32_t kIndex = 42; |
| 249 expected_index_ = kIndex; | 250 expected_index_ = kIndex; |
| 250 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _)) | 251 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _)) |
| 251 .WillOnce(Invoke(this, &GsmSMSClientTest::OnGet)); | 252 .WillOnce(Invoke(this, &GsmSMSClientTest::OnGet)); |
| 252 MockGetCallback callback; | 253 MockGetCallback callback; |
| 253 EXPECT_CALL(callback, Run(_)) | 254 EXPECT_CALL(callback, Run(_)) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 273 expected_result.SetWithoutPathExpansion( | 274 expected_result.SetWithoutPathExpansion( |
| 274 kNumberKey, new base::StringValue(kExampleNumber)); | 275 kNumberKey, new base::StringValue(kExampleNumber)); |
| 275 expected_result.SetWithoutPathExpansion(kTextKey, | 276 expected_result.SetWithoutPathExpansion(kTextKey, |
| 276 new base::StringValue(kExampleText)); | 277 new base::StringValue(kExampleText)); |
| 277 expected_result_ = &expected_result; | 278 expected_result_ = &expected_result; |
| 278 // Call Delete. | 279 // Call Delete. |
| 279 client_->Get(kServiceName, dbus::ObjectPath(kObjectPath), kIndex, | 280 client_->Get(kServiceName, dbus::ObjectPath(kObjectPath), kIndex, |
| 280 base::Bind(&MockGetCallback::Run, base::Unretained(&callback))); | 281 base::Bind(&MockGetCallback::Run, base::Unretained(&callback))); |
| 281 | 282 |
| 282 // Run the message loop. | 283 // Run the message loop. |
| 283 message_loop_.RunUntilIdle(); | 284 base::RunLoop().RunUntilIdle(); |
| 284 } | 285 } |
| 285 | 286 |
| 286 TEST_F(GsmSMSClientTest, List) { | 287 TEST_F(GsmSMSClientTest, List) { |
| 287 // Set expectations. | 288 // Set expectations. |
| 288 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _)) | 289 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _)) |
| 289 .WillOnce(Invoke(this, &GsmSMSClientTest::OnList)); | 290 .WillOnce(Invoke(this, &GsmSMSClientTest::OnList)); |
| 290 MockListCallback callback; | 291 MockListCallback callback; |
| 291 EXPECT_CALL(callback, Run(_)) | 292 EXPECT_CALL(callback, Run(_)) |
| 292 .WillOnce(Invoke(this, &GsmSMSClientTest::CheckResult)); | 293 .WillOnce(Invoke(this, &GsmSMSClientTest::CheckResult)); |
| 293 // Create response. | 294 // Create response. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 316 new base::StringValue(kExampleNumber)); | 317 new base::StringValue(kExampleNumber)); |
| 317 sms->SetWithoutPathExpansion(kTextKey, new base::StringValue(kExampleText)); | 318 sms->SetWithoutPathExpansion(kTextKey, new base::StringValue(kExampleText)); |
| 318 expected_result.Append(sms); | 319 expected_result.Append(sms); |
| 319 expected_result_ = &expected_result; | 320 expected_result_ = &expected_result; |
| 320 // Call List. | 321 // Call List. |
| 321 client_->List(kServiceName, dbus::ObjectPath(kObjectPath), | 322 client_->List(kServiceName, dbus::ObjectPath(kObjectPath), |
| 322 base::Bind(&MockListCallback::Run, | 323 base::Bind(&MockListCallback::Run, |
| 323 base::Unretained(&callback))); | 324 base::Unretained(&callback))); |
| 324 | 325 |
| 325 // Run the message loop. | 326 // Run the message loop. |
| 326 message_loop_.RunUntilIdle(); | 327 base::RunLoop().RunUntilIdle(); |
| 327 } | 328 } |
| 328 | 329 |
| 329 } // namespace chromeos | 330 } // namespace chromeos |
| OLD | NEW |