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#include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
6
7namespace chromeos {
8namespace input_method {
9
10MockInputMethodManager::State::State(MockInputMethodManager* manager)
11    : manager_(manager) {
12  active_input_method_ids.push_back("xkb:us::eng");
13}
14
15MockInputMethodManager::State::~State() {
16}
17
18MockInputMethodManager::MockInputMethodManager()
19    : add_observer_count_(0),
20      remove_observer_count_(0),
21      state_(new State(this)),
22      util_(&delegate_),
23      mod3_used_(false) {
24}
25
26MockInputMethodManager::~MockInputMethodManager() {
27}
28
29InputMethodManager::UISessionState MockInputMethodManager::GetUISessionState() {
30  return InputMethodManager::STATE_BROWSER_SCREEN;
31}
32
33void MockInputMethodManager::AddObserver(
34    InputMethodManager::Observer* observer) {
35  ++add_observer_count_;
36}
37
38void MockInputMethodManager::AddCandidateWindowObserver(
39    InputMethodManager::CandidateWindowObserver* observer) {
40}
41
42void MockInputMethodManager::RemoveObserver(
43    InputMethodManager::Observer* observer) {
44  ++remove_observer_count_;
45}
46
47void MockInputMethodManager::RemoveCandidateWindowObserver(
48    InputMethodManager::CandidateWindowObserver* observer) {
49}
50
51scoped_ptr<InputMethodDescriptors>
52MockInputMethodManager::GetSupportedInputMethods() const {
53  scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors);
54  result->push_back(
55      InputMethodUtil::GetFallbackInputMethodDescriptor());
56  return result.Pass();
57}
58
59scoped_ptr<InputMethodDescriptors>
60MockInputMethodManager::State::GetActiveInputMethods() const {
61  scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors);
62  result->push_back(
63      InputMethodUtil::GetFallbackInputMethodDescriptor());
64  return result.Pass();
65}
66
67const std::vector<std::string>&
68MockInputMethodManager::State::GetActiveInputMethodIds() const {
69  return active_input_method_ids;
70}
71
72size_t MockInputMethodManager::State::GetNumActiveInputMethods() const {
73  return 1;
74}
75
76const InputMethodDescriptor*
77MockInputMethodManager::State::GetInputMethodFromId(
78    const std::string& input_method_id) const {
79  static const InputMethodDescriptor defaultInputMethod =
80      InputMethodUtil::GetFallbackInputMethodDescriptor();
81  for (size_t i = 0; i < active_input_method_ids.size(); i++) {
82    if (input_method_id == active_input_method_ids[i]) {
83      return &defaultInputMethod;
84    }
85  }
86  return NULL;
87}
88
89void MockInputMethodManager::State::EnableLoginLayouts(
90    const std::string& language_code,
91    const std::vector<std::string>& initial_layout) {
92}
93
94void MockInputMethodManager::State::EnableLockScreenLayouts() {
95}
96
97bool MockInputMethodManager::State::ReplaceEnabledInputMethods(
98    const std::vector<std::string>& new_active_input_method_ids) {
99  return true;
100}
101
102bool MockInputMethodManager::State::EnableInputMethod(
103    const std::string& new_active_input_method_id) {
104  return true;
105}
106
107void MockInputMethodManager::State::ChangeInputMethod(
108    const std::string& input_method_id,
109    bool show_message) {
110}
111
112void MockInputMethodManager::ActivateInputMethodMenuItem(
113    const std::string& key) {
114}
115
116void MockInputMethodManager::State::AddInputMethodExtension(
117    const std::string& extension_id,
118    const InputMethodDescriptors& descriptors,
119    InputMethodEngineInterface* instance) {
120}
121
122void MockInputMethodManager::State::RemoveInputMethodExtension(
123    const std::string& extension_id) {
124}
125
126void MockInputMethodManager::State::GetInputMethodExtensions(
127    InputMethodDescriptors* result) {
128}
129
130void MockInputMethodManager::State::SetEnabledExtensionImes(
131    std::vector<std::string>* ids) {
132}
133
134void MockInputMethodManager::State::SetInputMethodLoginDefault() {
135}
136
137void MockInputMethodManager::State::SetInputMethodLoginDefaultFromVPD(
138    const std::string& locale,
139    const std::string& layout) {
140}
141
142bool MockInputMethodManager::State::SwitchToNextInputMethod() {
143  return true;
144}
145
146bool MockInputMethodManager::State::SwitchToPreviousInputMethod(
147    const ui::Accelerator& accelerator) {
148  return true;
149}
150
151bool MockInputMethodManager::State::SwitchInputMethod(
152    const ui::Accelerator& accelerator) {
153  return true;
154}
155
156InputMethodDescriptor MockInputMethodManager::State::GetCurrentInputMethod()
157    const {
158  InputMethodDescriptor descriptor =
159      InputMethodUtil::GetFallbackInputMethodDescriptor();
160  if (!current_input_method_id.empty()) {
161    return InputMethodDescriptor(current_input_method_id,
162                                 descriptor.name(),
163                                 descriptor.indicator(),
164                                 descriptor.keyboard_layouts(),
165                                 descriptor.language_codes(),
166                                 true,
167                                 GURL(),   // options page url.
168                                 GURL());  // input view page url.
169  }
170  return descriptor;
171}
172
173bool MockInputMethodManager::IsISOLevel5ShiftUsedByCurrentInputMethod() const {
174  return mod3_used_;
175}
176
177bool MockInputMethodManager::IsAltGrUsedByCurrentInputMethod() const {
178  return false;
179}
180
181ImeKeyboard* MockInputMethodManager::GetImeKeyboard() { return &keyboard_; }
182
183InputMethodUtil* MockInputMethodManager::GetInputMethodUtil() {
184  return &util_;
185}
186
187ComponentExtensionIMEManager*
188    MockInputMethodManager::GetComponentExtensionIMEManager() {
189  return comp_ime_manager_.get();
190}
191
192void MockInputMethodManager::SetComponentExtensionIMEManager(
193    scoped_ptr<ComponentExtensionIMEManager> comp_ime_manager) {
194  comp_ime_manager_ = comp_ime_manager.Pass();
195}
196
197void MockInputMethodManager::set_application_locale(const std::string& value) {
198  delegate_.set_active_locale(value);
199}
200
201bool MockInputMethodManager::IsLoginKeyboard(
202    const std::string& layout) const {
203  return true;
204}
205
206bool MockInputMethodManager::MigrateInputMethods(
207    std::vector<std::string>* input_method_ids) {
208  return false;
209}
210scoped_refptr<InputMethodManager::State> MockInputMethodManager::CreateNewState(
211    Profile* profile) {
212  NOTIMPLEMENTED();
213  return state_;
214}
215
216scoped_refptr<InputMethodManager::State>
217MockInputMethodManager::GetActiveIMEState() {
218  return scoped_refptr<InputMethodManager::State>(state_.get());
219}
220
221scoped_refptr<InputMethodManager::State> MockInputMethodManager::State::Clone()
222    const {
223  NOTIMPLEMENTED();
224  return manager_->GetActiveIMEState();
225}
226
227void MockInputMethodManager::SetState(
228    scoped_refptr<InputMethodManager::State> state) {
229  state_ = scoped_refptr<MockInputMethodManager::State>(
230      static_cast<MockInputMethodManager::State*>(state.get()));
231}
232
233void MockInputMethodManager::SetCurrentInputMethodId(
234    const std::string& input_method_id) {
235  state_->current_input_method_id = input_method_id;
236}
237
238}  // namespace input_method
239}  // namespace chromeos
240