OLD | NEW |
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/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 change.RemoveWord("bar"); | 207 change.RemoveWord("bar"); |
208 change.RemoveWord("foo"); | 208 change.RemoveWord("foo"); |
209 UpdateDictionaryFile(change, path); | 209 UpdateDictionaryFile(change, path); |
210 loaded_custom_words = LoadDictionaryFile(path); | 210 loaded_custom_words = LoadDictionaryFile(path); |
211 expected.clear(); | 211 expected.clear(); |
212 EXPECT_EQ(expected, loaded_custom_words); | 212 EXPECT_EQ(expected, loaded_custom_words); |
213 } | 213 } |
214 | 214 |
215 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) { | 215 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) { |
216 SpellcheckService* spellcheck_service = | 216 SpellcheckService* spellcheck_service = |
217 SpellcheckServiceFactory::GetForProfile(&profile_); | 217 SpellcheckServiceFactory::GetForContext(&profile_); |
218 SpellcheckCustomDictionary* custom_dictionary = | 218 SpellcheckCustomDictionary* custom_dictionary = |
219 spellcheck_service->GetCustomDictionary(); | 219 spellcheck_service->GetCustomDictionary(); |
220 TestingProfile profile2; | 220 TestingProfile profile2; |
221 SpellcheckService* spellcheck_service2 = | 221 SpellcheckService* spellcheck_service2 = |
222 static_cast<SpellcheckService*>( | 222 static_cast<SpellcheckService*>( |
223 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 223 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
224 &profile2, &BuildSpellcheckService)); | 224 &profile2, &BuildSpellcheckService)); |
225 SpellcheckCustomDictionary* custom_dictionary2 = | 225 SpellcheckCustomDictionary* custom_dictionary2 = |
226 spellcheck_service2->GetCustomDictionary(); | 226 spellcheck_service2->GetCustomDictionary(); |
227 | 227 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 base::ReadFileToString(path, &content); | 313 base::ReadFileToString(path, &content); |
314 content.append("corruption"); | 314 content.append("corruption"); |
315 file_util::WriteFile(path, content.c_str(), content.length()); | 315 file_util::WriteFile(path, content.c_str(), content.length()); |
316 loaded_custom_words = LoadDictionaryFile(path); | 316 loaded_custom_words = LoadDictionaryFile(path); |
317 EXPECT_EQ(expected, loaded_custom_words); | 317 EXPECT_EQ(expected, loaded_custom_words); |
318 } | 318 } |
319 | 319 |
320 TEST_F(SpellcheckCustomDictionaryTest, | 320 TEST_F(SpellcheckCustomDictionaryTest, |
321 GetAllSyncDataAccuratelyReflectsDictionaryState) { | 321 GetAllSyncDataAccuratelyReflectsDictionaryState) { |
322 SpellcheckCustomDictionary* dictionary = | 322 SpellcheckCustomDictionary* dictionary = |
323 SpellcheckServiceFactory::GetForProfile( | 323 SpellcheckServiceFactory::GetForContext( |
324 &profile_)->GetCustomDictionary(); | 324 &profile_)->GetCustomDictionary(); |
325 | 325 |
326 syncer::SyncDataList data = dictionary->GetAllSyncData(syncer::DICTIONARY); | 326 syncer::SyncDataList data = dictionary->GetAllSyncData(syncer::DICTIONARY); |
327 EXPECT_TRUE(data.empty()); | 327 EXPECT_TRUE(data.empty()); |
328 | 328 |
329 EXPECT_TRUE(dictionary->AddWord("bar")); | 329 EXPECT_TRUE(dictionary->AddWord("bar")); |
330 EXPECT_TRUE(dictionary->AddWord("foo")); | 330 EXPECT_TRUE(dictionary->AddWord("foo")); |
331 | 331 |
332 data = dictionary->GetAllSyncData(syncer::DICTIONARY); | 332 data = dictionary->GetAllSyncData(syncer::DICTIONARY); |
333 EXPECT_EQ(2UL, data.size()); | 333 EXPECT_EQ(2UL, data.size()); |
334 std::vector<std::string> words; | 334 std::vector<std::string> words; |
335 words.push_back("bar"); | 335 words.push_back("bar"); |
336 words.push_back("foo"); | 336 words.push_back("foo"); |
337 for (size_t i = 0; i < data.size(); i++) { | 337 for (size_t i = 0; i < data.size(); i++) { |
338 EXPECT_TRUE(data[i].GetSpecifics().has_dictionary()); | 338 EXPECT_TRUE(data[i].GetSpecifics().has_dictionary()); |
339 EXPECT_EQ(syncer::DICTIONARY, data[i].GetDataType()); | 339 EXPECT_EQ(syncer::DICTIONARY, data[i].GetDataType()); |
340 EXPECT_EQ(words[i], data[i].GetTag()); | 340 EXPECT_EQ(words[i], data[i].GetTag()); |
341 EXPECT_EQ(words[i], data[i].GetSpecifics().dictionary().word()); | 341 EXPECT_EQ(words[i], data[i].GetSpecifics().dictionary().word()); |
342 } | 342 } |
343 | 343 |
344 EXPECT_TRUE(dictionary->RemoveWord("bar")); | 344 EXPECT_TRUE(dictionary->RemoveWord("bar")); |
345 EXPECT_TRUE(dictionary->RemoveWord("foo")); | 345 EXPECT_TRUE(dictionary->RemoveWord("foo")); |
346 | 346 |
347 data = dictionary->GetAllSyncData(syncer::DICTIONARY); | 347 data = dictionary->GetAllSyncData(syncer::DICTIONARY); |
348 EXPECT_TRUE(data.empty()); | 348 EXPECT_TRUE(data.empty()); |
349 } | 349 } |
350 | 350 |
351 TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) { | 351 TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) { |
352 SpellcheckCustomDictionary* dictionary = | 352 SpellcheckCustomDictionary* dictionary = |
353 SpellcheckServiceFactory::GetForProfile( | 353 SpellcheckServiceFactory::GetForContext( |
354 &profile_)->GetCustomDictionary(); | 354 &profile_)->GetCustomDictionary(); |
355 | 355 |
356 SpellcheckCustomDictionary::Change change; | 356 SpellcheckCustomDictionary::Change change; |
357 for (size_t i = 0; | 357 for (size_t i = 0; |
358 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1; | 358 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1; |
359 i++) { | 359 i++) { |
360 change.AddWord("foo" + base::Uint64ToString(i)); | 360 change.AddWord("foo" + base::Uint64ToString(i)); |
361 } | 361 } |
362 Apply(*dictionary, change); | 362 Apply(*dictionary, change); |
363 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1, | 363 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1, |
(...skipping 15 matching lines...) Expand all Loading... |
379 | 379 |
380 dictionary->AddWord("snafoo"); | 380 dictionary->AddWord("snafoo"); |
381 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 2, | 381 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 2, |
382 dictionary->GetWords().size()); | 382 dictionary->GetWords().size()); |
383 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 383 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
384 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 384 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
385 } | 385 } |
386 | 386 |
387 TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) { | 387 TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) { |
388 SpellcheckService* spellcheck_service = | 388 SpellcheckService* spellcheck_service = |
389 SpellcheckServiceFactory::GetForProfile(&profile_); | 389 SpellcheckServiceFactory::GetForContext(&profile_); |
390 SpellcheckCustomDictionary* dictionary = | 390 SpellcheckCustomDictionary* dictionary = |
391 spellcheck_service->GetCustomDictionary(); | 391 spellcheck_service->GetCustomDictionary(); |
392 | 392 |
393 dictionary->AddWord("foo"); | 393 dictionary->AddWord("foo"); |
394 dictionary->AddWord("bar"); | 394 dictionary->AddWord("bar"); |
395 | 395 |
396 syncer::SyncChangeList changes; | 396 syncer::SyncChangeList changes; |
397 { | 397 { |
398 // Add existing word. | 398 // Add existing word. |
399 std::string word = "foo"; | 399 std::string word = "foo"; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 | 450 |
451 const WordSet& words = dictionary->GetWords(); | 451 const WordSet& words = dictionary->GetWords(); |
452 EXPECT_EQ(2UL, words.size()); | 452 EXPECT_EQ(2UL, words.size()); |
453 EXPECT_EQ(0UL, words.count("bar")); | 453 EXPECT_EQ(0UL, words.count("bar")); |
454 EXPECT_EQ(1UL, words.count("foo")); | 454 EXPECT_EQ(1UL, words.count("foo")); |
455 EXPECT_EQ(1UL, words.count("baz")); | 455 EXPECT_EQ(1UL, words.count("baz")); |
456 } | 456 } |
457 | 457 |
458 TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) { | 458 TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) { |
459 SpellcheckService* spellcheck_service = | 459 SpellcheckService* spellcheck_service = |
460 SpellcheckServiceFactory::GetForProfile(&profile_); | 460 SpellcheckServiceFactory::GetForContext(&profile_); |
461 SpellcheckCustomDictionary* custom_dictionary = | 461 SpellcheckCustomDictionary* custom_dictionary = |
462 spellcheck_service->GetCustomDictionary(); | 462 spellcheck_service->GetCustomDictionary(); |
463 TestingProfile profile2; | 463 TestingProfile profile2; |
464 SpellcheckService* spellcheck_service2 = | 464 SpellcheckService* spellcheck_service2 = |
465 static_cast<SpellcheckService*>( | 465 static_cast<SpellcheckService*>( |
466 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 466 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
467 &profile2, &BuildSpellcheckService)); | 467 &profile2, &BuildSpellcheckService)); |
468 SpellcheckCustomDictionary* custom_dictionary2 = | 468 SpellcheckCustomDictionary* custom_dictionary2 = |
469 spellcheck_service2->GetCustomDictionary(); | 469 spellcheck_service2->GetCustomDictionary(); |
470 | 470 |
(...skipping 25 matching lines...) Expand all Loading... |
496 EXPECT_TRUE(custom_dictionary->IsSyncing()); | 496 EXPECT_TRUE(custom_dictionary->IsSyncing()); |
497 | 497 |
498 WordSet words = custom_dictionary->GetWords(); | 498 WordSet words = custom_dictionary->GetWords(); |
499 WordSet words2 = custom_dictionary2->GetWords(); | 499 WordSet words2 = custom_dictionary2->GetWords(); |
500 EXPECT_EQ(words.size(), words2.size()); | 500 EXPECT_EQ(words.size(), words2.size()); |
501 EXPECT_EQ(words, words2); | 501 EXPECT_EQ(words, words2); |
502 } | 502 } |
503 | 503 |
504 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigBeforeSyncing) { | 504 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigBeforeSyncing) { |
505 SpellcheckService* spellcheck_service = | 505 SpellcheckService* spellcheck_service = |
506 SpellcheckServiceFactory::GetForProfile(&profile_); | 506 SpellcheckServiceFactory::GetForContext(&profile_); |
507 SpellcheckCustomDictionary* custom_dictionary = | 507 SpellcheckCustomDictionary* custom_dictionary = |
508 spellcheck_service->GetCustomDictionary(); | 508 spellcheck_service->GetCustomDictionary(); |
509 TestingProfile profile2; | 509 TestingProfile profile2; |
510 SpellcheckService* spellcheck_service2 = | 510 SpellcheckService* spellcheck_service2 = |
511 static_cast<SpellcheckService*>( | 511 static_cast<SpellcheckService*>( |
512 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 512 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
513 &profile2, &BuildSpellcheckService)); | 513 &profile2, &BuildSpellcheckService)); |
514 SpellcheckCustomDictionary* custom_dictionary2 = | 514 SpellcheckCustomDictionary* custom_dictionary2 = |
515 spellcheck_service2->GetCustomDictionary(); | 515 spellcheck_service2->GetCustomDictionary(); |
516 | 516 |
(...skipping 22 matching lines...) Expand all Loading... |
539 custom_dictionary2->GetWords().size()); | 539 custom_dictionary2->GetWords().size()); |
540 | 540 |
541 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 541 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
542 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 542 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
543 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 543 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
544 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 544 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
545 } | 545 } |
546 | 546 |
547 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) { | 547 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) { |
548 SpellcheckService* spellcheck_service = | 548 SpellcheckService* spellcheck_service = |
549 SpellcheckServiceFactory::GetForProfile(&profile_); | 549 SpellcheckServiceFactory::GetForContext(&profile_); |
550 SpellcheckCustomDictionary* custom_dictionary = | 550 SpellcheckCustomDictionary* custom_dictionary = |
551 spellcheck_service->GetCustomDictionary(); | 551 spellcheck_service->GetCustomDictionary(); |
552 TestingProfile profile2; | 552 TestingProfile profile2; |
553 SpellcheckService* spellcheck_service2 = | 553 SpellcheckService* spellcheck_service2 = |
554 static_cast<SpellcheckService*>( | 554 static_cast<SpellcheckService*>( |
555 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 555 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
556 &profile2, &BuildSpellcheckService)); | 556 &profile2, &BuildSpellcheckService)); |
557 SpellcheckCustomDictionary* custom_dictionary2 = | 557 SpellcheckCustomDictionary* custom_dictionary2 = |
558 spellcheck_service2->GetCustomDictionary(); | 558 spellcheck_service2->GetCustomDictionary(); |
559 | 559 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 custom_dictionary2->GetWords().size()); | 591 custom_dictionary2->GetWords().size()); |
592 | 592 |
593 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 593 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
594 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 594 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
595 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 595 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
596 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 596 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
597 } | 597 } |
598 | 598 |
599 TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) { | 599 TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) { |
600 SpellcheckService* spellcheck_service = | 600 SpellcheckService* spellcheck_service = |
601 SpellcheckServiceFactory::GetForProfile(&profile_); | 601 SpellcheckServiceFactory::GetForContext(&profile_); |
602 SpellcheckCustomDictionary* custom_dictionary = | 602 SpellcheckCustomDictionary* custom_dictionary = |
603 spellcheck_service->GetCustomDictionary(); | 603 spellcheck_service->GetCustomDictionary(); |
604 TestingProfile profile2; | 604 TestingProfile profile2; |
605 SpellcheckService* spellcheck_service2 = | 605 SpellcheckService* spellcheck_service2 = |
606 static_cast<SpellcheckService*>( | 606 static_cast<SpellcheckService*>( |
607 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 607 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
608 &profile2, &BuildSpellcheckService)); | 608 &profile2, &BuildSpellcheckService)); |
609 SpellcheckCustomDictionary* custom_dictionary2 = | 609 SpellcheckCustomDictionary* custom_dictionary2 = |
610 spellcheck_service2->GetCustomDictionary(); | 610 spellcheck_service2->GetCustomDictionary(); |
611 | 611 |
(...skipping 30 matching lines...) Expand all Loading... |
642 custom_dictionary2->GetWords().size()); | 642 custom_dictionary2->GetWords().size()); |
643 | 643 |
644 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 644 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
645 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 645 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
646 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 646 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
647 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 647 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
648 } | 648 } |
649 | 649 |
650 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) { | 650 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) { |
651 SpellcheckService* spellcheck_service = | 651 SpellcheckService* spellcheck_service = |
652 SpellcheckServiceFactory::GetForProfile(&profile_); | 652 SpellcheckServiceFactory::GetForContext(&profile_); |
653 SpellcheckCustomDictionary* custom_dictionary = | 653 SpellcheckCustomDictionary* custom_dictionary = |
654 spellcheck_service->GetCustomDictionary(); | 654 spellcheck_service->GetCustomDictionary(); |
655 TestingProfile profile2; | 655 TestingProfile profile2; |
656 SpellcheckService* spellcheck_service2 = | 656 SpellcheckService* spellcheck_service2 = |
657 static_cast<SpellcheckService*>( | 657 static_cast<SpellcheckService*>( |
658 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 658 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
659 &profile2, &BuildSpellcheckService)); | 659 &profile2, &BuildSpellcheckService)); |
660 SpellcheckCustomDictionary* custom_dictionary2 = | 660 SpellcheckCustomDictionary* custom_dictionary2 = |
661 spellcheck_service2->GetCustomDictionary(); | 661 spellcheck_service2->GetCustomDictionary(); |
662 | 662 |
(...skipping 25 matching lines...) Expand all Loading... |
688 custom_dictionary2->GetWords().size()); | 688 custom_dictionary2->GetWords().size()); |
689 | 689 |
690 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 690 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
691 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 691 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
692 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 692 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
693 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 693 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
694 } | 694 } |
695 | 695 |
696 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) { | 696 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) { |
697 SpellcheckService* spellcheck_service = | 697 SpellcheckService* spellcheck_service = |
698 SpellcheckServiceFactory::GetForProfile(&profile_); | 698 SpellcheckServiceFactory::GetForContext(&profile_); |
699 SpellcheckCustomDictionary* custom_dictionary = | 699 SpellcheckCustomDictionary* custom_dictionary = |
700 spellcheck_service->GetCustomDictionary(); | 700 spellcheck_service->GetCustomDictionary(); |
701 TestingProfile profile2; | 701 TestingProfile profile2; |
702 SpellcheckService* spellcheck_service2 = | 702 SpellcheckService* spellcheck_service2 = |
703 static_cast<SpellcheckService*>( | 703 static_cast<SpellcheckService*>( |
704 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 704 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
705 &profile2, &BuildSpellcheckService)); | 705 &profile2, &BuildSpellcheckService)); |
706 SpellcheckCustomDictionary* custom_dictionary2 = | 706 SpellcheckCustomDictionary* custom_dictionary2 = |
707 spellcheck_service2->GetCustomDictionary(); | 707 spellcheck_service2->GetCustomDictionary(); |
708 | 708 |
(...skipping 30 matching lines...) Expand all Loading... |
739 custom_dictionary2->GetWords().size()); | 739 custom_dictionary2->GetWords().size()); |
740 | 740 |
741 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 741 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
742 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 742 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
743 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 743 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
744 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 744 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
745 } | 745 } |
746 | 746 |
747 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) { | 747 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) { |
748 SpellcheckService* spellcheck_service = | 748 SpellcheckService* spellcheck_service = |
749 SpellcheckServiceFactory::GetForProfile(&profile_); | 749 SpellcheckServiceFactory::GetForContext(&profile_); |
750 SpellcheckCustomDictionary* custom_dictionary = | 750 SpellcheckCustomDictionary* custom_dictionary = |
751 spellcheck_service->GetCustomDictionary(); | 751 spellcheck_service->GetCustomDictionary(); |
752 TestingProfile profile2; | 752 TestingProfile profile2; |
753 SpellcheckService* spellcheck_service2 = | 753 SpellcheckService* spellcheck_service2 = |
754 static_cast<SpellcheckService*>( | 754 static_cast<SpellcheckService*>( |
755 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 755 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
756 &profile2, &BuildSpellcheckService)); | 756 &profile2, &BuildSpellcheckService)); |
757 SpellcheckCustomDictionary* custom_dictionary2 = | 757 SpellcheckCustomDictionary* custom_dictionary2 = |
758 spellcheck_service2->GetCustomDictionary(); | 758 spellcheck_service2->GetCustomDictionary(); |
759 | 759 |
(...skipping 17 matching lines...) Expand all Loading... |
777 | 777 |
778 EXPECT_EQ(2UL, custom_dictionary->GetWords().size()); | 778 EXPECT_EQ(2UL, custom_dictionary->GetWords().size()); |
779 EXPECT_EQ(2UL, custom_dictionary2->GetWords().size()); | 779 EXPECT_EQ(2UL, custom_dictionary2->GetWords().size()); |
780 | 780 |
781 EXPECT_EQ(2UL, custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 781 EXPECT_EQ(2UL, custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
782 EXPECT_EQ(2UL, custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 782 EXPECT_EQ(2UL, custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
783 } | 783 } |
784 | 784 |
785 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStartTooBigToSync) { | 785 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStartTooBigToSync) { |
786 SpellcheckService* spellcheck_service = | 786 SpellcheckService* spellcheck_service = |
787 SpellcheckServiceFactory::GetForProfile(&profile_); | 787 SpellcheckServiceFactory::GetForContext(&profile_); |
788 SpellcheckCustomDictionary* custom_dictionary = | 788 SpellcheckCustomDictionary* custom_dictionary = |
789 spellcheck_service->GetCustomDictionary(); | 789 spellcheck_service->GetCustomDictionary(); |
790 TestingProfile profile2; | 790 TestingProfile profile2; |
791 SpellcheckService* spellcheck_service2 = | 791 SpellcheckService* spellcheck_service2 = |
792 static_cast<SpellcheckService*>( | 792 static_cast<SpellcheckService*>( |
793 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 793 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
794 &profile2, &BuildSpellcheckService)); | 794 &profile2, &BuildSpellcheckService)); |
795 SpellcheckCustomDictionary* custom_dictionary2 = | 795 SpellcheckCustomDictionary* custom_dictionary2 = |
796 spellcheck_service2->GetCustomDictionary(); | 796 spellcheck_service2->GetCustomDictionary(); |
797 | 797 |
(...skipping 26 matching lines...) Expand all Loading... |
824 custom_dictionary2->GetWords().size()); | 824 custom_dictionary2->GetWords().size()); |
825 | 825 |
826 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 826 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
827 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 827 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
828 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 828 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
829 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 829 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
830 } | 830 } |
831 | 831 |
832 TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) { | 832 TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) { |
833 SpellcheckService* spellcheck_service = | 833 SpellcheckService* spellcheck_service = |
834 SpellcheckServiceFactory::GetForProfile(&profile_); | 834 SpellcheckServiceFactory::GetForContext(&profile_); |
835 SpellcheckCustomDictionary* custom_dictionary = | 835 SpellcheckCustomDictionary* custom_dictionary = |
836 spellcheck_service->GetCustomDictionary(); | 836 spellcheck_service->GetCustomDictionary(); |
837 TestingProfile profile2; | 837 TestingProfile profile2; |
838 SpellcheckService* spellcheck_service2 = | 838 SpellcheckService* spellcheck_service2 = |
839 static_cast<SpellcheckService*>( | 839 static_cast<SpellcheckService*>( |
840 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 840 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
841 &profile2, &BuildSpellcheckService)); | 841 &profile2, &BuildSpellcheckService)); |
842 SpellcheckCustomDictionary* custom_dictionary2 = | 842 SpellcheckCustomDictionary* custom_dictionary2 = |
843 spellcheck_service2->GetCustomDictionary(); | 843 spellcheck_service2->GetCustomDictionary(); |
844 | 844 |
(...skipping 26 matching lines...) Expand all Loading... |
871 custom_dictionary2->GetWords().size()); | 871 custom_dictionary2->GetWords().size()); |
872 | 872 |
873 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, | 873 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, |
874 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 874 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
875 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, | 875 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, |
876 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 876 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
877 } | 877 } |
878 | 878 |
879 TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) { | 879 TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) { |
880 SpellcheckService* spellcheck_service = | 880 SpellcheckService* spellcheck_service = |
881 SpellcheckServiceFactory::GetForProfile(&profile_); | 881 SpellcheckServiceFactory::GetForContext(&profile_); |
882 SpellcheckCustomDictionary* custom_dictionary = | 882 SpellcheckCustomDictionary* custom_dictionary = |
883 spellcheck_service->GetCustomDictionary(); | 883 spellcheck_service->GetCustomDictionary(); |
884 | 884 |
885 DictionaryObserverCounter observer; | 885 DictionaryObserverCounter observer; |
886 custom_dictionary->AddObserver(&observer); | 886 custom_dictionary->AddObserver(&observer); |
887 | 887 |
888 WordList custom_words; | 888 WordList custom_words; |
889 custom_words.push_back("foo"); | 889 custom_words.push_back("foo"); |
890 custom_words.push_back("bar"); | 890 custom_words.push_back("bar"); |
891 OnLoaded(*custom_dictionary, custom_words); | 891 OnLoaded(*custom_dictionary, custom_words); |
892 | 892 |
893 EXPECT_GE(observer.loads(), 1); | 893 EXPECT_GE(observer.loads(), 1); |
894 EXPECT_LE(observer.loads(), 2); | 894 EXPECT_LE(observer.loads(), 2); |
895 EXPECT_EQ(0, observer.changes()); | 895 EXPECT_EQ(0, observer.changes()); |
896 | 896 |
897 custom_dictionary->RemoveObserver(&observer); | 897 custom_dictionary->RemoveObserver(&observer); |
898 } | 898 } |
899 | 899 |
900 TEST_F(SpellcheckCustomDictionaryTest, DictionaryAddWordNotification) { | 900 TEST_F(SpellcheckCustomDictionaryTest, DictionaryAddWordNotification) { |
901 SpellcheckService* spellcheck_service = | 901 SpellcheckService* spellcheck_service = |
902 SpellcheckServiceFactory::GetForProfile(&profile_); | 902 SpellcheckServiceFactory::GetForContext(&profile_); |
903 SpellcheckCustomDictionary* custom_dictionary = | 903 SpellcheckCustomDictionary* custom_dictionary = |
904 spellcheck_service->GetCustomDictionary(); | 904 spellcheck_service->GetCustomDictionary(); |
905 | 905 |
906 OnLoaded(*custom_dictionary, WordList()); | 906 OnLoaded(*custom_dictionary, WordList()); |
907 | 907 |
908 DictionaryObserverCounter observer; | 908 DictionaryObserverCounter observer; |
909 custom_dictionary->AddObserver(&observer); | 909 custom_dictionary->AddObserver(&observer); |
910 | 910 |
911 EXPECT_TRUE(custom_dictionary->AddWord("foo")); | 911 EXPECT_TRUE(custom_dictionary->AddWord("foo")); |
912 EXPECT_TRUE(custom_dictionary->AddWord("bar")); | 912 EXPECT_TRUE(custom_dictionary->AddWord("bar")); |
913 EXPECT_FALSE(custom_dictionary->AddWord("bar")); | 913 EXPECT_FALSE(custom_dictionary->AddWord("bar")); |
914 | 914 |
915 EXPECT_EQ(2, observer.changes()); | 915 EXPECT_EQ(2, observer.changes()); |
916 | 916 |
917 custom_dictionary->RemoveObserver(&observer); | 917 custom_dictionary->RemoveObserver(&observer); |
918 } | 918 } |
919 | 919 |
920 TEST_F(SpellcheckCustomDictionaryTest, DictionaryRemoveWordNotification) { | 920 TEST_F(SpellcheckCustomDictionaryTest, DictionaryRemoveWordNotification) { |
921 SpellcheckService* spellcheck_service = | 921 SpellcheckService* spellcheck_service = |
922 SpellcheckServiceFactory::GetForProfile(&profile_); | 922 SpellcheckServiceFactory::GetForContext(&profile_); |
923 SpellcheckCustomDictionary* custom_dictionary = | 923 SpellcheckCustomDictionary* custom_dictionary = |
924 spellcheck_service->GetCustomDictionary(); | 924 spellcheck_service->GetCustomDictionary(); |
925 | 925 |
926 OnLoaded(*custom_dictionary, WordList()); | 926 OnLoaded(*custom_dictionary, WordList()); |
927 | 927 |
928 EXPECT_TRUE(custom_dictionary->AddWord("foo")); | 928 EXPECT_TRUE(custom_dictionary->AddWord("foo")); |
929 EXPECT_TRUE(custom_dictionary->AddWord("bar")); | 929 EXPECT_TRUE(custom_dictionary->AddWord("bar")); |
930 | 930 |
931 DictionaryObserverCounter observer; | 931 DictionaryObserverCounter observer; |
932 custom_dictionary->AddObserver(&observer); | 932 custom_dictionary->AddObserver(&observer); |
933 | 933 |
934 EXPECT_TRUE(custom_dictionary->RemoveWord("foo")); | 934 EXPECT_TRUE(custom_dictionary->RemoveWord("foo")); |
935 EXPECT_TRUE(custom_dictionary->RemoveWord("bar")); | 935 EXPECT_TRUE(custom_dictionary->RemoveWord("bar")); |
936 EXPECT_FALSE(custom_dictionary->RemoveWord("baz")); | 936 EXPECT_FALSE(custom_dictionary->RemoveWord("baz")); |
937 | 937 |
938 EXPECT_EQ(2, observer.changes()); | 938 EXPECT_EQ(2, observer.changes()); |
939 | 939 |
940 custom_dictionary->RemoveObserver(&observer); | 940 custom_dictionary->RemoveObserver(&observer); |
941 } | 941 } |
942 | 942 |
943 TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncNotification) { | 943 TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncNotification) { |
944 SpellcheckService* spellcheck_service = | 944 SpellcheckService* spellcheck_service = |
945 SpellcheckServiceFactory::GetForProfile(&profile_); | 945 SpellcheckServiceFactory::GetForContext(&profile_); |
946 SpellcheckCustomDictionary* custom_dictionary = | 946 SpellcheckCustomDictionary* custom_dictionary = |
947 spellcheck_service->GetCustomDictionary(); | 947 spellcheck_service->GetCustomDictionary(); |
948 TestingProfile profile2; | 948 TestingProfile profile2; |
949 SpellcheckService* spellcheck_service2 = | 949 SpellcheckService* spellcheck_service2 = |
950 static_cast<SpellcheckService*>( | 950 static_cast<SpellcheckService*>( |
951 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 951 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
952 &profile2, &BuildSpellcheckService)); | 952 &profile2, &BuildSpellcheckService)); |
953 SpellcheckCustomDictionary* custom_dictionary2 = | 953 SpellcheckCustomDictionary* custom_dictionary2 = |
954 spellcheck_service2->GetCustomDictionary(); | 954 spellcheck_service2->GetCustomDictionary(); |
955 | 955 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 996 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
997 &server_profile, &BuildSpellcheckService)); | 997 &server_profile, &BuildSpellcheckService)); |
998 | 998 |
999 // Here, |server_custom_dictionary| plays the role of the sync server. | 999 // Here, |server_custom_dictionary| plays the role of the sync server. |
1000 SpellcheckCustomDictionary* server_custom_dictionary = | 1000 SpellcheckCustomDictionary* server_custom_dictionary = |
1001 server_spellcheck_service->GetCustomDictionary(); | 1001 server_spellcheck_service->GetCustomDictionary(); |
1002 | 1002 |
1003 // Upload the maximum number of words to the sync server. | 1003 // Upload the maximum number of words to the sync server. |
1004 { | 1004 { |
1005 SpellcheckService* spellcheck_service = | 1005 SpellcheckService* spellcheck_service = |
1006 SpellcheckServiceFactory::GetForProfile(&profile_); | 1006 SpellcheckServiceFactory::GetForContext(&profile_); |
1007 SpellcheckCustomDictionary* custom_dictionary = | 1007 SpellcheckCustomDictionary* custom_dictionary = |
1008 spellcheck_service->GetCustomDictionary(); | 1008 spellcheck_service->GetCustomDictionary(); |
1009 | 1009 |
1010 SpellcheckCustomDictionary::Change change; | 1010 SpellcheckCustomDictionary::Change change; |
1011 for (size_t i = 0; | 1011 for (size_t i = 0; |
1012 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; | 1012 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; |
1013 ++i) { | 1013 ++i) { |
1014 change.AddWord("foo" + base::Uint64ToString(i)); | 1014 change.AddWord("foo" + base::Uint64ToString(i)); |
1015 } | 1015 } |
1016 Apply(*custom_dictionary, change); | 1016 Apply(*custom_dictionary, change); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); | 1124 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); |
1125 ASSERT_TRUE(histogram != NULL); | 1125 ASSERT_TRUE(histogram != NULL); |
1126 scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples(); | 1126 scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples(); |
1127 | 1127 |
1128 samples2->Subtract(*baseline); | 1128 samples2->Subtract(*baseline); |
1129 EXPECT_EQ(2,samples2->sum()); | 1129 EXPECT_EQ(2,samples2->sum()); |
1130 } | 1130 } |
1131 | 1131 |
1132 TEST_F(SpellcheckCustomDictionaryTest, HasWord) { | 1132 TEST_F(SpellcheckCustomDictionaryTest, HasWord) { |
1133 SpellcheckService* spellcheck_service = | 1133 SpellcheckService* spellcheck_service = |
1134 SpellcheckServiceFactory::GetForProfile(&profile_); | 1134 SpellcheckServiceFactory::GetForContext(&profile_); |
1135 SpellcheckCustomDictionary* custom_dictionary = | 1135 SpellcheckCustomDictionary* custom_dictionary = |
1136 spellcheck_service->GetCustomDictionary(); | 1136 spellcheck_service->GetCustomDictionary(); |
1137 OnLoaded(*custom_dictionary, WordList()); | 1137 OnLoaded(*custom_dictionary, WordList()); |
1138 EXPECT_FALSE(custom_dictionary->HasWord("foo")); | 1138 EXPECT_FALSE(custom_dictionary->HasWord("foo")); |
1139 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1139 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
1140 custom_dictionary->AddWord("foo"); | 1140 custom_dictionary->AddWord("foo"); |
1141 EXPECT_TRUE(custom_dictionary->HasWord("foo")); | 1141 EXPECT_TRUE(custom_dictionary->HasWord("foo")); |
1142 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1142 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
1143 } | 1143 } |
OLD | NEW |