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

Unified Diff: chrome/browser/search/search_unittest.cc

Issue 141893009: Create a new helper function to extract search terms from the URL irrespective of the availablility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 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/search.cc ('k') | chrome/browser/ui/browser_instant_controller.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/search_unittest.cc
diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc
index d1104eafffe999a328acf9f1daf7af4b72949351..db21ba53203a2e9ccee4455d663d41b971b67668 100644
--- a/chrome/browser/search/search_unittest.cc
+++ b/chrome/browser/search/search_unittest.cc
@@ -800,6 +800,56 @@ TEST_F(SearchTest, GetSearchResultPrefetchBaseURL) {
GetSearchResultPrefetchBaseURL(profile()));
}
+struct ExtractSearchTermsTestCase {
+ const char* url;
+ const char* expected_result;
+ const char* comment;
+};
+
+TEST_F(SearchTest, ExtractSearchTermsFromURL) {
+ const ExtractSearchTermsTestCase kTestCases[] = {
+ {chrome::kChromeSearchLocalNtpUrl, "", "NTP url"},
+ {"https://foo.com/instant?strk", "", "Invalid search url"},
+ {"https://foo.com/instant#strk", "", "Invalid search url"},
+ {"https://foo.com/alt#quux=foo", "foo", "Valid search url"},
+ {"https://foo.com/alt#quux=foo&strk", "foo", "Valid search url"}
+ };
+
+ for (size_t i = 0; i < arraysize(kTestCases); ++i) {
+ const ExtractSearchTermsTestCase& test = kTestCases[i];
+ EXPECT_EQ(
+ test.expected_result,
+ UTF16ToASCII(chrome::ExtractSearchTermsFromURL(profile(),
+ GURL(test.url))))
+ << test.url << " " << test.comment;
+ }
+}
+
+struct QueryExtractionAllowedTestCase {
+ const char* url;
+ bool expected_result;
+ const char* comment;
+};
+
+TEST_F(SearchTest, IsQueryExtractionAllowedForURL) {
+ const QueryExtractionAllowedTestCase kTestCases[] = {
+ {"http://foo.com/instant?strk", false, "HTTP URL"},
+ {"https://foo.com/instant?strk", true, "Valid URL"},
+ {"https://foo.com/instant?", false,
+ "No search terms replacement key"},
+ {"https://foo.com/alt#quux=foo", false,
+ "No search terms replacement key"},
+ {"https://foo.com/alt#quux=foo&strk", true, "Valid search url"}
+ };
+
+ for (size_t i = 0; i < arraysize(kTestCases); ++i) {
+ const QueryExtractionAllowedTestCase& test = kTestCases[i];
+ EXPECT_EQ(test.expected_result,
+ chrome::IsQueryExtractionAllowedForURL(profile(), GURL(test.url)))
+ << test.url << " " << test.comment;
+ }
+}
+
class SearchURLTest : public SearchTest {
protected:
virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url)
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/ui/browser_instant_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698