| 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/modem_messaging_client.h" | 5 #include "chromeos/dbus/modem_messaging_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "dbus/message.h" | 13 #include "dbus/message.h" |
| 13 #include "dbus/mock_bus.h" | 14 #include "dbus/mock_bus.h" |
| 14 #include "dbus/mock_object_proxy.h" | 15 #include "dbus/mock_object_proxy.h" |
| 15 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
| 16 #include "dbus/values_util.h" | 17 #include "dbus/values_util.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 const dbus::ObjectPath kSmsPath("/SMS/0"); | 168 const dbus::ObjectPath kSmsPath("/SMS/0"); |
| 168 const bool kComplete = true; | 169 const bool kComplete = true; |
| 169 MockSmsReceivedHandler handler; | 170 MockSmsReceivedHandler handler; |
| 170 EXPECT_CALL(handler, Run(kSmsPath, kComplete)).Times(1); | 171 EXPECT_CALL(handler, Run(kSmsPath, kComplete)).Times(1); |
| 171 // Set handler. | 172 // Set handler. |
| 172 client_->SetSmsReceivedHandler(kServiceName, dbus::ObjectPath(kObjectPath), | 173 client_->SetSmsReceivedHandler(kServiceName, dbus::ObjectPath(kObjectPath), |
| 173 base::Bind(&MockSmsReceivedHandler::Run, | 174 base::Bind(&MockSmsReceivedHandler::Run, |
| 174 base::Unretained(&handler))); | 175 base::Unretained(&handler))); |
| 175 | 176 |
| 176 // Run the message loop to run the signal connection result callback. | 177 // Run the message loop to run the signal connection result callback. |
| 177 message_loop_.RunUntilIdle(); | 178 base::RunLoop().RunUntilIdle(); |
| 178 | 179 |
| 179 // Send signal. | 180 // Send signal. |
| 180 dbus::Signal signal(modemmanager::kModemManager1MessagingInterface, | 181 dbus::Signal signal(modemmanager::kModemManager1MessagingInterface, |
| 181 modemmanager::kSMSAddedSignal); | 182 modemmanager::kSMSAddedSignal); |
| 182 dbus::MessageWriter writer(&signal); | 183 dbus::MessageWriter writer(&signal); |
| 183 writer.AppendObjectPath(kSmsPath); | 184 writer.AppendObjectPath(kSmsPath); |
| 184 writer.AppendBool(kComplete); | 185 writer.AppendBool(kComplete); |
| 185 ASSERT_FALSE(sms_received_callback_.is_null()); | 186 ASSERT_FALSE(sms_received_callback_.is_null()); |
| 186 sms_received_callback_.Run(&signal); | 187 sms_received_callback_.Run(&signal); |
| 187 // Reset handler. | 188 // Reset handler. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 200 EXPECT_CALL(callback, Run()).Times(1); | 201 EXPECT_CALL(callback, Run()).Times(1); |
| 201 // Create response. | 202 // Create response. |
| 202 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 203 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 203 response_ = response.get(); | 204 response_ = response.get(); |
| 204 // Call Delete. | 205 // Call Delete. |
| 205 client_->Delete(kServiceName, dbus::ObjectPath(kObjectPath), kSmsPath, | 206 client_->Delete(kServiceName, dbus::ObjectPath(kObjectPath), kSmsPath, |
| 206 base::Bind(&MockDeleteCallback::Run, | 207 base::Bind(&MockDeleteCallback::Run, |
| 207 base::Unretained(&callback))); | 208 base::Unretained(&callback))); |
| 208 | 209 |
| 209 // Run the message loop. | 210 // Run the message loop. |
| 210 message_loop_.RunUntilIdle(); | 211 base::RunLoop().RunUntilIdle(); |
| 211 } | 212 } |
| 212 | 213 |
| 213 TEST_F(ModemMessagingClientTest, List) { | 214 TEST_F(ModemMessagingClientTest, List) { |
| 214 // Set expectations. | 215 // Set expectations. |
| 215 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _)) | 216 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _)) |
| 216 .WillOnce(Invoke(this, &ModemMessagingClientTest::OnList)); | 217 .WillOnce(Invoke(this, &ModemMessagingClientTest::OnList)); |
| 217 MockListCallback callback; | 218 MockListCallback callback; |
| 218 EXPECT_CALL(callback, Run(_)) | 219 EXPECT_CALL(callback, Run(_)) |
| 219 .WillOnce(Invoke(this, &ModemMessagingClientTest::CheckResult)); | 220 .WillOnce(Invoke(this, &ModemMessagingClientTest::CheckResult)); |
| 220 // Create response. | 221 // Create response. |
| 221 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 222 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 222 dbus::ObjectPath path1("/SMS/1"); | 223 dbus::ObjectPath path1("/SMS/1"); |
| 223 dbus::ObjectPath path2("/SMS/2"); | 224 dbus::ObjectPath path2("/SMS/2"); |
| 224 std::vector<dbus::ObjectPath> expected_result; | 225 std::vector<dbus::ObjectPath> expected_result; |
| 225 expected_result.push_back(path1); | 226 expected_result.push_back(path1); |
| 226 expected_result.push_back(path2); | 227 expected_result.push_back(path2); |
| 227 | 228 |
| 228 dbus::MessageWriter writer(response.get()); | 229 dbus::MessageWriter writer(response.get()); |
| 229 writer.AppendArrayOfObjectPaths(expected_result); | 230 writer.AppendArrayOfObjectPaths(expected_result); |
| 230 response_ = response.get(); | 231 response_ = response.get(); |
| 231 | 232 |
| 232 // Save expected result. | 233 // Save expected result. |
| 233 expected_result_ = &expected_result; | 234 expected_result_ = &expected_result; |
| 234 // Call List. | 235 // Call List. |
| 235 client_->List(kServiceName, dbus::ObjectPath(kObjectPath), | 236 client_->List(kServiceName, dbus::ObjectPath(kObjectPath), |
| 236 base::Bind(&MockListCallback::Run, | 237 base::Bind(&MockListCallback::Run, |
| 237 base::Unretained(&callback))); | 238 base::Unretained(&callback))); |
| 238 | 239 |
| 239 // Run the message loop. | 240 // Run the message loop. |
| 240 message_loop_.RunUntilIdle(); | 241 base::RunLoop().RunUntilIdle(); |
| 241 } | 242 } |
| 242 | 243 |
| 243 } // namespace chromeos | 244 } // namespace chromeos |
| OLD | NEW |