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

Unified Diff: dbus/bus_unittest.cc

Issue 12022004: D-Bus: ObjectProxy remove function for Bus object. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Calls made from the right thread. Created 7 years, 11 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
« dbus/bus.cc ('K') | « dbus/bus.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/bus_unittest.cc
diff --git a/dbus/bus_unittest.cc b/dbus/bus_unittest.cc
index ca24041f86c309a07989cc379d6c6a197dc13059..ad336bcdb906f09370b282a780dfee697054a923 100644
--- a/dbus/bus_unittest.cc
+++ b/dbus/bus_unittest.cc
@@ -23,6 +23,14 @@ DBusHandlerResult DummyHandler(DBusConnection* connection,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
+// Used to test RemoveObjectProxy
+void OnRemoveObjectProxy(
+ const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ int options) {
+
Haruki Sato 2013/01/23 09:34:05 extra line?
deymo 2013/01/23 19:23:46 Done.
+}
+
} // namespace
TEST(BusTest, GetObjectProxy) {
@@ -84,6 +92,61 @@ TEST(BusTest, GetObjectProxyIgnoreUnknownService) {
bus->ShutdownAndBlock();
}
+TEST(BusTest, RemoveObjectProxy) {
+ // Setup the current thread's MessageLoop.
+ MessageLoop message_loop;
+
+ // Start the D-Bus thread.
+ base::Thread::Options thread_options;
+ thread_options.message_loop_type = MessageLoop::TYPE_IO;
+ base::Thread dbus_thread("D-Bus thread");
+ dbus_thread.StartWithOptions(thread_options);
+
+ // Create the bus.
+ dbus::Bus::Options options;
+ options.dbus_thread_message_loop_proxy = dbus_thread.message_loop_proxy();
+ scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
+ ASSERT_FALSE(bus->shutdown_completed());
+
+ // Try to remove a non existant object proxy should return false.
+ ASSERT_FALSE(
+ bus->RemoveObjectProxy("org.chromium.TestService",
+ dbus::ObjectPath("/org/chromium/TestObject"),
+ base::Bind(&OnRemoveObjectProxy)));
+
+ dbus::ObjectProxy* object_proxy1 =
+ bus->GetObjectProxy("org.chromium.TestService",
+ dbus::ObjectPath("/org/chromium/TestObject"));
+ ASSERT_TRUE(object_proxy1);
+
+ // Increment the reference count to the object proxy to avoid destroying it
+ // while removing the object.
+ object_proxy1->AddRef();
+
+ // Remove the object from the bus. This will invalidate any other usage of
+ // object_proxy1 other than destroy it.
+ ASSERT_TRUE(
+ bus->RemoveObjectProxy("org.chromium.TestService",
+ dbus::ObjectPath("/org/chromium/TestObject"),
+ base::Bind(&OnRemoveObjectProxy)));
+
+ // This should return a different object because the first object still
+ // exists thanks to the increased reference.
+ dbus::ObjectProxy* object_proxy2 =
+ bus->GetObjectProxy("org.chromium.TestService",
+ dbus::ObjectPath("/org/chromium/TestObject"));
+ ASSERT_TRUE(object_proxy2);
+ EXPECT_NE(object_proxy1, object_proxy2);
+
+ // Release object_proxy1.
+ object_proxy1->Release();
+
+ // Shut down synchronously.
+ bus->ShutdownOnDBusThreadAndBlock();
+ EXPECT_TRUE(bus->shutdown_completed());
+ dbus_thread.Stop();
+}
+
TEST(BusTest, GetExportedObject) {
dbus::Bus::Options options;
scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
« dbus/bus.cc ('K') | « dbus/bus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698