blob: 84bbb783f390a70d40f065173059bf46ce2096ab [file] [log] [blame]
adamk@chromium.org35c0eef2012-02-11 06:45:23 +09001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "dbus/bus.h"
6
satorux@chromium.orgd336d452011-09-02 15:56:23 +09007#include "base/bind.h"
avi0ad0ce02015-12-23 03:12:45 +09008#include "base/macros.h"
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +09009#include "base/memory/ref_counted.h"
avi@chromium.orga29af562013-07-18 08:00:30 +090010#include "base/message_loop/message_loop.h"
thestig@chromium.orgc2482f12013-06-11 07:52:34 +090011#include "base/run_loop.h"
satorux@chromium.orgd336d452011-09-02 15:56:23 +090012#include "base/threading/thread.h"
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090013#include "dbus/exported_object.h"
keybuk@google.combf4649a2012-02-15 06:29:06 +090014#include "dbus/object_path.h"
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090015#include "dbus/object_proxy.h"
deymo@chromium.org7894ebf2013-01-31 15:08:02 +090016#include "dbus/scoped_dbus_error.h"
thestig@chromium.orgc2482f12013-06-11 07:52:34 +090017#include "dbus/test_service.h"
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090018
19#include "testing/gtest/include/gtest/gtest.h"
20
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090021namespace dbus {
22
satorux@chromium.org66bc4c22011-10-06 09:20:53 +090023namespace {
24
thestig@chromium.orgc2482f12013-06-11 07:52:34 +090025// Test helper for BusTest.ListenForServiceOwnerChange that wraps a
26// base::RunLoop. At Run() time, the caller pass in the expected number of
27// quit calls, and at QuitIfConditionIsSatisified() time, only quit the RunLoop
28// if the expected number of quit calls have been reached.
29class RunLoopWithExpectedCount {
30 public:
31 RunLoopWithExpectedCount() : expected_quit_calls_(0), actual_quit_calls_(0) {}
32 ~RunLoopWithExpectedCount() {}
33
34 void Run(int expected_quit_calls) {
35 DCHECK_EQ(0, expected_quit_calls_);
36 DCHECK_EQ(0, actual_quit_calls_);
37 expected_quit_calls_ = expected_quit_calls;
38 run_loop_.reset(new base::RunLoop());
39 run_loop_->Run();
40 }
41
42 void QuitIfConditionIsSatisified() {
43 if (++actual_quit_calls_ != expected_quit_calls_)
44 return;
45 run_loop_->Quit();
46 expected_quit_calls_ = 0;
47 actual_quit_calls_ = 0;
48 }
49
50 private:
dcheng30c5a172016-04-09 07:55:04 +090051 std::unique_ptr<base::RunLoop> run_loop_;
thestig@chromium.orgc2482f12013-06-11 07:52:34 +090052 int expected_quit_calls_;
53 int actual_quit_calls_;
54
55 DISALLOW_COPY_AND_ASSIGN(RunLoopWithExpectedCount);
56};
57
58// Test helper for BusTest.ListenForServiceOwnerChange.
59void OnServiceOwnerChanged(RunLoopWithExpectedCount* run_loop_state,
60 std::string* service_owner,
61 int* num_of_owner_changes,
62 const std::string& new_service_owner) {
63 *service_owner = new_service_owner;
64 ++(*num_of_owner_changes);
65 run_loop_state->QuitIfConditionIsSatisified();
66}
67
satorux@chromium.org66bc4c22011-10-06 09:20:53 +090068} // namespace
69
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090070TEST(BusTest, GetObjectProxy) {
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090071 Bus::Options options;
72 scoped_refptr<Bus> bus = new Bus(options);
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090073
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090074 ObjectProxy* object_proxy1 =
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090075 bus->GetObjectProxy("org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090076 ObjectPath("/org/chromium/TestObject"));
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090077 ASSERT_TRUE(object_proxy1);
78
79 // This should return the same object.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090080 ObjectProxy* object_proxy2 =
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090081 bus->GetObjectProxy("org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090082 ObjectPath("/org/chromium/TestObject"));
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090083 ASSERT_TRUE(object_proxy2);
84 EXPECT_EQ(object_proxy1, object_proxy2);
85
86 // This should not.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090087 ObjectProxy* object_proxy3 =
keybuk@google.combf4649a2012-02-15 06:29:06 +090088 bus->GetObjectProxy(
89 "org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090090 ObjectPath("/org/chromium/DifferentTestObject"));
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090091 ASSERT_TRUE(object_proxy3);
92 EXPECT_NE(object_proxy1, object_proxy3);
satorux@chromium.orgf06eb892011-10-13 09:45:26 +090093
94 bus->ShutdownAndBlock();
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +090095}
96
adamk@chromium.org35c0eef2012-02-11 06:45:23 +090097TEST(BusTest, GetObjectProxyIgnoreUnknownService) {
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090098 Bus::Options options;
99 scoped_refptr<Bus> bus = new Bus(options);
adamk@chromium.org35c0eef2012-02-11 06:45:23 +0900100
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900101 ObjectProxy* object_proxy1 =
adamk@chromium.org35c0eef2012-02-11 06:45:23 +0900102 bus->GetObjectProxyWithOptions(
103 "org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900104 ObjectPath("/org/chromium/TestObject"),
105 ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS);
adamk@chromium.org35c0eef2012-02-11 06:45:23 +0900106 ASSERT_TRUE(object_proxy1);
107
108 // This should return the same object.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900109 ObjectProxy* object_proxy2 =
adamk@chromium.org35c0eef2012-02-11 06:45:23 +0900110 bus->GetObjectProxyWithOptions(
111 "org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900112 ObjectPath("/org/chromium/TestObject"),
113 ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS);
adamk@chromium.org35c0eef2012-02-11 06:45:23 +0900114 ASSERT_TRUE(object_proxy2);
115 EXPECT_EQ(object_proxy1, object_proxy2);
116
117 // This should not.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900118 ObjectProxy* object_proxy3 =
adamk@chromium.org35c0eef2012-02-11 06:45:23 +0900119 bus->GetObjectProxyWithOptions(
120 "org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900121 ObjectPath("/org/chromium/DifferentTestObject"),
122 ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS);
adamk@chromium.org35c0eef2012-02-11 06:45:23 +0900123 ASSERT_TRUE(object_proxy3);
124 EXPECT_NE(object_proxy1, object_proxy3);
125
126 bus->ShutdownAndBlock();
127}
128
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900129TEST(BusTest, RemoveObjectProxy) {
130 // Setup the current thread's MessageLoop.
xhwang@chromium.orgdff6b132013-05-02 01:10:30 +0900131 base::MessageLoop message_loop;
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900132
133 // Start the D-Bus thread.
134 base::Thread::Options thread_options;
xhwang@chromium.orgdff6b132013-05-02 01:10:30 +0900135 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900136 base::Thread dbus_thread("D-Bus thread");
137 dbus_thread.StartWithOptions(thread_options);
138
139 // Create the bus.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900140 Bus::Options options;
skyostile5a8dc42015-06-18 00:46:04 +0900141 options.dbus_task_runner = dbus_thread.task_runner();
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900142 scoped_refptr<Bus> bus = new Bus(options);
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900143 ASSERT_FALSE(bus->shutdown_completed());
144
145 // Try to remove a non existant object proxy should return false.
146 ASSERT_FALSE(
147 bus->RemoveObjectProxy("org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900148 ObjectPath("/org/chromium/TestObject"),
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900149 base::Bind(&base::DoNothing)));
150
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900151 ObjectProxy* object_proxy1 =
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900152 bus->GetObjectProxy("org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900153 ObjectPath("/org/chromium/TestObject"));
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900154 ASSERT_TRUE(object_proxy1);
155
156 // Increment the reference count to the object proxy to avoid destroying it
157 // while removing the object.
158 object_proxy1->AddRef();
159
160 // Remove the object from the bus. This will invalidate any other usage of
161 // object_proxy1 other than destroy it. We keep this object for a comparison
162 // at a later time.
163 ASSERT_TRUE(
164 bus->RemoveObjectProxy("org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900165 ObjectPath("/org/chromium/TestObject"),
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900166 base::Bind(&base::DoNothing)));
167
168 // This should return a different object because the first object was removed
169 // from the bus, but not deleted from memory.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900170 ObjectProxy* object_proxy2 =
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900171 bus->GetObjectProxy("org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900172 ObjectPath("/org/chromium/TestObject"));
deymo@chromium.org6d168a72013-01-30 05:29:12 +0900173 ASSERT_TRUE(object_proxy2);
174
175 // Compare the new object with the first object. The first object still exists
176 // thanks to the increased reference.
177 EXPECT_NE(object_proxy1, object_proxy2);
178
179 // Release object_proxy1.
180 object_proxy1->Release();
181
182 // Shut down synchronously.
183 bus->ShutdownOnDBusThreadAndBlock();
184 EXPECT_TRUE(bus->shutdown_completed());
185 dbus_thread.Stop();
186}
187
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +0900188TEST(BusTest, GetExportedObject) {
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900189 Bus::Options options;
190 scoped_refptr<Bus> bus = new Bus(options);
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +0900191
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900192 ExportedObject* object_proxy1 =
193 bus->GetExportedObject(ObjectPath("/org/chromium/TestObject"));
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +0900194 ASSERT_TRUE(object_proxy1);
195
196 // This should return the same object.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900197 ExportedObject* object_proxy2 =
198 bus->GetExportedObject(ObjectPath("/org/chromium/TestObject"));
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +0900199 ASSERT_TRUE(object_proxy2);
200 EXPECT_EQ(object_proxy1, object_proxy2);
201
202 // This should not.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900203 ExportedObject* object_proxy3 =
keybuk@google.combf4649a2012-02-15 06:29:06 +0900204 bus->GetExportedObject(
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900205 ObjectPath("/org/chromium/DifferentTestObject"));
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +0900206 ASSERT_TRUE(object_proxy3);
207 EXPECT_NE(object_proxy1, object_proxy3);
satorux@chromium.orgf06eb892011-10-13 09:45:26 +0900208
209 bus->ShutdownAndBlock();
satorux@chromium.orgdccbb7b2011-08-24 04:25:20 +0900210}
satorux@chromium.orgd336d452011-09-02 15:56:23 +0900211
deymo@chromium.org03ec2482013-01-24 09:58:35 +0900212TEST(BusTest, UnregisterExportedObject) {
keybuk@chromium.orgd2ca8f32012-03-14 10:18:35 +0900213 // Start the D-Bus thread.
214 base::Thread::Options thread_options;
xhwang@chromium.orgdff6b132013-05-02 01:10:30 +0900215 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
keybuk@chromium.orgd2ca8f32012-03-14 10:18:35 +0900216 base::Thread dbus_thread("D-Bus thread");
217 dbus_thread.StartWithOptions(thread_options);
218
219 // Create the bus.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900220 Bus::Options options;
skyostile5a8dc42015-06-18 00:46:04 +0900221 options.dbus_task_runner = dbus_thread.task_runner();
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900222 scoped_refptr<Bus> bus = new Bus(options);
keybuk@chromium.orgd2ca8f32012-03-14 10:18:35 +0900223 ASSERT_FALSE(bus->shutdown_completed());
224
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900225 ExportedObject* object_proxy1 =
226 bus->GetExportedObject(ObjectPath("/org/chromium/TestObject"));
keybuk@chromium.orgd2ca8f32012-03-14 10:18:35 +0900227 ASSERT_TRUE(object_proxy1);
228
deymo@chromium.org03ec2482013-01-24 09:58:35 +0900229 // Increment the reference count to the object proxy to avoid destroying it
230 // calling UnregisterExportedObject. This ensures the dbus::ExportedObject is
231 // not freed from memory. See http://crbug.com/137846 for details.
232 object_proxy1->AddRef();
233
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900234 bus->UnregisterExportedObject(ObjectPath("/org/chromium/TestObject"));
keybuk@chromium.orgd2ca8f32012-03-14 10:18:35 +0900235
deymo@chromium.org03ec2482013-01-24 09:58:35 +0900236 // This should return a new object because the object_proxy1 is still in
237 // alloc'ed memory.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900238 ExportedObject* object_proxy2 =
239 bus->GetExportedObject(ObjectPath("/org/chromium/TestObject"));
keybuk@chromium.orgd2ca8f32012-03-14 10:18:35 +0900240 ASSERT_TRUE(object_proxy2);
241 EXPECT_NE(object_proxy1, object_proxy2);
242
deymo@chromium.org03ec2482013-01-24 09:58:35 +0900243 // Release the incremented reference.
244 object_proxy1->Release();
245
keybuk@chromium.orgd2ca8f32012-03-14 10:18:35 +0900246 // Shut down synchronously.
247 bus->ShutdownOnDBusThreadAndBlock();
248 EXPECT_TRUE(bus->shutdown_completed());
249 dbus_thread.Stop();
250}
251
satorux@chromium.orgd336d452011-09-02 15:56:23 +0900252TEST(BusTest, ShutdownAndBlock) {
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900253 Bus::Options options;
254 scoped_refptr<Bus> bus = new Bus(options);
satorux@chromium.orgd336d452011-09-02 15:56:23 +0900255 ASSERT_FALSE(bus->shutdown_completed());
256
257 // Shut down synchronously.
258 bus->ShutdownAndBlock();
259 EXPECT_TRUE(bus->shutdown_completed());
260}
261
262TEST(BusTest, ShutdownAndBlockWithDBusThread) {
263 // Start the D-Bus thread.
264 base::Thread::Options thread_options;
xhwang@chromium.orgdff6b132013-05-02 01:10:30 +0900265 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
satorux@chromium.orgd336d452011-09-02 15:56:23 +0900266 base::Thread dbus_thread("D-Bus thread");
267 dbus_thread.StartWithOptions(thread_options);
268
269 // Create the bus.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900270 Bus::Options options;
skyostile5a8dc42015-06-18 00:46:04 +0900271 options.dbus_task_runner = dbus_thread.task_runner();
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900272 scoped_refptr<Bus> bus = new Bus(options);
satorux@chromium.orgd336d452011-09-02 15:56:23 +0900273 ASSERT_FALSE(bus->shutdown_completed());
274
275 // Shut down synchronously.
276 bus->ShutdownOnDBusThreadAndBlock();
277 EXPECT_TRUE(bus->shutdown_completed());
278 dbus_thread.Stop();
279}
satorux@chromium.org66bc4c22011-10-06 09:20:53 +0900280
deymo@chromium.org7894ebf2013-01-31 15:08:02 +0900281TEST(BusTest, DoubleAddAndRemoveMatch) {
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900282 Bus::Options options;
283 scoped_refptr<Bus> bus = new Bus(options);
284 ScopedDBusError error;
deymo@chromium.org7894ebf2013-01-31 15:08:02 +0900285
286 bus->Connect();
287
288 // Adds the same rule twice.
289 bus->AddMatch(
290 "type='signal',interface='org.chromium.TestService',path='/'",
291 error.get());
292 ASSERT_FALSE(error.is_set());
293
294 bus->AddMatch(
295 "type='signal',interface='org.chromium.TestService',path='/'",
296 error.get());
297 ASSERT_FALSE(error.is_set());
298
299 // Removes the same rule twice.
300 ASSERT_TRUE(bus->RemoveMatch(
301 "type='signal',interface='org.chromium.TestService',path='/'",
302 error.get()));
303 ASSERT_FALSE(error.is_set());
304
305 // The rule should be still in the bus since it was removed only once.
306 // A second removal shouldn't give an error.
307 ASSERT_TRUE(bus->RemoveMatch(
308 "type='signal',interface='org.chromium.TestService',path='/'",
309 error.get()));
310 ASSERT_FALSE(error.is_set());
311
312 // A third attemp to remove the same rule should fail.
313 ASSERT_FALSE(bus->RemoveMatch(
314 "type='signal',interface='org.chromium.TestService',path='/'",
315 error.get()));
316
317 bus->ShutdownAndBlock();
318}
thestig@chromium.orgc2482f12013-06-11 07:52:34 +0900319
320TEST(BusTest, ListenForServiceOwnerChange) {
321 // Setup the current thread's MessageLoop. Must be of TYPE_IO for the
322 // listeners to work.
323 base::MessageLoop message_loop(base::MessageLoop::TYPE_IO);
324 RunLoopWithExpectedCount run_loop_state;
325
326 // Create the bus.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900327 Bus::Options bus_options;
328 scoped_refptr<Bus> bus = new Bus(bus_options);
thestig@chromium.orgc2482f12013-06-11 07:52:34 +0900329
330 // Add a listener.
331 std::string service_owner1;
332 int num_of_owner_changes1 = 0;
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900333 Bus::GetServiceOwnerCallback callback1 =
thestig@chromium.orgc2482f12013-06-11 07:52:34 +0900334 base::Bind(&OnServiceOwnerChanged,
335 &run_loop_state,
336 &service_owner1,
337 &num_of_owner_changes1);
338 bus->ListenForServiceOwnerChange("org.chromium.TestService", callback1);
339 // This should be a no-op.
340 bus->ListenForServiceOwnerChange("org.chromium.TestService", callback1);
341 base::RunLoop().RunUntilIdle();
342
343 // Nothing has happened yet. Check initial state.
344 EXPECT_TRUE(service_owner1.empty());
345 EXPECT_EQ(0, num_of_owner_changes1);
346
347 // Make an ownership change.
cmasone@chromium.org989857e2013-07-31 15:34:59 +0900348 ASSERT_TRUE(bus->RequestOwnershipAndBlock("org.chromium.TestService",
349 Bus::REQUIRE_PRIMARY));
thestig@chromium.orgc2482f12013-06-11 07:52:34 +0900350 run_loop_state.Run(1);
351
352 {
353 // Get the current service owner and check to make sure the listener got
354 // the right value.
355 std::string current_service_owner =
356 bus->GetServiceOwnerAndBlock("org.chromium.TestService",
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900357 Bus::REPORT_ERRORS);
thestig@chromium.orgc2482f12013-06-11 07:52:34 +0900358 ASSERT_FALSE(current_service_owner.empty());
359
360 // Make sure the listener heard about the new owner.
361 EXPECT_EQ(current_service_owner, service_owner1);
362
363 // Test the second ListenForServiceOwnerChange() above is indeed a no-op.
364 EXPECT_EQ(1, num_of_owner_changes1);
365 }
366
367 // Add a second listener.
368 std::string service_owner2;
369 int num_of_owner_changes2 = 0;
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900370 Bus::GetServiceOwnerCallback callback2 =
thestig@chromium.orgc2482f12013-06-11 07:52:34 +0900371 base::Bind(&OnServiceOwnerChanged,
372 &run_loop_state,
373 &service_owner2,
374 &num_of_owner_changes2);
375 bus->ListenForServiceOwnerChange("org.chromium.TestService", callback2);
376 base::RunLoop().RunUntilIdle();
377
378 // Release the ownership and make sure the service owner listeners fire with
379 // the right values and the right number of times.
380 ASSERT_TRUE(bus->ReleaseOwnership("org.chromium.TestService"));
381 run_loop_state.Run(2);
382
383 EXPECT_TRUE(service_owner1.empty());
384 EXPECT_TRUE(service_owner2.empty());
385 EXPECT_EQ(2, num_of_owner_changes1);
386 EXPECT_EQ(1, num_of_owner_changes2);
387
388 // Unlisten so shutdown can proceed correctly.
389 bus->UnlistenForServiceOwnerChange("org.chromium.TestService", callback1);
390 bus->UnlistenForServiceOwnerChange("org.chromium.TestService", callback2);
391 base::RunLoop().RunUntilIdle();
392
393 // Shut down synchronously.
394 bus->ShutdownAndBlock();
395 EXPECT_TRUE(bus->shutdown_completed());
396}
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900397
zqiua84d25f2015-07-08 11:08:30 +0900398TEST(BusTest, GetConnectionName) {
399 Bus::Options options;
400 scoped_refptr<Bus> bus = new Bus(options);
401
402 // Connection name is empty since bus is not connected.
403 EXPECT_FALSE(bus->is_connected());
404 EXPECT_TRUE(bus->GetConnectionName().empty());
405
406 // Connect bus to D-Bus.
407 bus->Connect();
408
409 // Connection name is not empty after connection is established.
410 EXPECT_TRUE(bus->is_connected());
411 EXPECT_FALSE(bus->GetConnectionName().empty());
412
413 // Shut down synchronously.
414 bus->ShutdownAndBlock();
415 EXPECT_TRUE(bus->shutdown_completed());
416}
417
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +0900418} // namespace dbus