Index: chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc |
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc |
index a08da3fb34ceccac6d77f4e69b37e96ac524c319..f8471d9ad60dd8532bf95a62dcdeaf2c484ad647 100644 |
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc |
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc |
@@ -6,9 +6,13 @@ |
#include "base/file_util.h" |
#include "base/message_loop.h" |
+#include "base/metrics/histogram.h" |
+#include "base/metrics/histogram_samples.h" |
+#include "base/metrics/statistics_recorder.h" |
#include "base/strings/string_number_conversions.h" |
#include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
#include "chrome/browser/spellchecker/spellcheck_factory.h" |
+#include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
#include "chrome/browser/spellchecker/spellcheck_service.h" |
#include "chrome/common/chrome_constants.h" |
#include "chrome/common/spellcheck_common.h" |
@@ -22,6 +26,9 @@ |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+using base::HistogramBase; |
+using base::HistogramSamples; |
+using base::StatisticsRecorder; |
using content::BrowserThread; |
using chrome::spellcheck_common::WordList; |
@@ -62,6 +69,9 @@ class SpellcheckCustomDictionaryTest : public testing::Test { |
// Use SetTestingFactoryAndUse to force creation and initialization. |
SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
profile_.get(), &BuildSpellcheckService); |
+ |
+ base::StatisticsRecorder::Initialize(); |
please use gerrit instead
2013/04/04 00:31:55
Nit: No need for "base::" here since you're "using
rpetterson
2013/04/04 20:24:37
Done.
|
+ metrics_.reset(new SpellCheckHostMetrics); |
please use gerrit instead
2013/04/04 00:31:55
No need for an instance of SpellcheckHostMetrics o
rpetterson
2013/04/04 20:24:37
Done.
|
} |
virtual void TearDown() OVERRIDE { |
@@ -107,6 +117,7 @@ class SpellcheckCustomDictionaryTest : public testing::Test { |
content::TestBrowserThread file_thread_; |
scoped_ptr<TestingProfile> profile_; |
+ scoped_ptr<SpellCheckHostMetrics> metrics_; |
please use gerrit instead
2013/04/04 00:31:55
Ditto.
rpetterson
2013/04/04 20:24:37
Done.
|
}; |
// A wrapper around SpellcheckCustomDictionary that does not own the wrapped |
@@ -1074,3 +1085,45 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncLimit) { |
EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
server_custom_dictionary->GetWords().size()); |
} |
+ |
+TEST_F(SpellcheckCustomDictionaryTest, RecordSizeStatsCorrectly) { |
+ // Record a baseline. |
+ metrics_->RecordCustomWordCountStats(123); |
please use gerrit instead
2013/04/04 00:31:55
Ditto.
rpetterson
2013/04/04 20:24:37
Done.
|
+ |
+ HistogramBase* histogram = |
+ StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); |
+ ASSERT_TRUE(histogram != NULL); |
+ scoped_ptr<HistogramSamples> baseline = histogram->SnapshotSamples(); |
+ |
+ // Load the dictionary which should be empty. |
+ base::FilePath path = |
+ profile_->GetPath().Append(chrome::kCustomDictionaryFileName); |
+ WordList loaded_custom_words = LoadDictionaryFile(path); |
+ EXPECT_EQ(0u, loaded_custom_words.size()); |
+ |
+ // We expect there to be an entry with 0. |
+ histogram = |
+ StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); |
+ ASSERT_TRUE(histogram != NULL); |
+ scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); |
+ |
+ samples->Subtract(*baseline); |
+ EXPECT_EQ(0,samples->sum()); |
+ |
+ SpellcheckCustomDictionary::Change change; |
+ change.AddWord("bar"); |
+ change.AddWord("foo"); |
+ UpdateDictionaryFile(change, path); |
+ |
+ // Load the dictionary again and it should have 2 entries. |
+ loaded_custom_words = LoadDictionaryFile(path); |
+ EXPECT_EQ(2u, loaded_custom_words.size()); |
+ |
+ histogram = |
+ StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); |
+ ASSERT_TRUE(histogram != NULL); |
+ scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples(); |
+ |
+ samples2->Subtract(*baseline); |
+ EXPECT_EQ(2,samples2->sum()); |
+} |