| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 17 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
| 18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 19 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 20 #include "dbus/bus.h" | 21 #include "dbus/bus.h" |
| 21 #include "dbus/message.h" | 22 #include "dbus/message.h" |
| 22 #include "dbus/object_path.h" | 23 #include "dbus/object_path.h" |
| 23 #include "dbus/object_proxy.h" | 24 #include "dbus/object_proxy.h" |
| 24 #include "dbus/test_service.h" | 25 #include "dbus/test_service.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 CallMethod(&method_call, timeout_ms); | 435 CallMethod(&method_call, timeout_ms); |
| 435 | 436 |
| 436 // Remove the object proxy before receiving the result. | 437 // Remove the object proxy before receiving the result. |
| 437 // This results in cancelling the pending method call. | 438 // This results in cancelling the pending method call. |
| 438 bus_->RemoveObjectProxy(test_service_->service_name(), | 439 bus_->RemoveObjectProxy(test_service_->service_name(), |
| 439 ObjectPath("/org/chromium/TestObject"), | 440 ObjectPath("/org/chromium/TestObject"), |
| 440 base::Bind(&base::DoNothing)); | 441 base::Bind(&base::DoNothing)); |
| 441 | 442 |
| 442 // We shouldn't receive any responses. Wait for a while just to make sure. | 443 // We shouldn't receive any responses. Wait for a while just to make sure. |
| 443 run_loop_.reset(new base::RunLoop); | 444 run_loop_.reset(new base::RunLoop); |
| 444 message_loop_.PostDelayedTask(FROM_HERE, | 445 message_loop_.task_runner()->PostDelayedTask( |
| 445 run_loop_->QuitClosure(), | 446 FROM_HERE, run_loop_->QuitClosure(), TestTimeouts::tiny_timeout()); |
| 446 TestTimeouts::tiny_timeout()); | |
| 447 run_loop_->Run(); | 447 run_loop_->Run(); |
| 448 EXPECT_TRUE(response_strings_.empty()); | 448 EXPECT_TRUE(response_strings_.empty()); |
| 449 } | 449 } |
| 450 | 450 |
| 451 // Tests calling a method that sends its reply asynchronously. | 451 // Tests calling a method that sends its reply asynchronously. |
| 452 TEST_F(EndToEndAsyncTest, AsyncEcho) { | 452 TEST_F(EndToEndAsyncTest, AsyncEcho) { |
| 453 const char* kHello = "hello"; | 453 const char* kHello = "hello"; |
| 454 | 454 |
| 455 // Create the method call. | 455 // Create the method call. |
| 456 MethodCall method_call("org.chromium.TestInterface", "AsyncEcho"); | 456 MethodCall method_call("org.chromium.TestInterface", "AsyncEcho"); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 MessageWriter writer(&method_call); | 558 MessageWriter writer(&method_call); |
| 559 writer.AppendString(kHello); | 559 writer.AppendString(kHello); |
| 560 | 560 |
| 561 // Call the method with an empty callback. | 561 // Call the method with an empty callback. |
| 562 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; | 562 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; |
| 563 object_proxy_->CallMethod(&method_call, | 563 object_proxy_->CallMethod(&method_call, |
| 564 timeout_ms, | 564 timeout_ms, |
| 565 ObjectProxy::EmptyResponseCallback()); | 565 ObjectProxy::EmptyResponseCallback()); |
| 566 // Post a delayed task to quit the message loop. | 566 // Post a delayed task to quit the message loop. |
| 567 run_loop_.reset(new base::RunLoop); | 567 run_loop_.reset(new base::RunLoop); |
| 568 message_loop_.PostDelayedTask(FROM_HERE, | 568 message_loop_.task_runner()->PostDelayedTask( |
| 569 run_loop_->QuitClosure(), | 569 FROM_HERE, run_loop_->QuitClosure(), TestTimeouts::tiny_timeout()); |
| 570 TestTimeouts::tiny_timeout()); | |
| 571 run_loop_->Run(); | 570 run_loop_->Run(); |
| 572 // We cannot tell if the empty callback is called, but at least we can | 571 // We cannot tell if the empty callback is called, but at least we can |
| 573 // check if the test does not crash. | 572 // check if the test does not crash. |
| 574 } | 573 } |
| 575 | 574 |
| 576 TEST_F(EndToEndAsyncTest, TestSignal) { | 575 TEST_F(EndToEndAsyncTest, TestSignal) { |
| 577 const char kMessage[] = "hello, world"; | 576 const char kMessage[] = "hello, world"; |
| 578 // Send the test signal from the exported object. | 577 // Send the test signal from the exported object. |
| 579 test_service_->SendTestSignal(kMessage); | 578 test_service_->SendTestSignal(kMessage); |
| 580 // Receive the signal with the object proxy. The signal is handled in | 579 // Receive the signal with the object proxy. The signal is handled in |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 test_service_->SendTestSignal(kMessage); | 657 test_service_->SendTestSignal(kMessage); |
| 659 // Receive the signal with the object proxy. | 658 // Receive the signal with the object proxy. |
| 660 WaitForTestSignal(); | 659 WaitForTestSignal(); |
| 661 // Verify the string WAS received by the original handler. | 660 // Verify the string WAS received by the original handler. |
| 662 ASSERT_EQ(kMessage, test_signal_string_); | 661 ASSERT_EQ(kMessage, test_signal_string_); |
| 663 // Verify the signal WAS ALSO received by the additional handler. | 662 // Verify the signal WAS ALSO received by the additional handler. |
| 664 ASSERT_EQ(kMessage, additional_test_signal_string_); | 663 ASSERT_EQ(kMessage, additional_test_signal_string_); |
| 665 } | 664 } |
| 666 | 665 |
| 667 } // namespace dbus | 666 } // namespace dbus |
| OLD | NEW |