Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc

Issue 13428008: [Spellcheck] Record the number of words in the custom dictionary when the custom dictionary is load… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: removing the todo, fixing grammar Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_samples.h"
11 #include "base/metrics/statistics_recorder.h"
9 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" 13 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h"
11 #include "chrome/browser/spellchecker/spellcheck_factory.h" 14 #include "chrome/browser/spellchecker/spellcheck_factory.h"
15 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
12 #include "chrome/browser/spellchecker/spellcheck_service.h" 16 #include "chrome/browser/spellchecker/spellcheck_service.h"
13 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
14 #include "chrome/common/spellcheck_common.h" 18 #include "chrome/common/spellcheck_common.h"
15 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
17 #include "sync/api/sync_change.h" 21 #include "sync/api/sync_change.h"
18 #include "sync/api/sync_data.h" 22 #include "sync/api/sync_data.h"
19 #include "sync/api/sync_error_factory.h" 23 #include "sync/api/sync_error_factory.h"
20 #include "sync/api/sync_error_factory_mock.h" 24 #include "sync/api/sync_error_factory_mock.h"
21 #include "sync/protocol/sync.pb.h" 25 #include "sync/protocol/sync.pb.h"
22 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
24 28
29 using base::HistogramBase;
30 using base::HistogramSamples;
31 using base::StatisticsRecorder;
25 using content::BrowserThread; 32 using content::BrowserThread;
26 using chrome::spellcheck_common::WordList; 33 using chrome::spellcheck_common::WordList;
27 34
28 namespace { 35 namespace {
29 36
30 // Get all sync data for the custom dictionary without limiting to maximum 37 // Get all sync data for the custom dictionary without limiting to maximum
31 // number of syncable words. 38 // number of syncable words.
32 syncer::SyncDataList GetAllSyncDataNoLimit( 39 syncer::SyncDataList GetAllSyncDataNoLimit(
33 const SpellcheckCustomDictionary* dictionary) { 40 const SpellcheckCustomDictionary* dictionary) {
34 syncer::SyncDataList data; 41 syncer::SyncDataList data;
(...skipping 20 matching lines...) Expand all
55 SpellcheckCustomDictionaryTest() 62 SpellcheckCustomDictionaryTest()
56 : ui_thread_(BrowserThread::UI, &message_loop_), 63 : ui_thread_(BrowserThread::UI, &message_loop_),
57 file_thread_(BrowserThread::FILE, &message_loop_), 64 file_thread_(BrowserThread::FILE, &message_loop_),
58 profile_(new TestingProfile) { 65 profile_(new TestingProfile) {
59 } 66 }
60 67
61 virtual void SetUp() OVERRIDE { 68 virtual void SetUp() OVERRIDE {
62 // Use SetTestingFactoryAndUse to force creation and initialization. 69 // Use SetTestingFactoryAndUse to force creation and initialization.
63 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 70 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
64 profile_.get(), &BuildSpellcheckService); 71 profile_.get(), &BuildSpellcheckService);
72
73 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.
74 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.
65 } 75 }
66 76
67 virtual void TearDown() OVERRIDE { 77 virtual void TearDown() OVERRIDE {
68 MessageLoop::current()->RunUntilIdle(); 78 MessageLoop::current()->RunUntilIdle();
69 } 79 }
70 80
71 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private 81 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private
72 // function to avoid a large number of FRIEND_TEST declarations in 82 // function to avoid a large number of FRIEND_TEST declarations in
73 // SpellcheckCustomDictionary. 83 // SpellcheckCustomDictionary.
74 chrome::spellcheck_common::WordList LoadDictionaryFile( 84 chrome::spellcheck_common::WordList LoadDictionaryFile(
(...skipping 25 matching lines...) Expand all
100 SpellcheckCustomDictionary& dictionary, 110 SpellcheckCustomDictionary& dictionary,
101 const SpellcheckCustomDictionary::Change& change) { 111 const SpellcheckCustomDictionary::Change& change) {
102 return dictionary.Apply(change); 112 return dictionary.Apply(change);
103 } 113 }
104 114
105 MessageLoop message_loop_; 115 MessageLoop message_loop_;
106 content::TestBrowserThread ui_thread_; 116 content::TestBrowserThread ui_thread_;
107 content::TestBrowserThread file_thread_; 117 content::TestBrowserThread file_thread_;
108 118
109 scoped_ptr<TestingProfile> profile_; 119 scoped_ptr<TestingProfile> profile_;
120 scoped_ptr<SpellCheckHostMetrics> metrics_;
please use gerrit instead 2013/04/04 00:31:55 Ditto.
rpetterson 2013/04/04 20:24:37 Done.
110 }; 121 };
111 122
112 // A wrapper around SpellcheckCustomDictionary that does not own the wrapped 123 // A wrapper around SpellcheckCustomDictionary that does not own the wrapped
113 // object. An instance of this class can be inside of a scoped pointer safely 124 // object. An instance of this class can be inside of a scoped pointer safely
114 // while the dictionary is managed by another scoped pointer. 125 // while the dictionary is managed by another scoped pointer.
115 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { 126 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
116 public: 127 public:
117 explicit SyncChangeProcessorDelegate(SpellcheckCustomDictionary* dictionary) 128 explicit SyncChangeProcessorDelegate(SpellcheckCustomDictionary* dictionary)
118 : dictionary_(dictionary) {} 129 : dictionary_(dictionary) {}
119 virtual ~SyncChangeProcessorDelegate() {} 130 virtual ~SyncChangeProcessorDelegate() {}
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 EXPECT_FALSE(client_custom_dictionary->IsSyncing()); 1078 EXPECT_FALSE(client_custom_dictionary->IsSyncing());
1068 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2, 1079 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2,
1069 client_custom_dictionary->GetWords().size()); 1080 client_custom_dictionary->GetWords().size());
1070 } 1081 }
1071 1082
1072 // The sync server should not receive more words, because it has the maximum 1083 // The sync server should not receive more words, because it has the maximum
1073 // number of words already. 1084 // number of words already.
1074 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 1085 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
1075 server_custom_dictionary->GetWords().size()); 1086 server_custom_dictionary->GetWords().size());
1076 } 1087 }
1088
1089 TEST_F(SpellcheckCustomDictionaryTest, RecordSizeStatsCorrectly) {
1090 // Record a baseline.
1091 metrics_->RecordCustomWordCountStats(123);
please use gerrit instead 2013/04/04 00:31:55 Ditto.
rpetterson 2013/04/04 20:24:37 Done.
1092
1093 HistogramBase* histogram =
1094 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1095 ASSERT_TRUE(histogram != NULL);
1096 scoped_ptr<HistogramSamples> baseline = histogram->SnapshotSamples();
1097
1098 // Load the dictionary which should be empty.
1099 base::FilePath path =
1100 profile_->GetPath().Append(chrome::kCustomDictionaryFileName);
1101 WordList loaded_custom_words = LoadDictionaryFile(path);
1102 EXPECT_EQ(0u, loaded_custom_words.size());
1103
1104 // We expect there to be an entry with 0.
1105 histogram =
1106 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1107 ASSERT_TRUE(histogram != NULL);
1108 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
1109
1110 samples->Subtract(*baseline);
1111 EXPECT_EQ(0,samples->sum());
1112
1113 SpellcheckCustomDictionary::Change change;
1114 change.AddWord("bar");
1115 change.AddWord("foo");
1116 UpdateDictionaryFile(change, path);
1117
1118 // Load the dictionary again and it should have 2 entries.
1119 loaded_custom_words = LoadDictionaryFile(path);
1120 EXPECT_EQ(2u, loaded_custom_words.size());
1121
1122 histogram =
1123 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1124 ASSERT_TRUE(histogram != NULL);
1125 scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples();
1126
1127 samples2->Subtract(*baseline);
1128 EXPECT_EQ(2,samples2->sum());
1129 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_custom_dictionary.cc ('k') | chrome/browser/spellchecker/spellcheck_host_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698