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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 result); 1185 result);
1186 1186
1187 EXPECT_TRUE(url.ExtractSearchTermsFromURL( 1187 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
1188 GURL("http://windows-1251.ru/path/%E1%F3%EA%E2%FB%20%C0%20%E8%20A"), 1188 GURL("http://windows-1251.ru/path/%E1%F3%EA%E2%FB%20%C0%20%E8%20A"),
1189 search_terms_data_, &result)); 1189 search_terms_data_, &result));
1190 EXPECT_EQ( 1190 EXPECT_EQ(
1191 base::WideToUTF16(L"\x0431\x0443\x043A\x0432\x044B \x0410 \x0438 A"), 1191 base::WideToUTF16(L"\x0431\x0443\x043A\x0432\x044B \x0410 \x0438 A"),
1192 result); 1192 result);
1193 } 1193 }
1194 1194
1195 // Checks that the ExtractSearchTermsFromURL function strips constant
1196 // prefix/suffix strings from the search terms param.
1197 TEST_F(TemplateURLTest, ExtractSearchTermsWithPrefixAndSuffix) {
1198 TemplateURLData data;
1199 data.alternate_urls.push_back(
1200 "http://www.example.com/?q=chromium-{searchTerms}@chromium.org");
1201 data.alternate_urls.push_back(
1202 "http://www.example.com/chromium-{searchTerms}@chromium.org/info");
1203 TemplateURL url(data);
1204 base::string16 result;
1205
1206 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
1207 GURL("http://www.example.com/?q=chromium-dev@chromium.org"),
1208 search_terms_data_, &result));
1209 EXPECT_EQ(ASCIIToUTF16("dev"), result);
1210
1211 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
1212 GURL("http://www.example.com/chromium-dev@chromium.org/info"),
1213 search_terms_data_, &result));
1214 EXPECT_EQ(ASCIIToUTF16("dev"), result);
1215
1216 // Don't match if the prefix and suffix aren't there.
1217 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
1218 GURL("http://www.example.com/?q=invalid"), search_terms_data_, &result));
1219 }
1220
1195 TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) { 1221 TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) {
1196 TemplateURLData data; 1222 TemplateURLData data;
1197 data.SetURL("http://google.com/?q={searchTerms}"); 1223 data.SetURL("http://google.com/?q={searchTerms}");
1198 data.instant_url = "http://google.com/instant#q={searchTerms}"; 1224 data.instant_url = "http://google.com/instant#q={searchTerms}";
1199 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); 1225 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
1200 data.alternate_urls.push_back( 1226 data.alternate_urls.push_back(
1201 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); 1227 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
1202 data.search_terms_replacement_key = "espv"; 1228 data.search_terms_replacement_key = "espv";
1203 TemplateURL url(data); 1229 TemplateURL url(data);
1204 1230
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 GURL("https://www.foo.org/search?q=Y+Z"), 1804 GURL("https://www.foo.org/search?q=Y+Z"),
1779 search_terms_data_, &search_terms)); 1805 search_terms_data_, &search_terms));
1780 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms); 1806 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms);
1781 EXPECT_TRUE(url.ExtractSearchTermsFromURL( 1807 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
1782 GURL("https://www.foo.org/s#q=123"), 1808 GURL("https://www.foo.org/s#q=123"),
1783 search_terms_data_, &search_terms)); 1809 search_terms_data_, &search_terms));
1784 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms); 1810 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms);
1785 1811
1786 search_terms_data_.set_google_base_url("http://www.google.com/"); 1812 search_terms_data_.set_google_base_url("http://www.google.com/");
1787 } 1813 }
OLDNEW
« 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