Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: chrome/browser/search_engines/template_url_service_sync_unittest.cc

Issue 10458077: When the Google base URL changes and causes keyword updates, save those to the database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 // Bring down a copy of the prepopulate engine from Sync with the old values, 1626 // Bring down a copy of the prepopulate engine from Sync with the old values,
1627 // including the old timestamp and the same GUID. Ensure that it loses 1627 // including the old timestamp and the same GUID. Ensure that it loses
1628 // conflict resolution against the local value, and an update is sent to the 1628 // conflict resolution against the local value, and an update is sent to the
1629 // server. The new timestamp should be preserved. 1629 // server. The new timestamp should be preserved.
1630 SyncDataList initial_data; 1630 SyncDataList initial_data;
1631 data_copy.SetKeyword(original_keyword); 1631 data_copy.SetKeyword(original_keyword);
1632 data_copy.sync_guid = sync_guid; 1632 data_copy.sync_guid = sync_guid;
1633 scoped_ptr<TemplateURL> sync_turl( 1633 scoped_ptr<TemplateURL> sync_turl(
1634 new TemplateURL(prepop_turls[0]->profile(), data_copy)); 1634 new TemplateURL(prepop_turls[0]->profile(), data_copy));
1635 initial_data.push_back( 1635 initial_data.push_back(
1636 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl.get())); 1636 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl));
1637 1637
1638 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, 1638 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1639 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); 1639 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory());
1640 1640
1641 ASSERT_EQ(added_turl, model()->GetTemplateURLForKeyword( 1641 ASSERT_EQ(added_turl, model()->GetTemplateURLForKeyword(
1642 ASCIIToUTF16(kNewKeyword))); 1642 ASCIIToUTF16(kNewKeyword)));
1643 EXPECT_EQ(new_timestamp, added_turl->last_modified()); 1643 EXPECT_EQ(new_timestamp, added_turl->last_modified());
1644 SyncChange change = processor()->change_for_guid(sync_guid); 1644 SyncChange change = processor()->change_for_guid(sync_guid);
1645 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); 1645 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
1646 EXPECT_EQ(kNewKeyword, 1646 EXPECT_EQ(kNewKeyword,
1647 change.sync_data().GetSpecifics().search_engine().keyword()); 1647 change.sync_data().GetSpecifics().search_engine().keyword());
1648 EXPECT_EQ(new_timestamp, base::Time::FromInternalValue( 1648 EXPECT_EQ(new_timestamp, base::Time::FromInternalValue(
1649 change.sync_data().GetSpecifics().search_engine().last_modified())); 1649 change.sync_data().GetSpecifics().search_engine().last_modified()));
1650 } 1650 }
1651
1652 TEST_F(TemplateURLServiceSyncTest, SyncBaseURLs) {
1653 // Verify that bringing in a remote TemplateURL that uses Google base URLs
1654 // causes it to get a local keyword that matches the local base URL.
1655 test_util_a_.SetGoogleBaseURL(GURL("http://google.com/"));
1656 SyncDataList initial_data;
1657 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(
1658 ASCIIToUTF16("google.co.uk"), "{google:baseURL}search?q={searchTerms}",
1659 "guid"));
1660 initial_data.push_back(
1661 TemplateURLService::CreateSyncDataFromTemplateURL(*turl));
1662 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1663 PassProcessor(), CreateAndPassSyncErrorFactory());
1664 TemplateURL* synced_turl = model()->GetTemplateURLForGUID("guid");
1665 ASSERT_TRUE(synced_turl);
1666 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword());
1667 EXPECT_EQ(0U, processor()->change_list_size());
1668
1669 // Remote updates to this URL's keyword should be silently ignored.
1670 SyncChangeList changes;
1671 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE,
1672 CreateTestTemplateURL(ASCIIToUTF16("google.de"),
1673 "{google:baseURL}search?q={searchTerms}", "guid")));
1674 model()->ProcessSyncChanges(FROM_HERE, changes);
1675 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword());
1676 EXPECT_EQ(0U, processor()->change_list_size());
1677
1678 // A local change to the Google base URL should update the keyword and
1679 // generate a sync change.
1680 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/"));
1681 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword());
1682 EXPECT_EQ(1U, processor()->change_list_size());
1683 ASSERT_TRUE(processor()->contains_guid("guid"));
1684 SyncChange change(processor()->change_for_guid("guid"));
1685 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
1686 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data()));
1687 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | chrome/browser/search_engines/template_url_service_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698