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

Unified Diff: components/search_engines/template_url_unittest.cc

Issue 1978553002: Refactor extracting search terms from Template URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@support-prefix-path-matching-when-extracting-terms-from-template-url
Patch Set: Created 4 years, 7 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 4cecbd773ddb2145bf565277f3df9bd33357f0ef..924621c949d0c7162913c8e92cfd59ad38fd7c9a 100644
--- a/components/search_engines/template_url_unittest.cc
+++ b/components/search_engines/template_url_unittest.cc
@@ -717,78 +717,80 @@ TEST_F(TemplateURLTest, HostAndSearchTermKey) {
struct TestData {
const std::string url;
const std::string host;
+ const url::Parsed::ComponentType location;
const std::string path;
const std::string search_term_key;
+ const std::string search_term_value_prefix;
+ const std::string search_term_value_suffix;
} test_data[] = {
- { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
- { "http://blah/{searchTerms}", "blah", "/", ""},
+ { "http://blah/?foo=bar&q={searchTerms}&b=x",
+ "blah", url::Parsed::QUERY, "/", "q", "", ""},
- // No term should result in empty values.
- { "http://blah/", "", "", ""},
+ { "http://blah/?foo=bar#q={searchTerms}&b=x",
+ "blah", url::Parsed::REF, "/", "q", "", ""},
- // Multiple terms should result in empty values.
- { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
+ { "http://blah/{searchTerms}",
+ "blah", url::Parsed::PATH, "/", "", "/", ""},
- // Term in the host shouldn't match.
- { "http://{searchTerms}", "", "", ""},
+ { "http://blah/{searchTerms}/",
+ "blah", url::Parsed::PATH, "//", "", "/", "/"},
- { "http://blah/?q={searchTerms}", "blah", "/", "q"},
- { "https://blah/?q={searchTerms}", "blah", "/", "q"},
+ { "http://blah/begin/{searchTerms}/end",
+ "blah", url::Parsed::PATH, "/begin//end", "", "/begin/", "/end"},
- // Single term with extra chars in value should match.
- { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
- };
+ // No term should result in empty values.
+ { "http://blah/", "", url::Parsed::QUERY, "", "", "", ""},
- for (size_t i = 0; i < arraysize(test_data); ++i) {
- TemplateURLData data;
- data.SetURL(test_data[i].url);
- TemplateURL url(data);
- EXPECT_EQ(test_data[i].host, url.url_ref().GetHost(search_terms_data_));
- EXPECT_EQ(test_data[i].path, url.url_ref().GetPath(search_terms_data_));
- EXPECT_EQ(test_data[i].search_term_key,
- url.url_ref().GetSearchTermKey(search_terms_data_));
- }
-}
+ // Term in the host shouldn't match.
+ { "http://{searchTerms}", "", url::Parsed::QUERY, "", "", "", "" },
-TEST_F(TemplateURLTest, SearchTermKeyLocation) {
- struct TestData {
- const std::string url;
- const url::Parsed::ComponentType location;
- const std::string path;
- size_t position_in_path;
- } test_data[] = {
- { "http://blah/{searchTerms}/", url::Parsed::PATH, "//", 1 },
- { "http://blah/{searchTerms}", url::Parsed::PATH, "/", 1 },
- { "http://blah/begin/{searchTerms}/end", url::Parsed::PATH, "/begin//end", 7 },
-
- { "http://blah/?foo=bar&q={searchTerms}&b=x", url::Parsed::QUERY,
- "/", std::string::npos },
- { "http://blah/?foo=bar#x={searchTerms}&b=x", url::Parsed::REF,
- "/", std::string::npos },
// searchTerms is a key, not a value, so this should result in an empty
// value.
{ "http://blah/?foo=bar#x=012345678901234&a=b&{searchTerms}=x",
- url::Parsed::QUERY, std::string(), std::string::npos },
-
- // Multiple search terms should result in empty values.
- { "http://blah/{searchTerms}?q={searchTerms}", url::Parsed::QUERY,
- "", std::string::npos },
- { "http://blah/{searchTerms}#x={searchTerms}", url::Parsed::QUERY,
- "", std::string::npos },
- { "http://blah/?q={searchTerms}#x={searchTerms}", url::Parsed::QUERY,
- "", std::string::npos },
+ "", url::Parsed::QUERY, "", "", "", "" },
+
+ // Multiple terms should result in empty values.
+ { "http://blah/?q={searchTerms}&x={searchTerms}",
+ "", url::Parsed::QUERY, "", "", "", "" },
+
+ { "http://blah/{searchTerms}?q={searchTerms}",
+ "", url::Parsed::QUERY, "", "", "", "" },
+
+ { "http://blah/{searchTerms}#x={searchTerms}",
+ "", url::Parsed::QUERY, "", "", "", "" },
+
+ // Fixed prefixes and suffixes in query or ref.
+ { "http://blah/?q=stock:{searchTerms}",
+ "blah", url::Parsed::QUERY, "/", "q", "stock:", ""},
+
+ { "http://www.example.com/?q=chromium-{searchTerms}@chromium.org",
+ "www.example.com", url::Parsed::QUERY, "/", "q", "chromium-",
+ "@chromium.org" },
+
+ { "http://www.example.com/#q=chromium-{searchTerms}@chromium.org",
+ "www.example.com", url::Parsed::REF, "/", "q", "chromium-",
+ "@chromium.org" },
+
+ { "http://www.example.com/chromium-{searchTerms}@chromium.org/info",
+ "www.example.com", url::Parsed::PATH, "/chromium-@chromium.org/info",
+ "", "/chromium-", "@chromium.org/info" },
};
for (size_t i = 0; i < arraysize(test_data); ++i) {
TemplateURLData data;
data.SetURL(test_data[i].url);
TemplateURL url(data);
+ const TemplateURLRef& url_ref = url.url_ref();
+ EXPECT_EQ(test_data[i].host, url_ref.GetHost(search_terms_data_));
EXPECT_EQ(test_data[i].location,
- url.url_ref().GetSearchTermKeyLocation(search_terms_data_));
- EXPECT_EQ(test_data[i].path,
- url.url_ref().GetPath(search_terms_data_));
- EXPECT_EQ(test_data[i].position_in_path,
- url.url_ref().GetSearchTermPositionInPath(search_terms_data_));
+ url_ref.GetSearchTermKeyLocation(search_terms_data_));
+ EXPECT_EQ(test_data[i].path, url_ref.GetPath(search_terms_data_));
+ EXPECT_EQ(test_data[i].search_term_key,
+ url_ref.GetSearchTermKey(search_terms_data_));
+ EXPECT_EQ(test_data[i].search_term_value_prefix,
+ url_ref.GetSearchTermValuePrefix(search_terms_data_));
+ EXPECT_EQ(test_data[i].search_term_value_suffix,
+ url_ref.GetSearchTermValueSuffix(search_terms_data_));
}
}
« 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