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

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: responding to comments 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 StatisticsRecorder::Initialize();
65 } 74 }
66 75
67 virtual void TearDown() OVERRIDE { 76 virtual void TearDown() OVERRIDE {
68 MessageLoop::current()->RunUntilIdle(); 77 MessageLoop::current()->RunUntilIdle();
69 } 78 }
70 79
71 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private 80 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private
72 // function to avoid a large number of FRIEND_TEST declarations in 81 // function to avoid a large number of FRIEND_TEST declarations in
73 // SpellcheckCustomDictionary. 82 // SpellcheckCustomDictionary.
74 chrome::spellcheck_common::WordList LoadDictionaryFile( 83 chrome::spellcheck_common::WordList LoadDictionaryFile(
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 EXPECT_FALSE(client_custom_dictionary->IsSyncing()); 1076 EXPECT_FALSE(client_custom_dictionary->IsSyncing());
1068 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2, 1077 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2,
1069 client_custom_dictionary->GetWords().size()); 1078 client_custom_dictionary->GetWords().size());
1070 } 1079 }
1071 1080
1072 // The sync server should not receive more words, because it has the maximum 1081 // The sync server should not receive more words, because it has the maximum
1073 // number of words already. 1082 // number of words already.
1074 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 1083 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
1075 server_custom_dictionary->GetWords().size()); 1084 server_custom_dictionary->GetWords().size());
1076 } 1085 }
1086
1087 TEST_F(SpellcheckCustomDictionaryTest, RecordSizeStatsCorrectly) {
1088 // Record a baseline.
1089 SpellCheckHostMetrics::RecordCustomWordCountStats(123);
1090
1091 HistogramBase* histogram =
1092 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1093 ASSERT_TRUE(histogram != NULL);
1094 scoped_ptr<HistogramSamples> baseline = histogram->SnapshotSamples();
1095
1096 // Load the dictionary which should be empty.
1097 base::FilePath path =
1098 profile_->GetPath().Append(chrome::kCustomDictionaryFileName);
1099 WordList loaded_custom_words = LoadDictionaryFile(path);
1100 EXPECT_EQ(0u, loaded_custom_words.size());
1101
1102 // We expect there to be an entry with 0.
1103 histogram =
1104 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1105 ASSERT_TRUE(histogram != NULL);
1106 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
1107
1108 samples->Subtract(*baseline);
1109 EXPECT_EQ(0,samples->sum());
1110
1111 SpellcheckCustomDictionary::Change change;
1112 change.AddWord("bar");
1113 change.AddWord("foo");
1114 UpdateDictionaryFile(change, path);
1115
1116 // Load the dictionary again and it should have 2 entries.
1117 loaded_custom_words = LoadDictionaryFile(path);
1118 EXPECT_EQ(2u, loaded_custom_words.size());
1119
1120 histogram =
1121 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1122 ASSERT_TRUE(histogram != NULL);
1123 scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples();
1124
1125 samples2->Subtract(*baseline);
1126 EXPECT_EQ(2,samples2->sum());
1127 }
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