[omnibox] Add GOOGLE_OMNIBOX_FOCUS_TYPE replacement to TemplateURL
This adds the oft= parameter for the google.com TemplateURL.
The parameter is omitted unless oft=1 for ON_FOCUS specifically.
It also adds a unit test.
Bug: 963173
Change-Id: I07f1236275605c603bc63567b738abd3efc757a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1669912
Commit-Queue: Tommy Li <[email protected]>
Reviewed-by: Mark Pearson <[email protected]>
Cr-Commit-Position: refs/heads/master@{#673052}
diff --git a/components/search_engines/template_url_unittest.cc b/components/search_engines/template_url_unittest.cc
index b4a4c96..a19a834 100644
--- a/components/search_engines/template_url_unittest.cc
+++ b/components/search_engines/template_url_unittest.cc
@@ -732,6 +732,39 @@
}
}
+// Tests replacing omnibox focus type (&oft=).
+TEST_F(TemplateURLTest, ReplaceOmniboxFocusType) {
+ struct TestData {
+ const base::string16 search_term;
+ TemplateURLRef::SearchTermsArgs::OmniboxFocusType omnibox_focus_type;
+ const std::string url;
+ const std::string expected_result;
+ } test_data[] = {
+ {ASCIIToUTF16("foo"),
+ TemplateURLRef::SearchTermsArgs::OmniboxFocusType::DEFAULT,
+ "{google:baseURL}?{searchTerms}&{google:omniboxFocusType}",
+ "http://www.google.com/?foo&"},
+ {ASCIIToUTF16("foo"),
+ TemplateURLRef::SearchTermsArgs::OmniboxFocusType::ON_FOCUS,
+ "{google:baseURL}?{searchTerms}&{google:omniboxFocusType}",
+ "http://www.google.com/?foo&oft=1&"},
+ };
+ TemplateURLData data;
+ data.input_encodings.push_back("UTF-8");
+ for (size_t i = 0; i < base::size(test_data); ++i) {
+ data.SetURL(test_data[i].url);
+ TemplateURL url(data);
+ EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
+ ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
+ TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
+ search_terms_args.omnibox_focus_type = test_data[i].omnibox_focus_type;
+ GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
+ search_terms_data_));
+ ASSERT_TRUE(result.is_valid());
+ EXPECT_EQ(test_data[i].expected_result, result.spec());
+ }
+}
+
// Tests replacing currentPageUrl.
TEST_F(TemplateURLTest, ReplaceCurrentPageUrl) {
struct TestData {