[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / chromeos / dbus / services / service_provider_test_helper.h
blob196f6a61fffd9d9ca98193aa781135ce6d50265d
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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_SERVICES_SERVICE_PROVIDER_TEST_HELPER_H_
6 #define CHROMEOS_DBUS_SERVICES_SERVICE_PROVIDER_TEST_HELPER_H_
8 #include <string>
10 #include "base/message_loop/message_loop.h"
11 #include "chromeos/dbus/services/cros_dbus_service.h"
12 #include "dbus/mock_exported_object.h"
13 #include "dbus/mock_object_proxy.h"
14 #include "dbus/object_proxy.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace dbus {
20 class MockBus;
22 } // namespace dbus
24 namespace chromeos {
26 // Helps to implement |CrosDBusService::ServiceProviderInterface| unittests.
27 // Setups mocking of dbus classes.
28 // Class can test only one method call in time. SetUp() must be called before
29 // testing new call to the same method or different method.
31 // Sample usage:
32 // ServiceProviderTestHelper helper;
33 // helper.Setup(...);
34 // helper.SetUpReturnSignal(...); // optional.
35 // helper.CallMethod(...);
36 // helper.TearDown();
37 class ServiceProviderTestHelper {
38 public:
39 ServiceProviderTestHelper();
40 ~ServiceProviderTestHelper();
42 // Sets up helper. Should be called before |CallMethod()|.
43 void SetUp(const std::string& exported_method_name,
44 CrosDBusService::ServiceProviderInterface* service_provider);
46 // Setups return signal callback. It's optional and don't need to be called
47 // if tested method doesn't use signal to return results.
48 void SetUpReturnSignal(
49 const std::string& interface_name,
50 const std::string& signal_name,
51 dbus::ObjectProxy::SignalCallback signal_callback,
52 dbus::ObjectProxy::OnConnectedCallback on_connected_callback);
54 // Calls tested dbus method.
55 scoped_ptr<dbus::Response> CallMethod(dbus::MethodCall* method_call);
57 // Cleanups helper. Should be called after |CallMethod()|.
58 void TearDown();
60 private:
61 // Behaves as |mock_exported_object_|'s ExportMethod().
62 void MockExportMethod(
63 const std::string& interface_name,
64 const std::string& method_name,
65 dbus::ExportedObject::MethodCallCallback method_callback,
66 dbus::ExportedObject::OnExportedCallback on_exported_callback);
68 // Calls exported method and waits for a response for |mock_object_proxy_|.
69 dbus::Response* MockCallMethodAndBlock(
70 dbus::MethodCall* method_call,
71 ::testing::Unused);
73 // Behaves as |mock_object_proxy_|'s ConnectToSignal().
74 void MockConnectToSignal(
75 const std::string& interface_name,
76 const std::string& signal_name,
77 dbus::ObjectProxy::SignalCallback signal_callback,
78 dbus::ObjectProxy::OnConnectedCallback connected_callback);
80 // Behaves as |mock_exported_object_|'s SendSignal().
81 void MockSendSignal(dbus::Signal* signal);
83 // Receives a response and makes it available to MockCallMethodAndBlock().
84 void OnResponse(scoped_ptr<dbus::Response> response);
86 scoped_refptr<dbus::MockBus> mock_bus_;
87 scoped_refptr<dbus::MockExportedObject> mock_exported_object_;
88 scoped_refptr<dbus::MockObjectProxy> mock_object_proxy_;
89 dbus::ExportedObject::MethodCallCallback method_callback_;
90 dbus::ObjectProxy::SignalCallback on_signal_callback_;
91 base::MessageLoop message_loop_;
92 bool response_received_;
93 scoped_ptr<dbus::Response> response_;
96 } // namespace chromeos
98 #endif // CHROMEOS_DBUS_SERVICES_SERVICE_PROVIDER_TEST_HELPER_H_