OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "dbus/bus.h" | 5 #include "dbus/bus.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // This should not. | 101 // This should not. |
102 dbus::ExportedObject* object_proxy3 = | 102 dbus::ExportedObject* object_proxy3 = |
103 bus->GetExportedObject( | 103 bus->GetExportedObject( |
104 dbus::ObjectPath("/org/chromium/DifferentTestObject")); | 104 dbus::ObjectPath("/org/chromium/DifferentTestObject")); |
105 ASSERT_TRUE(object_proxy3); | 105 ASSERT_TRUE(object_proxy3); |
106 EXPECT_NE(object_proxy1, object_proxy3); | 106 EXPECT_NE(object_proxy1, object_proxy3); |
107 | 107 |
108 bus->ShutdownAndBlock(); | 108 bus->ShutdownAndBlock(); |
109 } | 109 } |
110 | 110 |
| 111 TEST(BusTest, UnregisterExportedObject) { |
| 112 // Start the D-Bus thread. |
| 113 base::Thread::Options thread_options; |
| 114 thread_options.message_loop_type = MessageLoop::TYPE_IO; |
| 115 base::Thread dbus_thread("D-Bus thread"); |
| 116 dbus_thread.StartWithOptions(thread_options); |
| 117 |
| 118 // Create the bus. |
| 119 dbus::Bus::Options options; |
| 120 options.dbus_thread_message_loop_proxy = dbus_thread.message_loop_proxy(); |
| 121 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
| 122 ASSERT_FALSE(bus->shutdown_completed()); |
| 123 |
| 124 dbus::ExportedObject* object_proxy1 = |
| 125 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); |
| 126 ASSERT_TRUE(object_proxy1); |
| 127 |
| 128 bus->UnregisterExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); |
| 129 |
| 130 // This should return a new object. |
| 131 dbus::ExportedObject* object_proxy2 = |
| 132 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); |
| 133 ASSERT_TRUE(object_proxy2); |
| 134 EXPECT_NE(object_proxy1, object_proxy2); |
| 135 |
| 136 // Shut down synchronously. |
| 137 bus->ShutdownOnDBusThreadAndBlock(); |
| 138 EXPECT_TRUE(bus->shutdown_completed()); |
| 139 dbus_thread.Stop(); |
| 140 } |
| 141 |
111 TEST(BusTest, ShutdownAndBlock) { | 142 TEST(BusTest, ShutdownAndBlock) { |
112 dbus::Bus::Options options; | 143 dbus::Bus::Options options; |
113 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 144 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
114 ASSERT_FALSE(bus->shutdown_completed()); | 145 ASSERT_FALSE(bus->shutdown_completed()); |
115 | 146 |
116 // Shut down synchronously. | 147 // Shut down synchronously. |
117 bus->ShutdownAndBlock(); | 148 bus->ShutdownAndBlock(); |
118 EXPECT_TRUE(bus->shutdown_completed()); | 149 EXPECT_TRUE(bus->shutdown_completed()); |
119 } | 150 } |
120 | 151 |
(...skipping 29 matching lines...) Expand all Loading... |
150 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); | 181 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); |
151 // Can add the same function with different data. | 182 // Can add the same function with different data. |
152 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); | 183 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); |
153 | 184 |
154 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 185 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
155 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 186 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
156 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); | 187 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); |
157 | 188 |
158 bus->ShutdownAndBlock(); | 189 bus->ShutdownAndBlock(); |
159 } | 190 } |
OLD | NEW |