Chromium Code Reviews| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/search_engines/search_terms_data.h" | 10 #include "chrome/browser/search_engines/search_terms_data.h" |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 | 464 |
| 465 // If we force the method, it should uniquify the keyword even if it is | 465 // If we force the method, it should uniquify the keyword even if it is |
| 466 // currently unique, and skip the host-based autogenerated keyword. | 466 // currently unique, and skip the host-based autogenerated keyword. |
| 467 turl.reset( | 467 turl.reset( |
| 468 CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com")); | 468 CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com")); |
| 469 new_keyword = model()->UniquifyKeyword(*turl, true); | 469 new_keyword = model()->UniquifyKeyword(*turl, true); |
| 470 EXPECT_EQ(ASCIIToUTF16("unique_"), new_keyword); | 470 EXPECT_EQ(ASCIIToUTF16("unique_"), new_keyword); |
| 471 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 471 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
| 472 } | 472 } |
| 473 | 473 |
| 474 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictNeitherAutoreplace) { | 474 TEST_F(TemplateURLServiceSyncTest, IsLocalTemplateURLBetter) { |
| 475 // Test some edge cases of this function. | |
| 476 const struct { | |
| 477 time_t local_time; | |
| 478 time_t sync_time; | |
| 479 bool local_is_default; | |
| 480 bool local_created_by_policy; | |
| 481 bool expected_result; | |
| 482 } test_cases[] = { | |
| 483 // Sync is better by timestamp but local is Default. | |
| 484 {10, 100, true, false, true}, | |
| 485 // Sync is better by timestamp but local is Create by Policy. | |
| 486 {10, 100, false, true, true}, | |
| 487 // Tie. Sync wins. | |
| 488 {100, 100, false, false, false}, | |
| 489 }; | |
| 490 | |
| 491 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | |
| 492 TemplateURL* local_turl = CreateTestTemplateURL( | |
| 493 ASCIIToUTF16("localkey"), "www.local.com", "localguid", | |
| 494 test_cases[i].local_time, true, test_cases[i].local_created_by_policy); | |
| 495 model()->Add(local_turl); | |
| 496 if (test_cases[i].local_is_default) | |
| 497 model()->SetDefaultSearchProvider(local_turl); | |
| 498 | |
| 499 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL( | |
| 500 ASCIIToUTF16("synckey"), "www.sync.com", "syncguid", | |
| 501 test_cases[i].sync_time)); | |
| 502 EXPECT_EQ(test_cases[i].expected_result, | |
| 503 model()->IsLocalTemplateURLBetter(local_turl, sync_turl.get())); | |
| 504 | |
| 505 // Undo the changes. | |
| 506 if (test_cases[i].local_is_default) | |
| 507 model()->SetDefaultSearchProvider(NULL); | |
| 508 model()->Remove(local_turl); | |
| 509 } | |
| 510 } | |
| 511 | |
| 512 TEST_F(TemplateURLServiceSyncTest, ResolveSyncKeywordConflict) { | |
| 475 // This tests cases where neither the sync nor the local TemplateURL are | 513 // This tests cases where neither the sync nor the local TemplateURL are |
| 476 // marked safe_for_autoreplace. | 514 // marked safe_for_autoreplace. |
| 477 | 515 |
| 478 // Create a keyword that conflicts, and make it older. Sync keyword is | 516 // Create a keyword that conflicts, and make it older. Sync keyword is |
| 479 // uniquified, and a syncer::SyncChange is added. | 517 // uniquified, and a syncer::SyncChange is added. |
| 480 string16 original_turl_keyword = ASCIIToUTF16("key1"); | 518 string16 original_turl_keyword = ASCIIToUTF16("key1"); |
| 481 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | 519 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 482 "http://key1.com", std::string(), 9000); | 520 "http://key1.com", std::string(), 9000); |
| 483 model()->Add(original_turl); | 521 model()->Add(original_turl); |
| 484 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, | 522 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, |
| 485 "http://new.com", "remote", 8999)); | 523 "http://new.com", "remote", 8999)); |
| 486 syncer::SyncChangeList changes; | 524 syncer::SyncChangeList changes; |
| 487 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 525 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); |
| 488 original_turl, &changes)); | |
| 489 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); | 526 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); |
| 490 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); | 527 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); |
| 491 ASSERT_EQ(1U, changes.size()); | 528 ASSERT_EQ(1U, changes.size()); |
| 492 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); | 529 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); |
| 493 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 530 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 494 changes.clear(); | 531 changes.clear(); |
| 495 model()->Remove(original_turl); | 532 model()->Remove(original_turl); |
| 496 | 533 |
| 497 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange | 534 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange |
| 498 // is added (which in a normal run would be deleted by PruneSyncChanges() when | 535 // is added (which in a normal run would be deleted by PruneSyncChanges() when |
| 499 // the local GUID doesn't appear in the sync GUID list). Also ensure that | 536 // the local GUID doesn't appear in the sync GUID list). Also ensure that |
| 500 // this does not change the safe_for_autoreplace flag or the TemplateURLID in | 537 // this does not change the safe_for_autoreplace flag or the TemplateURLID in |
| 501 // the original. | 538 // the original. |
| 502 original_turl = CreateTestTemplateURL(original_turl_keyword, | 539 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 503 "http://key1.com", "local", 9000); | 540 "http://key1.com", "local", 9000); |
| 504 model()->Add(original_turl); | 541 model()->Add(original_turl); |
| 505 TemplateURLID original_id = original_turl->id(); | 542 TemplateURLID original_id = original_turl->id(); |
| 506 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 543 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 507 std::string(), 9001)); | 544 std::string(), 9001)); |
| 508 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 545 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); |
| 509 original_turl, &changes)); | |
| 510 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 546 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 511 EXPECT_NE(original_turl_keyword, original_turl->keyword()); | 547 EXPECT_NE(original_turl_keyword, original_turl->keyword()); |
| 512 EXPECT_FALSE(original_turl->safe_for_autoreplace()); | 548 EXPECT_FALSE(original_turl->safe_for_autoreplace()); |
| 513 EXPECT_EQ(original_id, original_turl->id()); | 549 EXPECT_EQ(original_id, original_turl->id()); |
| 514 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); | 550 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 515 ASSERT_EQ(1U, changes.size()); | 551 ASSERT_EQ(1U, changes.size()); |
| 516 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); | 552 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); |
| 517 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 553 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 518 changes.clear(); | 554 changes.clear(); |
| 519 model()->Remove(original_turl); | 555 model()->Remove(original_turl); |
| 520 | 556 |
| 521 // Equal times. Same result as above. Sync left alone, original uniquified so | 557 // Equal times. Same result as above. Sync left alone, original uniquified so |
| 522 // sync_turl can fit. | 558 // sync_turl can fit. |
| 523 original_turl = CreateTestTemplateURL(original_turl_keyword, | 559 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 524 "http://key1.com", "local2", 9000); | 560 "http://key1.com", "local2", 9000); |
| 525 model()->Add(original_turl); | 561 model()->Add(original_turl); |
| 526 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 562 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 527 std::string(), 9000)); | 563 std::string(), 9000)); |
| 528 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 564 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); |
| 529 original_turl, &changes)); | |
| 530 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 565 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 531 EXPECT_NE(original_turl_keyword, original_turl->keyword()); | 566 EXPECT_NE(original_turl_keyword, original_turl->keyword()); |
| 532 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); | 567 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 533 ASSERT_EQ(1U, changes.size()); | 568 ASSERT_EQ(1U, changes.size()); |
| 534 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); | 569 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); |
| 535 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 570 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 536 changes.clear(); | 571 changes.clear(); |
| 537 model()->Remove(original_turl); | 572 model()->Remove(original_turl); |
| 538 | 573 |
| 539 // Sync is newer, but original TemplateURL is created by policy, so it wins. | 574 // Sync is newer, but original TemplateURL is created by policy, so it wins. |
| 540 // Sync keyword is uniquified, and a syncer::SyncChange is added. | 575 // Sync keyword is uniquified, and a syncer::SyncChange is added. |
| 541 original_turl = CreateTestTemplateURL(original_turl_keyword, | 576 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 542 "http://key1.com", std::string(), 9000, false, true); | 577 "http://key1.com", std::string(), 9000, false, true); |
| 543 model()->Add(original_turl); | 578 model()->Add(original_turl); |
| 544 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 579 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 545 "remote2", 9999)); | 580 "remote2", 9999)); |
| 546 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 581 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); |
| 547 original_turl, &changes)); | |
| 548 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); | 582 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); |
| 549 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); | 583 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); |
| 550 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); | 584 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); |
| 551 ASSERT_EQ(1U, changes.size()); | 585 ASSERT_EQ(1U, changes.size()); |
| 552 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); | 586 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); |
| 553 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 587 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 554 changes.clear(); | 588 changes.clear(); |
| 555 model()->Remove(original_turl); | 589 model()->Remove(original_turl); |
| 556 } | 590 } |
| 557 | 591 |
| 558 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictBothAutoreplace) { | |
| 559 // This tests cases where both the sync and the local TemplateURL are marked | |
| 560 // safe_for_autoreplace. | |
| 561 | |
| 562 // Create a keyword that conflicts, and make it older. SyncChange is added, | |
| 563 // function returns false. | |
| 564 string16 original_turl_keyword = ASCIIToUTF16("key1"); | |
| 565 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | |
| 566 "http://key1.com", std::string(), 9000, true); | |
| 567 model()->Add(original_turl); | |
| 568 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, | |
| 569 "http://new.com", "remote", 8999, true)); | |
| 570 syncer::SyncChangeList changes; | |
| 571 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | |
| 572 original_turl, &changes)); | |
| 573 EXPECT_EQ(original_turl, | |
| 574 model()->GetTemplateURLForKeyword(original_turl_keyword)); | |
| 575 ASSERT_EQ(1U, changes.size()); | |
| 576 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); | |
| 577 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); | |
| 578 changes.clear(); | |
| 579 model()->Remove(original_turl); | |
| 580 | |
| 581 // Sync is newer. Original TemplateURL is removed from the model. A | |
| 582 // syncer::SyncChange is added (which in a normal run would be deleted by | |
| 583 // PruneSyncChanges() when the local GUID doesn't appear in the sync GUID | |
| 584 // list). | |
| 585 original_turl = CreateTestTemplateURL(original_turl_keyword, | |
| 586 "http://key1.com", "local", 9000, true); | |
| 587 model()->Add(original_turl); | |
| 588 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | |
| 589 std::string(), 9001, true)); | |
| 590 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | |
| 591 original_turl, &changes)); | |
| 592 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | |
| 593 EXPECT_TRUE(model()->GetTemplateURLs().empty()); | |
| 594 ASSERT_EQ(1U, changes.size()); | |
| 595 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); | |
| 596 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); | |
| 597 changes.clear(); | |
| 598 | |
| 599 // Equal times. Same result as above. Sync left alone, original removed so | |
| 600 // sync_turl can fit. | |
| 601 original_turl = CreateTestTemplateURL(original_turl_keyword, | |
| 602 "http://key1.com", "local2", 9000, true); | |
| 603 model()->Add(original_turl); | |
| 604 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | |
| 605 std::string(), 9000, true)); | |
| 606 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | |
| 607 original_turl, &changes)); | |
| 608 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | |
| 609 EXPECT_TRUE(model()->GetTemplateURLs().empty()); | |
| 610 ASSERT_EQ(1U, changes.size()); | |
| 611 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); | |
| 612 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); | |
| 613 changes.clear(); | |
| 614 | |
| 615 // Sync is newer, but original TemplateURL is created by policy, so it wins. | |
| 616 // syncer::SyncChange is added, function returns false. | |
| 617 original_turl = CreateTestTemplateURL(original_turl_keyword, | |
| 618 "http://key1.com", std::string(), 9000, true, true); | |
| 619 model()->Add(original_turl); | |
| 620 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | |
| 621 "remote2", 9999, true)); | |
| 622 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | |
| 623 original_turl, &changes)); | |
| 624 EXPECT_EQ(original_turl, | |
| 625 model()->GetTemplateURLForKeyword(original_turl_keyword)); | |
| 626 ASSERT_EQ(1U, changes.size()); | |
| 627 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); | |
| 628 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); | |
| 629 changes.clear(); | |
| 630 model()->Remove(original_turl); | |
| 631 } | |
| 632 | |
| 633 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictOneAutoreplace) { | |
| 634 // This tests cases where either the sync or the local TemplateURL is marked | |
| 635 // safe_for_autoreplace, but the other is not. Basically, we run the same | |
| 636 // tests as in SyncKeywordConflictBothAutoreplace, but mark the keywords so as | |
| 637 // to reverse the outcome of each test. | |
| 638 | |
| 639 // Create a keyword that conflicts, and make it older. Normally the local | |
| 640 // TemplateURL would win this. | |
| 641 string16 original_turl_keyword = ASCIIToUTF16("key1"); | |
| 642 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | |
| 643 "http://key1.com", "local", 9000, true); | |
| 644 model()->Add(original_turl); | |
| 645 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, | |
| 646 "http://new.com", std::string(), 8999)); | |
| 647 syncer::SyncChangeList changes; | |
| 648 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | |
| 649 original_turl, &changes)); | |
| 650 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | |
| 651 EXPECT_TRUE(model()->GetTemplateURLs().empty()); | |
| 652 ASSERT_EQ(1U, changes.size()); | |
| 653 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); | |
| 654 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); | |
| 655 changes.clear(); | |
| 656 | |
| 657 // Sync is newer. Normally the sync TemplateURL would win this. | |
| 658 original_turl = CreateTestTemplateURL(original_turl_keyword, | |
| 659 "http://key1.com", std::string(), 9000); | |
| 660 model()->Add(original_turl); | |
| 661 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | |
| 662 "remote", 9001, true)); | |
| 663 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | |
| 664 original_turl, &changes)); | |
| 665 EXPECT_EQ(original_turl, | |
| 666 model()->GetTemplateURLForKeyword(original_turl_keyword)); | |
| 667 ASSERT_EQ(1U, changes.size()); | |
| 668 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); | |
| 669 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); | |
| 670 changes.clear(); | |
| 671 model()->Remove(original_turl); | |
| 672 | |
| 673 // Equal times. Same result as above. | |
| 674 original_turl = CreateTestTemplateURL(original_turl_keyword, | |
| 675 "http://key1.com", std::string(), 9000); | |
| 676 model()->Add(original_turl); | |
| 677 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | |
| 678 "remote2", 9000, true)); | |
| 679 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | |
| 680 original_turl, &changes)); | |
| 681 EXPECT_EQ(original_turl, | |
| 682 model()->GetTemplateURLForKeyword(original_turl_keyword)); | |
| 683 ASSERT_EQ(1U, changes.size()); | |
| 684 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); | |
| 685 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); | |
| 686 changes.clear(); | |
| 687 model()->Remove(original_turl); | |
| 688 | |
| 689 // We don't run the "created by policy" test since URLs created by policy are | |
| 690 // never safe_for_autoreplace. | |
| 691 } | |
| 692 | |
| 693 TEST_F(TemplateURLServiceSyncTest, FindDuplicateOfSyncTemplateURL) { | |
| 694 TemplateURL* original_turl = | |
| 695 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"); | |
| 696 model()->Add(original_turl); | |
| 697 | |
| 698 // No matches at all. | |
| 699 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | |
| 700 "http://key2.com")); | |
| 701 EXPECT_EQ(NULL, model()->FindDuplicateOfSyncTemplateURL(*sync_turl)); | |
| 702 | |
| 703 // URL matches, but not keyword. No dupe. | |
| 704 sync_turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | |
| 705 "http://key1.com")); | |
| 706 EXPECT_EQ(NULL, model()->FindDuplicateOfSyncTemplateURL(*sync_turl)); | |
| 707 | |
| 708 // Keyword matches, but not URL. No dupe. | |
| 709 sync_turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), | |
| 710 "http://key2.com")); | |
| 711 EXPECT_EQ(NULL, model()->FindDuplicateOfSyncTemplateURL(*sync_turl)); | |
| 712 | |
| 713 // Duplicate. | |
| 714 sync_turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), | |
| 715 "http://key1.com")); | |
| 716 const TemplateURL* dupe_turl = | |
| 717 model()->FindDuplicateOfSyncTemplateURL(*sync_turl); | |
| 718 ASSERT_TRUE(dupe_turl); | |
| 719 EXPECT_EQ(dupe_turl->keyword(), sync_turl->keyword()); | |
| 720 EXPECT_EQ(dupe_turl->url(), sync_turl->url()); | |
| 721 } | |
| 722 | |
| 723 TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { | |
| 724 TemplateURL* original_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | |
| 725 "http://key1.com", std::string(), 9000); | |
| 726 model()->Add(original_turl); | |
| 727 TemplateURL* sync_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | |
| 728 "http://key1.com", std::string(), 9001); | |
| 729 std::string original_guid = original_turl->sync_guid(); | |
| 730 syncer::SyncChangeList changes; | |
| 731 | |
| 732 // The sync TemplateURL is newer. It should replace the original TemplateURL | |
| 733 // and a syncer::SyncChange should be added to the list. | |
| 734 // Note that MergeSyncAndLocalURLDuplicates takes ownership of sync_turl. | |
| 735 model()->MergeSyncAndLocalURLDuplicates(sync_turl, original_turl, &changes); | |
| 736 TemplateURL* result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); | |
| 737 ASSERT_TRUE(result); | |
| 738 EXPECT_EQ(9001, result->last_modified().ToTimeT()); | |
| 739 EXPECT_EQ(1U, changes.size()); | |
| 740 // We expect a change to delete the local entry. | |
| 741 syncer::SyncChange change = changes.at(0); | |
| 742 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); | |
| 743 EXPECT_EQ(original_guid, | |
| 744 change.sync_data().GetSpecifics().search_engine().sync_guid()); | |
| 745 changes.clear(); | |
| 746 | |
| 747 // The sync TemplateURL is older. The existing TemplateURL should win and a | |
| 748 // syncer::SyncChange should be added to the list. | |
| 749 TemplateURL* sync_turl2 = CreateTestTemplateURL(ASCIIToUTF16("key1"), | |
| 750 "http://key1.com", std::string(), 8999); | |
| 751 std::string sync_guid = sync_turl2->sync_guid(); | |
| 752 model()->MergeSyncAndLocalURLDuplicates(sync_turl2, sync_turl, &changes); | |
| 753 result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); | |
| 754 ASSERT_TRUE(result); | |
| 755 EXPECT_EQ(9001, result->last_modified().ToTimeT()); | |
| 756 EXPECT_EQ(1U, changes.size()); | |
| 757 // We expect a change to update the sync entry. | |
| 758 change = changes.at(0); | |
| 759 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | |
| 760 EXPECT_EQ(sync_guid, | |
| 761 change.sync_data().GetSpecifics().search_engine().sync_guid()); | |
| 762 } | |
| 763 | |
| 764 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { | 592 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { |
| 765 model()->MergeDataAndStartSyncing( | 593 model()->MergeDataAndStartSyncing( |
| 766 syncer::SEARCH_ENGINES, syncer::SyncDataList(), | 594 syncer::SEARCH_ENGINES, syncer::SyncDataList(), |
| 767 PassProcessor(), CreateAndPassSyncErrorFactory()); | 595 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 768 | 596 |
| 769 EXPECT_EQ(0U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 597 EXPECT_EQ(0U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 770 EXPECT_EQ(0U, processor()->change_list_size()); | 598 EXPECT_EQ(0U, processor()->change_list_size()); |
| 771 } | 599 } |
| 772 | 600 |
| 773 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { | 601 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 891 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 719 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 892 "http://expected.com", "bbb", 100)); // keyword conflict | 720 "http://expected.com", "bbb", 100)); // keyword conflict |
| 893 | 721 |
| 894 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), | 722 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), |
| 895 "http://unique.com", "ccc")); // add | 723 "http://unique.com", "ccc")); // add |
| 896 | 724 |
| 897 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 725 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 898 CreateInitialSyncData(), PassProcessor(), | 726 CreateInitialSyncData(), PassProcessor(), |
| 899 CreateAndPassSyncErrorFactory()); | 727 CreateAndPassSyncErrorFactory()); |
| 900 | 728 |
| 901 // The dupe results in a merge. The other two should be added to the model. | 729 // The dupe and conflict results in merges, as local values are always merged |
| 902 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 730 // with sync values if there is a keyword conflict. The unique keyword should |
| 731 // be added. | |
| 732 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
| 903 | 733 |
| 904 // The key1 duplicate results in the local copy winning. Ensure that Sync's | 734 // The key1 duplicate results in the local copy winning. Ensure that Sync's |
| 905 // copy was not added, and the local copy is pushed upstream to Sync as an | 735 // copy was not added, and the local copy is pushed upstream to Sync as an |
| 906 // update. The local copy should have received the sync data's GUID. | 736 // update. The local copy should have received the sync data's GUID. |
|
Nicolas Zea
2012/08/06 19:35:23
In this case, the reason we push the local copy up
SteveT
2012/08/07 00:17:09
That is the idea, and this should still happen aft
| |
| 907 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 737 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 908 // Check changes for the UPDATE. | 738 // Check changes for the UPDATE. |
| 909 ASSERT_TRUE(processor()->contains_guid("key1")); | 739 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 910 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); | 740 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
| 911 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 741 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
| 742 // The local sync_guid should no longer be found. | |
| 912 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 743 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
| 913 | 744 |
| 914 // The key2 keyword conflict results in the local copy winning, so ensure it | 745 // The key2 keyword conflict results in a merge, with the values of the local |
| 915 // retains the original keyword, and that an update to the sync copy is pushed | 746 // copy winning, so ensure it retains the original URL, and that an update to |
| 916 // upstream to Sync. Both TemplateURLs should be found locally, however. | 747 // the sync guid is pushed upstream to Sync. |
| 917 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); | 748 const TemplateURL* key2 = model()->GetTemplateURLForGUID("key2"); |
| 918 EXPECT_TRUE(key2); | 749 ASSERT_TRUE(key2); |
| 919 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); | 750 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); |
|
Nicolas Zea
2012/08/06 19:35:23
check key2 url?
SteveT
2012/08/07 00:17:09
Done.
| |
| 920 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | |
| 921 // Check changes for the UPDATE. | 751 // Check changes for the UPDATE. |
| 922 ASSERT_TRUE(processor()->contains_guid("key2")); | 752 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 923 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); | 753 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
| 924 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 754 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
| 925 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); | 755 EXPECT_EQ("key2", GetKeyword(key2_change.sync_data())); |
| 756 EXPECT_EQ("http://expected.com", GetURL(key2_change.sync_data())); | |
| 757 // The local sync_guid should no longer be found. | |
| 758 EXPECT_FALSE(model()->GetTemplateURLForGUID("bbb")); | |
| 926 | 759 |
| 927 // The last TemplateURL should have had no conflicts and was just added. It | 760 // The last TemplateURL should have had no conflicts and was just added. It |
| 928 // should not have replaced the third local TemplateURL. | 761 // should not have replaced the third local TemplateURL. |
| 929 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); | 762 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); |
| 930 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 763 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 931 | 764 |
| 932 // Two UPDATEs and two ADDs. | 765 // Two UPDATEs and one ADD. |
| 933 EXPECT_EQ(4U, processor()->change_list_size()); | 766 EXPECT_EQ(3U, processor()->change_list_size()); |
| 934 // Two ADDs should be pushed up to Sync. | 767 // One ADDs should be pushed up to Sync. |
| 935 ASSERT_TRUE(processor()->contains_guid("bbb")); | |
| 936 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | |
| 937 processor()->change_for_guid("bbb").change_type()); | |
| 938 ASSERT_TRUE(processor()->contains_guid("ccc")); | 768 ASSERT_TRUE(processor()->contains_guid("ccc")); |
| 939 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 769 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 940 processor()->change_for_guid("ccc").change_type()); | 770 processor()->change_for_guid("ccc").change_type()); |
| 941 } | 771 } |
| 942 | 772 |
| 943 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { | 773 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { |
| 944 // GUIDs all differ, so this is data to be added from Sync, but the timestamps | 774 // GUIDs all differ, so Sync may overtake some entries, but the timestamps |
| 945 // from Sync are newer. Set up the local data so that one is a dupe, one has a | 775 // from Sync are newer. Set up the local data so that one is a dupe, one has a |
| 946 // conflicting keyword, and the last has no conflicts (a clean ADD). | 776 // conflicting keyword, and the last has no conflicts (a clean ADD). |
| 947 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 777 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
| 948 "aaa", 10)); // dupe | 778 "aaa", 10)); // dupe |
| 949 | 779 |
| 950 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 780 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 951 "http://expected.com", "bbb", 10)); // keyword conflict | 781 "http://expected.com", "bbb", 10)); // keyword conflict |
| 952 | 782 |
| 953 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), | 783 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), |
| 954 "http://unique.com", "ccc", 10)); // add | 784 "http://unique.com", "ccc", 10)); // add |
| 955 | 785 |
| 956 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 786 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 957 CreateInitialSyncData(), PassProcessor(), | 787 CreateInitialSyncData(), PassProcessor(), |
| 958 CreateAndPassSyncErrorFactory()); | 788 CreateAndPassSyncErrorFactory()); |
| 959 | 789 |
| 960 // The dupe results in a merge. The other two should be added to the model. | 790 // The dupe and keyword conflict results in merges. The unique keyword be |
| 961 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 791 // added to the model. |
| 792 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
| 962 | 793 |
| 963 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's | 794 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's |
| 964 // copy replaced the local copy. | 795 // copy replaced the local copy. |
| 965 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 796 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 966 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 797 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
|
Nicolas Zea
2012/08/06 19:35:23
check processor didn't receive anything for either
SteveT
2012/08/07 00:17:09
Done.
| |
| 967 | 798 |
| 968 // The key2 keyword conflict results in Sync's copy winning, so ensure it | 799 // The key2 keyword conflict results in Sync's copy winning, so ensure it |
| 969 // retains the original keyword. The local copy should get a uniquified | 800 // retains the original keyword and is added. The local copy should be |
| 970 // keyword. Both TemplateURLs should be found locally. | 801 // removed. |
| 971 const TemplateURL* key2_sync = model()->GetTemplateURLForGUID("key2"); | 802 const TemplateURL* key2_sync = model()->GetTemplateURLForGUID("key2"); |
| 972 ASSERT_TRUE(key2_sync); | 803 ASSERT_TRUE(key2_sync); |
| 973 EXPECT_EQ(ASCIIToUTF16("key2"), key2_sync->keyword()); | 804 EXPECT_EQ(ASCIIToUTF16("key2"), key2_sync->keyword()); |
| 974 const TemplateURL* key2_local = model()->GetTemplateURLForGUID("bbb"); | 805 EXPECT_FALSE(model()->GetTemplateURLForGUID("bbb")); |
| 975 ASSERT_TRUE(key2_local); | |
| 976 EXPECT_EQ(ASCIIToUTF16("expected.com"), key2_local->keyword()); | |
| 977 | 806 |
| 978 // The last TemplateURL should have had no conflicts and was just added. It | 807 // The last TemplateURL should have had no conflicts and was just added. It |
| 979 // should not have replaced the third local TemplateURL. | 808 // should not have replaced the third local TemplateURL. |
| 980 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); | 809 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); |
| 981 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 810 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 982 | 811 |
| 983 // Two ADDs. | 812 // One ADD. |
| 984 EXPECT_EQ(2U, processor()->change_list_size()); | 813 EXPECT_EQ(1U, processor()->change_list_size()); |
| 985 // Two ADDs should be pushed up to Sync. | 814 // One ADDs should be pushed up to Sync. |
| 986 ASSERT_TRUE(processor()->contains_guid("bbb")); | |
| 987 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | |
| 988 processor()->change_for_guid("bbb").change_type()); | |
| 989 ASSERT_TRUE(processor()->contains_guid("ccc")); | 815 ASSERT_TRUE(processor()->contains_guid("ccc")); |
| 990 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 816 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 991 processor()->change_for_guid("ccc").change_type()); | 817 processor()->change_for_guid("ccc").change_type()); |
| 992 } | 818 } |
| 993 | 819 |
| 994 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { | 820 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { |
| 995 // We initially have no data. | 821 // We initially have no data. |
| 996 model()->MergeDataAndStartSyncing( | 822 model()->MergeDataAndStartSyncing( |
| 997 syncer::SEARCH_ENGINES, syncer::SyncDataList(), | 823 syncer::SEARCH_ENGINES, syncer::SyncDataList(), |
| 998 PassProcessor(), CreateAndPassSyncErrorFactory()); | 824 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1128 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); | 954 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); |
| 1129 | 955 |
| 1130 ASSERT_TRUE(processor()->contains_guid("aaa")); | 956 ASSERT_TRUE(processor()->contains_guid("aaa")); |
| 1131 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 957 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
| 1132 processor()->change_for_guid("aaa").change_type()); | 958 processor()->change_for_guid("aaa").change_type()); |
| 1133 ASSERT_TRUE(processor()->contains_guid("key1")); | 959 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1134 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 960 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
| 1135 processor()->change_for_guid("key1").change_type()); | 961 processor()->change_for_guid("key1").change_type()); |
| 1136 } | 962 } |
| 1137 | 963 |
| 1138 TEST_F(TemplateURLServiceSyncTest, RemoveUpdatedURLOnConflict) { | |
| 1139 // Updating a local replaceable URL to have the same keyword as a local | |
| 1140 // non-replaceable URL should result in the former being removed from the | |
| 1141 // model entirely. | |
| 1142 syncer::SyncDataList initial_data; | |
| 1143 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync"), | |
| 1144 "http://sync.com", "sync", 100, true)); | |
| 1145 initial_data.push_back( | |
| 1146 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | |
| 1147 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
| 1148 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
| 1149 | |
| 1150 TemplateURL* new_turl = | |
| 1151 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://local.com", "local"); | |
| 1152 model()->Add(new_turl); | |
| 1153 | |
| 1154 syncer::SyncChangeList changes; | |
| 1155 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | |
| 1156 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://sync.com", "sync", | |
| 1157 110, true))); | |
| 1158 model()->ProcessSyncChanges(FROM_HERE, changes); | |
| 1159 | |
| 1160 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); | |
| 1161 EXPECT_EQ("local", | |
| 1162 model()->GetTemplateURLForKeyword(ASCIIToUTF16("local"))->sync_guid()); | |
| 1163 EXPECT_EQ(1U, processor()->change_list_size()); | |
| 1164 ASSERT_TRUE(processor()->contains_guid("sync")); | |
| 1165 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | |
| 1166 processor()->change_for_guid("sync").change_type()); | |
| 1167 } | |
| 1168 | |
| 1169 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { | 964 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { |
| 1170 // Ensure that ProcessTemplateURLChange is called and pushes the correct | 965 // Ensure that ProcessTemplateURLChange is called and pushes the correct |
| 1171 // changes to Sync whenever local changes are made to TemplateURLs. | 966 // changes to Sync whenever local changes are made to TemplateURLs. |
| 1172 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 967 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1173 CreateInitialSyncData(), PassProcessor(), | 968 CreateInitialSyncData(), PassProcessor(), |
| 1174 CreateAndPassSyncErrorFactory()); | 969 CreateAndPassSyncErrorFactory()); |
| 1175 | 970 |
| 1176 // Add a new search engine. | 971 // Add a new search engine. |
| 1177 TemplateURL* new_turl = | 972 TemplateURL* new_turl = |
| 1178 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); | 973 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1284 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); | 1079 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
| 1285 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 1080 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
| 1286 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); | 1081 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); |
| 1287 } | 1082 } |
| 1288 | 1083 |
| 1289 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { | 1084 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { |
| 1290 // Sync brings in some autogenerated keywords, but the generated keywords we | 1085 // Sync brings in some autogenerated keywords, but the generated keywords we |
| 1291 // try to create conflict with ones in the model. | 1086 // try to create conflict with ones in the model. |
| 1292 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( | 1087 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( |
| 1293 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); | 1088 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); |
| 1294 TemplateURL* google = CreateTestTemplateURL(google_keyword, | 1089 const std::string local_google_url = |
| 1295 "{google:baseURL}1/search?q={searchTerms}"); | 1090 "{google:baseURL}1/search?q={searchTerms}"; |
| 1091 TemplateURL* google = CreateTestTemplateURL(google_keyword, local_google_url); | |
| 1296 model()->Add(google); | 1092 model()->Add(google); |
| 1297 TemplateURL* other = | 1093 TemplateURL* other = |
| 1298 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); | 1094 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); |
| 1299 model()->Add(other); | 1095 model()->Add(other); |
| 1300 syncer::SyncDataList initial_data; | 1096 syncer::SyncDataList initial_data; |
| 1301 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), | 1097 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), |
| 1302 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); | 1098 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); |
| 1303 initial_data.push_back( | 1099 initial_data.push_back( |
| 1304 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1100 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1101 const std::string synced_other_url = "http://other.com/search?q={searchTerms}" ; | |
| 1305 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), | 1102 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), |
| 1306 "http://other.com/search?q={searchTerms}", "sync2", 150)); | 1103 synced_other_url, "sync2", 150)); |
| 1307 initial_data.push_back( | 1104 initial_data.push_back( |
| 1308 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1105 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1106 | |
| 1107 // Before we merge the data, grab the local sync_guids so we can ensure that | |
| 1108 // they've been replaced. | |
| 1109 const std::string local_google_guid = google->sync_guid(); | |
| 1110 const std::string local_other_guid = other->sync_guid(); | |
| 1111 | |
| 1309 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1112 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1310 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1113 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1311 | 1114 |
| 1312 // In this case, the conflicts should be handled just like any other keyword | 1115 // In this case, the conflicts should be handled just like any other keyword |
| 1313 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. | 1116 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. |
| 1314 EXPECT_EQ(google_keyword, google->keyword()); | 1117 // Since the initial TemplateURLs were local only, they should be merged with |
| 1315 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), | 1118 // the sync TemplateURLs (GUIDs transferred over). |
| 1316 model()->GetTemplateURLForGUID("sync1")->keyword()); | 1119 EXPECT_FALSE(model()->GetTemplateURLForGUID(local_google_guid)); |
| 1317 EXPECT_EQ(ASCIIToUTF16("other.com_"), other->keyword()); | 1120 ASSERT_TRUE(model()->GetTemplateURLForGUID("sync1")); |
| 1121 EXPECT_EQ(google_keyword, model()->GetTemplateURLForGUID("sync1")->keyword()); | |
| 1122 EXPECT_FALSE(model()->GetTemplateURLForGUID(local_other_guid)); | |
| 1123 ASSERT_TRUE(model()->GetTemplateURLForGUID("sync2")); | |
| 1318 EXPECT_EQ(ASCIIToUTF16("other.com"), | 1124 EXPECT_EQ(ASCIIToUTF16("other.com"), |
| 1319 model()->GetTemplateURLForGUID("sync2")->keyword()); | 1125 model()->GetTemplateURLForGUID("sync2")->keyword()); |
| 1320 | 1126 |
| 1321 // Both synced URLs should have associated UPDATEs, since both needed their | 1127 // Both synced URLs should have associated UPDATEs, since both needed their |
| 1322 // keywords to be generated (and sync1 needed conflict resolution as well). | 1128 // keywords to be generated. |
| 1323 EXPECT_GE(processor()->change_list_size(), 2U); | 1129 EXPECT_EQ(processor()->change_list_size(), 2U); |
|
Nicolas Zea
2012/08/06 19:35:23
Why does the synced other turl get updated? Doesn'
SteveT
2012/08/07 00:17:09
This particular test sets the autogenerate_keyword
Nicolas Zea
2012/08/07 17:45:43
SG
| |
| 1324 ASSERT_TRUE(processor()->contains_guid("sync1")); | 1130 ASSERT_TRUE(processor()->contains_guid("sync1")); |
| 1325 syncer::SyncChange sync1_change = processor()->change_for_guid("sync1"); | 1131 syncer::SyncChange sync1_change = processor()->change_for_guid("sync1"); |
| 1326 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync1_change.change_type()); | 1132 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync1_change.change_type()); |
| 1327 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), | 1133 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(sync1_change.sync_data()))); |
| 1328 UTF8ToUTF16(GetKeyword(sync1_change.sync_data()))); | 1134 EXPECT_EQ(local_google_url, GetURL(sync1_change.sync_data())); |
| 1329 ASSERT_TRUE(processor()->contains_guid("sync2")); | 1135 ASSERT_TRUE(processor()->contains_guid("sync2")); |
| 1330 syncer::SyncChange sync2_change = processor()->change_for_guid("sync2"); | 1136 syncer::SyncChange sync2_change = processor()->change_for_guid("sync2"); |
| 1331 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type()); | 1137 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type()); |
| 1332 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); | 1138 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); |
| 1139 EXPECT_EQ(synced_other_url, GetURL(sync2_change.sync_data())); | |
| 1333 } | 1140 } |
| 1334 | 1141 |
| 1335 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { | 1142 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { |
| 1336 // Sync brings in two autogenerated keywords and both use Google base URLs. | 1143 // Sync brings in two autogenerated keywords and both use Google base URLs. |
| 1337 // We make the first older so that it will get renamed once before the second | 1144 // We make the first older so that it will get renamed once before the second |
| 1338 // and then again once after (when we resolve conflicts for the second). | 1145 // and then again once after (when we resolve conflicts for the second). |
| 1339 syncer::SyncDataList initial_data; | 1146 syncer::SyncDataList initial_data; |
| 1340 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1147 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1341 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); | 1148 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); |
| 1342 initial_data.push_back( | 1149 initial_data.push_back( |
| 1343 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1150 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1344 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1151 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1345 "{google:baseURL}2/search?q={searchTerms}", "key2")); | 1152 "{google:baseURL}2/search?q={searchTerms}", "key2")); |
| 1346 initial_data.push_back( | 1153 initial_data.push_back( |
| 1347 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1154 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1348 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1155 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1349 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1156 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1350 | 1157 |
| 1351 // We should still have coalesced the updates to one each. | 1158 // We should still have coalesced the updates to one each. |
| 1352 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( | 1159 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( |
| 1353 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); | 1160 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); |
| 1354 TemplateURL* keyword1 = | 1161 TemplateURL* keyword1 = |
| 1355 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); | 1162 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); |
| 1356 ASSERT_FALSE(keyword1 == NULL); | 1163 ASSERT_FALSE(keyword1 == NULL); |
| 1357 EXPECT_EQ("key1", keyword1->sync_guid()); | 1164 EXPECT_EQ("key1", keyword1->sync_guid()); |
| 1358 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); | 1165 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); |
| 1359 ASSERT_FALSE(keyword2 == NULL); | 1166 ASSERT_FALSE(keyword2 == NULL); |
| 1360 EXPECT_EQ("key2", keyword2->sync_guid()); | 1167 EXPECT_EQ("key2", keyword2->sync_guid()); |
| 1168 | |
| 1361 EXPECT_GE(processor()->change_list_size(), 2U); | 1169 EXPECT_GE(processor()->change_list_size(), 2U); |
| 1362 ASSERT_TRUE(processor()->contains_guid("key1")); | 1170 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1363 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); | 1171 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
| 1364 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 1172 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
| 1365 EXPECT_EQ(keyword1->keyword(), | 1173 EXPECT_EQ(keyword1->keyword(), |
| 1366 UTF8ToUTF16(GetKeyword(key1_change.sync_data()))); | 1174 UTF8ToUTF16(GetKeyword(key1_change.sync_data()))); |
| 1367 ASSERT_TRUE(processor()->contains_guid("key2")); | 1175 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1368 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); | 1176 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
| 1369 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 1177 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
| 1370 EXPECT_EQ(keyword2->keyword(), | 1178 EXPECT_EQ(keyword2->keyword(), |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1844 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1652 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1845 // The key1 entry should be different from the default but conflict in the | 1653 // The key1 entry should be different from the default but conflict in the |
| 1846 // keyword. | 1654 // keyword. |
| 1847 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, | 1655 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, |
| 1848 "http://key1.com/{searchTerms}", "key1", 90)); | 1656 "http://key1.com/{searchTerms}", "key1", 90)); |
| 1849 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1657 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1850 | 1658 |
| 1851 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1659 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1852 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1660 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1853 | 1661 |
| 1854 // The conflicting TemplateURL should be added, but it should have lost | 1662 // Since the local default was not yet synced, it should be merged with the |
| 1855 // conflict resolution against the default. | 1663 // conflicting TemplateURL. However, it's values should have been preserved |
| 1856 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1664 // since it would have won conflict resolution due to being the default. |
| 1857 const TemplateURL* winner = model()->GetTemplateURLForGUID("whateverguid"); | 1665 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1666 const TemplateURL* winner = model()->GetTemplateURLForGUID("key1"); | |
| 1858 ASSERT_TRUE(winner); | 1667 ASSERT_TRUE(winner); |
| 1859 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); | 1668 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); |
| 1860 EXPECT_EQ(keyword, winner->keyword()); | 1669 EXPECT_EQ(keyword, winner->keyword()); |
|
Nicolas Zea
2012/08/06 19:35:23
check url too? Also that the processor received an
SteveT
2012/08/07 00:17:09
Done.
| |
| 1861 const TemplateURL* loser = model()->GetTemplateURLForGUID("key1"); | 1670 |
| 1862 ASSERT_TRUE(loser); | 1671 // There is no loser, as the two were merged together. The local sync_guid |
| 1863 EXPECT_EQ(ASCIIToUTF16("key1.com"), loser->keyword()); | 1672 // should no longer be found in the model. |
| 1673 const TemplateURL* loser = model()->GetTemplateURLForGUID("whateverguid"); | |
| 1674 ASSERT_FALSE(loser); | |
| 1864 } | 1675 } |
| 1865 | 1676 |
| 1866 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { | 1677 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { |
| 1867 // Create a couple of bogus entries to sync. | 1678 // Create a couple of bogus entries to sync. |
| 1868 syncer::SyncDataList initial_data; | 1679 syncer::SyncDataList initial_data; |
| 1869 scoped_ptr<TemplateURL> turl( | 1680 scoped_ptr<TemplateURL> turl( |
| 1870 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1681 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); |
| 1871 initial_data.push_back( | 1682 initial_data.push_back( |
| 1872 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); | 1683 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); |
| 1873 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 1684 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2005 // A local change to the Google base URL should update the keyword and | 1816 // A local change to the Google base URL should update the keyword and |
| 2006 // generate a sync change. | 1817 // generate a sync change. |
| 2007 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); | 1818 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); |
| 2008 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); | 1819 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); |
| 2009 EXPECT_EQ(1U, processor()->change_list_size()); | 1820 EXPECT_EQ(1U, processor()->change_list_size()); |
| 2010 ASSERT_TRUE(processor()->contains_guid("guid")); | 1821 ASSERT_TRUE(processor()->contains_guid("guid")); |
| 2011 syncer::SyncChange change(processor()->change_for_guid("guid")); | 1822 syncer::SyncChange change(processor()->change_for_guid("guid")); |
| 2012 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | 1823 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 2013 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); | 1824 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); |
| 2014 } | 1825 } |
| OLD | NEW |