Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / input_method / mock_input_method_manager.h
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
15 namespace chromeos {
16 namespace input_method {
17
18 // The mock implementation of InputMethodManager for testing.
19 class MockInputMethodManager : public InputMethodManager {
20  public:
21   class State : public InputMethodManager::State {
22    public:
23     explicit State(MockInputMethodManager* manager);
24
25     virtual scoped_refptr<InputMethodManager::State> Clone() const override;
26     virtual void AddInputMethodExtension(
27         const std::string& extension_id,
28         const InputMethodDescriptors& descriptors,
29         InputMethodEngineInterface* instance) override;
30     virtual void RemoveInputMethodExtension(
31         const std::string& extension_id) override;
32     virtual void ChangeInputMethod(const std::string& input_method_id,
33                                    bool show_message) override;
34     virtual bool EnableInputMethod(
35         const std::string& new_active_input_method_id) override;
36     virtual void EnableLoginLayouts(
37         const std::string& language_code,
38         const std::vector<std::string>& initial_layouts) override;
39     virtual void EnableLockScreenLayouts() override;
40     virtual void GetInputMethodExtensions(
41         InputMethodDescriptors* result) override;
42     virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods()
43         const override;
44     virtual const std::vector<std::string>& GetActiveInputMethodIds()
45         const override;
46     virtual const InputMethodDescriptor* GetInputMethodFromId(
47         const std::string& input_method_id) const override;
48     virtual size_t GetNumActiveInputMethods() const override;
49     virtual void SetEnabledExtensionImes(
50         std::vector<std::string>* ids) override;
51     virtual void SetInputMethodLoginDefault() override;
52     virtual void SetInputMethodLoginDefaultFromVPD(
53         const std::string& locale,
54         const std::string& layout) override;
55     virtual bool SwitchToNextInputMethod() override;
56     virtual bool SwitchToPreviousInputMethod(
57         const ui::Accelerator& accelerator) override;
58     virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) override;
59     virtual InputMethodDescriptor GetCurrentInputMethod() const override;
60     virtual bool ReplaceEnabledInputMethods(
61         const std::vector<std::string>& new_active_input_method_ids) override;
62
63     // The value GetCurrentInputMethod().id() will return.
64     std::string current_input_method_id;
65
66     // The active input method ids cache (actually default only)
67     std::vector<std::string> active_input_method_ids;
68
69    protected:
70     friend base::RefCounted<chromeos::input_method::InputMethodManager::State>;
71     virtual ~State();
72
73     MockInputMethodManager* const manager_;
74   };
75
76   MockInputMethodManager();
77   virtual ~MockInputMethodManager();
78
79   // InputMethodManager override:
80   virtual UISessionState GetUISessionState() override;
81   virtual void AddObserver(InputMethodManager::Observer* observer) override;
82   virtual void AddCandidateWindowObserver(
83       InputMethodManager::CandidateWindowObserver* observer) override;
84   virtual void RemoveObserver(InputMethodManager::Observer* observer) override;
85   virtual void RemoveCandidateWindowObserver(
86       InputMethodManager::CandidateWindowObserver* observer) override;
87   virtual scoped_ptr<InputMethodDescriptors>
88       GetSupportedInputMethods() const override;
89   virtual void ActivateInputMethodMenuItem(const std::string& key) override;
90   virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const override;
91   virtual bool IsAltGrUsedByCurrentInputMethod() const override;
92   virtual ImeKeyboard* GetImeKeyboard() override;
93   virtual InputMethodUtil* GetInputMethodUtil() override;
94   virtual ComponentExtensionIMEManager*
95       GetComponentExtensionIMEManager() override;
96   virtual bool IsLoginKeyboard(const std::string& layout) const override;
97   virtual bool MigrateInputMethods(
98        std::vector<std::string>* input_method_ids) override;
99   virtual scoped_refptr<InputMethodManager::State> CreateNewState(
100       Profile* profile) override;
101   virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() override;
102   virtual void SetState(
103       scoped_refptr<InputMethodManager::State> state) override;
104
105   // Sets an input method ID which will be returned by GetCurrentInputMethod().
106   void SetCurrentInputMethodId(const std::string& input_method_id);
107
108   void SetComponentExtensionIMEManager(
109       scoped_ptr<ComponentExtensionIMEManager> comp_ime_manager);
110
111   // Set values that will be provided to the InputMethodUtil.
112   void set_application_locale(const std::string& value);
113
114   // Set the value returned by IsISOLevel5ShiftUsedByCurrentInputMethod
115   void set_mod3_used(bool value) { mod3_used_ = value; }
116
117   // TODO(yusukes): Add more variables for counting the numbers of the API calls
118   int add_observer_count_;
119   int remove_observer_count_;
120
121  protected:
122   scoped_refptr<State> state_;
123
124  private:
125   FakeInputMethodDelegate delegate_;  // used by util_
126   InputMethodUtil util_;
127   FakeImeKeyboard keyboard_;
128   bool mod3_used_;
129   scoped_ptr<ComponentExtensionIMEManager> comp_ime_manager_;
130
131   DISALLOW_COPY_AND_ASSIGN(MockInputMethodManager);
132 };
133
134 }  // namespace input_method
135 }  // namespace chromeos
136
137 #endif  // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MOCK_INPUT_METHOD_MANAGER_H_