| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/metrics/histogram.h" | 6 #include "base/metrics/histogram.h" |
| 7 #include "base/metrics/histogram_samples.h" | 7 #include "base/metrics/histogram_samples.h" |
| 8 #include "base/metrics/statistics_recorder.h" | 8 #include "base/metrics/statistics_recorder.h" |
| 9 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 9 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 10 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 10 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
| 11 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h" | 11 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h" |
| 12 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" | 12 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" |
| 13 #include "chromeos/ime/extension_ime_util.h" | 13 #include "chromeos/ime/extension_ime_util.h" |
| 14 #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" | 14 #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/base/ime/chromeos/mock_ime_input_context_handler.h" | 16 #include "ui/base/ime/chromeos/mock_ime_input_context_handler.h" |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 | 19 |
| 20 namespace input_method { | 20 namespace input_method { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kTestExtensionId[] = "mppnpdlheglhdfmldimlhpnegondlapf"; | 23 const char kTestExtensionId[] = "mppnpdlheglhdfmldimlhpnegondlapf"; |
| 24 const char kTestExtensionId2[] = "dmpipdbjkoajgdeppkffbjhngfckdloi"; | 24 const char kTestExtensionId2[] = "dmpipdbjkoajgdeppkffbjhngfckdloi"; |
| 25 const char kTestImeEngineId[] = "test_engine_id"; | 25 const char kTestImeComponentId[] = "test_engine_id"; |
| 26 | 26 |
| 27 const char* kHistogramNames[] = { | 27 const char* kHistogramNames[] = { |
| 28 "InputMethod.Enable.test_engine_id", "InputMethod.Commit.test_engine_id", | 28 "InputMethod.Enable.test_engine_id", "InputMethod.Commit.test_engine_id", |
| 29 "InputMethod.CommitCharacter.test_engine_id", | 29 "InputMethod.CommitCharacter.test_engine_id", |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 scoped_ptr<base::HistogramSamples> GetHistogramSamples( | 32 scoped_ptr<base::HistogramSamples> GetHistogramSamples( |
| 33 const char* histogram_name) { | 33 const char* histogram_name) { |
| 34 base::HistogramBase* histogram = | 34 base::HistogramBase* histogram = |
| 35 base::StatisticsRecorder::FindHistogram(histogram_name); | 35 base::StatisticsRecorder::FindHistogram(histogram_name); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 48 void InitInputMethod() { | 48 void InitInputMethod() { |
| 49 ComponentExtensionIMEManager* comp_ime_manager = | 49 ComponentExtensionIMEManager* comp_ime_manager = |
| 50 new ComponentExtensionIMEManager; | 50 new ComponentExtensionIMEManager; |
| 51 MockComponentExtIMEManagerDelegate* delegate = | 51 MockComponentExtIMEManagerDelegate* delegate = |
| 52 new MockComponentExtIMEManagerDelegate; | 52 new MockComponentExtIMEManagerDelegate; |
| 53 | 53 |
| 54 ComponentExtensionIME ext1; | 54 ComponentExtensionIME ext1; |
| 55 ext1.id = kTestExtensionId; | 55 ext1.id = kTestExtensionId; |
| 56 | 56 |
| 57 ComponentExtensionEngine ext1_engine1; | 57 ComponentExtensionEngine ext1_engine1; |
| 58 ext1_engine1.engine_id = kTestImeEngineId; | 58 ext1_engine1.engine_id = kTestImeComponentId; |
| 59 ext1_engine1.language_codes.push_back("en-US"); | 59 ext1_engine1.language_codes.push_back("en-US"); |
| 60 ext1_engine1.layouts.push_back("us"); | 60 ext1_engine1.layouts.push_back("us"); |
| 61 ext1.engines.push_back(ext1_engine1); | 61 ext1.engines.push_back(ext1_engine1); |
| 62 | 62 |
| 63 std::vector<ComponentExtensionIME> ime_list; | 63 std::vector<ComponentExtensionIME> ime_list; |
| 64 ime_list.push_back(ext1); | 64 ime_list.push_back(ext1); |
| 65 delegate->set_ime_list(ime_list); | 65 delegate->set_ime_list(ime_list); |
| 66 comp_ime_manager->Initialize( | 66 comp_ime_manager->Initialize( |
| 67 scoped_ptr<ComponentExtensionIMEManagerDelegate>(delegate).Pass()); | 67 scoped_ptr<ComponentExtensionIMEManagerDelegate>(delegate).Pass()); |
| 68 | 68 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 scoped_ptr<base::HistogramSamples> delta_samples( | 168 scoped_ptr<base::HistogramSamples> delta_samples( |
| 169 GetHistogramSamplesDelta(histogram_name)); | 169 GetHistogramSamplesDelta(histogram_name)); |
| 170 EXPECT_EQ(total_count, delta_samples->TotalCount()); | 170 EXPECT_EQ(total_count, delta_samples->TotalCount()); |
| 171 EXPECT_EQ(sample_count, delta_samples->GetCount(sample)); | 171 EXPECT_EQ(sample_count, delta_samples->GetCount(sample)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void CreateEngine(bool whitelisted) { | 174 void CreateEngine(bool whitelisted) { |
| 175 engine_.reset(new InputMethodEngine()); | 175 engine_.reset(new InputMethodEngine()); |
| 176 observer_ = new TestObserver(); | 176 observer_ = new TestObserver(); |
| 177 scoped_ptr<InputMethodEngineInterface::Observer> observer_ptr(observer_); | 177 scoped_ptr<InputMethodEngineInterface::Observer> observer_ptr(observer_); |
| 178 engine_->Initialize(NULL /* profile */, | 178 engine_->Initialize(observer_ptr.Pass(), |
| 179 observer_ptr.Pass(), | 179 whitelisted ? kTestExtensionId : kTestExtensionId2); |
| 180 "", | |
| 181 whitelisted ? kTestExtensionId : kTestExtensionId2, | |
| 182 kTestImeEngineId, | |
| 183 languages_, | |
| 184 layouts_, | |
| 185 options_page_, | |
| 186 input_view_); | |
| 187 } | 180 } |
| 188 | 181 |
| 189 void FocusIn(ui::TextInputType input_type) { | 182 void FocusIn(ui::TextInputType input_type) { |
| 190 IMEEngineHandlerInterface::InputContext input_context( | 183 IMEEngineHandlerInterface::InputContext input_context( |
| 191 input_type, ui::TEXT_INPUT_MODE_DEFAULT); | 184 input_type, ui::TEXT_INPUT_MODE_DEFAULT); |
| 192 engine_->FocusIn(input_context); | 185 engine_->FocusIn(input_context); |
| 193 IMEBridge::Get()->SetCurrentTextInputType(input_type); | 186 IMEBridge::Get()->SetCurrentTextInputType(input_type); |
| 194 } | 187 } |
| 195 | 188 |
| 196 scoped_ptr<InputMethodEngine> engine_; | 189 scoped_ptr<InputMethodEngine> engine_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 211 DISALLOW_COPY_AND_ASSIGN(InputMethodEngineTest); | 204 DISALLOW_COPY_AND_ASSIGN(InputMethodEngineTest); |
| 212 }; | 205 }; |
| 213 | 206 |
| 214 } // namespace | 207 } // namespace |
| 215 | 208 |
| 216 TEST_F(InputMethodEngineTest, TestSwitching) { | 209 TEST_F(InputMethodEngineTest, TestSwitching) { |
| 217 CreateEngine(false); | 210 CreateEngine(false); |
| 218 // Enable/disable with focus. | 211 // Enable/disable with focus. |
| 219 FocusIn(ui::TEXT_INPUT_TYPE_URL); | 212 FocusIn(ui::TEXT_INPUT_TYPE_URL); |
| 220 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 213 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 221 engine_->Enable(); | 214 engine_->Enable(kTestImeComponentId); |
| 222 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 215 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 223 engine_->Disable(); | 216 engine_->Disable(); |
| 224 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 217 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 225 // Enable/disable without focus. | 218 // Enable/disable without focus. |
| 226 engine_->FocusOut(); | 219 engine_->FocusOut(); |
| 227 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 220 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 228 engine_->Enable(); | 221 engine_->Enable(kTestImeComponentId); |
| 229 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 222 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 230 engine_->Disable(); | 223 engine_->Disable(); |
| 231 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 224 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 232 // Focus change when enabled. | 225 // Focus change when enabled. |
| 233 engine_->Enable(); | 226 engine_->Enable(kTestImeComponentId); |
| 234 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 227 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 235 engine_->FocusOut(); | 228 engine_->FocusOut(); |
| 236 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); | 229 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); |
| 237 // Focus change when disabled. | 230 // Focus change when disabled. |
| 238 engine_->Disable(); | 231 engine_->Disable(); |
| 239 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 232 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 240 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); | 233 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); |
| 241 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 234 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 242 engine_->FocusOut(); | 235 engine_->FocusOut(); |
| 243 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 236 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 244 } | 237 } |
| 245 | 238 |
| 246 TEST_F(InputMethodEngineTest, TestSwitching_Password_3rd_Party) { | 239 TEST_F(InputMethodEngineTest, TestSwitching_Password_3rd_Party) { |
| 247 CreateEngine(false); | 240 CreateEngine(false); |
| 248 // Enable/disable with focus. | 241 // Enable/disable with focus. |
| 249 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 242 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 250 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 243 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 251 engine_->Enable(); | 244 engine_->Enable(kTestImeComponentId); |
| 252 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 245 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 253 engine_->Disable(); | 246 engine_->Disable(); |
| 254 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 247 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 255 // Focus change when enabled. | 248 // Focus change when enabled. |
| 256 engine_->Enable(); | 249 engine_->Enable(kTestImeComponentId); |
| 257 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 250 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 258 engine_->FocusOut(); | 251 engine_->FocusOut(); |
| 259 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); | 252 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); |
| 260 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 253 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 261 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); | 254 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 262 engine_->Disable(); | 255 engine_->Disable(); |
| 263 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 256 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 264 } | 257 } |
| 265 | 258 |
| 266 TEST_F(InputMethodEngineTest, TestSwitching_Password_Whitelisted) { | 259 TEST_F(InputMethodEngineTest, TestSwitching_Password_Whitelisted) { |
| 267 CreateEngine(true); | 260 CreateEngine(true); |
| 268 // Enable/disable with focus. | 261 // Enable/disable with focus. |
| 269 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 262 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 270 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 263 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 271 engine_->Enable(); | 264 engine_->Enable(kTestImeComponentId); |
| 272 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 265 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 273 engine_->Disable(); | 266 engine_->Disable(); |
| 274 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 267 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 275 // Focus change when enabled. | 268 // Focus change when enabled. |
| 276 engine_->Enable(); | 269 engine_->Enable(kTestImeComponentId); |
| 277 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 270 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 278 engine_->FocusOut(); | 271 engine_->FocusOut(); |
| 279 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); | 272 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); |
| 280 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 273 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 281 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); | 274 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 282 engine_->Disable(); | 275 engine_->Disable(); |
| 283 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 276 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 284 } | 277 } |
| 285 | 278 |
| 286 TEST_F(InputMethodEngineTest, TestHistograms) { | 279 TEST_F(InputMethodEngineTest, TestHistograms) { |
| 287 CreateEngine(true); | 280 CreateEngine(true); |
| 288 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); | 281 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); |
| 289 engine_->Enable(); | 282 engine_->Enable(kTestImeComponentId); |
| 290 std::string error; | 283 std::string error; |
| 291 ExpectNewSample("InputMethod.Enable.test_engine_id", 1, 1, 1); | 284 ExpectNewSample("InputMethod.Enable.test_engine_id", 1, 1, 1); |
| 292 engine_->CommitText(1, "input", &error); | 285 engine_->CommitText(1, "input", &error); |
| 293 engine_->CommitText(1, "入力", &error); | 286 engine_->CommitText(1, "入力", &error); |
| 294 engine_->CommitText(1, "input入力", &error); | 287 engine_->CommitText(1, "input入力", &error); |
| 295 ExpectNewSample("InputMethod.Commit.test_engine_id", 1, 3, 3); | 288 ExpectNewSample("InputMethod.Commit.test_engine_id", 1, 3, 3); |
| 296 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 5, 3, 1); | 289 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 5, 3, 1); |
| 297 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 2, 3, 1); | 290 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 2, 3, 1); |
| 298 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 7, 3, 1); | 291 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 7, 3, 1); |
| 299 } | 292 } |
| 300 | 293 |
| 301 } // namespace input_method | 294 } // namespace input_method |
| 302 } // namespace chromeos | 295 } // namespace chromeos |
| OLD | NEW |