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

Side by Side Diff: dbus/object_proxy_unittest.cc

Issue 25488002: dbus: Add ObjectProxy::WaitForServiceToBeAvailable() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Also test already-available case Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dbus/object_proxy.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h"
7 #include "base/run_loop.h"
8 #include "dbus/bus.h"
9 #include "dbus/object_proxy.h"
10 #include "dbus/test_service.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace dbus {
14 namespace {
15
16 class ObjectProxyTest : public testing::Test {
17 protected:
18 virtual void SetUp() OVERRIDE {
19 Bus::Options bus_options;
20 bus_options.bus_type = Bus::SESSION;
21 bus_options.connection_type = Bus::PRIVATE;
22 bus_ = new Bus(bus_options);
23
24 object_proxy_ = bus_->GetObjectProxy(
25 "org.chromium.TestService", ObjectPath("/org/chromium/TestObject"));
26 }
27
28 virtual void TearDown() OVERRIDE {
29 bus_->ShutdownAndBlock();
30 }
31
32 base::MessageLoopForIO message_loop_;
33 scoped_refptr<Bus> bus_;
34 ObjectProxy* object_proxy_;
35 };
36
37 // Used as a WaitForServiceToBeAvailableCallback.
38 void OnServiceIsAvailable(scoped_ptr<base::RunLoop>* run_loop,
39 bool service_is_available) {
40 EXPECT_TRUE(service_is_available);
41 ASSERT_TRUE(*run_loop);
42 (*run_loop)->Quit();
43 }
44
45 TEST_F(ObjectProxyTest, WaitForServiceToBeAvailable) {
46 scoped_ptr<base::RunLoop> run_loop;
47
48 // Callback is not yet called because the service is not available.
49 object_proxy_->WaitForServiceToBeAvailable(
50 base::Bind(&OnServiceIsAvailable, &run_loop));
51 base::RunLoop().RunUntilIdle();
52
53 // Start the service.
54 TestService::Options options;
55 TestService test_service(options);
56 ASSERT_TRUE(test_service.StartService());
57 ASSERT_TRUE(test_service.WaitUntilServiceIsStarted());
58 ASSERT_TRUE(test_service.has_ownership());
59
60 // Callback is called beacuse the service became available.
61 run_loop.reset(new base::RunLoop);
62 run_loop->Run();
63
64 // Callback is called because the service is already available.
65 run_loop.reset(new base::RunLoop);
66 object_proxy_->WaitForServiceToBeAvailable(
67 base::Bind(&OnServiceIsAvailable, &run_loop));
68 run_loop->Run();
69
70 // Shut down the service.
71 test_service.ShutdownAndBlock();
72 test_service.Stop();
73 }
74
75 } // namespace
76 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/object_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698