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

Unified Diff: chrome/browser/search_engines/template_url_unittest.cc

Issue 12623029: Upstreaming mechanism to add query refinement to omnibox searches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Applied Peter's comments. Created 7 years, 9 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
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | chrome/browser/ui/app_list/search_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search_engines/template_url_unittest.cc
diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc
index 9ef9678bd1f2451bf0d588b9846199629bdead4a..9768933d7b594f12ab1c51be72adb67a0c01e7cc 100644
--- a/chrome/browser/search_engines/template_url_unittest.cc
+++ b/chrome/browser/search_engines/template_url_unittest.cc
@@ -925,3 +925,72 @@ TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) {
EXPECT_TRUE(url.HasSearchTermsReplacementKey(
GURL("http://bing.com/#espv")));
}
+
+TEST_F(TemplateURLTest, ReplaceSearchTermsInURL) {
+ TemplateURLData data;
+ data.SetURL("http://google.com/?q={searchTerms}");
+ data.instant_url = "http://google.com/instant#q={searchTerms}";
+ data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
+ data.alternate_urls.push_back(
+ "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
+ TemplateURL url(NULL, data);
+ TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("Bob Morane"));
+ GURL result;
+
+ EXPECT_TRUE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/?q=something"), search_terms, &result));
+ EXPECT_EQ(GURL("http://google.com/?q=Bob%20Morane"), result);
+
+ result = GURL("http://should.not.change.com");
+ EXPECT_FALSE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.ca/?q=something"), search_terms, &result));
+ EXPECT_EQ(GURL("http://should.not.change.com"), result);
+
+ EXPECT_FALSE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/foo/?q=foo"), search_terms, &result));
+
+ EXPECT_TRUE(url.ReplaceSearchTermsInURL(
+ GURL("https://google.com/?q=foo"), search_terms, &result));
+ EXPECT_EQ(GURL("https://google.com/?q=Bob%20Morane"), result);
+
+ EXPECT_FALSE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com:8080/?q=foo"), search_terms, &result));
+
+ EXPECT_TRUE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/?q=1+2+3&b=456"), search_terms, &result));
+ EXPECT_EQ(GURL("http://google.com/?q=Bob%20Morane&b=456"), result);
+
+ // Note: Spaces in REF parameters are not escaped. See TryEncoding() in
+ // template_url.cc for details.
+ EXPECT_TRUE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/alt/?q=123#q=456"), search_terms, &result));
+ EXPECT_EQ(GURL("http://google.com/alt/?q=123#q=Bob Morane"), result);
+
+ EXPECT_TRUE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/alt/?a=012&q=123&b=456#f=789"), search_terms,
+ &result));
+ EXPECT_EQ(GURL("http://google.com/alt/?a=012&q=Bob%20Morane&b=456#f=789"),
+ result);
+
+ EXPECT_TRUE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/alt/?a=012&q=123&b=456#j=abc&q=789&h=def9"),
+ search_terms, &result));
+ EXPECT_EQ(GURL("http://google.com/alt/?a=012&q=123&b=456"
+ "#j=abc&q=Bob Morane&h=def9"), result);
+
+ EXPECT_FALSE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/alt/?q="), search_terms, &result));
+
+ EXPECT_FALSE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/alt/?#q="), search_terms, &result));
+
+ EXPECT_FALSE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/alt/?q=#q="), search_terms, &result));
+
+ EXPECT_FALSE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/alt/?q=123#q="), search_terms, &result));
+
+ EXPECT_TRUE(url.ReplaceSearchTermsInURL(
+ GURL("http://google.com/alt/?q=#q=123"), search_terms, &result));
+ EXPECT_EQ(GURL("http://google.com/alt/?q=#q=Bob Morane"), result);
+}
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | chrome/browser/ui/app_list/search_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698