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

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
Index: chrome/browser/search/search_unittest.cc
diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc
index 94aae245412189d23b1242ba5ce734250c3ba3df..2831c7f66e02acd511603c5d0a7b5fd2b430f0fd 100644
--- a/chrome/browser/search/search_unittest.cc
+++ b/chrome/browser/search/search_unittest.cc
@@ -799,6 +799,56 @@ TEST_F(SearchTest, GetSearchResultPrefetchBaseURL) {
GetSearchResultPrefetchBaseURL(profile()));
}
+struct SearchURLTestCase {
samarth 2014/02/12 18:02:39 s/SearchURLTestCase/ExtractSearchTermsTestCase/
kmadhusu 2014/02/12 19:58:09 Done.
+ const char* url;
+ const char* expected_result;
+ const char* comment;
+};
+
+TEST_F(SearchTest, ExtractSearchTermsFromURL) {
+ const SearchURLTestCase 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 SearchURLTestCase& test = kTestCases[i];
+ EXPECT_EQ(
+ test.expected_result,
+ UTF16ToASCII(chrome::ExtractSearchTermsFromURL(profile(),
+ GURL(test.url))))
+ << test.url << " " << test.comment;
+ }
+}
+
+struct InstantURLTestCase {
samarth 2014/02/12 18:02:39 QueryExtractionAllowedTestCase
kmadhusu 2014/02/12 19:58:09 Done.
+ const char* url;
+ bool expected_result;
+ const char* comment;
+};
+
+TEST_F(SearchTest, IsQueryExtractionAllowedForURL) {
+ const InstantURLTestCase 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 InstantURLTestCase& test = kTestCases[i];
+ EXPECT_EQ(test.expected_result,
+ chrome::IsQueryExtractionAllowedForURL(profile(), GURL(test.url)))
+ << test.url << " " << test.comment;
+ }
+}
+
typedef SearchTest IsQueryExtractionEnabledTest;
TEST_F(IsQueryExtractionEnabledTest, NotSet) {

Powered by Google App Engine
This is Rietveld 408576698