Chromium Code Reviews| Index: dbus/bus_unittest.cc |
| diff --git a/dbus/bus_unittest.cc b/dbus/bus_unittest.cc |
| index bc155e75686dc05ce3248bc4524a4d2f981c6056..acbdaabc54cf194542c7c37c1ab76c940d827a5c 100644 |
| --- a/dbus/bus_unittest.cc |
| +++ b/dbus/bus_unittest.cc |
| @@ -84,6 +84,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(&base::DoNothing))); |
| + |
| + 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. |
|
satorux1
2013/01/29 03:58:39
Maybe add: We keep this object for a comparison at
deymo
2013/01/29 04:09:05
Done.
|
| + ASSERT_TRUE( |
| + bus->RemoveObjectProxy("org.chromium.TestService", |
| + dbus::ObjectPath("/org/chromium/TestObject"), |
| + base::Bind(&base::DoNothing))); |
| + |
| + // This should return a different object because the first object still |
| + // exists thanks to the increased reference. |
|
satorux1
2013/01/29 03:58:39
The comment was a bit confusing. Maybe:
// This s
deymo
2013/01/29 04:09:05
Done but added the fact that the object_proxy1 is
|
| + dbus::ObjectProxy* object_proxy2 = |
| + bus->GetObjectProxy("org.chromium.TestService", |
| + dbus::ObjectPath("/org/chromium/TestObject")); |
| + ASSERT_TRUE(object_proxy2); |
|
satorux1
2013/01/29 03:58:39
Then add something like
// Compare the new object
deymo
2013/01/29 04:09:05
Done.
|
| + 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); |