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

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

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments. merge to ToT. Murder a DB thread and more TestBrowserThreads. Created 7 years, 5 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 | Annotate | Revision Log
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"
9 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_samples.h" 9 #include "base/metrics/histogram_samples.h"
11 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" 12 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h"
14 #include "chrome/browser/spellchecker/spellcheck_factory.h" 13 #include "chrome/browser/spellchecker/spellcheck_factory.h"
15 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 14 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
16 #include "chrome/browser/spellchecker/spellcheck_service.h" 15 #include "chrome/browser/spellchecker/spellcheck_service.h"
17 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/spellcheck_common.h" 17 #include "chrome/common/spellcheck_common.h"
19 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "net/url_request/test_url_fetcher_factory.h"
21 #include "sync/api/sync_change.h" 21 #include "sync/api/sync_change.h"
22 #include "sync/api/sync_data.h" 22 #include "sync/api/sync_data.h"
23 #include "sync/api/sync_error_factory.h" 23 #include "sync/api/sync_error_factory.h"
24 #include "sync/api/sync_error_factory_mock.h" 24 #include "sync/api/sync_error_factory_mock.h"
25 #include "sync/protocol/sync.pb.h" 25 #include "sync/protocol/sync.pb.h"
26 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 using base::HistogramBase; 29 using base::HistogramBase;
30 using base::HistogramSamples; 30 using base::HistogramSamples;
31 using base::StatisticsRecorder; 31 using base::StatisticsRecorder;
32 using content::BrowserThread;
33 using chrome::spellcheck_common::WordList; 32 using chrome::spellcheck_common::WordList;
34 using chrome::spellcheck_common::WordSet; 33 using chrome::spellcheck_common::WordSet;
35 34
36 namespace { 35 namespace {
37 36
38 // 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
39 // number of syncable words. 38 // number of syncable words.
40 syncer::SyncDataList GetAllSyncDataNoLimit( 39 syncer::SyncDataList GetAllSyncDataNoLimit(
41 const SpellcheckCustomDictionary* dictionary) { 40 const SpellcheckCustomDictionary* dictionary) {
42 syncer::SyncDataList data; 41 syncer::SyncDataList data;
(...skipping 10 matching lines...) Expand all
53 52
54 } // namespace 53 } // namespace
55 54
56 static BrowserContextKeyedService* BuildSpellcheckService( 55 static BrowserContextKeyedService* BuildSpellcheckService(
57 content::BrowserContext* profile) { 56 content::BrowserContext* profile) {
58 return new SpellcheckService(static_cast<Profile*>(profile)); 57 return new SpellcheckService(static_cast<Profile*>(profile));
59 } 58 }
60 59
61 class SpellcheckCustomDictionaryTest : public testing::Test { 60 class SpellcheckCustomDictionaryTest : public testing::Test {
62 protected: 61 protected:
63 SpellcheckCustomDictionaryTest()
64 : ui_thread_(BrowserThread::UI, &message_loop_),
65 file_thread_(BrowserThread::FILE, &message_loop_),
66 profile_(new TestingProfile) {
67 }
68
69 virtual void SetUp() OVERRIDE { 62 virtual void SetUp() OVERRIDE {
70 // Use SetTestingFactoryAndUse to force creation and initialization. 63 // Use SetTestingFactoryAndUse to force creation and initialization.
71 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 64 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
72 profile_.get(), &BuildSpellcheckService); 65 &profile_, &BuildSpellcheckService);
73 66
74 StatisticsRecorder::Initialize(); 67 StatisticsRecorder::Initialize();
75 } 68 }
76 69
77 virtual void TearDown() OVERRIDE {
78 base::MessageLoop::current()->RunUntilIdle();
79 }
80
81 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private 70 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private
82 // function to avoid a large number of FRIEND_TEST declarations in 71 // function to avoid a large number of FRIEND_TEST declarations in
83 // SpellcheckCustomDictionary. 72 // SpellcheckCustomDictionary.
84 chrome::spellcheck_common::WordList LoadDictionaryFile( 73 chrome::spellcheck_common::WordList LoadDictionaryFile(
85 const base::FilePath& path) { 74 const base::FilePath& path) {
86 return SpellcheckCustomDictionary::LoadDictionaryFile(path); 75 return SpellcheckCustomDictionary::LoadDictionaryFile(path);
87 } 76 }
88 77
89 // A wrapper around SpellcheckCustomDictionary::UpdateDictionaryFile private 78 // A wrapper around SpellcheckCustomDictionary::UpdateDictionaryFile private
90 // function to avoid a large number of FRIEND_TEST declarations in 79 // function to avoid a large number of FRIEND_TEST declarations in
(...skipping 14 matching lines...) Expand all
105 } 94 }
106 95
107 // A wrapper around SpellcheckCustomDictionary::Apply private method to avoid 96 // A wrapper around SpellcheckCustomDictionary::Apply private method to avoid
108 // a large number of FRIEND_TEST declarations in SpellcheckCustomDictionary. 97 // a large number of FRIEND_TEST declarations in SpellcheckCustomDictionary.
109 void Apply( 98 void Apply(
110 SpellcheckCustomDictionary& dictionary, 99 SpellcheckCustomDictionary& dictionary,
111 const SpellcheckCustomDictionary::Change& change) { 100 const SpellcheckCustomDictionary::Change& change) {
112 return dictionary.Apply(change); 101 return dictionary.Apply(change);
113 } 102 }
114 103
115 base::MessageLoop message_loop_; 104 content::TestBrowserThreadBundle thread_bundle_;
116 content::TestBrowserThread ui_thread_;
117 content::TestBrowserThread file_thread_;
118 105
119 scoped_ptr<TestingProfile> profile_; 106 TestingProfile profile_;
107 net::TestURLFetcherFactory fetcher_factory_;
120 }; 108 };
121 109
122 // A wrapper around SpellcheckCustomDictionary that does not own the wrapped 110 // A wrapper around SpellcheckCustomDictionary that does not own the wrapped
123 // object. An instance of this class can be inside of a scoped pointer safely 111 // object. An instance of this class can be inside of a scoped pointer safely
124 // while the dictionary is managed by another scoped pointer. 112 // while the dictionary is managed by another scoped pointer.
125 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { 113 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
126 public: 114 public:
127 explicit SyncChangeProcessorDelegate(SpellcheckCustomDictionary* dictionary) 115 explicit SyncChangeProcessorDelegate(SpellcheckCustomDictionary* dictionary)
128 : dictionary_(dictionary) {} 116 : dictionary_(dictionary) {}
129 virtual ~SyncChangeProcessorDelegate() {} 117 virtual ~SyncChangeProcessorDelegate() {}
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 const SpellcheckCustomDictionary::Change& change) OVERRIDE { changes_++; } 168 const SpellcheckCustomDictionary::Change& change) OVERRIDE { changes_++; }
181 169
182 private: 170 private:
183 int loads_; 171 int loads_;
184 int changes_; 172 int changes_;
185 DISALLOW_COPY_AND_ASSIGN(DictionaryObserverCounter); 173 DISALLOW_COPY_AND_ASSIGN(DictionaryObserverCounter);
186 }; 174 };
187 175
188 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { 176 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) {
189 base::FilePath path = 177 base::FilePath path =
190 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); 178 profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
191 WordList loaded_custom_words = LoadDictionaryFile(path); 179 WordList loaded_custom_words = LoadDictionaryFile(path);
192 180
193 // The custom word list should be empty now. 181 // The custom word list should be empty now.
194 WordList expected; 182 WordList expected;
195 EXPECT_EQ(expected, loaded_custom_words); 183 EXPECT_EQ(expected, loaded_custom_words);
196 184
197 SpellcheckCustomDictionary::Change change; 185 SpellcheckCustomDictionary::Change change;
198 change.AddWord("bar"); 186 change.AddWord("bar");
199 change.AddWord("foo"); 187 change.AddWord("foo");
200 188
201 UpdateDictionaryFile(change, path); 189 UpdateDictionaryFile(change, path);
202 expected.push_back("bar"); 190 expected.push_back("bar");
203 expected.push_back("foo"); 191 expected.push_back("foo");
204 192
205 // The custom word list should include written words. 193 // The custom word list should include written words.
206 loaded_custom_words = LoadDictionaryFile(path); 194 loaded_custom_words = LoadDictionaryFile(path);
207 EXPECT_EQ(expected, loaded_custom_words); 195 EXPECT_EQ(expected, loaded_custom_words);
208 196
209 change = SpellcheckCustomDictionary::Change(); 197 change = SpellcheckCustomDictionary::Change();
210 change.RemoveWord("bar"); 198 change.RemoveWord("bar");
211 change.RemoveWord("foo"); 199 change.RemoveWord("foo");
212 UpdateDictionaryFile(change, path); 200 UpdateDictionaryFile(change, path);
213 loaded_custom_words = LoadDictionaryFile(path); 201 loaded_custom_words = LoadDictionaryFile(path);
214 expected.clear(); 202 expected.clear();
215 EXPECT_EQ(expected, loaded_custom_words); 203 EXPECT_EQ(expected, loaded_custom_words);
216 } 204 }
217 205
218 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) { 206 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) {
219 SpellcheckService* spellcheck_service = 207 SpellcheckService* spellcheck_service =
220 SpellcheckServiceFactory::GetForProfile(profile_.get()); 208 SpellcheckServiceFactory::GetForProfile(&profile_);
221 SpellcheckCustomDictionary* custom_dictionary = 209 SpellcheckCustomDictionary* custom_dictionary =
222 spellcheck_service->GetCustomDictionary(); 210 spellcheck_service->GetCustomDictionary();
223 TestingProfile profile2; 211 TestingProfile profile2;
224 SpellcheckService* spellcheck_service2 = 212 SpellcheckService* spellcheck_service2 =
225 static_cast<SpellcheckService*>( 213 static_cast<SpellcheckService*>(
226 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 214 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
227 &profile2, &BuildSpellcheckService)); 215 &profile2, &BuildSpellcheckService));
228 SpellcheckCustomDictionary* custom_dictionary2 = 216 SpellcheckCustomDictionary* custom_dictionary2 =
229 spellcheck_service2->GetCustomDictionary(); 217 spellcheck_service2->GetCustomDictionary();
230 218
(...skipping 13 matching lines...) Expand all
244 WordSet actual1 = custom_dictionary->GetWords(); 232 WordSet actual1 = custom_dictionary->GetWords();
245 EXPECT_EQ(actual1, expected1); 233 EXPECT_EQ(actual1, expected1);
246 234
247 WordSet actual2 = custom_dictionary2->GetWords(); 235 WordSet actual2 = custom_dictionary2->GetWords();
248 EXPECT_EQ(actual2, expected2); 236 EXPECT_EQ(actual2, expected2);
249 } 237 }
250 238
251 // Legacy empty dictionary should be converted to new format empty dictionary. 239 // Legacy empty dictionary should be converted to new format empty dictionary.
252 TEST_F(SpellcheckCustomDictionaryTest, LegacyEmptyDictionaryShouldBeConverted) { 240 TEST_F(SpellcheckCustomDictionaryTest, LegacyEmptyDictionaryShouldBeConverted) {
253 base::FilePath path = 241 base::FilePath path =
254 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); 242 profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
255 243
256 std::string content; 244 std::string content;
257 file_util::WriteFile(path, content.c_str(), content.length()); 245 file_util::WriteFile(path, content.c_str(), content.length());
258 WordList loaded_custom_words = LoadDictionaryFile(path); 246 WordList loaded_custom_words = LoadDictionaryFile(path);
259 EXPECT_TRUE(loaded_custom_words.empty()); 247 EXPECT_TRUE(loaded_custom_words.empty());
260 } 248 }
261 249
262 // Legacy dictionary with two words should be converted to new format dictionary 250 // Legacy dictionary with two words should be converted to new format dictionary
263 // with two words. 251 // with two words.
264 TEST_F(SpellcheckCustomDictionaryTest, 252 TEST_F(SpellcheckCustomDictionaryTest,
265 LegacyDictionaryWithTwoWordsShouldBeConverted) { 253 LegacyDictionaryWithTwoWordsShouldBeConverted) {
266 base::FilePath path = 254 base::FilePath path =
267 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); 255 profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
268 256
269 std::string content = "foo\nbar\nfoo\n"; 257 std::string content = "foo\nbar\nfoo\n";
270 file_util::WriteFile(path, content.c_str(), content.length()); 258 file_util::WriteFile(path, content.c_str(), content.length());
271 WordList loaded_custom_words = LoadDictionaryFile(path); 259 WordList loaded_custom_words = LoadDictionaryFile(path);
272 WordList expected; 260 WordList expected;
273 expected.push_back("bar"); 261 expected.push_back("bar");
274 expected.push_back("foo"); 262 expected.push_back("foo");
275 EXPECT_EQ(expected, loaded_custom_words); 263 EXPECT_EQ(expected, loaded_custom_words);
276 } 264 }
277 265
278 // Illegal words should be removed. Leading and trailing whitespace should be 266 // Illegal words should be removed. Leading and trailing whitespace should be
279 // trimmed. 267 // trimmed.
280 TEST_F(SpellcheckCustomDictionaryTest, 268 TEST_F(SpellcheckCustomDictionaryTest,
281 IllegalWordsShouldBeRemovedFromDictionary) { 269 IllegalWordsShouldBeRemovedFromDictionary) {
282 base::FilePath path = 270 base::FilePath path =
283 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); 271 profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
284 272
285 std::string content = "foo\n foo bar \n\n \nbar\n" 273 std::string content = "foo\n foo bar \n\n \nbar\n"
286 "01234567890123456789012345678901234567890123456789" 274 "01234567890123456789012345678901234567890123456789"
287 "01234567890123456789012345678901234567890123456789"; 275 "01234567890123456789012345678901234567890123456789";
288 file_util::WriteFile(path, content.c_str(), content.length()); 276 file_util::WriteFile(path, content.c_str(), content.length());
289 WordList loaded_custom_words = LoadDictionaryFile(path); 277 WordList loaded_custom_words = LoadDictionaryFile(path);
290 WordList expected; 278 WordList expected;
291 expected.push_back("bar"); 279 expected.push_back("bar");
292 expected.push_back("foo"); 280 expected.push_back("foo");
293 expected.push_back("foo bar"); 281 expected.push_back("foo bar");
294 EXPECT_EQ(expected, loaded_custom_words); 282 EXPECT_EQ(expected, loaded_custom_words);
295 } 283 }
296 284
297 // Write to dictionary should backup previous version and write the word to the 285 // Write to dictionary should backup previous version and write the word to the
298 // end of the dictionary. If the dictionary file is corrupted on disk, the 286 // end of the dictionary. If the dictionary file is corrupted on disk, the
299 // previous version should be reloaded. 287 // previous version should be reloaded.
300 TEST_F(SpellcheckCustomDictionaryTest, CorruptedWriteShouldBeRecovered) { 288 TEST_F(SpellcheckCustomDictionaryTest, CorruptedWriteShouldBeRecovered) {
301 base::FilePath path = 289 base::FilePath path =
302 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); 290 profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
303 291
304 std::string content = "foo\nbar"; 292 std::string content = "foo\nbar";
305 file_util::WriteFile(path, content.c_str(), content.length()); 293 file_util::WriteFile(path, content.c_str(), content.length());
306 WordList loaded_custom_words = LoadDictionaryFile(path); 294 WordList loaded_custom_words = LoadDictionaryFile(path);
307 WordList expected; 295 WordList expected;
308 expected.push_back("bar"); 296 expected.push_back("bar");
309 expected.push_back("foo"); 297 expected.push_back("foo");
310 EXPECT_EQ(expected, loaded_custom_words); 298 EXPECT_EQ(expected, loaded_custom_words);
311 299
312 SpellcheckCustomDictionary::Change change; 300 SpellcheckCustomDictionary::Change change;
313 change.AddWord("baz"); 301 change.AddWord("baz");
314 UpdateDictionaryFile(change, path); 302 UpdateDictionaryFile(change, path);
315 content.clear(); 303 content.clear();
316 file_util::ReadFileToString(path, &content); 304 file_util::ReadFileToString(path, &content);
317 content.append("corruption"); 305 content.append("corruption");
318 file_util::WriteFile(path, content.c_str(), content.length()); 306 file_util::WriteFile(path, content.c_str(), content.length());
319 loaded_custom_words = LoadDictionaryFile(path); 307 loaded_custom_words = LoadDictionaryFile(path);
320 EXPECT_EQ(expected, loaded_custom_words); 308 EXPECT_EQ(expected, loaded_custom_words);
321 } 309 }
322 310
323 TEST_F(SpellcheckCustomDictionaryTest, 311 TEST_F(SpellcheckCustomDictionaryTest,
324 GetAllSyncDataAccuratelyReflectsDictionaryState) { 312 GetAllSyncDataAccuratelyReflectsDictionaryState) {
325 SpellcheckCustomDictionary* dictionary = 313 SpellcheckCustomDictionary* dictionary =
326 SpellcheckServiceFactory::GetForProfile( 314 SpellcheckServiceFactory::GetForProfile(
327 profile_.get())->GetCustomDictionary(); 315 &profile_)->GetCustomDictionary();
328 316
329 syncer::SyncDataList data = dictionary->GetAllSyncData(syncer::DICTIONARY); 317 syncer::SyncDataList data = dictionary->GetAllSyncData(syncer::DICTIONARY);
330 EXPECT_TRUE(data.empty()); 318 EXPECT_TRUE(data.empty());
331 319
332 EXPECT_TRUE(dictionary->AddWord("bar")); 320 EXPECT_TRUE(dictionary->AddWord("bar"));
333 EXPECT_TRUE(dictionary->AddWord("foo")); 321 EXPECT_TRUE(dictionary->AddWord("foo"));
334 322
335 data = dictionary->GetAllSyncData(syncer::DICTIONARY); 323 data = dictionary->GetAllSyncData(syncer::DICTIONARY);
336 EXPECT_EQ(2UL, data.size()); 324 EXPECT_EQ(2UL, data.size());
337 std::vector<std::string> words; 325 std::vector<std::string> words;
338 words.push_back("bar"); 326 words.push_back("bar");
339 words.push_back("foo"); 327 words.push_back("foo");
340 for (size_t i = 0; i < data.size(); i++) { 328 for (size_t i = 0; i < data.size(); i++) {
341 EXPECT_TRUE(data[i].GetSpecifics().has_dictionary()); 329 EXPECT_TRUE(data[i].GetSpecifics().has_dictionary());
342 EXPECT_EQ(syncer::DICTIONARY, data[i].GetDataType()); 330 EXPECT_EQ(syncer::DICTIONARY, data[i].GetDataType());
343 EXPECT_EQ(words[i], data[i].GetTag()); 331 EXPECT_EQ(words[i], data[i].GetTag());
344 EXPECT_EQ(words[i], data[i].GetSpecifics().dictionary().word()); 332 EXPECT_EQ(words[i], data[i].GetSpecifics().dictionary().word());
345 } 333 }
346 334
347 EXPECT_TRUE(dictionary->RemoveWord("bar")); 335 EXPECT_TRUE(dictionary->RemoveWord("bar"));
348 EXPECT_TRUE(dictionary->RemoveWord("foo")); 336 EXPECT_TRUE(dictionary->RemoveWord("foo"));
349 337
350 data = dictionary->GetAllSyncData(syncer::DICTIONARY); 338 data = dictionary->GetAllSyncData(syncer::DICTIONARY);
351 EXPECT_TRUE(data.empty()); 339 EXPECT_TRUE(data.empty());
352 } 340 }
353 341
354 TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) { 342 TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) {
355 SpellcheckCustomDictionary* dictionary = 343 SpellcheckCustomDictionary* dictionary =
356 SpellcheckServiceFactory::GetForProfile( 344 SpellcheckServiceFactory::GetForProfile(
357 profile_.get())->GetCustomDictionary(); 345 &profile_)->GetCustomDictionary();
358 346
359 SpellcheckCustomDictionary::Change change; 347 SpellcheckCustomDictionary::Change change;
360 for (size_t i = 0; 348 for (size_t i = 0;
361 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1; 349 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1;
362 i++) { 350 i++) {
363 change.AddWord("foo" + base::Uint64ToString(i)); 351 change.AddWord("foo" + base::Uint64ToString(i));
364 } 352 }
365 Apply(*dictionary, change); 353 Apply(*dictionary, change);
366 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1, 354 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1,
367 dictionary->GetWords().size()); 355 dictionary->GetWords().size());
(...skipping 14 matching lines...) Expand all
382 370
383 dictionary->AddWord("snafoo"); 371 dictionary->AddWord("snafoo");
384 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 2, 372 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 2,
385 dictionary->GetWords().size()); 373 dictionary->GetWords().size());
386 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 374 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
387 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 375 dictionary->GetAllSyncData(syncer::DICTIONARY).size());
388 } 376 }
389 377
390 TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) { 378 TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) {
391 SpellcheckService* spellcheck_service = 379 SpellcheckService* spellcheck_service =
392 SpellcheckServiceFactory::GetForProfile(profile_.get()); 380 SpellcheckServiceFactory::GetForProfile(&profile_);
393 SpellcheckCustomDictionary* dictionary = 381 SpellcheckCustomDictionary* dictionary =
394 spellcheck_service->GetCustomDictionary(); 382 spellcheck_service->GetCustomDictionary();
395 383
396 dictionary->AddWord("foo"); 384 dictionary->AddWord("foo");
397 dictionary->AddWord("bar"); 385 dictionary->AddWord("bar");
398 386
399 syncer::SyncChangeList changes; 387 syncer::SyncChangeList changes;
400 { 388 {
401 // Add existing word. 389 // Add existing word.
402 std::string word = "foo"; 390 std::string word = "foo";
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 441
454 const WordSet& words = dictionary->GetWords(); 442 const WordSet& words = dictionary->GetWords();
455 EXPECT_EQ(2UL, words.size()); 443 EXPECT_EQ(2UL, words.size());
456 EXPECT_EQ(0UL, words.count("bar")); 444 EXPECT_EQ(0UL, words.count("bar"));
457 EXPECT_EQ(1UL, words.count("foo")); 445 EXPECT_EQ(1UL, words.count("foo"));
458 EXPECT_EQ(1UL, words.count("baz")); 446 EXPECT_EQ(1UL, words.count("baz"));
459 } 447 }
460 448
461 TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) { 449 TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) {
462 SpellcheckService* spellcheck_service = 450 SpellcheckService* spellcheck_service =
463 SpellcheckServiceFactory::GetForProfile(profile_.get()); 451 SpellcheckServiceFactory::GetForProfile(&profile_);
464 SpellcheckCustomDictionary* custom_dictionary = 452 SpellcheckCustomDictionary* custom_dictionary =
465 spellcheck_service->GetCustomDictionary(); 453 spellcheck_service->GetCustomDictionary();
466 TestingProfile profile2; 454 TestingProfile profile2;
467 SpellcheckService* spellcheck_service2 = 455 SpellcheckService* spellcheck_service2 =
468 static_cast<SpellcheckService*>( 456 static_cast<SpellcheckService*>(
469 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 457 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
470 &profile2, &BuildSpellcheckService)); 458 &profile2, &BuildSpellcheckService));
471 SpellcheckCustomDictionary* custom_dictionary2 = 459 SpellcheckCustomDictionary* custom_dictionary2 =
472 spellcheck_service2->GetCustomDictionary(); 460 spellcheck_service2->GetCustomDictionary();
473 461
(...skipping 25 matching lines...) Expand all
499 EXPECT_TRUE(custom_dictionary->IsSyncing()); 487 EXPECT_TRUE(custom_dictionary->IsSyncing());
500 488
501 WordSet words = custom_dictionary->GetWords(); 489 WordSet words = custom_dictionary->GetWords();
502 WordSet words2 = custom_dictionary2->GetWords(); 490 WordSet words2 = custom_dictionary2->GetWords();
503 EXPECT_EQ(words.size(), words2.size()); 491 EXPECT_EQ(words.size(), words2.size());
504 EXPECT_EQ(words, words2); 492 EXPECT_EQ(words, words2);
505 } 493 }
506 494
507 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigBeforeSyncing) { 495 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigBeforeSyncing) {
508 SpellcheckService* spellcheck_service = 496 SpellcheckService* spellcheck_service =
509 SpellcheckServiceFactory::GetForProfile(profile_.get()); 497 SpellcheckServiceFactory::GetForProfile(&profile_);
510 SpellcheckCustomDictionary* custom_dictionary = 498 SpellcheckCustomDictionary* custom_dictionary =
511 spellcheck_service->GetCustomDictionary(); 499 spellcheck_service->GetCustomDictionary();
512 TestingProfile profile2; 500 TestingProfile profile2;
513 SpellcheckService* spellcheck_service2 = 501 SpellcheckService* spellcheck_service2 =
514 static_cast<SpellcheckService*>( 502 static_cast<SpellcheckService*>(
515 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 503 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
516 &profile2, &BuildSpellcheckService)); 504 &profile2, &BuildSpellcheckService));
517 SpellcheckCustomDictionary* custom_dictionary2 = 505 SpellcheckCustomDictionary* custom_dictionary2 =
518 spellcheck_service2->GetCustomDictionary(); 506 spellcheck_service2->GetCustomDictionary();
519 507
(...skipping 22 matching lines...) Expand all
542 custom_dictionary2->GetWords().size()); 530 custom_dictionary2->GetWords().size());
543 531
544 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 532 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
545 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 533 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size());
546 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 534 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
547 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); 535 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size());
548 } 536 }
549 537
550 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) { 538 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) {
551 SpellcheckService* spellcheck_service = 539 SpellcheckService* spellcheck_service =
552 SpellcheckServiceFactory::GetForProfile(profile_.get()); 540 SpellcheckServiceFactory::GetForProfile(&profile_);
553 SpellcheckCustomDictionary* custom_dictionary = 541 SpellcheckCustomDictionary* custom_dictionary =
554 spellcheck_service->GetCustomDictionary(); 542 spellcheck_service->GetCustomDictionary();
555 TestingProfile profile2; 543 TestingProfile profile2;
556 SpellcheckService* spellcheck_service2 = 544 SpellcheckService* spellcheck_service2 =
557 static_cast<SpellcheckService*>( 545 static_cast<SpellcheckService*>(
558 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 546 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
559 &profile2, &BuildSpellcheckService)); 547 &profile2, &BuildSpellcheckService));
560 SpellcheckCustomDictionary* custom_dictionary2 = 548 SpellcheckCustomDictionary* custom_dictionary2 =
561 spellcheck_service2->GetCustomDictionary(); 549 spellcheck_service2->GetCustomDictionary();
562 550
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 custom_dictionary2->GetWords().size()); 582 custom_dictionary2->GetWords().size());
595 583
596 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 584 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
597 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 585 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size());
598 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 586 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
599 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); 587 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size());
600 } 588 }
601 589
602 TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) { 590 TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) {
603 SpellcheckService* spellcheck_service = 591 SpellcheckService* spellcheck_service =
604 SpellcheckServiceFactory::GetForProfile(profile_.get()); 592 SpellcheckServiceFactory::GetForProfile(&profile_);
605 SpellcheckCustomDictionary* custom_dictionary = 593 SpellcheckCustomDictionary* custom_dictionary =
606 spellcheck_service->GetCustomDictionary(); 594 spellcheck_service->GetCustomDictionary();
607 TestingProfile profile2; 595 TestingProfile profile2;
608 SpellcheckService* spellcheck_service2 = 596 SpellcheckService* spellcheck_service2 =
609 static_cast<SpellcheckService*>( 597 static_cast<SpellcheckService*>(
610 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 598 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
611 &profile2, &BuildSpellcheckService)); 599 &profile2, &BuildSpellcheckService));
612 SpellcheckCustomDictionary* custom_dictionary2 = 600 SpellcheckCustomDictionary* custom_dictionary2 =
613 spellcheck_service2->GetCustomDictionary(); 601 spellcheck_service2->GetCustomDictionary();
614 602
(...skipping 30 matching lines...) Expand all
645 custom_dictionary2->GetWords().size()); 633 custom_dictionary2->GetWords().size());
646 634
647 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 635 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
648 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 636 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size());
649 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 637 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
650 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); 638 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size());
651 } 639 }
652 640
653 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) { 641 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) {
654 SpellcheckService* spellcheck_service = 642 SpellcheckService* spellcheck_service =
655 SpellcheckServiceFactory::GetForProfile(profile_.get()); 643 SpellcheckServiceFactory::GetForProfile(&profile_);
656 SpellcheckCustomDictionary* custom_dictionary = 644 SpellcheckCustomDictionary* custom_dictionary =
657 spellcheck_service->GetCustomDictionary(); 645 spellcheck_service->GetCustomDictionary();
658 TestingProfile profile2; 646 TestingProfile profile2;
659 SpellcheckService* spellcheck_service2 = 647 SpellcheckService* spellcheck_service2 =
660 static_cast<SpellcheckService*>( 648 static_cast<SpellcheckService*>(
661 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 649 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
662 &profile2, &BuildSpellcheckService)); 650 &profile2, &BuildSpellcheckService));
663 SpellcheckCustomDictionary* custom_dictionary2 = 651 SpellcheckCustomDictionary* custom_dictionary2 =
664 spellcheck_service2->GetCustomDictionary(); 652 spellcheck_service2->GetCustomDictionary();
665 653
(...skipping 25 matching lines...) Expand all
691 custom_dictionary2->GetWords().size()); 679 custom_dictionary2->GetWords().size());
692 680
693 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 681 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
694 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 682 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size());
695 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 683 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
696 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); 684 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size());
697 } 685 }
698 686
699 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) { 687 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) {
700 SpellcheckService* spellcheck_service = 688 SpellcheckService* spellcheck_service =
701 SpellcheckServiceFactory::GetForProfile(profile_.get()); 689 SpellcheckServiceFactory::GetForProfile(&profile_);
702 SpellcheckCustomDictionary* custom_dictionary = 690 SpellcheckCustomDictionary* custom_dictionary =
703 spellcheck_service->GetCustomDictionary(); 691 spellcheck_service->GetCustomDictionary();
704 TestingProfile profile2; 692 TestingProfile profile2;
705 SpellcheckService* spellcheck_service2 = 693 SpellcheckService* spellcheck_service2 =
706 static_cast<SpellcheckService*>( 694 static_cast<SpellcheckService*>(
707 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 695 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
708 &profile2, &BuildSpellcheckService)); 696 &profile2, &BuildSpellcheckService));
709 SpellcheckCustomDictionary* custom_dictionary2 = 697 SpellcheckCustomDictionary* custom_dictionary2 =
710 spellcheck_service2->GetCustomDictionary(); 698 spellcheck_service2->GetCustomDictionary();
711 699
(...skipping 30 matching lines...) Expand all
742 custom_dictionary2->GetWords().size()); 730 custom_dictionary2->GetWords().size());
743 731
744 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 732 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
745 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 733 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size());
746 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 734 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
747 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); 735 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size());
748 } 736 }
749 737
750 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) { 738 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) {
751 SpellcheckService* spellcheck_service = 739 SpellcheckService* spellcheck_service =
752 SpellcheckServiceFactory::GetForProfile(profile_.get()); 740 SpellcheckServiceFactory::GetForProfile(&profile_);
753 SpellcheckCustomDictionary* custom_dictionary = 741 SpellcheckCustomDictionary* custom_dictionary =
754 spellcheck_service->GetCustomDictionary(); 742 spellcheck_service->GetCustomDictionary();
755 TestingProfile profile2; 743 TestingProfile profile2;
756 SpellcheckService* spellcheck_service2 = 744 SpellcheckService* spellcheck_service2 =
757 static_cast<SpellcheckService*>( 745 static_cast<SpellcheckService*>(
758 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 746 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
759 &profile2, &BuildSpellcheckService)); 747 &profile2, &BuildSpellcheckService));
760 SpellcheckCustomDictionary* custom_dictionary2 = 748 SpellcheckCustomDictionary* custom_dictionary2 =
761 spellcheck_service2->GetCustomDictionary(); 749 spellcheck_service2->GetCustomDictionary();
762 750
(...skipping 17 matching lines...) Expand all
780 768
781 EXPECT_EQ(2UL, custom_dictionary->GetWords().size()); 769 EXPECT_EQ(2UL, custom_dictionary->GetWords().size());
782 EXPECT_EQ(2UL, custom_dictionary2->GetWords().size()); 770 EXPECT_EQ(2UL, custom_dictionary2->GetWords().size());
783 771
784 EXPECT_EQ(2UL, custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 772 EXPECT_EQ(2UL, custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size());
785 EXPECT_EQ(2UL, custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); 773 EXPECT_EQ(2UL, custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size());
786 } 774 }
787 775
788 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStartTooBigToSync) { 776 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStartTooBigToSync) {
789 SpellcheckService* spellcheck_service = 777 SpellcheckService* spellcheck_service =
790 SpellcheckServiceFactory::GetForProfile(profile_.get()); 778 SpellcheckServiceFactory::GetForProfile(&profile_);
791 SpellcheckCustomDictionary* custom_dictionary = 779 SpellcheckCustomDictionary* custom_dictionary =
792 spellcheck_service->GetCustomDictionary(); 780 spellcheck_service->GetCustomDictionary();
793 TestingProfile profile2; 781 TestingProfile profile2;
794 SpellcheckService* spellcheck_service2 = 782 SpellcheckService* spellcheck_service2 =
795 static_cast<SpellcheckService*>( 783 static_cast<SpellcheckService*>(
796 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 784 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
797 &profile2, &BuildSpellcheckService)); 785 &profile2, &BuildSpellcheckService));
798 SpellcheckCustomDictionary* custom_dictionary2 = 786 SpellcheckCustomDictionary* custom_dictionary2 =
799 spellcheck_service2->GetCustomDictionary(); 787 spellcheck_service2->GetCustomDictionary();
800 788
(...skipping 26 matching lines...) Expand all
827 custom_dictionary2->GetWords().size()); 815 custom_dictionary2->GetWords().size());
828 816
829 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 817 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
830 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 818 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size());
831 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, 819 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
832 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); 820 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size());
833 } 821 }
834 822
835 TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) { 823 TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) {
836 SpellcheckService* spellcheck_service = 824 SpellcheckService* spellcheck_service =
837 SpellcheckServiceFactory::GetForProfile(profile_.get()); 825 SpellcheckServiceFactory::GetForProfile(&profile_);
838 SpellcheckCustomDictionary* custom_dictionary = 826 SpellcheckCustomDictionary* custom_dictionary =
839 spellcheck_service->GetCustomDictionary(); 827 spellcheck_service->GetCustomDictionary();
840 TestingProfile profile2; 828 TestingProfile profile2;
841 SpellcheckService* spellcheck_service2 = 829 SpellcheckService* spellcheck_service2 =
842 static_cast<SpellcheckService*>( 830 static_cast<SpellcheckService*>(
843 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 831 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
844 &profile2, &BuildSpellcheckService)); 832 &profile2, &BuildSpellcheckService));
845 SpellcheckCustomDictionary* custom_dictionary2 = 833 SpellcheckCustomDictionary* custom_dictionary2 =
846 spellcheck_service2->GetCustomDictionary(); 834 spellcheck_service2->GetCustomDictionary();
847 835
(...skipping 26 matching lines...) Expand all
874 custom_dictionary2->GetWords().size()); 862 custom_dictionary2->GetWords().size());
875 863
876 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, 864 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2,
877 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); 865 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size());
878 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, 866 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2,
879 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); 867 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size());
880 } 868 }
881 869
882 TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) { 870 TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) {
883 SpellcheckService* spellcheck_service = 871 SpellcheckService* spellcheck_service =
884 SpellcheckServiceFactory::GetForProfile(profile_.get()); 872 SpellcheckServiceFactory::GetForProfile(&profile_);
885 SpellcheckCustomDictionary* custom_dictionary = 873 SpellcheckCustomDictionary* custom_dictionary =
886 spellcheck_service->GetCustomDictionary(); 874 spellcheck_service->GetCustomDictionary();
887 875
888 DictionaryObserverCounter observer; 876 DictionaryObserverCounter observer;
889 custom_dictionary->AddObserver(&observer); 877 custom_dictionary->AddObserver(&observer);
890 878
891 WordList custom_words; 879 WordList custom_words;
892 custom_words.push_back("foo"); 880 custom_words.push_back("foo");
893 custom_words.push_back("bar"); 881 custom_words.push_back("bar");
894 OnLoaded(*custom_dictionary, custom_words); 882 OnLoaded(*custom_dictionary, custom_words);
895 883
896 EXPECT_GE(observer.loads(), 1); 884 EXPECT_GE(observer.loads(), 1);
897 EXPECT_LE(observer.loads(), 2); 885 EXPECT_LE(observer.loads(), 2);
898 EXPECT_EQ(0, observer.changes()); 886 EXPECT_EQ(0, observer.changes());
899 887
900 custom_dictionary->RemoveObserver(&observer); 888 custom_dictionary->RemoveObserver(&observer);
901 } 889 }
902 890
903 TEST_F(SpellcheckCustomDictionaryTest, DictionaryAddWordNotification) { 891 TEST_F(SpellcheckCustomDictionaryTest, DictionaryAddWordNotification) {
904 SpellcheckService* spellcheck_service = 892 SpellcheckService* spellcheck_service =
905 SpellcheckServiceFactory::GetForProfile(profile_.get()); 893 SpellcheckServiceFactory::GetForProfile(&profile_);
906 SpellcheckCustomDictionary* custom_dictionary = 894 SpellcheckCustomDictionary* custom_dictionary =
907 spellcheck_service->GetCustomDictionary(); 895 spellcheck_service->GetCustomDictionary();
908 896
909 OnLoaded(*custom_dictionary, WordList()); 897 OnLoaded(*custom_dictionary, WordList());
910 898
911 DictionaryObserverCounter observer; 899 DictionaryObserverCounter observer;
912 custom_dictionary->AddObserver(&observer); 900 custom_dictionary->AddObserver(&observer);
913 901
914 EXPECT_TRUE(custom_dictionary->AddWord("foo")); 902 EXPECT_TRUE(custom_dictionary->AddWord("foo"));
915 EXPECT_TRUE(custom_dictionary->AddWord("bar")); 903 EXPECT_TRUE(custom_dictionary->AddWord("bar"));
916 EXPECT_FALSE(custom_dictionary->AddWord("bar")); 904 EXPECT_FALSE(custom_dictionary->AddWord("bar"));
917 905
918 EXPECT_EQ(2, observer.changes()); 906 EXPECT_EQ(2, observer.changes());
919 907
920 custom_dictionary->RemoveObserver(&observer); 908 custom_dictionary->RemoveObserver(&observer);
921 } 909 }
922 910
923 TEST_F(SpellcheckCustomDictionaryTest, DictionaryRemoveWordNotification) { 911 TEST_F(SpellcheckCustomDictionaryTest, DictionaryRemoveWordNotification) {
924 SpellcheckService* spellcheck_service = 912 SpellcheckService* spellcheck_service =
925 SpellcheckServiceFactory::GetForProfile(profile_.get()); 913 SpellcheckServiceFactory::GetForProfile(&profile_);
926 SpellcheckCustomDictionary* custom_dictionary = 914 SpellcheckCustomDictionary* custom_dictionary =
927 spellcheck_service->GetCustomDictionary(); 915 spellcheck_service->GetCustomDictionary();
928 916
929 OnLoaded(*custom_dictionary, WordList()); 917 OnLoaded(*custom_dictionary, WordList());
930 918
931 EXPECT_TRUE(custom_dictionary->AddWord("foo")); 919 EXPECT_TRUE(custom_dictionary->AddWord("foo"));
932 EXPECT_TRUE(custom_dictionary->AddWord("bar")); 920 EXPECT_TRUE(custom_dictionary->AddWord("bar"));
933 921
934 DictionaryObserverCounter observer; 922 DictionaryObserverCounter observer;
935 custom_dictionary->AddObserver(&observer); 923 custom_dictionary->AddObserver(&observer);
936 924
937 EXPECT_TRUE(custom_dictionary->RemoveWord("foo")); 925 EXPECT_TRUE(custom_dictionary->RemoveWord("foo"));
938 EXPECT_TRUE(custom_dictionary->RemoveWord("bar")); 926 EXPECT_TRUE(custom_dictionary->RemoveWord("bar"));
939 EXPECT_FALSE(custom_dictionary->RemoveWord("baz")); 927 EXPECT_FALSE(custom_dictionary->RemoveWord("baz"));
940 928
941 EXPECT_EQ(2, observer.changes()); 929 EXPECT_EQ(2, observer.changes());
942 930
943 custom_dictionary->RemoveObserver(&observer); 931 custom_dictionary->RemoveObserver(&observer);
944 } 932 }
945 933
946 TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncNotification) { 934 TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncNotification) {
947 SpellcheckService* spellcheck_service = 935 SpellcheckService* spellcheck_service =
948 SpellcheckServiceFactory::GetForProfile(profile_.get()); 936 SpellcheckServiceFactory::GetForProfile(&profile_);
949 SpellcheckCustomDictionary* custom_dictionary = 937 SpellcheckCustomDictionary* custom_dictionary =
950 spellcheck_service->GetCustomDictionary(); 938 spellcheck_service->GetCustomDictionary();
951 TestingProfile profile2; 939 TestingProfile profile2;
952 SpellcheckService* spellcheck_service2 = 940 SpellcheckService* spellcheck_service2 =
953 static_cast<SpellcheckService*>( 941 static_cast<SpellcheckService*>(
954 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 942 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
955 &profile2, &BuildSpellcheckService)); 943 &profile2, &BuildSpellcheckService));
956 SpellcheckCustomDictionary* custom_dictionary2 = 944 SpellcheckCustomDictionary* custom_dictionary2 =
957 spellcheck_service2->GetCustomDictionary(); 945 spellcheck_service2->GetCustomDictionary();
958 946
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( 987 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
1000 &server_profile, &BuildSpellcheckService)); 988 &server_profile, &BuildSpellcheckService));
1001 989
1002 // Here, |server_custom_dictionary| plays the role of the sync server. 990 // Here, |server_custom_dictionary| plays the role of the sync server.
1003 SpellcheckCustomDictionary* server_custom_dictionary = 991 SpellcheckCustomDictionary* server_custom_dictionary =
1004 server_spellcheck_service->GetCustomDictionary(); 992 server_spellcheck_service->GetCustomDictionary();
1005 993
1006 // Upload the maximum number of words to the sync server. 994 // Upload the maximum number of words to the sync server.
1007 { 995 {
1008 SpellcheckService* spellcheck_service = 996 SpellcheckService* spellcheck_service =
1009 SpellcheckServiceFactory::GetForProfile(profile_.get()); 997 SpellcheckServiceFactory::GetForProfile(&profile_);
1010 SpellcheckCustomDictionary* custom_dictionary = 998 SpellcheckCustomDictionary* custom_dictionary =
1011 spellcheck_service->GetCustomDictionary(); 999 spellcheck_service->GetCustomDictionary();
1012 1000
1013 SpellcheckCustomDictionary::Change change; 1001 SpellcheckCustomDictionary::Change change;
1014 for (size_t i = 0; 1002 for (size_t i = 0;
1015 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; 1003 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS;
1016 ++i) { 1004 ++i) {
1017 change.AddWord("foo" + base::Uint64ToString(i)); 1005 change.AddWord("foo" + base::Uint64ToString(i));
1018 } 1006 }
1019 Apply(*custom_dictionary, change); 1007 Apply(*custom_dictionary, change);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 // Record a baseline. 1073 // Record a baseline.
1086 SpellCheckHostMetrics::RecordCustomWordCountStats(123); 1074 SpellCheckHostMetrics::RecordCustomWordCountStats(123);
1087 1075
1088 HistogramBase* histogram = 1076 HistogramBase* histogram =
1089 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); 1077 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1090 ASSERT_TRUE(histogram != NULL); 1078 ASSERT_TRUE(histogram != NULL);
1091 scoped_ptr<HistogramSamples> baseline = histogram->SnapshotSamples(); 1079 scoped_ptr<HistogramSamples> baseline = histogram->SnapshotSamples();
1092 1080
1093 // Load the dictionary which should be empty. 1081 // Load the dictionary which should be empty.
1094 base::FilePath path = 1082 base::FilePath path =
1095 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); 1083 profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
1096 WordList loaded_custom_words = LoadDictionaryFile(path); 1084 WordList loaded_custom_words = LoadDictionaryFile(path);
1097 EXPECT_EQ(0u, loaded_custom_words.size()); 1085 EXPECT_EQ(0u, loaded_custom_words.size());
1098 1086
1099 // We expect there to be an entry with 0. 1087 // We expect there to be an entry with 0.
1100 histogram = 1088 histogram =
1101 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); 1089 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1102 ASSERT_TRUE(histogram != NULL); 1090 ASSERT_TRUE(histogram != NULL);
1103 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); 1091 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
1104 1092
1105 samples->Subtract(*baseline); 1093 samples->Subtract(*baseline);
(...skipping 12 matching lines...) Expand all
1118 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); 1106 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords");
1119 ASSERT_TRUE(histogram != NULL); 1107 ASSERT_TRUE(histogram != NULL);
1120 scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples(); 1108 scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples();
1121 1109
1122 samples2->Subtract(*baseline); 1110 samples2->Subtract(*baseline);
1123 EXPECT_EQ(2,samples2->sum()); 1111 EXPECT_EQ(2,samples2->sum());
1124 } 1112 }
1125 1113
1126 TEST_F(SpellcheckCustomDictionaryTest, HasWord) { 1114 TEST_F(SpellcheckCustomDictionaryTest, HasWord) {
1127 SpellcheckService* spellcheck_service = 1115 SpellcheckService* spellcheck_service =
1128 SpellcheckServiceFactory::GetForProfile(profile_.get()); 1116 SpellcheckServiceFactory::GetForProfile(&profile_);
1129 SpellcheckCustomDictionary* custom_dictionary = 1117 SpellcheckCustomDictionary* custom_dictionary =
1130 spellcheck_service->GetCustomDictionary(); 1118 spellcheck_service->GetCustomDictionary();
1131 OnLoaded(*custom_dictionary, WordList()); 1119 OnLoaded(*custom_dictionary, WordList());
1132 EXPECT_FALSE(custom_dictionary->HasWord("foo")); 1120 EXPECT_FALSE(custom_dictionary->HasWord("foo"));
1133 EXPECT_FALSE(custom_dictionary->HasWord("bar")); 1121 EXPECT_FALSE(custom_dictionary->HasWord("bar"));
1134 custom_dictionary->AddWord("foo"); 1122 custom_dictionary->AddWord("foo");
1135 EXPECT_TRUE(custom_dictionary->HasWord("foo")); 1123 EXPECT_TRUE(custom_dictionary->HasWord("foo"));
1136 EXPECT_FALSE(custom_dictionary->HasWord("bar")); 1124 EXPECT_FALSE(custom_dictionary->HasWord("bar"));
1137 } 1125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698