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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1656 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1657 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1657 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1658 model()->SetUserSelectedDefaultSearchProvider( | 1658 model()->SetUserSelectedDefaultSearchProvider( |
1659 model()->GetTemplateURLForGUID("key2")); | 1659 model()->GetTemplateURLForGUID("key2")); |
1660 | 1660 |
1661 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1661 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1662 ASSERT_FALSE(model()->is_default_search_managed()); | 1662 ASSERT_FALSE(model()->is_default_search_managed()); |
1663 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1663 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
1664 | 1664 |
1665 // Change the default search provider to a managed one. | 1665 // Change the default search provider to a managed one. |
1666 const char kName[] = "manageddefault"; | 1666 TemplateURLData managed; |
1667 const char kSearchURL[] = "http://manageddefault.com/search?t={searchTerms}"; | 1667 managed.SetShortName(ASCIIToUTF16("manageddefault")); |
1668 const char kIconURL[] = "http://manageddefault.com/icon.jpg"; | 1668 managed.SetKeyword(ASCIIToUTF16("manageddefault")); |
1669 const char kEncodings[] = "UTF-16;UTF-32"; | 1669 managed.SetURL("http://manageddefault.com/search?t={searchTerms}"); |
1670 const char kAlternateURL[] = | 1670 managed.favicon_url = GURL("http://manageddefault.com/icon.jpg"); |
1671 "http://manageddefault.com/search#t={searchTerms}"; | 1671 managed.input_encodings = {"UTF-16", "UTF-32"}; |
1672 const char kSearchTermsReplacementKey[] = "espv"; | 1672 managed.alternate_urls = {"http://manageddefault.com/search#t={searchTerms}"}; |
1673 test_util_a_->SetManagedDefaultSearchPreferences(true, kName, kName, | 1673 managed.search_terms_replacement_key = "espv"; |
1674 kSearchURL, std::string(), kIconURL, kEncodings, kAlternateURL, | 1674 |
1675 kSearchTermsReplacementKey); | 1675 SetManagedDefaultSearchPreferences(managed, true, test_util_a_->profile()); |
1676 const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider(); | 1676 const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider(); |
1677 | 1677 |
1678 EXPECT_TRUE(model()->is_default_search_managed()); | 1678 EXPECT_TRUE(model()->is_default_search_managed()); |
1679 | 1679 |
1680 // Add a new entry from Sync. It should still sync in despite the default | 1680 // Add a new entry from Sync. It should still sync in despite the default |
1681 // being managed. | 1681 // being managed. |
1682 syncer::SyncChangeList changes; | 1682 syncer::SyncChangeList changes; |
1683 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1683 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
1684 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), | 1684 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), |
1685 "http://new.com/{searchTerms}", | 1685 "http://new.com/{searchTerms}", |
1686 "newdefault"))); | 1686 "newdefault"))); |
1687 model()->ProcessSyncChanges(FROM_HERE, changes); | 1687 model()->ProcessSyncChanges(FROM_HERE, changes); |
1688 | 1688 |
1689 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1689 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1690 | 1690 |
1691 // Change kSyncedDefaultSearchProviderGUID to point to the new entry and | 1691 // Change kSyncedDefaultSearchProviderGUID to point to the new entry and |
1692 // ensure that the DSP remains managed. | 1692 // ensure that the DSP remains managed. |
1693 profile_a()->GetTestingPrefService()->SetString( | 1693 profile_a()->GetTestingPrefService()->SetString( |
1694 prefs::kSyncedDefaultSearchProviderGUID, | 1694 prefs::kSyncedDefaultSearchProviderGUID, |
1695 "newdefault"); | 1695 "newdefault"); |
1696 | 1696 |
1697 EXPECT_EQ(dsp_turl, model()->GetDefaultSearchProvider()); | 1697 EXPECT_EQ(dsp_turl, model()->GetDefaultSearchProvider()); |
1698 EXPECT_TRUE(model()->is_default_search_managed()); | 1698 EXPECT_TRUE(model()->is_default_search_managed()); |
1699 | 1699 |
1700 // Go unmanaged. Ensure that the DSP changes to the expected pending entry | 1700 // Go unmanaged. Ensure that the DSP changes to the expected pending entry |
1701 // from Sync. | 1701 // from Sync. |
1702 const TemplateURL* expected_default = | 1702 const TemplateURL* expected_default = |
1703 model()->GetTemplateURLForGUID("newdefault"); | 1703 model()->GetTemplateURLForGUID("newdefault"); |
1704 test_util_a_->RemoveManagedDefaultSearchPreferences(); | 1704 RemoveManagedDefaultSearchPreferences(test_util_a_->profile()); |
1705 | 1705 |
1706 EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider()); | 1706 EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider()); |
1707 } | 1707 } |
1708 | 1708 |
1709 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { | 1709 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { |
1710 // If the value from Sync is a duplicate of the local default and is newer, it | 1710 // If the value from Sync is a duplicate of the local default and is newer, it |
1711 // should safely replace the local value and set as the new default. | 1711 // should safely replace the local value and set as the new default. |
1712 TemplateURL* default_turl = model()->Add(CreateTestTemplateURL( | 1712 TemplateURL* default_turl = model()->Add(CreateTestTemplateURL( |
1713 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "whateverguid", | 1713 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "whateverguid", |
1714 10)); | 1714 10)); |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2315 | 2315 |
2316 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { | 2316 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { |
2317 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), | 2317 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), |
2318 "http://key1.com")); | 2318 "http://key1.com")); |
2319 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 2319 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
2320 | 2320 |
2321 model()->MergeDataAndStartSyncing( | 2321 model()->MergeDataAndStartSyncing( |
2322 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), | 2322 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), |
2323 CreateAndPassSyncErrorFactory()); | 2323 CreateAndPassSyncErrorFactory()); |
2324 } | 2324 } |
OLD | NEW |