| 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" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(observer_ptr.Pass(), | 178 engine_->Initialize(observer_ptr.Pass(), |
| 179 "", | 179 whitelisted ? kTestExtensionId : kTestExtensionId2); |
| 180 whitelisted ? kTestExtensionId : kTestExtensionId2, | |
| 181 kTestImeEngineId, | |
| 182 languages_, | |
| 183 layouts_, | |
| 184 options_page_, | |
| 185 input_view_); | |
| 186 } | 180 } |
| 187 | 181 |
| 188 void FocusIn(ui::TextInputType input_type) { | 182 void FocusIn(ui::TextInputType input_type) { |
| 189 IMEEngineHandlerInterface::InputContext input_context( | 183 IMEEngineHandlerInterface::InputContext input_context( |
| 190 input_type, ui::TEXT_INPUT_MODE_DEFAULT); | 184 input_type, ui::TEXT_INPUT_MODE_DEFAULT); |
| 191 engine_->FocusIn(input_context); | 185 engine_->FocusIn(input_context); |
| 192 IMEBridge::Get()->SetCurrentTextInputType(input_type); | 186 IMEBridge::Get()->SetCurrentTextInputType(input_type); |
| 193 } | 187 } |
| 194 | 188 |
| 195 scoped_ptr<InputMethodEngine> engine_; | 189 scoped_ptr<InputMethodEngine> engine_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 210 DISALLOW_COPY_AND_ASSIGN(InputMethodEngineTest); | 204 DISALLOW_COPY_AND_ASSIGN(InputMethodEngineTest); |
| 211 }; | 205 }; |
| 212 | 206 |
| 213 } // namespace | 207 } // namespace |
| 214 | 208 |
| 215 TEST_F(InputMethodEngineTest, TestSwitching) { | 209 TEST_F(InputMethodEngineTest, TestSwitching) { |
| 216 CreateEngine(false); | 210 CreateEngine(false); |
| 217 // Enable/disable with focus. | 211 // Enable/disable with focus. |
| 218 FocusIn(ui::TEXT_INPUT_TYPE_URL); | 212 FocusIn(ui::TEXT_INPUT_TYPE_URL); |
| 219 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 213 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 220 engine_->Enable(); | 214 engine_->Enable(kTestImeEngineId); |
| 221 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 215 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 222 engine_->Disable(); | 216 engine_->Disable(); |
| 223 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 217 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 224 // Enable/disable without focus. | 218 // Enable/disable without focus. |
| 225 engine_->FocusOut(); | 219 engine_->FocusOut(); |
| 226 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 220 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 227 engine_->Enable(); | 221 engine_->Enable(kTestImeEngineId); |
| 228 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 222 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 229 engine_->Disable(); | 223 engine_->Disable(); |
| 230 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 224 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 231 // Focus change when enabled. | 225 // Focus change when enabled. |
| 232 engine_->Enable(); | 226 engine_->Enable(kTestImeEngineId); |
| 233 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 227 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 234 engine_->FocusOut(); | 228 engine_->FocusOut(); |
| 235 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); | 229 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); |
| 236 // Focus change when disabled. | 230 // Focus change when disabled. |
| 237 engine_->Disable(); | 231 engine_->Disable(); |
| 238 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 232 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 239 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); | 233 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); |
| 240 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 234 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 241 engine_->FocusOut(); | 235 engine_->FocusOut(); |
| 242 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 236 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 243 } | 237 } |
| 244 | 238 |
| 245 TEST_F(InputMethodEngineTest, TestSwitching_Password_3rd_Party) { | 239 TEST_F(InputMethodEngineTest, TestSwitching_Password_3rd_Party) { |
| 246 CreateEngine(false); | 240 CreateEngine(false); |
| 247 // Enable/disable with focus. | 241 // Enable/disable with focus. |
| 248 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 242 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 249 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 243 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 250 engine_->Enable(); | 244 engine_->Enable(kTestImeEngineId); |
| 251 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 245 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 252 engine_->Disable(); | 246 engine_->Disable(); |
| 253 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 247 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 254 // Focus change when enabled. | 248 // Focus change when enabled. |
| 255 engine_->Enable(); | 249 engine_->Enable(kTestImeEngineId); |
| 256 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 250 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 257 engine_->FocusOut(); | 251 engine_->FocusOut(); |
| 258 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); | 252 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); |
| 259 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 253 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 260 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); | 254 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 261 engine_->Disable(); | 255 engine_->Disable(); |
| 262 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 256 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 263 } | 257 } |
| 264 | 258 |
| 265 TEST_F(InputMethodEngineTest, TestSwitching_Password_Whitelisted) { | 259 TEST_F(InputMethodEngineTest, TestSwitching_Password_Whitelisted) { |
| 266 CreateEngine(true); | 260 CreateEngine(true); |
| 267 // Enable/disable with focus. | 261 // Enable/disable with focus. |
| 268 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 262 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 269 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); | 263 EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); |
| 270 engine_->Enable(); | 264 engine_->Enable(kTestImeEngineId); |
| 271 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 265 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 272 engine_->Disable(); | 266 engine_->Disable(); |
| 273 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 267 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 274 // Focus change when enabled. | 268 // Focus change when enabled. |
| 275 engine_->Enable(); | 269 engine_->Enable(kTestImeEngineId); |
| 276 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); | 270 EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 277 engine_->FocusOut(); | 271 engine_->FocusOut(); |
| 278 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); | 272 EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); |
| 279 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 273 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 280 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); | 274 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); |
| 281 engine_->Disable(); | 275 engine_->Disable(); |
| 282 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 276 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
| 283 } | 277 } |
| 284 | 278 |
| 285 TEST_F(InputMethodEngineTest, TestHistograms) { | 279 TEST_F(InputMethodEngineTest, TestHistograms) { |
| 286 CreateEngine(true); | 280 CreateEngine(true); |
| 287 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); | 281 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); |
| 288 engine_->Enable(); | 282 engine_->Enable(kTestImeEngineId); |
| 289 std::string error; | 283 std::string error; |
| 290 ExpectNewSample("InputMethod.Enable.test_engine_id", 1, 1, 1); | 284 ExpectNewSample("InputMethod.Enable.test_engine_id", 1, 1, 1); |
| 291 engine_->CommitText(1, "input", &error); | 285 engine_->CommitText(1, "input", &error); |
| 292 engine_->CommitText(1, "入力", &error); | 286 engine_->CommitText(1, "入力", &error); |
| 293 engine_->CommitText(1, "input入力", &error); | 287 engine_->CommitText(1, "input入力", &error); |
| 294 ExpectNewSample("InputMethod.Commit.test_engine_id", 1, 3, 3); | 288 ExpectNewSample("InputMethod.Commit.test_engine_id", 1, 3, 3); |
| 295 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 5, 3, 1); | 289 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 5, 3, 1); |
| 296 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 2, 3, 1); | 290 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 2, 3, 1); |
| 297 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 7, 3, 1); | 291 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 7, 3, 1); |
| 298 } | 292 } |
| 299 | 293 |
| 300 } // namespace input_method | 294 } // namespace input_method |
| 301 } // namespace chromeos | 295 } // namespace chromeos |
| OLD | NEW |