| 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 "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" | 5 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/metrics/histogram_samples.h" | 16 #include "base/metrics/histogram_samples.h" |
| 17 #include "base/metrics/statistics_recorder.h" | 17 #include "base/metrics/statistics_recorder.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 21 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 22 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 22 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| 23 #include "chrome/browser/spellchecker/spellcheck_service.h" | 23 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/spellcheck_common.h" | |
| 26 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 26 #include "components/spellcheck/common/spellcheck_common.h" |
| 27 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
| 28 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
| 29 #include "sync/api/sync_change.h" | 29 #include "sync/api/sync_change.h" |
| 30 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 30 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
| 31 #include "sync/api/sync_data.h" | 31 #include "sync/api/sync_data.h" |
| 32 #include "sync/api/sync_error_factory.h" | 32 #include "sync/api/sync_error_factory.h" |
| 33 #include "sync/api/sync_error_factory_mock.h" | 33 #include "sync/api/sync_error_factory_mock.h" |
| 34 #include "sync/protocol/sync.pb.h" | 34 #include "sync/protocol/sync.pb.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 data = dictionary->GetAllSyncData(syncer::DICTIONARY); | 327 data = dictionary->GetAllSyncData(syncer::DICTIONARY); |
| 328 EXPECT_TRUE(data.empty()); | 328 EXPECT_TRUE(data.empty()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) { | 331 TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) { |
| 332 SpellcheckCustomDictionary* dictionary = | 332 SpellcheckCustomDictionary* dictionary = |
| 333 SpellcheckServiceFactory::GetForContext( | 333 SpellcheckServiceFactory::GetForContext( |
| 334 &profile_)->GetCustomDictionary(); | 334 &profile_)->GetCustomDictionary(); |
| 335 | 335 |
| 336 SpellcheckCustomDictionary::Change change; | 336 SpellcheckCustomDictionary::Change change; |
| 337 for (size_t i = 0; | 337 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS - 1; i++) { |
| 338 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1; | |
| 339 i++) { | |
| 340 change.AddWord("foo" + base::Uint64ToString(i)); | 338 change.AddWord("foo" + base::Uint64ToString(i)); |
| 341 } | 339 } |
| 342 Apply(*dictionary, change); | 340 Apply(*dictionary, change); |
| 343 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1, | 341 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS - 1, |
| 344 dictionary->GetWords().size()); | 342 dictionary->GetWords().size()); |
| 345 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1, | 343 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS - 1, |
| 346 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 344 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 347 | 345 |
| 348 dictionary->AddWord("baz"); | 346 dictionary->AddWord("baz"); |
| 349 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 347 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 350 dictionary->GetWords().size()); | 348 dictionary->GetWords().size()); |
| 351 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 349 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 352 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 350 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 353 | 351 |
| 354 dictionary->AddWord("bar"); | 352 dictionary->AddWord("bar"); |
| 355 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 353 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 356 dictionary->GetWords().size()); | 354 dictionary->GetWords().size()); |
| 357 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 355 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 358 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 356 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 359 | 357 |
| 360 dictionary->AddWord("snafoo"); | 358 dictionary->AddWord("snafoo"); |
| 361 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 2, | 359 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 2, |
| 362 dictionary->GetWords().size()); | 360 dictionary->GetWords().size()); |
| 363 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 361 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 364 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 362 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 365 } | 363 } |
| 366 | 364 |
| 367 TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) { | 365 TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) { |
| 368 SpellcheckService* spellcheck_service = | 366 SpellcheckService* spellcheck_service = |
| 369 SpellcheckServiceFactory::GetForContext(&profile_); | 367 SpellcheckServiceFactory::GetForContext(&profile_); |
| 370 SpellcheckCustomDictionary* dictionary = | 368 SpellcheckCustomDictionary* dictionary = |
| 371 spellcheck_service->GetCustomDictionary(); | 369 spellcheck_service->GetCustomDictionary(); |
| 372 | 370 |
| 373 dictionary->AddWord("foo"); | 371 dictionary->AddWord("foo"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 spellcheck_service->GetCustomDictionary(); | 440 spellcheck_service->GetCustomDictionary(); |
| 443 TestingProfile profile2; | 441 TestingProfile profile2; |
| 444 SpellcheckService* spellcheck_service2 = | 442 SpellcheckService* spellcheck_service2 = |
| 445 static_cast<SpellcheckService*>( | 443 static_cast<SpellcheckService*>( |
| 446 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 444 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 447 &profile2, &BuildSpellcheckService)); | 445 &profile2, &BuildSpellcheckService)); |
| 448 SpellcheckCustomDictionary* custom_dictionary2 = | 446 SpellcheckCustomDictionary* custom_dictionary2 = |
| 449 spellcheck_service2->GetCustomDictionary(); | 447 spellcheck_service2->GetCustomDictionary(); |
| 450 | 448 |
| 451 SpellcheckCustomDictionary::Change change; | 449 SpellcheckCustomDictionary::Change change; |
| 452 for (size_t i = 0; | 450 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS / 2; ++i) { |
| 453 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2; | |
| 454 ++i) { | |
| 455 change.AddWord("foo" + base::Uint64ToString(i)); | 451 change.AddWord("foo" + base::Uint64ToString(i)); |
| 456 } | 452 } |
| 457 Apply(*custom_dictionary, change); | 453 Apply(*custom_dictionary, change); |
| 458 | 454 |
| 459 SpellcheckCustomDictionary::Change change2; | 455 SpellcheckCustomDictionary::Change change2; |
| 460 for (size_t i = 0; | 456 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS / 2; ++i) { |
| 461 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2; | |
| 462 ++i) { | |
| 463 change2.AddWord("bar" + base::Uint64ToString(i)); | 457 change2.AddWord("bar" + base::Uint64ToString(i)); |
| 464 } | 458 } |
| 465 Apply(*custom_dictionary2, change2); | 459 Apply(*custom_dictionary2, change2); |
| 466 | 460 |
| 467 int error_counter = 0; | 461 int error_counter = 0; |
| 468 EXPECT_FALSE(custom_dictionary | 462 EXPECT_FALSE(custom_dictionary |
| 469 ->MergeDataAndStartSyncing( | 463 ->MergeDataAndStartSyncing( |
| 470 syncer::DICTIONARY, | 464 syncer::DICTIONARY, |
| 471 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), | 465 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), |
| 472 std::unique_ptr<syncer::SyncChangeProcessor>( | 466 std::unique_ptr<syncer::SyncChangeProcessor>( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 spellcheck_service->GetCustomDictionary(); | 537 spellcheck_service->GetCustomDictionary(); |
| 544 TestingProfile profile2; | 538 TestingProfile profile2; |
| 545 SpellcheckService* spellcheck_service2 = | 539 SpellcheckService* spellcheck_service2 = |
| 546 static_cast<SpellcheckService*>( | 540 static_cast<SpellcheckService*>( |
| 547 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 541 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 548 &profile2, &BuildSpellcheckService)); | 542 &profile2, &BuildSpellcheckService)); |
| 549 SpellcheckCustomDictionary* custom_dictionary2 = | 543 SpellcheckCustomDictionary* custom_dictionary2 = |
| 550 spellcheck_service2->GetCustomDictionary(); | 544 spellcheck_service2->GetCustomDictionary(); |
| 551 | 545 |
| 552 SpellcheckCustomDictionary::Change change; | 546 SpellcheckCustomDictionary::Change change; |
| 553 for (size_t i = 0; | 547 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1; ++i) { |
| 554 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1; | |
| 555 ++i) { | |
| 556 change.AddWord("foo" + base::Uint64ToString(i)); | 548 change.AddWord("foo" + base::Uint64ToString(i)); |
| 557 } | 549 } |
| 558 Apply(*custom_dictionary, change); | 550 Apply(*custom_dictionary, change); |
| 559 | 551 |
| 560 int error_counter = 0; | 552 int error_counter = 0; |
| 561 EXPECT_FALSE(custom_dictionary | 553 EXPECT_FALSE(custom_dictionary |
| 562 ->MergeDataAndStartSyncing( | 554 ->MergeDataAndStartSyncing( |
| 563 syncer::DICTIONARY, | 555 syncer::DICTIONARY, |
| 564 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), | 556 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), |
| 565 std::unique_ptr<syncer::SyncChangeProcessor>( | 557 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 566 new syncer::SyncChangeProcessorWrapperForTest( | 558 new syncer::SyncChangeProcessorWrapperForTest( |
| 567 custom_dictionary2)), | 559 custom_dictionary2)), |
| 568 std::unique_ptr<syncer::SyncErrorFactory>( | 560 std::unique_ptr<syncer::SyncErrorFactory>( |
| 569 new SyncErrorFactoryStub(&error_counter))) | 561 new SyncErrorFactoryStub(&error_counter))) |
| 570 .error() | 562 .error() |
| 571 .IsSet()); | 563 .IsSet()); |
| 572 EXPECT_EQ(0, error_counter); | 564 EXPECT_EQ(0, error_counter); |
| 573 EXPECT_FALSE(custom_dictionary->IsSyncing()); | 565 EXPECT_FALSE(custom_dictionary->IsSyncing()); |
| 574 | 566 |
| 575 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 567 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 576 custom_dictionary->GetWords().size()); | 568 custom_dictionary->GetWords().size()); |
| 577 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 569 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 578 custom_dictionary2->GetWords().size()); | 570 custom_dictionary2->GetWords().size()); |
| 579 | 571 |
| 580 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 572 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 581 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 573 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 582 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 574 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 583 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 575 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 584 } | 576 } |
| 585 | 577 |
| 586 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) { | 578 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) { |
| 587 SpellcheckService* spellcheck_service = | 579 SpellcheckService* spellcheck_service = |
| 588 SpellcheckServiceFactory::GetForContext(&profile_); | 580 SpellcheckServiceFactory::GetForContext(&profile_); |
| 589 SpellcheckCustomDictionary* custom_dictionary = | 581 SpellcheckCustomDictionary* custom_dictionary = |
| 590 spellcheck_service->GetCustomDictionary(); | 582 spellcheck_service->GetCustomDictionary(); |
| 591 TestingProfile profile2; | 583 TestingProfile profile2; |
| 592 SpellcheckService* spellcheck_service2 = | 584 SpellcheckService* spellcheck_service2 = |
| 593 static_cast<SpellcheckService*>( | 585 static_cast<SpellcheckService*>( |
| 594 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 586 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 595 &profile2, &BuildSpellcheckService)); | 587 &profile2, &BuildSpellcheckService)); |
| 596 SpellcheckCustomDictionary* custom_dictionary2 = | 588 SpellcheckCustomDictionary* custom_dictionary2 = |
| 597 spellcheck_service2->GetCustomDictionary(); | 589 spellcheck_service2->GetCustomDictionary(); |
| 598 | 590 |
| 599 SpellcheckCustomDictionary::Change change; | 591 SpellcheckCustomDictionary::Change change; |
| 600 SpellcheckCustomDictionary::Change change2; | 592 SpellcheckCustomDictionary::Change change2; |
| 601 for (size_t i = 0; | 593 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS; ++i) { |
| 602 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; | |
| 603 ++i) { | |
| 604 change.AddWord("foo" + base::Uint64ToString(i)); | 594 change.AddWord("foo" + base::Uint64ToString(i)); |
| 605 change2.AddWord("bar" + base::Uint64ToString(i)); | 595 change2.AddWord("bar" + base::Uint64ToString(i)); |
| 606 } | 596 } |
| 607 change.AddWord("foo"); | 597 change.AddWord("foo"); |
| 608 Apply(*custom_dictionary, change); | 598 Apply(*custom_dictionary, change); |
| 609 Apply(*custom_dictionary2, change2); | 599 Apply(*custom_dictionary2, change2); |
| 610 | 600 |
| 611 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 601 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 612 custom_dictionary->GetWords().size()); | 602 custom_dictionary->GetWords().size()); |
| 613 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 603 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 614 custom_dictionary2->GetWords().size()); | 604 custom_dictionary2->GetWords().size()); |
| 615 | 605 |
| 616 int error_counter = 0; | 606 int error_counter = 0; |
| 617 EXPECT_FALSE(custom_dictionary | 607 EXPECT_FALSE(custom_dictionary |
| 618 ->MergeDataAndStartSyncing( | 608 ->MergeDataAndStartSyncing( |
| 619 syncer::DICTIONARY, | 609 syncer::DICTIONARY, |
| 620 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), | 610 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), |
| 621 std::unique_ptr<syncer::SyncChangeProcessor>( | 611 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 622 new syncer::SyncChangeProcessorWrapperForTest( | 612 new syncer::SyncChangeProcessorWrapperForTest( |
| 623 custom_dictionary2)), | 613 custom_dictionary2)), |
| 624 std::unique_ptr<syncer::SyncErrorFactory>( | 614 std::unique_ptr<syncer::SyncErrorFactory>( |
| 625 new SyncErrorFactoryStub(&error_counter))) | 615 new SyncErrorFactoryStub(&error_counter))) |
| 626 .error() | 616 .error() |
| 627 .IsSet()); | 617 .IsSet()); |
| 628 EXPECT_EQ(0, error_counter); | 618 EXPECT_EQ(0, error_counter); |
| 629 EXPECT_FALSE(custom_dictionary->IsSyncing()); | 619 EXPECT_FALSE(custom_dictionary->IsSyncing()); |
| 630 | 620 |
| 631 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2 + 1, | 621 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS * 2 + 1, |
| 632 custom_dictionary->GetWords().size()); | 622 custom_dictionary->GetWords().size()); |
| 633 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 623 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 634 custom_dictionary2->GetWords().size()); | 624 custom_dictionary2->GetWords().size()); |
| 635 | 625 |
| 636 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 626 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 637 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 627 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 638 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 628 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 639 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 629 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 640 } | 630 } |
| 641 | 631 |
| 642 TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) { | 632 TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) { |
| 643 SpellcheckService* spellcheck_service = | 633 SpellcheckService* spellcheck_service = |
| 644 SpellcheckServiceFactory::GetForContext(&profile_); | 634 SpellcheckServiceFactory::GetForContext(&profile_); |
| 645 SpellcheckCustomDictionary* custom_dictionary = | 635 SpellcheckCustomDictionary* custom_dictionary = |
| 646 spellcheck_service->GetCustomDictionary(); | 636 spellcheck_service->GetCustomDictionary(); |
| 647 TestingProfile profile2; | 637 TestingProfile profile2; |
| 648 SpellcheckService* spellcheck_service2 = | 638 SpellcheckService* spellcheck_service2 = |
| 649 static_cast<SpellcheckService*>( | 639 static_cast<SpellcheckService*>( |
| 650 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 640 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 651 &profile2, &BuildSpellcheckService)); | 641 &profile2, &BuildSpellcheckService)); |
| 652 SpellcheckCustomDictionary* custom_dictionary2 = | 642 SpellcheckCustomDictionary* custom_dictionary2 = |
| 653 spellcheck_service2->GetCustomDictionary(); | 643 spellcheck_service2->GetCustomDictionary(); |
| 654 | 644 |
| 655 SpellcheckCustomDictionary::Change change; | 645 SpellcheckCustomDictionary::Change change; |
| 656 SpellcheckCustomDictionary::Change change2; | 646 SpellcheckCustomDictionary::Change change2; |
| 657 for (size_t i = 0; | 647 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1; ++i) { |
| 658 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1; | |
| 659 ++i) { | |
| 660 change.AddWord("foo" + base::Uint64ToString(i)); | 648 change.AddWord("foo" + base::Uint64ToString(i)); |
| 661 change2.AddWord("bar" + base::Uint64ToString(i)); | 649 change2.AddWord("bar" + base::Uint64ToString(i)); |
| 662 } | 650 } |
| 663 Apply(*custom_dictionary, change); | 651 Apply(*custom_dictionary, change); |
| 664 Apply(*custom_dictionary2, change2); | 652 Apply(*custom_dictionary2, change2); |
| 665 | 653 |
| 666 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 654 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 667 custom_dictionary->GetWords().size()); | 655 custom_dictionary->GetWords().size()); |
| 668 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 656 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 669 custom_dictionary2->GetWords().size()); | 657 custom_dictionary2->GetWords().size()); |
| 670 | 658 |
| 671 int error_counter = 0; | 659 int error_counter = 0; |
| 672 EXPECT_FALSE(custom_dictionary | 660 EXPECT_FALSE(custom_dictionary |
| 673 ->MergeDataAndStartSyncing( | 661 ->MergeDataAndStartSyncing( |
| 674 syncer::DICTIONARY, | 662 syncer::DICTIONARY, |
| 675 GetAllSyncDataNoLimit(custom_dictionary2), | 663 GetAllSyncDataNoLimit(custom_dictionary2), |
| 676 std::unique_ptr<syncer::SyncChangeProcessor>( | 664 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 677 new syncer::SyncChangeProcessorWrapperForTest( | 665 new syncer::SyncChangeProcessorWrapperForTest( |
| 678 custom_dictionary2)), | 666 custom_dictionary2)), |
| 679 std::unique_ptr<syncer::SyncErrorFactory>( | 667 std::unique_ptr<syncer::SyncErrorFactory>( |
| 680 new SyncErrorFactoryStub(&error_counter))) | 668 new SyncErrorFactoryStub(&error_counter))) |
| 681 .error() | 669 .error() |
| 682 .IsSet()); | 670 .IsSet()); |
| 683 EXPECT_EQ(0, error_counter); | 671 EXPECT_EQ(0, error_counter); |
| 684 EXPECT_FALSE(custom_dictionary->IsSyncing()); | 672 EXPECT_FALSE(custom_dictionary->IsSyncing()); |
| 685 | 673 |
| 686 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2 + 2, | 674 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS * 2 + 2, |
| 687 custom_dictionary->GetWords().size()); | 675 custom_dictionary->GetWords().size()); |
| 688 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 676 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 689 custom_dictionary2->GetWords().size()); | 677 custom_dictionary2->GetWords().size()); |
| 690 | 678 |
| 691 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 679 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 692 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 680 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 693 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 681 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 694 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 682 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 695 } | 683 } |
| 696 | 684 |
| 697 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) { | 685 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) { |
| 698 SpellcheckService* spellcheck_service = | 686 SpellcheckService* spellcheck_service = |
| 699 SpellcheckServiceFactory::GetForContext(&profile_); | 687 SpellcheckServiceFactory::GetForContext(&profile_); |
| 700 SpellcheckCustomDictionary* custom_dictionary = | 688 SpellcheckCustomDictionary* custom_dictionary = |
| 701 spellcheck_service->GetCustomDictionary(); | 689 spellcheck_service->GetCustomDictionary(); |
| 702 TestingProfile profile2; | 690 TestingProfile profile2; |
| 703 SpellcheckService* spellcheck_service2 = | 691 SpellcheckService* spellcheck_service2 = |
| 704 static_cast<SpellcheckService*>( | 692 static_cast<SpellcheckService*>( |
| 705 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 693 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 706 &profile2, &BuildSpellcheckService)); | 694 &profile2, &BuildSpellcheckService)); |
| 707 SpellcheckCustomDictionary* custom_dictionary2 = | 695 SpellcheckCustomDictionary* custom_dictionary2 = |
| 708 spellcheck_service2->GetCustomDictionary(); | 696 spellcheck_service2->GetCustomDictionary(); |
| 709 | 697 |
| 710 SpellcheckCustomDictionary::Change change; | 698 SpellcheckCustomDictionary::Change change; |
| 711 for (size_t i = 0; | 699 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS - 1; ++i) { |
| 712 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1; | |
| 713 ++i) { | |
| 714 change.AddWord("foo" + base::Uint64ToString(i)); | 700 change.AddWord("foo" + base::Uint64ToString(i)); |
| 715 } | 701 } |
| 716 Apply(*custom_dictionary, change); | 702 Apply(*custom_dictionary, change); |
| 717 | 703 |
| 718 custom_dictionary2->AddWord("bar"); | 704 custom_dictionary2->AddWord("bar"); |
| 719 custom_dictionary2->AddWord("baz"); | 705 custom_dictionary2->AddWord("baz"); |
| 720 | 706 |
| 721 int error_counter = 0; | 707 int error_counter = 0; |
| 722 EXPECT_FALSE(custom_dictionary | 708 EXPECT_FALSE(custom_dictionary |
| 723 ->MergeDataAndStartSyncing( | 709 ->MergeDataAndStartSyncing( |
| 724 syncer::DICTIONARY, | 710 syncer::DICTIONARY, |
| 725 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), | 711 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), |
| 726 std::unique_ptr<syncer::SyncChangeProcessor>( | 712 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 727 new syncer::SyncChangeProcessorWrapperForTest( | 713 new syncer::SyncChangeProcessorWrapperForTest( |
| 728 custom_dictionary2)), | 714 custom_dictionary2)), |
| 729 std::unique_ptr<syncer::SyncErrorFactory>( | 715 std::unique_ptr<syncer::SyncErrorFactory>( |
| 730 new SyncErrorFactoryStub(&error_counter))) | 716 new SyncErrorFactoryStub(&error_counter))) |
| 731 .error() | 717 .error() |
| 732 .IsSet()); | 718 .IsSet()); |
| 733 EXPECT_EQ(0, error_counter); | 719 EXPECT_EQ(0, error_counter); |
| 734 EXPECT_FALSE(custom_dictionary->IsSyncing()); | 720 EXPECT_FALSE(custom_dictionary->IsSyncing()); |
| 735 | 721 |
| 736 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 722 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 737 custom_dictionary->GetWords().size()); | 723 custom_dictionary->GetWords().size()); |
| 738 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 724 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 739 custom_dictionary2->GetWords().size()); | 725 custom_dictionary2->GetWords().size()); |
| 740 | 726 |
| 741 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 727 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 742 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 728 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 743 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 729 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 744 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 730 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 745 } | 731 } |
| 746 | 732 |
| 747 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) { | 733 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) { |
| 748 SpellcheckService* spellcheck_service = | 734 SpellcheckService* spellcheck_service = |
| 749 SpellcheckServiceFactory::GetForContext(&profile_); | 735 SpellcheckServiceFactory::GetForContext(&profile_); |
| 750 SpellcheckCustomDictionary* custom_dictionary = | 736 SpellcheckCustomDictionary* custom_dictionary = |
| 751 spellcheck_service->GetCustomDictionary(); | 737 spellcheck_service->GetCustomDictionary(); |
| 752 TestingProfile profile2; | 738 TestingProfile profile2; |
| 753 SpellcheckService* spellcheck_service2 = | 739 SpellcheckService* spellcheck_service2 = |
| 754 static_cast<SpellcheckService*>( | 740 static_cast<SpellcheckService*>( |
| 755 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 741 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 756 &profile2, &BuildSpellcheckService)); | 742 &profile2, &BuildSpellcheckService)); |
| 757 SpellcheckCustomDictionary* custom_dictionary2 = | 743 SpellcheckCustomDictionary* custom_dictionary2 = |
| 758 spellcheck_service2->GetCustomDictionary(); | 744 spellcheck_service2->GetCustomDictionary(); |
| 759 | 745 |
| 760 SpellcheckCustomDictionary::Change change; | 746 SpellcheckCustomDictionary::Change change; |
| 761 for (size_t i = 0; | 747 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS - 1; ++i) { |
| 762 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1; | |
| 763 ++i) { | |
| 764 change.AddWord("foo" + base::Uint64ToString(i)); | 748 change.AddWord("foo" + base::Uint64ToString(i)); |
| 765 } | 749 } |
| 766 Apply(*custom_dictionary, change); | 750 Apply(*custom_dictionary, change); |
| 767 | 751 |
| 768 int error_counter = 0; | 752 int error_counter = 0; |
| 769 EXPECT_FALSE(custom_dictionary | 753 EXPECT_FALSE(custom_dictionary |
| 770 ->MergeDataAndStartSyncing( | 754 ->MergeDataAndStartSyncing( |
| 771 syncer::DICTIONARY, | 755 syncer::DICTIONARY, |
| 772 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), | 756 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), |
| 773 std::unique_ptr<syncer::SyncChangeProcessor>( | 757 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 774 new syncer::SyncChangeProcessorWrapperForTest( | 758 new syncer::SyncChangeProcessorWrapperForTest( |
| 775 custom_dictionary2)), | 759 custom_dictionary2)), |
| 776 std::unique_ptr<syncer::SyncErrorFactory>( | 760 std::unique_ptr<syncer::SyncErrorFactory>( |
| 777 new SyncErrorFactoryStub(&error_counter))) | 761 new SyncErrorFactoryStub(&error_counter))) |
| 778 .error() | 762 .error() |
| 779 .IsSet()); | 763 .IsSet()); |
| 780 EXPECT_EQ(0, error_counter); | 764 EXPECT_EQ(0, error_counter); |
| 781 EXPECT_TRUE(custom_dictionary->IsSyncing()); | 765 EXPECT_TRUE(custom_dictionary->IsSyncing()); |
| 782 | 766 |
| 783 custom_dictionary->AddWord("bar"); | 767 custom_dictionary->AddWord("bar"); |
| 784 EXPECT_EQ(0, error_counter); | 768 EXPECT_EQ(0, error_counter); |
| 785 EXPECT_TRUE(custom_dictionary->IsSyncing()); | 769 EXPECT_TRUE(custom_dictionary->IsSyncing()); |
| 786 | 770 |
| 787 custom_dictionary->AddWord("baz"); | 771 custom_dictionary->AddWord("baz"); |
| 788 EXPECT_EQ(0, error_counter); | 772 EXPECT_EQ(0, error_counter); |
| 789 EXPECT_FALSE(custom_dictionary->IsSyncing()); | 773 EXPECT_FALSE(custom_dictionary->IsSyncing()); |
| 790 | 774 |
| 791 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 775 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 792 custom_dictionary->GetWords().size()); | 776 custom_dictionary->GetWords().size()); |
| 793 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 777 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 794 custom_dictionary2->GetWords().size()); | 778 custom_dictionary2->GetWords().size()); |
| 795 | 779 |
| 796 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 780 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 797 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 781 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 798 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 782 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 799 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 783 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 800 } | 784 } |
| 801 | 785 |
| 802 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) { | 786 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) { |
| 803 SpellcheckService* spellcheck_service = | 787 SpellcheckService* spellcheck_service = |
| 804 SpellcheckServiceFactory::GetForContext(&profile_); | 788 SpellcheckServiceFactory::GetForContext(&profile_); |
| 805 SpellcheckCustomDictionary* custom_dictionary = | 789 SpellcheckCustomDictionary* custom_dictionary = |
| 806 spellcheck_service->GetCustomDictionary(); | 790 spellcheck_service->GetCustomDictionary(); |
| 807 TestingProfile profile2; | 791 TestingProfile profile2; |
| 808 SpellcheckService* spellcheck_service2 = | 792 SpellcheckService* spellcheck_service2 = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 custom_dictionary2)), | 851 custom_dictionary2)), |
| 868 std::unique_ptr<syncer::SyncErrorFactory>( | 852 std::unique_ptr<syncer::SyncErrorFactory>( |
| 869 new SyncErrorFactoryStub(&error_counter))) | 853 new SyncErrorFactoryStub(&error_counter))) |
| 870 .error() | 854 .error() |
| 871 .IsSet()); | 855 .IsSet()); |
| 872 EXPECT_EQ(0, error_counter); | 856 EXPECT_EQ(0, error_counter); |
| 873 EXPECT_TRUE(custom_dictionary->IsSyncing()); | 857 EXPECT_TRUE(custom_dictionary->IsSyncing()); |
| 874 | 858 |
| 875 std::unique_ptr<std::set<std::string>> custom_words( | 859 std::unique_ptr<std::set<std::string>> custom_words( |
| 876 new std::set<std::string>); | 860 new std::set<std::string>); |
| 877 for (size_t i = 0; | 861 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS; ++i) { |
| 878 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; | |
| 879 ++i) { | |
| 880 custom_words->insert(custom_words->end(), "foo" + base::Uint64ToString(i)); | 862 custom_words->insert(custom_words->end(), "foo" + base::Uint64ToString(i)); |
| 881 } | 863 } |
| 882 OnLoaded(*custom_dictionary, std::move(custom_words)); | 864 OnLoaded(*custom_dictionary, std::move(custom_words)); |
| 883 EXPECT_EQ(0, error_counter); | 865 EXPECT_EQ(0, error_counter); |
| 884 EXPECT_FALSE(custom_dictionary->IsSyncing()); | 866 EXPECT_FALSE(custom_dictionary->IsSyncing()); |
| 885 | 867 |
| 886 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 1, | 868 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS + 1, |
| 887 custom_dictionary->GetWords().size()); | 869 custom_dictionary->GetWords().size()); |
| 888 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 870 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 889 custom_dictionary2->GetWords().size()); | 871 custom_dictionary2->GetWords().size()); |
| 890 | 872 |
| 891 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 873 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 892 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 874 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 893 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 875 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 894 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 876 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 895 } | 877 } |
| 896 | 878 |
| 897 TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) { | 879 TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) { |
| 898 SpellcheckService* spellcheck_service = | 880 SpellcheckService* spellcheck_service = |
| 899 SpellcheckServiceFactory::GetForContext(&profile_); | 881 SpellcheckServiceFactory::GetForContext(&profile_); |
| 900 SpellcheckCustomDictionary* custom_dictionary = | 882 SpellcheckCustomDictionary* custom_dictionary = |
| 901 spellcheck_service->GetCustomDictionary(); | 883 spellcheck_service->GetCustomDictionary(); |
| 902 TestingProfile profile2; | 884 TestingProfile profile2; |
| 903 SpellcheckService* spellcheck_service2 = | 885 SpellcheckService* spellcheck_service2 = |
| 904 static_cast<SpellcheckService*>( | 886 static_cast<SpellcheckService*>( |
| 905 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 887 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 906 &profile2, &BuildSpellcheckService)); | 888 &profile2, &BuildSpellcheckService)); |
| 907 SpellcheckCustomDictionary* custom_dictionary2 = | 889 SpellcheckCustomDictionary* custom_dictionary2 = |
| 908 spellcheck_service2->GetCustomDictionary(); | 890 spellcheck_service2->GetCustomDictionary(); |
| 909 | 891 |
| 910 SpellcheckCustomDictionary::Change change; | 892 SpellcheckCustomDictionary::Change change; |
| 911 for (size_t i = 0; | 893 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS / 2; ++i) { |
| 912 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2; | |
| 913 ++i) { | |
| 914 change.AddWord("foo" + base::Uint64ToString(i)); | 894 change.AddWord("foo" + base::Uint64ToString(i)); |
| 915 } | 895 } |
| 916 Apply(*custom_dictionary, change); | 896 Apply(*custom_dictionary, change); |
| 917 | 897 |
| 918 int error_counter = 0; | 898 int error_counter = 0; |
| 919 EXPECT_FALSE(custom_dictionary | 899 EXPECT_FALSE(custom_dictionary |
| 920 ->MergeDataAndStartSyncing( | 900 ->MergeDataAndStartSyncing( |
| 921 syncer::DICTIONARY, | 901 syncer::DICTIONARY, |
| 922 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), | 902 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY), |
| 923 std::unique_ptr<syncer::SyncChangeProcessor>( | 903 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 924 new syncer::SyncChangeProcessorWrapperForTest( | 904 new syncer::SyncChangeProcessorWrapperForTest( |
| 925 custom_dictionary2)), | 905 custom_dictionary2)), |
| 926 std::unique_ptr<syncer::SyncErrorFactory>( | 906 std::unique_ptr<syncer::SyncErrorFactory>( |
| 927 new SyncErrorFactoryStub(&error_counter))) | 907 new SyncErrorFactoryStub(&error_counter))) |
| 928 .error() | 908 .error() |
| 929 .IsSet()); | 909 .IsSet()); |
| 930 EXPECT_EQ(0, error_counter); | 910 EXPECT_EQ(0, error_counter); |
| 931 EXPECT_TRUE(custom_dictionary->IsSyncing()); | 911 EXPECT_TRUE(custom_dictionary->IsSyncing()); |
| 932 | 912 |
| 933 OnLoaded(*custom_dictionary, | 913 OnLoaded(*custom_dictionary, |
| 934 base::WrapUnique(new std::set<std::string>(change.to_add()))); | 914 base::WrapUnique(new std::set<std::string>(change.to_add()))); |
| 935 EXPECT_EQ(0, error_counter); | 915 EXPECT_EQ(0, error_counter); |
| 936 EXPECT_TRUE(custom_dictionary->IsSyncing()); | 916 EXPECT_TRUE(custom_dictionary->IsSyncing()); |
| 937 | 917 |
| 938 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, | 918 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS / 2, |
| 939 custom_dictionary->GetWords().size()); | 919 custom_dictionary->GetWords().size()); |
| 940 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, | 920 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS / 2, |
| 941 custom_dictionary2->GetWords().size()); | 921 custom_dictionary2->GetWords().size()); |
| 942 | 922 |
| 943 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, | 923 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS / 2, |
| 944 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 924 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 945 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, | 925 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS / 2, |
| 946 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 926 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 947 } | 927 } |
| 948 | 928 |
| 949 TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) { | 929 TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) { |
| 950 SpellcheckService* spellcheck_service = | 930 SpellcheckService* spellcheck_service = |
| 951 SpellcheckServiceFactory::GetForContext(&profile_); | 931 SpellcheckServiceFactory::GetForContext(&profile_); |
| 952 SpellcheckCustomDictionary* custom_dictionary = | 932 SpellcheckCustomDictionary* custom_dictionary = |
| 953 spellcheck_service->GetCustomDictionary(); | 933 spellcheck_service->GetCustomDictionary(); |
| 954 | 934 |
| 955 DictionaryObserverCounter observer; | 935 DictionaryObserverCounter observer; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 server_spellcheck_service->GetCustomDictionary(); | 1056 server_spellcheck_service->GetCustomDictionary(); |
| 1077 | 1057 |
| 1078 // Upload the maximum number of words to the sync server. | 1058 // Upload the maximum number of words to the sync server. |
| 1079 { | 1059 { |
| 1080 SpellcheckService* spellcheck_service = | 1060 SpellcheckService* spellcheck_service = |
| 1081 SpellcheckServiceFactory::GetForContext(&profile_); | 1061 SpellcheckServiceFactory::GetForContext(&profile_); |
| 1082 SpellcheckCustomDictionary* custom_dictionary = | 1062 SpellcheckCustomDictionary* custom_dictionary = |
| 1083 spellcheck_service->GetCustomDictionary(); | 1063 spellcheck_service->GetCustomDictionary(); |
| 1084 | 1064 |
| 1085 SpellcheckCustomDictionary::Change change; | 1065 SpellcheckCustomDictionary::Change change; |
| 1086 for (size_t i = 0; | 1066 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS; ++i) { |
| 1087 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; | |
| 1088 ++i) { | |
| 1089 change.AddWord("foo" + base::Uint64ToString(i)); | 1067 change.AddWord("foo" + base::Uint64ToString(i)); |
| 1090 } | 1068 } |
| 1091 Apply(*custom_dictionary, change); | 1069 Apply(*custom_dictionary, change); |
| 1092 | 1070 |
| 1093 int error_counter = 0; | 1071 int error_counter = 0; |
| 1094 EXPECT_FALSE( | 1072 EXPECT_FALSE( |
| 1095 custom_dictionary | 1073 custom_dictionary |
| 1096 ->MergeDataAndStartSyncing( | 1074 ->MergeDataAndStartSyncing( |
| 1097 syncer::DICTIONARY, | 1075 syncer::DICTIONARY, |
| 1098 server_custom_dictionary->GetAllSyncData(syncer::DICTIONARY), | 1076 server_custom_dictionary->GetAllSyncData(syncer::DICTIONARY), |
| 1099 std::unique_ptr<syncer::SyncChangeProcessor>( | 1077 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 1100 new syncer::SyncChangeProcessorWrapperForTest( | 1078 new syncer::SyncChangeProcessorWrapperForTest( |
| 1101 server_custom_dictionary)), | 1079 server_custom_dictionary)), |
| 1102 std::unique_ptr<syncer::SyncErrorFactory>( | 1080 std::unique_ptr<syncer::SyncErrorFactory>( |
| 1103 new SyncErrorFactoryStub(&error_counter))) | 1081 new SyncErrorFactoryStub(&error_counter))) |
| 1104 .error() | 1082 .error() |
| 1105 .IsSet()); | 1083 .IsSet()); |
| 1106 EXPECT_EQ(0, error_counter); | 1084 EXPECT_EQ(0, error_counter); |
| 1107 EXPECT_TRUE(custom_dictionary->IsSyncing()); | 1085 EXPECT_TRUE(custom_dictionary->IsSyncing()); |
| 1108 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 1086 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 1109 custom_dictionary->GetWords().size()); | 1087 custom_dictionary->GetWords().size()); |
| 1110 } | 1088 } |
| 1111 | 1089 |
| 1112 // The sync server now has the maximum number of words. | 1090 // The sync server now has the maximum number of words. |
| 1113 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 1091 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 1114 server_custom_dictionary->GetWords().size()); | 1092 server_custom_dictionary->GetWords().size()); |
| 1115 | 1093 |
| 1116 // Associate the sync server with a client that also has the maximum number of | 1094 // Associate the sync server with a client that also has the maximum number of |
| 1117 // words, but all of these words are different from the ones on the sync | 1095 // words, but all of these words are different from the ones on the sync |
| 1118 // server. | 1096 // server. |
| 1119 { | 1097 { |
| 1120 TestingProfile client_profile; | 1098 TestingProfile client_profile; |
| 1121 SpellcheckService* client_spellcheck_service = | 1099 SpellcheckService* client_spellcheck_service = |
| 1122 static_cast<SpellcheckService*>( | 1100 static_cast<SpellcheckService*>( |
| 1123 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 1101 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 1124 &client_profile, &BuildSpellcheckService)); | 1102 &client_profile, &BuildSpellcheckService)); |
| 1125 | 1103 |
| 1126 // Here, |client_custom_dictionary| plays the role of the client. | 1104 // Here, |client_custom_dictionary| plays the role of the client. |
| 1127 SpellcheckCustomDictionary* client_custom_dictionary = | 1105 SpellcheckCustomDictionary* client_custom_dictionary = |
| 1128 client_spellcheck_service->GetCustomDictionary(); | 1106 client_spellcheck_service->GetCustomDictionary(); |
| 1129 | 1107 |
| 1130 // Add the maximum number of words to the client. These words are all | 1108 // Add the maximum number of words to the client. These words are all |
| 1131 // different from those on the server. | 1109 // different from those on the server. |
| 1132 SpellcheckCustomDictionary::Change change; | 1110 SpellcheckCustomDictionary::Change change; |
| 1133 for (size_t i = 0; | 1111 for (size_t i = 0; i < spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS; ++i) { |
| 1134 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; | |
| 1135 ++i) { | |
| 1136 change.AddWord("bar" + base::Uint64ToString(i)); | 1112 change.AddWord("bar" + base::Uint64ToString(i)); |
| 1137 } | 1113 } |
| 1138 Apply(*client_custom_dictionary, change); | 1114 Apply(*client_custom_dictionary, change); |
| 1139 | 1115 |
| 1140 // Associate the server and the client. | 1116 // Associate the server and the client. |
| 1141 int error_counter = 0; | 1117 int error_counter = 0; |
| 1142 EXPECT_FALSE( | 1118 EXPECT_FALSE( |
| 1143 client_custom_dictionary | 1119 client_custom_dictionary |
| 1144 ->MergeDataAndStartSyncing( | 1120 ->MergeDataAndStartSyncing( |
| 1145 syncer::DICTIONARY, | 1121 syncer::DICTIONARY, |
| 1146 server_custom_dictionary->GetAllSyncData(syncer::DICTIONARY), | 1122 server_custom_dictionary->GetAllSyncData(syncer::DICTIONARY), |
| 1147 std::unique_ptr<syncer::SyncChangeProcessor>( | 1123 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 1148 new syncer::SyncChangeProcessorWrapperForTest( | 1124 new syncer::SyncChangeProcessorWrapperForTest( |
| 1149 server_custom_dictionary)), | 1125 server_custom_dictionary)), |
| 1150 std::unique_ptr<syncer::SyncErrorFactory>( | 1126 std::unique_ptr<syncer::SyncErrorFactory>( |
| 1151 new SyncErrorFactoryStub(&error_counter))) | 1127 new SyncErrorFactoryStub(&error_counter))) |
| 1152 .error() | 1128 .error() |
| 1153 .IsSet()); | 1129 .IsSet()); |
| 1154 EXPECT_EQ(0, error_counter); | 1130 EXPECT_EQ(0, error_counter); |
| 1155 EXPECT_FALSE(client_custom_dictionary->IsSyncing()); | 1131 EXPECT_FALSE(client_custom_dictionary->IsSyncing()); |
| 1156 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2, | 1132 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS * 2, |
| 1157 client_custom_dictionary->GetWords().size()); | 1133 client_custom_dictionary->GetWords().size()); |
| 1158 } | 1134 } |
| 1159 | 1135 |
| 1160 // The sync server should not receive more words, because it has the maximum | 1136 // The sync server should not receive more words, because it has the maximum |
| 1161 // number of words already. | 1137 // number of words already. |
| 1162 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 1138 EXPECT_EQ(spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 1163 server_custom_dictionary->GetWords().size()); | 1139 server_custom_dictionary->GetWords().size()); |
| 1164 } | 1140 } |
| 1165 | 1141 |
| 1166 TEST_F(SpellcheckCustomDictionaryTest, RecordSizeStatsCorrectly) { | 1142 TEST_F(SpellcheckCustomDictionaryTest, RecordSizeStatsCorrectly) { |
| 1167 #if defined(OS_WIN) | 1143 #if defined(OS_WIN) |
| 1168 // Failing consistently on Win7. See crbug.com/230534. | 1144 // Failing consistently on Win7. See crbug.com/230534. |
| 1169 if (base::win::GetVersion() >= base::win::VERSION_VISTA) | 1145 if (base::win::GetVersion() >= base::win::VERSION_VISTA) |
| 1170 return; | 1146 return; |
| 1171 #endif | 1147 #endif |
| 1172 // Record a baseline. | 1148 // Record a baseline. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 SpellcheckServiceFactory::GetForContext(&profile_); | 1194 SpellcheckServiceFactory::GetForContext(&profile_); |
| 1219 SpellcheckCustomDictionary* custom_dictionary = | 1195 SpellcheckCustomDictionary* custom_dictionary = |
| 1220 spellcheck_service->GetCustomDictionary(); | 1196 spellcheck_service->GetCustomDictionary(); |
| 1221 OnLoaded(*custom_dictionary, base::WrapUnique(new std::set<std::string>)); | 1197 OnLoaded(*custom_dictionary, base::WrapUnique(new std::set<std::string>)); |
| 1222 EXPECT_FALSE(custom_dictionary->HasWord("foo")); | 1198 EXPECT_FALSE(custom_dictionary->HasWord("foo")); |
| 1223 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1199 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
| 1224 custom_dictionary->AddWord("foo"); | 1200 custom_dictionary->AddWord("foo"); |
| 1225 EXPECT_TRUE(custom_dictionary->HasWord("foo")); | 1201 EXPECT_TRUE(custom_dictionary->HasWord("foo")); |
| 1226 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1202 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
| 1227 } | 1203 } |
| OLD | NEW |