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 kTestImeComponentId[] = "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.CommitLength", |
29 "InputMethod.CommitCharacter.test_engine_id", | |
30 }; | 29 }; |
31 | 30 |
32 scoped_ptr<base::HistogramSamples> GetHistogramSamples( | 31 scoped_ptr<base::HistogramSamples> GetHistogramSamples( |
33 const char* histogram_name) { | 32 const char* histogram_name) { |
34 base::HistogramBase* histogram = | 33 base::HistogramBase* histogram = |
35 base::StatisticsRecorder::FindHistogram(histogram_name); | 34 base::StatisticsRecorder::FindHistogram(histogram_name); |
36 EXPECT_NE(static_cast<base::HistogramBase*>(NULL), histogram); | 35 EXPECT_NE(static_cast<base::HistogramBase*>(NULL), histogram); |
37 return histogram->SnapshotSamples().Pass(); | 36 return histogram->SnapshotSamples().Pass(); |
38 } | 37 } |
39 | 38 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 } | 161 } |
163 | 162 |
164 void ExpectNewSample(const char* histogram_name, | 163 void ExpectNewSample(const char* histogram_name, |
165 base::HistogramBase::Sample sample, | 164 base::HistogramBase::Sample sample, |
166 int total_count, | 165 int total_count, |
167 int sample_count) { | 166 int sample_count) { |
168 scoped_ptr<base::HistogramSamples> delta_samples( | 167 scoped_ptr<base::HistogramSamples> delta_samples( |
169 GetHistogramSamplesDelta(histogram_name)); | 168 GetHistogramSamplesDelta(histogram_name)); |
170 EXPECT_EQ(total_count, delta_samples->TotalCount()); | 169 EXPECT_EQ(total_count, delta_samples->TotalCount()); |
171 EXPECT_EQ(sample_count, delta_samples->GetCount(sample)); | 170 EXPECT_EQ(sample_count, delta_samples->GetCount(sample)); |
172 } | 171 } |
Ilya Sherman
2014/09/16 00:00:28
Please use base::HistogramTester [1] rather than r
Shu Chen
2014/09/16 16:36:29
Done. But the test failed at ExpectUniqueSample(),
Ilya Sherman
2014/09/16 21:51:48
Thanks for updating the test code!
ExpectUniqueSa
Shu Chen
2014/09/17 15:17:27
Done.
| |
173 | 172 |
174 void CreateEngine(bool whitelisted) { | 173 void CreateEngine(bool whitelisted) { |
175 engine_.reset(new InputMethodEngine()); | 174 engine_.reset(new InputMethodEngine()); |
176 observer_ = new TestObserver(); | 175 observer_ = new TestObserver(); |
177 scoped_ptr<InputMethodEngineInterface::Observer> observer_ptr(observer_); | 176 scoped_ptr<InputMethodEngineInterface::Observer> observer_ptr(observer_); |
178 engine_->Initialize(observer_ptr.Pass(), | 177 engine_->Initialize(observer_ptr.Pass(), |
179 whitelisted ? kTestExtensionId : kTestExtensionId2); | 178 whitelisted ? kTestExtensionId : kTestExtensionId2); |
180 } | 179 } |
181 | 180 |
182 void FocusIn(ui::TextInputType input_type) { | 181 void FocusIn(ui::TextInputType input_type) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); | 272 FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); |
274 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); | 273 EXPECT_EQ(ONFOCUS, observer_->GetCallsBitmapAndReset()); |
275 engine_->Disable(); | 274 engine_->Disable(); |
276 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); | 275 EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); |
277 } | 276 } |
278 | 277 |
279 TEST_F(InputMethodEngineTest, TestHistograms) { | 278 TEST_F(InputMethodEngineTest, TestHistograms) { |
280 CreateEngine(true); | 279 CreateEngine(true); |
281 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); | 280 FocusIn(ui::TEXT_INPUT_TYPE_TEXT); |
282 engine_->Enable(kTestImeComponentId); | 281 engine_->Enable(kTestImeComponentId); |
282 std::vector<InputMethodEngineInterface::SegmentInfo> segments; | |
283 engine_->SetComposition( | |
284 engine_->GetCotextIdForTesting(), "test", 0, 0, 0, segments, NULL); | |
283 std::string error; | 285 std::string error; |
284 ExpectNewSample("InputMethod.Enable.test_engine_id", 1, 1, 1); | |
285 engine_->CommitText(1, "input", &error); | 286 engine_->CommitText(1, "input", &error); |
286 engine_->CommitText(1, "入力", &error); | 287 engine_->CommitText(1, |
287 engine_->CommitText(1, "input入力", &error); | 288 "\xE5\x85\xA5\xE5\x8A\x9B", // 2 UTF-8 characters |
288 ExpectNewSample("InputMethod.Commit.test_engine_id", 1, 3, 3); | 289 &error); |
289 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 5, 3, 1); | 290 engine_->CommitText(1, "input\xE5\x85\xA5\xE5\x8A\x9B", &error); |
290 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 2, 3, 1); | 291 ExpectNewSample("InputMethod.CommitLength", 5, 3, 1); |
291 ExpectNewSample("InputMethod.CommitCharacter.test_engine_id", 7, 3, 1); | 292 ExpectNewSample("InputMethod.CommitLength", 2, 3, 1); |
293 ExpectNewSample("InputMethod.CommitLength", 7, 3, 1); | |
292 } | 294 } |
293 | 295 |
294 } // namespace input_method | 296 } // namespace input_method |
295 } // namespace chromeos | 297 } // namespace chromeos |
OLD | NEW |