OLD | NEW |
1 // Copyright (c) 2011 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 <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/test/test_timeouts.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
16 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
17 #include "dbus/message.h" | 17 #include "dbus/message.h" |
| 18 #include "dbus/object_path.h" |
18 #include "dbus/object_proxy.h" | 19 #include "dbus/object_proxy.h" |
19 #include "dbus/test_service.h" | 20 #include "dbus/test_service.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 // The end-to-end test exercises the asynchronous APIs in ObjectProxy and | 23 // The end-to-end test exercises the asynchronous APIs in ObjectProxy and |
23 // ExportedObject. | 24 // ExportedObject. |
24 class EndToEndAsyncTest : public testing::Test { | 25 class EndToEndAsyncTest : public testing::Test { |
25 public: | 26 public: |
26 EndToEndAsyncTest() { | 27 EndToEndAsyncTest() { |
27 } | 28 } |
(...skipping 16 matching lines...) Expand all Loading... |
44 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); | 45 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); |
45 ASSERT_TRUE(test_service_->HasDBusThread()); | 46 ASSERT_TRUE(test_service_->HasDBusThread()); |
46 | 47 |
47 // Create the client, using the D-Bus thread. | 48 // Create the client, using the D-Bus thread. |
48 dbus::Bus::Options bus_options; | 49 dbus::Bus::Options bus_options; |
49 bus_options.bus_type = dbus::Bus::SESSION; | 50 bus_options.bus_type = dbus::Bus::SESSION; |
50 bus_options.connection_type = dbus::Bus::PRIVATE; | 51 bus_options.connection_type = dbus::Bus::PRIVATE; |
51 bus_options.dbus_thread_message_loop_proxy = | 52 bus_options.dbus_thread_message_loop_proxy = |
52 dbus_thread_->message_loop_proxy(); | 53 dbus_thread_->message_loop_proxy(); |
53 bus_ = new dbus::Bus(bus_options); | 54 bus_ = new dbus::Bus(bus_options); |
54 object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService", | 55 object_proxy_ = bus_->GetObjectProxy( |
55 "/org/chromium/TestObject"); | 56 "org.chromium.TestService", |
| 57 dbus::ObjectPath("/org/chromium/TestObject")); |
56 ASSERT_TRUE(bus_->HasDBusThread()); | 58 ASSERT_TRUE(bus_->HasDBusThread()); |
57 | 59 |
58 // Connect to the "Test" signal of "org.chromium.TestInterface" from | 60 // Connect to the "Test" signal of "org.chromium.TestInterface" from |
59 // the remote object. | 61 // the remote object. |
60 object_proxy_->ConnectToSignal( | 62 object_proxy_->ConnectToSignal( |
61 "org.chromium.TestInterface", | 63 "org.chromium.TestInterface", |
62 "Test", | 64 "Test", |
63 base::Bind(&EndToEndAsyncTest::OnTestSignal, | 65 base::Bind(&EndToEndAsyncTest::OnTestSignal, |
64 base::Unretained(this)), | 66 base::Unretained(this)), |
65 base::Bind(&EndToEndAsyncTest::OnConnected, | 67 base::Bind(&EndToEndAsyncTest::OnConnected, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 TEST_F(EndToEndAsyncTest, TestSignalFromRoot) { | 303 TEST_F(EndToEndAsyncTest, TestSignalFromRoot) { |
302 const char kMessage[] = "hello, world"; | 304 const char kMessage[] = "hello, world"; |
303 // Send the test signal from the root object path, to see if we can | 305 // Send the test signal from the root object path, to see if we can |
304 // handle signals sent from "/", like dbus-send does. | 306 // handle signals sent from "/", like dbus-send does. |
305 test_service_->SendTestSignalFromRoot(kMessage); | 307 test_service_->SendTestSignalFromRoot(kMessage); |
306 // Receive the signal with the object proxy. The signal is handled in | 308 // Receive the signal with the object proxy. The signal is handled in |
307 // EndToEndAsyncTest::OnTestSignal() in the main thread. | 309 // EndToEndAsyncTest::OnTestSignal() in the main thread. |
308 WaitForTestSignal(); | 310 WaitForTestSignal(); |
309 ASSERT_EQ(kMessage, test_signal_string_); | 311 ASSERT_EQ(kMessage, test_signal_string_); |
310 } | 312 } |
OLD | NEW |