Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3150)

Unified Diff: dbus/end_to_end_async_unittest.cc

Issue 9508005: dbus: verify object path of incoming signals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fixes Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dbus/object_proxy.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/end_to_end_async_unittest.cc
diff --git a/dbus/end_to_end_async_unittest.cc b/dbus/end_to_end_async_unittest.cc
index 9a88b42cffec6d1830bd479ab8b9bb9a3a5ee8ca..302b7b4758569fa0aa732a5a8f2110834f81145a 100644
--- a/dbus/end_to_end_async_unittest.cc
+++ b/dbus/end_to_end_async_unittest.cc
@@ -83,6 +83,24 @@ class EndToEndAsyncTest : public testing::Test {
base::Unretained(this)));
// Wait until the object proxy is connected to the signal.
message_loop_.Run();
+
+ // Create a second object proxy for the root object.
+ root_object_proxy_ = bus_->GetObjectProxy(
+ "org.chromium.TestService",
+ dbus::ObjectPath("/"));
+ ASSERT_TRUE(bus_->HasDBusThread());
+
+ // Connect to the "Test" signal of "org.chromium.TestInterface" from
+ // the root remote object too.
+ root_object_proxy_->ConnectToSignal(
+ "org.chromium.TestInterface",
+ "Test",
+ base::Bind(&EndToEndAsyncTest::OnRootTestSignal,
+ base::Unretained(this)),
+ base::Bind(&EndToEndAsyncTest::OnConnected,
+ base::Unretained(this)));
+ // Wait until the root object proxy is connected to the signal.
+ message_loop_.Run();
}
virtual void TearDown() {
@@ -140,6 +158,15 @@ class EndToEndAsyncTest : public testing::Test {
message_loop_.Quit();
}
+ // Called when the "Test" signal is received, in the main thread, by
+ // the root object proxy. Copy the string payload to
+ // |root_test_signal_string_|.
+ void OnRootTestSignal(dbus::Signal* signal) {
+ dbus::MessageReader reader(signal);
+ ASSERT_TRUE(reader.PopString(&root_test_signal_string_));
+ message_loop_.Quit();
+ }
+
// Called when the "Test2" signal is received, in the main thread.
void OnTest2Signal(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
@@ -165,9 +192,12 @@ class EndToEndAsyncTest : public testing::Test {
scoped_ptr<base::Thread> dbus_thread_;
scoped_refptr<dbus::Bus> bus_;
dbus::ObjectProxy* object_proxy_;
+ dbus::ObjectProxy* root_object_proxy_;
scoped_ptr<dbus::TestService> test_service_;
// Text message from "Test" signal.
std::string test_signal_string_;
+ // Text message from "Test" signal delivered to root.
+ std::string root_test_signal_string_;
};
TEST_F(EndToEndAsyncTest, Echo) {
@@ -302,11 +332,14 @@ TEST_F(EndToEndAsyncTest, TestSignal) {
TEST_F(EndToEndAsyncTest, TestSignalFromRoot) {
const char kMessage[] = "hello, world";
- // Send the test signal from the root object path, to see if we can
- // handle signals sent from "/", like dbus-send does.
+ // Object proxies are tied to a particular object path, if a signal
+ // arrives from a different object path like "/" the first object proxy
+ // |object_proxy_| should not handle it, and should leave it for the root
+ // object proxy |root_object_proxy_|.
test_service_->SendTestSignalFromRoot(kMessage);
- // Receive the signal with the object proxy. The signal is handled in
- // EndToEndAsyncTest::OnTestSignal() in the main thread.
WaitForTestSignal();
- ASSERT_EQ(kMessage, test_signal_string_);
+ // Verify the signal was not received by the specific proxy.
+ ASSERT_TRUE(test_signal_string_.empty());
+ // Verify the string WAS received by the root proxy.
+ ASSERT_EQ(kMessage, root_test_signal_string_);
}
« no previous file with comments | « no previous file | dbus/object_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698