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 157 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(kTestImeEngineId); |
Yuki
2014/08/06 04:42:23
s/Engine/Component/
Shu Chen
2014/08/06 05:45:03
Done.
| |
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(kTestImeEngineId); |
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(kTestImeEngineId); |
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(kTestImeEngineId); |
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(kTestImeEngineId); |
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(kTestImeEngineId); |
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(kTestImeEngineId); |
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(kTestImeEngineId); |
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 |