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

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: Addressed comments. 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 d20dadd3dd3760e2637fb647fa7d586231a778d1..c35bdda06bc7c4a67afb8a4ac5f0f670a6c2cfe3 100644
--- a/chrome/browser/search/search_unittest.cc
+++ b/chrome/browser/search/search_unittest.cc
@@ -776,6 +776,56 @@ TEST_F(SearchTest, GetSearchResultPrefetchBaseURL) {
GetSearchResultPrefetchBaseURL(profile()));
}
+struct SearchURLTestCase {
+ 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 {
+ const char* url;
+ bool expected_result;
+ const char* comment;
+};
+
+TEST_F(SearchTest, IsSuitableForInstant) {
Jered 2014/02/11 23:33:28 Update this test case?
kmadhusu 2014/02/12 00:24:57 Oops. Fixed.
+ 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::IsSuitableURLForInstant(profile(), GURL(test.url)))
+ << test.url << " " << test.comment;
+ }
+}
+
typedef SearchTest IsQueryExtractionEnabledTest;
TEST_F(IsQueryExtractionEnabledTest, NotSet) {

Powered by Google App Engine
This is Rietveld 408576698