OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/test/test_timeouts.h" |
13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
15 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
16 #include "dbus/message.h" | 17 #include "dbus/message.h" |
17 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
18 #include "dbus/test_service.h" | 19 #include "dbus/test_service.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 // The end-to-end test exercises the asynchronous APIs in ObjectProxy and | 22 // The end-to-end test exercises the asynchronous APIs in ObjectProxy and |
22 // ExportedObject. | 23 // ExportedObject. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 dbus::MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); | 219 dbus::MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); |
219 | 220 |
220 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; | 221 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; |
221 CallMethod(&method_call, timeout_ms); | 222 CallMethod(&method_call, timeout_ms); |
222 WaitForResponses(1); | 223 WaitForResponses(1); |
223 | 224 |
224 // Should fail because the method is broken. | 225 // Should fail because the method is broken. |
225 ASSERT_EQ("", response_strings_[0]); | 226 ASSERT_EQ("", response_strings_[0]); |
226 } | 227 } |
227 | 228 |
| 229 TEST_F(EndToEndAsyncTest, EmptyResponseCallback) { |
| 230 const char* kHello = "hello"; |
| 231 |
| 232 // Create the method call. |
| 233 dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); |
| 234 dbus::MessageWriter writer(&method_call); |
| 235 writer.AppendString(kHello); |
| 236 |
| 237 // Call the method with an empty callback. |
| 238 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; |
| 239 object_proxy_->CallMethod(&method_call, |
| 240 timeout_ms, |
| 241 dbus::ObjectProxy::EmptyResponseCallback()); |
| 242 // Post a delayed task to quit the message loop. |
| 243 message_loop_.PostDelayedTask(FROM_HERE, |
| 244 MessageLoop::QuitClosure(), |
| 245 TestTimeouts::tiny_timeout_ms()); |
| 246 message_loop_.Run(); |
| 247 // We cannot tell if the empty callback is called, but at least we can |
| 248 // check if the test does not crash. |
| 249 } |
| 250 |
228 TEST_F(EndToEndAsyncTest, TestSignal) { | 251 TEST_F(EndToEndAsyncTest, TestSignal) { |
229 const char kMessage[] = "hello, world"; | 252 const char kMessage[] = "hello, world"; |
230 // Send the test signal from the exported object. | 253 // Send the test signal from the exported object. |
231 test_service_->SendTestSignal(kMessage); | 254 test_service_->SendTestSignal(kMessage); |
232 // Receive the signal with the object proxy. The signal is handled in | 255 // Receive the signal with the object proxy. The signal is handled in |
233 // EndToEndAsyncTest::OnTestSignal() in the main thread. | 256 // EndToEndAsyncTest::OnTestSignal() in the main thread. |
234 WaitForTestSignal(); | 257 WaitForTestSignal(); |
235 ASSERT_EQ(kMessage, test_signal_string_); | 258 ASSERT_EQ(kMessage, test_signal_string_); |
236 } | 259 } |
237 | 260 |
238 TEST_F(EndToEndAsyncTest, TestSignalFromRoot) { | 261 TEST_F(EndToEndAsyncTest, TestSignalFromRoot) { |
239 const char kMessage[] = "hello, world"; | 262 const char kMessage[] = "hello, world"; |
240 // Send the test signal from the root object path, to see if we can | 263 // Send the test signal from the root object path, to see if we can |
241 // handle signals sent from "/", like dbus-send does. | 264 // handle signals sent from "/", like dbus-send does. |
242 test_service_->SendTestSignalFromRoot(kMessage); | 265 test_service_->SendTestSignalFromRoot(kMessage); |
243 // Receive the signal with the object proxy. The signal is handled in | 266 // Receive the signal with the object proxy. The signal is handled in |
244 // EndToEndAsyncTest::OnTestSignal() in the main thread. | 267 // EndToEndAsyncTest::OnTestSignal() in the main thread. |
245 WaitForTestSignal(); | 268 WaitForTestSignal(); |
246 ASSERT_EQ(kMessage, test_signal_string_); | 269 ASSERT_EQ(kMessage, test_signal_string_); |
247 } | 270 } |
OLD | NEW |