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