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

Unified Diff: components/search_engines/template_url_unittest.cc

Issue 2659353002: Fix TemplateUrl::MatchesData comparison of search_terms_replacement_key (reland) (Closed)
Patch Set: Fixed after review, remove redundant check Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/search_engines/template_url_unittest.cc
diff --git a/components/search_engines/template_url_unittest.cc b/components/search_engines/template_url_unittest.cc
index 47630f348925dd2bb0dcf7e096f5724ea6f76dd3..f6309f5373ae1d22e1b0a9c7f811b0c5de1c2441 100644
--- a/components/search_engines/template_url_unittest.cc
+++ b/components/search_engines/template_url_unittest.cc
@@ -1868,3 +1868,47 @@ TEST_F(TemplateURLTest, InvalidateCachedValues) {
search_terms_data_.set_google_base_url("http://www.google.com/");
}
+
+// Test that TemplateURL object created with settings for google engine
+// matches its TemplateURLData.
+TEST_F(TemplateURLTest, MatchesData) {
+ TemplateURLData data;
+ data.SetURL("{google:baseURL}search?q={searchTerms}");
+ data.SetShortName(ASCIIToUTF16("Google"));
+ data.SetKeyword(ASCIIToUTF16("google.com"));
+ data.suggestions_url = "{google:baseSuggestURL}search?q={searchTerms}";
+ data.instant_url = "{google:baseURL}webhp";
+ data.image_url = "{google:baseURL}searchbyimage/upload";
+ data.new_tab_url = "{google:baseURL}_/chrome/newtab";
+ data.contextual_search_url = "{google:baseURL}_/contextualsearch";
+ data.image_url_post_params = "encoded_image={google:imageThumbnail}";
+ data.alternate_urls.push_back("{google:baseURL}s#q={searchTerms}");
+ // search_terms_replacement_key with value of
+ // "{google:instantExtendedEnabledKey}" is replaced inside TemplateUrl
+ // constructor so must be handled specially inside MatchesData.
+ data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}";
+ TemplateURL url(data);
+ EXPECT_TRUE(TemplateURL::MatchesData(&url, &data, search_terms_data_));
+}
+
+// Test for correct replacement of GoogleInstantExtendedEnabledKey param.
+TEST_F(TemplateURLTest, GoogleInstantExtendedEnabledReplacement) {
+ TemplateURLData data;
+ data.SetURL(
+ "{google:baseURL}search/"
+ "?{google:instantExtendedEnabledKey}&q={searchTerms}");
+ data.SetShortName(ASCIIToUTF16("Google"));
+ data.SetKeyword(ASCIIToUTF16("google.com"));
+ data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}";
+ TemplateURL turl(data);
+ EXPECT_TRUE(TemplateURL::MatchesData(&turl, &data, search_terms_data_));
+ // Expect that replacement of search_terms_replacement_key in TemplateURL
+ // constructor is correct.
+ EXPECT_EQ("espv", turl.search_terms_replacement_key());
+ // Expect that replacement of {google:instantExtendedEnabledKey} in search url
+ // is correct.
+ GURL search_generated = turl.GenerateSearchURL(search_terms_data_);
+ EXPECT_EQ("http://www.google.com/search/?espv&q=blah.blah.blah.blah.blah",
+ search_generated.spec());
+ EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated));
+}

Powered by Google App Engine
This is Rietveld 408576698