cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / dbus / object_proxy_unittest.cc
blob22130b64bc343352eedd633872d545dd44c01489
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.
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"
13 namespace dbus {
14 namespace {
16 class ObjectProxyTest : public testing::Test {
17 protected:
18 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);
24 object_proxy_ = bus_->GetObjectProxy(
25 "org.chromium.TestService", ObjectPath("/org/chromium/TestObject"));
28 void TearDown() override { bus_->ShutdownAndBlock(); }
30 base::MessageLoopForIO message_loop_;
31 scoped_refptr<Bus> bus_;
32 ObjectProxy* object_proxy_;
35 // Used as a WaitForServiceToBeAvailableCallback.
36 void OnServiceIsAvailable(scoped_ptr<base::RunLoop>* run_loop,
37 bool service_is_available) {
38 EXPECT_TRUE(service_is_available);
39 ASSERT_TRUE(*run_loop);
40 (*run_loop)->Quit();
43 TEST_F(ObjectProxyTest, WaitForServiceToBeAvailable) {
44 scoped_ptr<base::RunLoop> run_loop;
46 // Callback is not yet called because the service is not available.
47 object_proxy_->WaitForServiceToBeAvailable(
48 base::Bind(&OnServiceIsAvailable, &run_loop));
49 base::RunLoop().RunUntilIdle();
51 // Start the service.
52 TestService::Options options;
53 TestService test_service(options);
54 ASSERT_TRUE(test_service.StartService());
55 ASSERT_TRUE(test_service.WaitUntilServiceIsStarted());
56 ASSERT_TRUE(test_service.has_ownership());
58 // Callback is called beacuse the service became available.
59 run_loop.reset(new base::RunLoop);
60 run_loop->Run();
62 // Callback is called because the service is already available.
63 run_loop.reset(new base::RunLoop);
64 object_proxy_->WaitForServiceToBeAvailable(
65 base::Bind(&OnServiceIsAvailable, &run_loop));
66 run_loop->Run();
68 // Shut down the service.
69 test_service.ShutdownAndBlock();
70 test_service.Stop();
73 } // namespace
74 } // namespace dbus