mock_input_method_manager.h revision a02191e04bc25c4935f804f2c080ae28663d096d
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.
4
5#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MOCK_INPUT_METHOD_MANAGER_H_
6#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MOCK_INPUT_METHOD_MANAGER_H_
7
8#include "chrome/browser/chromeos/input_method/input_method_util.h"
9#include "chromeos/ime/component_extension_ime_manager.h"
10#include "chromeos/ime/fake_ime_keyboard.h"
11#include "chromeos/ime/fake_input_method_delegate.h"
12#include "chromeos/ime/input_method_manager.h"
13#include "chromeos/ime/input_method_whitelist.h"
14
15namespace chromeos {
16namespace input_method {
17
18// The mock implementation of InputMethodManager for testing.
19class MockInputMethodManager : public InputMethodManager {
20 public:
21  MockInputMethodManager();
22  virtual ~MockInputMethodManager();
23
24  // InputMethodManager override:
25  virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE;
26  virtual void AddCandidateWindowObserver(
27      InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
28  virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE;
29  virtual void RemoveCandidateWindowObserver(
30      InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
31  virtual scoped_ptr<InputMethodDescriptors>
32      GetSupportedInputMethods() const OVERRIDE;
33  virtual scoped_ptr<InputMethodDescriptors>
34      GetActiveInputMethods() const OVERRIDE;
35  virtual const std::vector<std::string>& GetActiveInputMethodIds() const
36      OVERRIDE;
37  virtual size_t GetNumActiveInputMethods() const OVERRIDE;
38  virtual const InputMethodDescriptor* GetInputMethodFromId(
39      const std::string& input_method_id) const OVERRIDE;
40  virtual void EnableLoginLayouts(
41      const std::string& language_code,
42      const std::vector<std::string>& initial_layout) OVERRIDE;
43  virtual bool ReplaceEnabledInputMethods(
44      const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
45  virtual bool EnableInputMethod(
46      const std::string& new_active_input_method_id) OVERRIDE;
47  virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE;
48  virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE;
49  virtual void AddInputMethodExtension(
50      const std::string& id,
51      InputMethodEngineInterface* instance) OVERRIDE;
52  virtual void RemoveInputMethodExtension(const std::string& id) OVERRIDE;
53  virtual void GetInputMethodExtensions(
54      InputMethodDescriptors* result) OVERRIDE;
55  virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE;
56  virtual void SetInputMethodLoginDefault() OVERRIDE;
57  virtual bool SwitchToNextInputMethod() OVERRIDE;
58  virtual bool SwitchToPreviousInputMethod(
59      const ui::Accelerator& accelerator) OVERRIDE;
60  virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
61  virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
62  virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const OVERRIDE;
63  virtual bool IsAltGrUsedByCurrentInputMethod() const OVERRIDE;
64  virtual ImeKeyboard* GetImeKeyboard() OVERRIDE;
65  virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE;
66  virtual ComponentExtensionIMEManager*
67      GetComponentExtensionIMEManager() OVERRIDE;
68  virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE;
69  virtual bool MigrateXkbInputMethods(
70       std::vector<std::string>* input_method_ids) OVERRIDE;
71
72  // Sets an input method ID which will be returned by GetCurrentInputMethod().
73  void SetCurrentInputMethodId(const std::string& input_method_id) {
74    current_input_method_id_ = input_method_id;
75  }
76
77  void SetComponentExtensionIMEManager(
78      scoped_ptr<ComponentExtensionIMEManager> comp_ime_manager);
79
80  // Set values that will be provided to the InputMethodUtil.
81  void set_application_locale(const std::string& value);
82
83  // Set the value returned by IsISOLevel5ShiftUsedByCurrentInputMethod
84  void set_mod3_used(bool value) { mod3_used_ = value; }
85
86  // TODO(yusukes): Add more variables for counting the numbers of the API calls
87  int add_observer_count_;
88  int remove_observer_count_;
89
90 private:
91  // The value GetCurrentInputMethod().id() will return.
92  std::string current_input_method_id_;
93
94  InputMethodWhitelist whitelist_;
95  FakeInputMethodDelegate delegate_;  // used by util_
96  InputMethodUtil util_;
97  FakeImeKeyboard keyboard_;
98  bool mod3_used_;
99  scoped_ptr<ComponentExtensionIMEManager> comp_ime_manager_;
100
101  // The active input method ids cache (actually default only)
102  std::vector<std::string> active_input_method_ids_;
103
104  DISALLOW_COPY_AND_ASSIGN(MockInputMethodManager);
105};
106
107}  // namespace input_method
108}  // namespace chromeos
109
110#endif  // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MOCK_INPUT_METHOD_MANAGER_H_
111