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 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1563 // Now sync the initial data. | 1563 // Now sync the initial data. |
1564 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1564 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
1565 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1565 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1566 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1566 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1567 | 1567 |
1568 // Ensure that the new entries were added and the default has not changed. | 1568 // Ensure that the new entries were added and the default has not changed. |
1569 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1569 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1570 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1570 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); |
1571 } | 1571 } |
1572 | 1572 |
1573 TEST_F(TemplateURLServiceSyncTest, NewDefaultIsAlreadySynced) { | |
1574 // Ensure that if the synced DSP pref changed to another synced entry (as | |
1575 // opposed to coming in as a new entry), it gets reset correctly. | |
1576 // Start by setting kSyncedDefaultSearchProviderGUID to the entry that should | |
1577 // end up as the default. Note that this must be done before the initial | |
1578 // entries are added as otherwise this call will set the DSP immediately. | |
1579 profile_a()->GetTestingPrefService()->SetString( | |
1580 prefs::kSyncedDefaultSearchProviderGUID, "key2"); | |
1581 | |
1582 syncer::SyncDataList initial_data = CreateInitialSyncData(); | |
1583 // Ensure that our candidate default supports replacement. | |
1584 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | |
1585 "http://key2.com/{searchTerms}", "key2", 90)); | |
1586 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | |
1587 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | |
1588 iter != initial_data.end(); ++iter) { | |
1589 TemplateURL* converted = Deserialize(*iter); | |
1590 model()->Add(converted); | |
1591 } | |
1592 | |
1593 // Set the initial default to something other than the desired default. | |
1594 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key1")); | |
1595 | |
1596 // Merge in the same data (i.e. already synced entries). | |
1597 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
1598 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
1599 | |
1600 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1601 TemplateURL* expected_default = model()->GetDefaultSearchProvider(); | |
Nicolas Zea
2012/08/16 20:03:03
nit: this isn't the expected, but the current righ
SteveT
2012/08/16 20:24:00
Right, renamed this variable.
| |
1602 ASSERT_TRUE(expected_default); | |
1603 EXPECT_EQ("key2", expected_default->sync_guid()); | |
1604 EXPECT_EQ(ASCIIToUTF16("key2"), expected_default->keyword()); | |
1605 } | |
1606 | |
1573 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { | 1607 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { |
1574 // First start off with a few entries and make sure we can set an unmanaged | 1608 // First start off with a few entries and make sure we can set an unmanaged |
1575 // default search provider. | 1609 // default search provider. |
1576 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1610 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
1577 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1611 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1578 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1612 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1579 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); | 1613 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); |
1580 | 1614 |
1581 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1615 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1582 ASSERT_FALSE(model()->is_default_search_managed()); | 1616 ASSERT_FALSE(model()->is_default_search_managed()); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1975 if (test_cases[i].present_in_model == SYNC || | 2009 if (test_cases[i].present_in_model == SYNC || |
1976 test_cases[i].present_in_model == BOTH) { | 2010 test_cases[i].present_in_model == BOTH) { |
1977 ASSERT_TRUE(model()->GetTemplateURLForGUID(sync_guid)); | 2011 ASSERT_TRUE(model()->GetTemplateURLForGUID(sync_guid)); |
1978 EXPECT_EQ(expected_sync_keyword, sync_turl->keyword()); | 2012 EXPECT_EQ(expected_sync_keyword, sync_turl->keyword()); |
1979 EXPECT_EQ(sync_url, sync_turl->url()); | 2013 EXPECT_EQ(sync_url, sync_turl->url()); |
1980 EXPECT_EQ(sync_last_modified, sync_turl->last_modified().ToTimeT()); | 2014 EXPECT_EQ(sync_last_modified, sync_turl->last_modified().ToTimeT()); |
1981 model()->Remove(model()->GetTemplateURLForGUID(sync_guid)); | 2015 model()->Remove(model()->GetTemplateURLForGUID(sync_guid)); |
1982 } | 2016 } |
1983 } // for | 2017 } // for |
1984 } | 2018 } |
OLD | NEW |