| 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/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); | 224 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() | 227 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() |
| 228 : sync_processor_(new TestChangeProcessor), | 228 : sync_processor_(new TestChangeProcessor), |
| 229 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( | 229 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( |
| 230 sync_processor_.get())) {} | 230 sync_processor_.get())) {} |
| 231 | 231 |
| 232 void TemplateURLServiceSyncTest::SetUp() { | 232 void TemplateURLServiceSyncTest::SetUp() { |
| 233 TemplateURLService::set_fallback_search_engines_disabled(true); | |
| 234 test_util_a_.SetUp(); | 233 test_util_a_.SetUp(); |
| 235 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull | 234 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull |
| 236 // in the prepopulate data, which the sync tests don't care about (and would | 235 // in the prepopulate data, which the sync tests don't care about (and would |
| 237 // just foul them up). | 236 // just foul them up). |
| 238 test_util_a_.ChangeModelToLoadState(); | 237 test_util_a_.ChangeModelToLoadState(); |
| 239 profile_b_.reset(new TestingProfile); | 238 profile_b_.reset(new TestingProfile); |
| 240 TemplateURLServiceFactory::GetInstance()-> | 239 TemplateURLServiceFactory::GetInstance()-> |
| 241 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); | 240 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); |
| 242 model_b_.reset(new TemplateURLService(profile_b_.get())); | 241 model_b_.reset(new TemplateURLService(profile_b_.get())); |
| 243 model_b_->Load(); | 242 model_b_->Load(); |
| 244 } | 243 } |
| 245 | 244 |
| 246 void TemplateURLServiceSyncTest::TearDown() { | 245 void TemplateURLServiceSyncTest::TearDown() { |
| 247 test_util_a_.TearDown(); | 246 test_util_a_.TearDown(); |
| 248 TemplateURLService::set_fallback_search_engines_disabled(false); | |
| 249 } | 247 } |
| 250 | 248 |
| 251 scoped_ptr<syncer::SyncChangeProcessor> | 249 scoped_ptr<syncer::SyncChangeProcessor> |
| 252 TemplateURLServiceSyncTest::PassProcessor() { | 250 TemplateURLServiceSyncTest::PassProcessor() { |
| 253 return sync_processor_wrapper_.PassAs<syncer::SyncChangeProcessor>(); | 251 return sync_processor_wrapper_.PassAs<syncer::SyncChangeProcessor>(); |
| 254 } | 252 } |
| 255 | 253 |
| 256 scoped_ptr<syncer::SyncErrorFactory> TemplateURLServiceSyncTest:: | 254 scoped_ptr<syncer::SyncErrorFactory> TemplateURLServiceSyncTest:: |
| 257 CreateAndPassSyncErrorFactory() { | 255 CreateAndPassSyncErrorFactory() { |
| 258 return scoped_ptr<syncer::SyncErrorFactory>( | 256 return scoped_ptr<syncer::SyncErrorFactory>( |
| (...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1629 // Now sync the initial data. | 1627 // Now sync the initial data. |
| 1630 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1628 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1631 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1629 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1632 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1630 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1633 | 1631 |
| 1634 // Ensure that the new entries were added and the default has not changed. | 1632 // Ensure that the new entries were added and the default has not changed. |
| 1635 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1633 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1636 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1634 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1637 } | 1635 } |
| 1638 | 1636 |
| 1637 TEST_F(TemplateURLServiceSyncTest, NewDefaultIsAlreadySynced) { |
| 1638 // Ensure that if the synced DSP pref changed to another synced entry (as |
| 1639 // opposed to coming in as a new entry), it gets reset correctly. |
| 1640 // Start by setting kSyncedDefaultSearchProviderGUID to the entry that should |
| 1641 // end up as the default. Note that this must be done before the initial |
| 1642 // entries are added as otherwise this call will set the DSP immediately. |
| 1643 profile_a()->GetTestingPrefService()->SetString( |
| 1644 prefs::kSyncedDefaultSearchProviderGUID, "key2"); |
| 1645 |
| 1646 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1647 // Ensure that our candidate default supports replacement. |
| 1648 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1649 "http://key2.com/{searchTerms}", "key2", 90)); |
| 1650 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1651 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 1652 iter != initial_data.end(); ++iter) { |
| 1653 TemplateURL* converted = Deserialize(*iter); |
| 1654 model()->Add(converted); |
| 1655 } |
| 1656 |
| 1657 // Set the initial default to something other than the desired default. |
| 1658 model()->SetUserSelectedDefaultSearchProvider( |
| 1659 model()->GetTemplateURLForGUID("key1")); |
| 1660 |
| 1661 // Merge in the same data (i.e. already synced entries). |
| 1662 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1663 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1664 |
| 1665 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1666 TemplateURL* current_default = model()->GetDefaultSearchProvider(); |
| 1667 ASSERT_TRUE(current_default); |
| 1668 EXPECT_EQ("key2", current_default->sync_guid()); |
| 1669 EXPECT_EQ(ASCIIToUTF16("key2"), current_default->keyword()); |
| 1670 } |
| 1671 |
| 1639 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { | 1672 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { |
| 1640 // First start off with a few entries and make sure we can set an unmanaged | 1673 // First start off with a few entries and make sure we can set an unmanaged |
| 1641 // default search provider. | 1674 // default search provider. |
| 1642 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1675 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1643 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1676 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1644 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1677 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1645 model()->SetUserSelectedDefaultSearchProvider( | 1678 model()->SetUserSelectedDefaultSearchProvider( |
| 1646 model()->GetTemplateURLForGUID("key2")); | 1679 model()->GetTemplateURLForGUID("key2")); |
| 1647 | 1680 |
| 1648 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1681 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 2242 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
| 2210 syncer::SEARCH_ENGINES, list, PassProcessor(), | 2243 syncer::SEARCH_ENGINES, list, PassProcessor(), |
| 2211 CreateAndPassSyncErrorFactory()); | 2244 CreateAndPassSyncErrorFactory()); |
| 2212 | 2245 |
| 2213 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); | 2246 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); |
| 2214 EXPECT_TRUE(result_turl); | 2247 EXPECT_TRUE(result_turl); |
| 2215 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); | 2248 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); |
| 2216 EXPECT_EQ(default_turl->short_name, result_turl->short_name()); | 2249 EXPECT_EQ(default_turl->short_name, result_turl->short_name()); |
| 2217 EXPECT_EQ(default_turl->url(), result_turl->url()); | 2250 EXPECT_EQ(default_turl->url(), result_turl->url()); |
| 2218 } | 2251 } |
| 2219 | |
| 2220 TEST_F(TemplateURLServiceSyncTest, GUIDUpdatedOnDefaultSearchChange) { | |
| 2221 const char kGUID[] = "initdefault"; | |
| 2222 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), | |
| 2223 "http://thewhat.com/{searchTerms}", | |
| 2224 kGUID)); | |
| 2225 model()->SetUserSelectedDefaultSearchProvider( | |
| 2226 model()->GetTemplateURLForGUID(kGUID)); | |
| 2227 | |
| 2228 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | |
| 2229 ASSERT_TRUE(default_search); | |
| 2230 | |
| 2231 const char kNewGUID[] = "newdefault"; | |
| 2232 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), | |
| 2233 "http://thewhat.com/{searchTerms}", | |
| 2234 kNewGUID)); | |
| 2235 model()->SetUserSelectedDefaultSearchProvider( | |
| 2236 model()->GetTemplateURLForGUID(kNewGUID)); | |
| 2237 | |
| 2238 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString( | |
| 2239 prefs::kSyncedDefaultSearchProviderGUID)); | |
| 2240 } | |
| OLD | NEW |