summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/ibus/mock_ibus_client.h
blob: 9011be77782e82e8559ea654e3e4343c9a86f9f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_DBUS_IBUS_MOCK_IBUS_CLIENT_H_
#define CHROMEOS_DBUS_IBUS_MOCK_IBUS_CLIENT_H_

#include <string>
#include "base/callback.h"
#include "chromeos/dbus/ibus/ibus_client.h"

namespace chromeos {

class MockIBusClient : public IBusClient {
 public:
  MockIBusClient();
  virtual ~MockIBusClient();

  typedef base::Callback<void(const std::string& client_name,
                              const CreateInputContextCallback& callback,
                              const ErrorCallback& error_callback)>
      CreateInputContextHandler;
  typedef base::Callback<void(const IBusComponent& ibus_component,
                              const RegisterComponentCallback& callback,
                              const ErrorCallback& error_callback)>
      RegisterComponentHandler;

  // IBusClient override.
  virtual void CreateInputContext(const std::string& client_name,
                                  const CreateInputContextCallback& callback,
                                  const ErrorCallback& error_callback) OVERRIDE;

  // IBusClient override.
  virtual void RegisterComponent(const IBusComponent& ibus_component,
                                 const RegisterComponentCallback& callback,
                                 const ErrorCallback& error_callback) OVERRIDE;

  // IBusClient override.
  virtual void SetGlobalEngine(const std::string& engine_name,
                               const ErrorCallback& error_callback) OVERRIDE;

  // IBusClient override.
  virtual void Exit(ExitOption option,
                    const ErrorCallback& error_callback) OVERRIDE;

  // Function handler for CreateInputContext. The CreateInputContext function
  // invokes |create_input_context_handler_| unless it's not null.
  void set_create_input_context_handler(
      const CreateInputContextHandler& handler) {
    create_input_context_handler_ = handler;
  }

  // Function handler for RegisterComponent. The RegisterComponent function
  // invokes |register_component_handler_| unless it's not null.
  void set_register_component_handler(
      const RegisterComponentHandler& handler) {
    register_component_handler_ = handler;
  }

  // Call count of CreateInputContext().
  int create_input_context_call_count() const {
    return create_input_context_call_count_;
  }

  // Call count of RegisterComponent().
  int register_component_call_count() const {
    return register_component_call_count_;
  }

  int set_global_engine_call_count() const {
    return set_global_engine_call_count_;
  }

  const std::string& latest_global_engine_name() const {
    return latest_global_engine_name_;
  }

 private:
  CreateInputContextHandler create_input_context_handler_;
  RegisterComponentHandler register_component_handler_;
  int create_input_context_call_count_;
  int register_component_call_count_;
  int set_global_engine_call_count_;
  std::string latest_global_engine_name_;

  DISALLOW_COPY_AND_ASSIGN(MockIBusClient);
};

}  // namespace chromeos

#endif  // CHROMEOS_DBUS_IBUS_MOCK_IBUS_CLIENT_H_