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 7715f7d1826f822f28878f0b327242c7edd36016..6f2e0830817c3c7e19ecf593b82081f8a003f04e 100644 |
--- a/dbus/end_to_end_async_unittest.cc |
+++ b/dbus/end_to_end_async_unittest.cc |
@@ -20,6 +20,26 @@ |
#include "dbus/test_service.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+namespace dbus { |
+class DisconnectableBusForTesting : public Bus { |
+ public: |
+ explicit DisconnectableBusForTesting(const Options& options) |
+ : Bus(options) {} |
+ |
+ // Disconnects on-going connection. |
+ void CloseConnection() { |
+ CHECK(is_connected()) << "There is no on-going connection."; |
+ dbus_connection_close(connection_); |
+ } |
+ |
+ protected: |
+ ~DisconnectableBusForTesting() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(DisconnectableBusForTesting); |
+}; |
+} // namespace dbus |
+ |
namespace { |
// See comments in ObjectProxy::RunResponseCallback() for why the number was |
@@ -32,10 +52,12 @@ const int kHugePayloadSize = 64 << 20; // 64 MB |
// ExportedObject. |
class EndToEndAsyncTest : public testing::Test { |
public: |
- EndToEndAsyncTest() { |
- } |
+ EndToEndAsyncTest() : on_disconnected_callcount_(0) {} |
satorux1
2013/02/13 08:06:53
callcount -> call_count
Seigo Nonaka
2013/02/13 09:45:29
Done.
|
virtual void SetUp() { |
+ // Reset function call count. |
+ on_disconnected_callcount_ = 0; |
+ |
// Make the main thread not to allow IO. |
base::ThreadRestrictions::SetIOAllowed(false); |
@@ -125,6 +147,12 @@ class EndToEndAsyncTest : public testing::Test { |
test_service_->Stop(); |
} |
+ // Callback function for "Disconnected" signal. |
+ void OnDisconnected() { |
+ ++on_disconnected_callcount_; |
+ message_loop_.Quit(); |
+ } |
+ |
protected: |
// Replaces the bus with a broken one. |
void SetUpBrokenBus() { |
@@ -148,6 +176,38 @@ class EndToEndAsyncTest : public testing::Test { |
dbus::ObjectPath("/org/chromium/TestObject")); |
} |
+ // Replace the bus with DisconnectableBusFOrTesting. |
+ void SetUpDisconnectableBus() { |
+ // Shut down the existing bus. |
+ bus_->ShutdownOnDBusThreadAndBlock(); |
+ |
+ // Create new disconnectable bus. |
+ dbus::Bus::Options bus_options; |
+ bus_options.bus_type = dbus::Bus::SESSION; |
+ bus_options.connection_type = dbus::Bus::PRIVATE; |
+ bus_options.dbus_thread_message_loop_proxy = |
+ dbus_thread_->message_loop_proxy(); |
+ bus_ = new dbus::DisconnectableBusForTesting(bus_options); |
+ ASSERT_TRUE(bus_->HasDBusThread()); |
+ |
+ // Create new object proxy. |
+ object_proxy_ = bus_->GetObjectProxy( |
+ "org.chromium.TestService", |
+ dbus::ObjectPath("/org/chromium/TestObject")); |
+ |
+ // Connect to the "Test" signal of "org.chromium.TestInterface" from |
+ // the remote object. |
+ object_proxy_->ConnectToSignal( |
+ "org.chromium.TestInterface", |
+ "Test", |
+ base::Bind(&EndToEndAsyncTest::OnTestSignal, |
+ base::Unretained(this)), |
+ base::Bind(&EndToEndAsyncTest::OnConnected, |
+ base::Unretained(this))); |
+ // Wait until the object proxy is connected to the signal. |
+ message_loop_.Run(); |
+ } |
+ |
// Calls the method asynchronously. OnResponse() will be called once the |
// response is received. |
void CallMethod(dbus::MethodCall* method_call, |
@@ -260,6 +320,7 @@ class EndToEndAsyncTest : public testing::Test { |
std::string test_signal_string_; |
// Text message from "Test" signal delivered to root. |
std::string root_test_signal_string_; |
+ int on_disconnected_callcount_; |
}; |
TEST_F(EndToEndAsyncTest, Echo) { |
@@ -572,6 +633,29 @@ TEST_F(EndToEndAsyncTest, TestHugeSignal) { |
ASSERT_EQ(kHugeMessage, test_signal_string_); |
} |
+TEST_F(EndToEndAsyncTest, DisconnectedSignal) { |
+ // Set up a disconnectable bus. |
+ SetUpDisconnectableBus(); |
+ dbus::DisconnectableBusForTesting* disconnectable_bus = |
+ static_cast<dbus::DisconnectableBusForTesting*>(bus_.get()); |
+ |
+ disconnectable_bus->SetDisconnectedCallback( |
+ base::Bind(&EndToEndAsyncTest::OnDisconnected, |
+ base::Unretained(this))); |
+ |
+ // Request diconnect from daemon. |
+ disconnectable_bus->PostTaskToDBusThread( |
+ FROM_HERE, |
+ base::Bind( |
+ &dbus::DisconnectableBusForTesting::CloseConnection, |
+ base::Unretained(disconnectable_bus))); |
+ |
+ // OnDisconnected will quit message loop. |
+ message_loop_.Run(); |
+ |
+ EXPECT_EQ(1, on_disconnected_callcount_); |
+} |
+ |
class SignalReplacementTest : public EndToEndAsyncTest { |
public: |
SignalReplacementTest() { |