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

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: 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
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..c035a606877124e02f0b1162ff5c57bd79d46917 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);
+
+ // To be safe, still succeed if they're missing. This is no worse than the
+ // previous behavior.
+ EXPECT_TRUE(url.ExtractSearchTermsFromURL(
+ GURL("http://www.example.com/?q=invalid"), search_terms_data_, &result));
+ EXPECT_EQ(ASCIIToUTF16("invalid"), result);
Peter Kasting 2016/04/21 19:48:57 Hmm. I don't think we should allow "foo.com/?q=xy
jbroman 2016/04/21 21:01:42 My reasoning was that they were accepted before th
+}
+
TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) {
TemplateURLData data;
data.SetURL("http://google.com/?q={searchTerms}");
« components/search_engines/template_url.cc ('K') | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698