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 <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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 157 |
| 158 void Shutdown() override {} | 158 void Shutdown() override {} |
| 159 void SetOwner(TemplateURLService* owner) override {} | 159 void SetOwner(TemplateURLService* owner) override {} |
| 160 void DeleteAllSearchTermsForKeyword(TemplateURLID id) override {} | 160 void DeleteAllSearchTermsForKeyword(TemplateURLID id) override {} |
| 161 void SetKeywordSearchTermsForURL( | 161 void SetKeywordSearchTermsForURL( |
| 162 const GURL& url, | 162 const GURL& url, |
| 163 TemplateURLID id, | 163 TemplateURLID id, |
| 164 const base::string16& term) override {} | 164 const base::string16& term) override {} |
| 165 void AddKeywordGeneratedVisit(const GURL& url) override {} | 165 void AddKeywordGeneratedVisit(const GURL& url) override {} |
| 166 bool IsOmniboxExtensionURL(const std::string& url) override { return false; } | 166 bool IsOmniboxExtensionURL(const std::string& url) override { return false; } |
| 167 std::string GetExtensionControllingDSEPref() override { | |
| 168 return std::string(); | |
| 169 } | |
| 167 }; | 170 }; |
| 168 | 171 |
| 169 } // namespace | 172 } // namespace |
| 170 | 173 |
| 171 | 174 |
| 172 // TemplateURLServiceSyncTest ------------------------------------------------- | 175 // TemplateURLServiceSyncTest ------------------------------------------------- |
| 173 | 176 |
| 174 class TemplateURLServiceSyncTest : public testing::Test { | 177 class TemplateURLServiceSyncTest : public testing::Test { |
| 175 public: | 178 public: |
| 176 typedef TemplateURLService::SyncDataMap SyncDataMap; | 179 typedef TemplateURLService::SyncDataMap SyncDataMap; |
| (...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1699 | 1702 |
| 1700 // Go unmanaged. Ensure that the DSP changes to the expected pending entry | 1703 // Go unmanaged. Ensure that the DSP changes to the expected pending entry |
| 1701 // from Sync. | 1704 // from Sync. |
| 1702 const TemplateURL* expected_default = | 1705 const TemplateURL* expected_default = |
| 1703 model()->GetTemplateURLForGUID("newdefault"); | 1706 model()->GetTemplateURLForGUID("newdefault"); |
| 1704 RemoveManagedDefaultSearchPreferences(test_util_a_->profile()); | 1707 RemoveManagedDefaultSearchPreferences(test_util_a_->profile()); |
| 1705 | 1708 |
| 1706 EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider()); | 1709 EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider()); |
| 1707 } | 1710 } |
| 1708 | 1711 |
| 1712 TEST_F(TemplateURLServiceSyncTest, SyncWithExtensionDefaultSearch) { | |
|
vasilii
2016/12/06 19:16:42
I meant a different scenario in mind when I asked
Alexander Yashkin
2016/12/09 08:19:52
Ok, got it, added GetAllSyncDataWithSearchOverride
| |
| 1713 // First start off with a few entries and make sure we can set an extension | |
| 1714 // default search provider. | |
| 1715 syncer::SyncDataList initial_data = CreateInitialSyncData(); | |
| 1716 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
| 1717 PassProcessor(), | |
| 1718 CreateAndPassSyncErrorFactory()); | |
| 1719 model()->SetUserSelectedDefaultSearchProvider( | |
| 1720 model()->GetTemplateURLForGUID("key2")); | |
| 1721 | |
| 1722 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
| 1723 ASSERT_FALSE(model()->is_default_search_managed()); | |
| 1724 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | |
| 1725 | |
| 1726 // Change the default search provider to a extension one. | |
| 1727 TemplateURLData extension; | |
| 1728 extension.SetShortName(ASCIIToUTF16("extensiondefault")); | |
| 1729 extension.SetKeyword(ASCIIToUTF16("extensiondefault")); | |
| 1730 extension.SetURL("http://extensiondefault.com/search?t={searchTerms}"); | |
| 1731 extension.favicon_url = GURL("http://extensiondefault.com/icon.jpg"); | |
| 1732 extension.input_encodings = {"UTF-16", "UTF-32"}; | |
| 1733 extension.alternate_urls = { | |
| 1734 "http://extensiondefault.com/search#t={searchTerms}"}; | |
| 1735 extension.search_terms_replacement_key = "espv"; | |
|
vasilii
2016/12/06 19:16:42
Do you wanna use your helper function here?
Alexander Yashkin
2016/12/09 08:19:52
Done
| |
| 1736 | |
| 1737 auto ext_dse = base::MakeUnique<TemplateURL>( | |
| 1738 extension, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | |
| 1739 auto ext_info = base::MakeUnique<TemplateURL::AssociatedExtensionInfo>("ext"); | |
| 1740 ext_info->wants_to_be_default_engine = true; | |
| 1741 test_util_a_->AddExtensionControlledTURL(std::move(ext_dse), | |
| 1742 std::move(ext_info)); | |
| 1743 | |
| 1744 const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider(); | |
| 1745 EXPECT_TRUE(model()->IsExtensionControlledDefaultSearch()); | |
| 1746 | |
| 1747 // Add a new entry from Sync. It should still sync in despite the default | |
| 1748 // being extension controlled. | |
| 1749 syncer::SyncChangeList changes; | |
| 1750 changes.push_back(CreateTestSyncChange( | |
| 1751 syncer::SyncChange::ACTION_ADD, | |
| 1752 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), | |
| 1753 "http://new.com/{searchTerms}", "newdefault"))); | |
| 1754 model()->ProcessSyncChanges(FROM_HERE, changes); | |
| 1755 | |
| 1756 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
| 1757 | |
| 1758 // Change kSyncedDefaultSearchProviderGUID to point to the new entry and | |
| 1759 // ensure that the DSP remains extension controlled. | |
| 1760 profile_a()->GetTestingPrefService()->SetString( | |
| 1761 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); | |
| 1762 | |
| 1763 EXPECT_EQ(dsp_turl, model()->GetDefaultSearchProvider()); | |
| 1764 EXPECT_TRUE(model()->IsExtensionControlledDefaultSearch()); | |
| 1765 | |
| 1766 // Remove extension DSE. Ensure that the DSP changes to the expected pending | |
| 1767 // entry from Sync. | |
| 1768 const TemplateURL* expected_default = | |
| 1769 model()->GetTemplateURLForGUID("newdefault"); | |
| 1770 test_util_a_->RemoveExtensionDefaultSearchFromPrefs("ext"); | |
| 1771 | |
| 1772 EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider()); | |
| 1773 } | |
| 1774 | |
| 1709 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { | 1775 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { |
| 1710 // If the value from Sync is a duplicate of the local default and is newer, it | 1776 // 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. | 1777 // should safely replace the local value and set as the new default. |
| 1712 TemplateURL* default_turl = model()->Add(CreateTestTemplateURL( | 1778 TemplateURL* default_turl = model()->Add(CreateTestTemplateURL( |
| 1713 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "whateverguid", | 1779 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "whateverguid", |
| 1714 10)); | 1780 10)); |
| 1715 model()->SetUserSelectedDefaultSearchProvider(default_turl); | 1781 model()->SetUserSelectedDefaultSearchProvider(default_turl); |
| 1716 | 1782 |
| 1717 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1783 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1718 // The key1 entry should be a duplicate of the default. | 1784 // The key1 entry should be a duplicate of the default. |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2315 | 2381 |
| 2316 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { | 2382 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { |
| 2317 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), | 2383 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), |
| 2318 "http://key1.com")); | 2384 "http://key1.com")); |
| 2319 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 2385 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 2320 | 2386 |
| 2321 model()->MergeDataAndStartSyncing( | 2387 model()->MergeDataAndStartSyncing( |
| 2322 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), | 2388 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), |
| 2323 CreateAndPassSyncErrorFactory()); | 2389 CreateAndPassSyncErrorFactory()); |
| 2324 } | 2390 } |
| OLD | NEW |