summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorstevet@chromium.org <stevet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 21:30:13 +0000
committerstevet@chromium.org <stevet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 21:30:13 +0000
commit68670d65153bdcd60136979ebffa3e0e57567928 (patch)
tree76ad2aeb62a5f903a92a4d0eefe47773705f6ebf /chrome/browser
parentc56874b25ed391c6ac5fa189331dfbcf35167a3b (diff)
downloadchromium_src-68670d65153bdcd60136979ebffa3e0e57567928.zip
chromium_src-68670d65153bdcd60136979ebffa3e0e57567928.tar.gz
chromium_src-68670d65153bdcd60136979ebffa3e0e57567928.tar.bz2
Change our new DSP finding logic to expect the DSP to be in the default list.
Add a unit test for this. BUG=132939 TEST=none Review URL: https://chromiumcodereview.appspot.com/10553004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142816 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/search_engines/template_url_service.cc4
-rw-r--r--chrome/browser/search_engines/template_url_service_sync_unittest.cc15
-rw-r--r--chrome/browser/search_engines/template_url_service_unittest.cc33
3 files changed, 49 insertions, 3 deletions
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index 383ee1b..36a7a3b 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -89,8 +89,10 @@ TemplateURL* FirstPotentialDefaultEngine(
const TemplateURLService::TemplateURLVector& template_urls) {
for (TemplateURLService::TemplateURLVector::const_iterator i(
template_urls.begin()); i != template_urls.end(); ++i) {
- if (!(*i)->IsExtensionKeyword() && (*i)->SupportsReplacement())
+ if ((*i)->ShowInDefaultList()) {
+ DCHECK(!(*i)->IsExtensionKeyword());
return *i;
+ }
}
return NULL;
}
diff --git a/chrome/browser/search_engines/template_url_service_sync_unittest.cc b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
index c9a53e7..ca83416 100644
--- a/chrome/browser/search_engines/template_url_service_sync_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
@@ -1558,8 +1558,19 @@ TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedAndReplaced) {
"http://key1.com/{searchTerms}", "key1", 90));
// Create a second default search provider for the
// FindNewDefaultSearchProvider method to find.
- scoped_ptr<TemplateURL> turl2(CreateTestTemplateURL(ASCIIToUTF16("key2"),
- "http://key2.com/{searchTerms}", "key2", 100));
+ TemplateURLData data;
+ data.short_name = ASCIIToUTF16("unittest");
+ data.SetKeyword(ASCIIToUTF16("key2"));
+ data.SetURL("http://key2.com/{searchTerms}");
+ data.favicon_url = GURL("http://favicon.url");
+ data.safe_for_autoreplace = false;
+ data.date_created = Time::FromTimeT(100);
+ data.last_modified = Time::FromTimeT(100);
+ data.created_by_policy = false;
+ data.prepopulate_id = 999999;
+ data.sync_guid = "key2";
+ data.show_in_default_list = true;
+ scoped_ptr<TemplateURL> turl2(new TemplateURL(NULL, data));
initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(
*turl1));
initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(
diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc
index deba940..fb43f83 100644
--- a/chrome/browser/search_engines/template_url_service_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_unittest.cc
@@ -1167,6 +1167,39 @@ TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) {
AssertEquals(*cloned_url, *default_search);
}
+TEST_F(TemplateURLServiceTest, FindNewDefaultSearchProvider) {
+ // Ensure that if our service is initially empty, we don't initial have a
+ // valid new DSP.
+ EXPECT_FALSE(model()->FindNewDefaultSearchProvider());
+
+ // Add a few entries with searchTerms, but ensure only the last one is in the
+ // default list.
+ AddKeywordWithDate("name1", "key1", "http://foo1/{searchTerms}",
+ "http://sugg1", "http://icon1", true, "UTF-8;UTF-16", Time(), Time());
+ AddKeywordWithDate("name2", "key2", "http://foo2/{searchTerms}",
+ "http://sugg2", "http://icon1", true, "UTF-8;UTF-16", Time(), Time());
+ AddKeywordWithDate("name3", "key3", "http://foo1/{searchTerms}",
+ "http://sugg3", "http://icon3", true, "UTF-8;UTF-16", Time(), Time());
+ TemplateURLData data;
+ data.short_name = ASCIIToUTF16("valid");
+ data.SetKeyword(ASCIIToUTF16("validkeyword"));
+ data.SetURL("http://valid/{searchTerms}");
+ data.favicon_url = GURL("http://validicon");
+ data.show_in_default_list = true;
+ TemplateURL* valid_turl(new TemplateURL(test_util_.profile(), data));
+ model()->Add(valid_turl);
+ EXPECT_EQ(4U, model()->GetTemplateURLs().size());
+
+ // Request a new DSP from the service and only expect the valid one.
+ TemplateURL* new_default = model()->FindNewDefaultSearchProvider();
+ ASSERT_TRUE(new_default);
+ EXPECT_EQ(valid_turl, new_default);
+
+ // Remove the default we received and ensure that the service returns NULL.
+ model()->Remove(new_default);
+ EXPECT_FALSE(model()->FindNewDefaultSearchProvider());
+}
+
// Make sure that the load routine doesn't delete
// prepopulated engines that no longer exist in the prepopulate data if
// it is the default search provider.