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

Unified Diff: components/search_engines/template_url_unittest.cc

Issue 1902263002: Support fixed prefixes and suffixes when extracting terms from search template URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 4 years, 8 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 | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 828559760d7873da2c45ea457738d403ce346ffb..4cecbd773ddb2145bf565277f3df9bd33357f0ef 100644
--- a/components/search_engines/template_url_unittest.cc
+++ b/components/search_engines/template_url_unittest.cc
@@ -1192,6 +1192,32 @@ TEST_F(TemplateURLTest, ExtractSearchTermsFromNonUTF8URL) {
result);
}
+// Checks that the ExtractSearchTermsFromURL function strips constant
+// prefix/suffix strings from the search terms param.
+TEST_F(TemplateURLTest, ExtractSearchTermsWithPrefixAndSuffix) {
+ TemplateURLData data;
+ data.alternate_urls.push_back(
+ "http://www.example.com/?q=chromium-{searchTerms}@chromium.org");
+ data.alternate_urls.push_back(
+ "http://www.example.com/chromium-{searchTerms}@chromium.org/info");
+ TemplateURL url(data);
+ base::string16 result;
+
+ EXPECT_TRUE(url.ExtractSearchTermsFromURL(
+ GURL("http://www.example.com/?q=chromium-dev@chromium.org"),
+ search_terms_data_, &result));
+ EXPECT_EQ(ASCIIToUTF16("dev"), result);
+
+ EXPECT_TRUE(url.ExtractSearchTermsFromURL(
+ GURL("http://www.example.com/chromium-dev@chromium.org/info"),
+ search_terms_data_, &result));
+ EXPECT_EQ(ASCIIToUTF16("dev"), result);
+
+ // Don't match if the prefix and suffix aren't there.
+ EXPECT_FALSE(url.ExtractSearchTermsFromURL(
+ GURL("http://www.example.com/?q=invalid"), search_terms_data_, &result));
+}
+
TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) {
TemplateURLData data;
data.SetURL("http://google.com/?q={searchTerms}");
« no previous file with comments | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698