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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 dbus::Bus::Options bus_options; | 48 dbus::Bus::Options bus_options; |
49 bus_options.bus_type = dbus::Bus::SESSION; | 49 bus_options.bus_type = dbus::Bus::SESSION; |
50 bus_options.connection_type = dbus::Bus::PRIVATE; | 50 bus_options.connection_type = dbus::Bus::PRIVATE; |
51 bus_options.dbus_thread_message_loop_proxy = | 51 bus_options.dbus_thread_message_loop_proxy = |
52 dbus_thread_->message_loop_proxy(); | 52 dbus_thread_->message_loop_proxy(); |
53 bus_ = new dbus::Bus(bus_options); | 53 bus_ = new dbus::Bus(bus_options); |
54 object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService", | 54 object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService", |
55 "/org/chromium/TestObject"); | 55 "/org/chromium/TestObject"); |
56 ASSERT_TRUE(bus_->HasDBusThread()); | 56 ASSERT_TRUE(bus_->HasDBusThread()); |
57 | 57 |
58 // Connect to the "Test" signal from the remote object. | 58 // Connect to the "Test" signal of "org.chromium.TestInterface" from |
59 // the remote object. | |
59 object_proxy_->ConnectToSignal( | 60 object_proxy_->ConnectToSignal( |
60 "org.chromium.TestInterface", | 61 "org.chromium.TestInterface", |
61 "Test", | 62 "Test", |
62 base::Bind(&EndToEndAsyncTest::OnTestSignal, | 63 base::Bind(&EndToEndAsyncTest::OnTestSignal, |
63 base::Unretained(this)), | 64 base::Unretained(this)), |
64 base::Bind(&EndToEndAsyncTest::OnConnected, | 65 base::Bind(&EndToEndAsyncTest::OnConnected, |
65 base::Unretained(this))); | 66 base::Unretained(this))); |
67 // Connect to the "Test2" signal of "org.chromium.TestInterface" from | |
68 // the remote object. There was a bug where we were emitting error | |
69 // messages like "Requested to remove an unknown match rule: ..." at | |
70 // the shutdown of Bus when an object proxy is connected to more than | |
71 // one signal of the same interface. See crosbug.com/23382 for details. | |
72 object_proxy_->ConnectToSignal( | |
73 "org.chromium.TestInterface", | |
74 "Test2", | |
75 base::Bind(&EndToEndAsyncTest::OnTest2Signal, | |
76 base::Unretained(this)), | |
77 base::Bind(&EndToEndAsyncTest::OnConnected, | |
78 base::Unretained(this))); | |
66 // Wait until the object proxy is connected to the signal. | 79 // Wait until the object proxy is connected to the signal. |
67 message_loop_.Run(); | 80 message_loop_.Run(); |
68 } | 81 } |
69 | 82 |
70 virtual void TearDown() { | 83 virtual void TearDown() { |
71 bus_->ShutdownOnDBusThreadAndBlock(); | 84 bus_->ShutdownOnDBusThreadAndBlock(); |
72 | 85 |
73 // Shut down the service. | 86 // Shut down the service. |
74 test_service_->ShutdownAndBlock(); | 87 test_service_->ShutdownAndBlock(); |
75 | 88 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 }; | 128 }; |
116 | 129 |
117 // Called when the "Test" signal is received, in the main thread. | 130 // Called when the "Test" signal is received, in the main thread. |
118 // Copy the string payload to |test_signal_string_|. | 131 // Copy the string payload to |test_signal_string_|. |
119 void OnTestSignal(dbus::Signal* signal) { | 132 void OnTestSignal(dbus::Signal* signal) { |
120 dbus::MessageReader reader(signal); | 133 dbus::MessageReader reader(signal); |
121 ASSERT_TRUE(reader.PopString(&test_signal_string_)); | 134 ASSERT_TRUE(reader.PopString(&test_signal_string_)); |
122 message_loop_.Quit(); | 135 message_loop_.Quit(); |
123 } | 136 } |
124 | 137 |
138 // Called when the "Test2" signal is received, in the main thread. | |
139 // Copy the string payload to |test_signal_string_|. | |
stevenjb
2011/11/23 21:24:55
Copy comment invalid.
satorux1
2011/11/23 21:47:37
Done.
| |
140 void OnTest2Signal(dbus::Signal* signal) { | |
141 dbus::MessageReader reader(signal); | |
142 message_loop_.Quit(); | |
143 } | |
144 | |
125 // Called when connected to the signal. | 145 // Called when connected to the signal. |
126 void OnConnected(const std::string& interface_name, | 146 void OnConnected(const std::string& interface_name, |
127 const std::string& signal_name, | 147 const std::string& signal_name, |
128 bool success) { | 148 bool success) { |
129 ASSERT_TRUE(success); | 149 ASSERT_TRUE(success); |
130 message_loop_.Quit(); | 150 message_loop_.Quit(); |
131 } | 151 } |
132 | 152 |
133 // Wait for the hey signal to be received. | 153 // Wait for the hey signal to be received. |
134 void WaitForTestSignal() { | 154 void WaitForTestSignal() { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 TEST_F(EndToEndAsyncTest, TestSignalFromRoot) { | 281 TEST_F(EndToEndAsyncTest, TestSignalFromRoot) { |
262 const char kMessage[] = "hello, world"; | 282 const char kMessage[] = "hello, world"; |
263 // Send the test signal from the root object path, to see if we can | 283 // Send the test signal from the root object path, to see if we can |
264 // handle signals sent from "/", like dbus-send does. | 284 // handle signals sent from "/", like dbus-send does. |
265 test_service_->SendTestSignalFromRoot(kMessage); | 285 test_service_->SendTestSignalFromRoot(kMessage); |
266 // Receive the signal with the object proxy. The signal is handled in | 286 // Receive the signal with the object proxy. The signal is handled in |
267 // EndToEndAsyncTest::OnTestSignal() in the main thread. | 287 // EndToEndAsyncTest::OnTestSignal() in the main thread. |
268 WaitForTestSignal(); | 288 WaitForTestSignal(); |
269 ASSERT_EQ(kMessage, test_signal_string_); | 289 ASSERT_EQ(kMessage, test_signal_string_); |
270 } | 290 } |
OLD | NEW |