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