blob: 0474033d015349ec6034bfa934f696b75890cca8 [file] [log] [blame]
[email protected]63f021882014-07-11 03:14:161// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]d82443b2009-01-15 19:54:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]12bd05872009-03-17 19:25:065#include "base/base_paths.h"
[email protected]56fa29592013-07-02 20:25:536#include "base/command_line.h"
[email protected]2f3bc6512013-08-28 03:56:277#include "base/strings/string_number_conversions.h"
[email protected]24a555b62013-06-10 22:01:178#include "base/strings/string_util.h"
[email protected]e309f312013-06-07 21:50:089#include "base/strings/utf_string_conversions.h"
[email protected]332d17d22014-06-20 16:56:0310#include "components/metrics/proto/omnibox_event.pb.h"
[email protected]420472b22014-06-10 13:34:4311#include "components/metrics/proto/omnibox_input_type.pb.h"
[email protected]5c3c6e482014-06-23 09:47:1812#include "components/search_engines/search_engines_switches.h"
[email protected]798baa8e2014-06-20 05:42:4413#include "components/search_engines/search_terms_data.h"
[email protected]d550cb02014-06-25 06:48:1114#include "components/search_engines/template_url.h"
[email protected]d82443b2009-01-15 19:54:5615#include "testing/gtest/include/gtest/gtest.h"
16
[email protected]f911df52013-12-24 23:24:2317using base::ASCIIToUTF16;
18
[email protected]b37bdfe2012-03-16 20:53:2719// TestSearchTermsData --------------------------------------------------------
20
[email protected]375bd7312010-08-30 22:18:1321// Simple implementation of SearchTermsData.
22class TestSearchTermsData : public SearchTermsData {
23 public:
[email protected]b37bdfe2012-03-16 20:53:2724 explicit TestSearchTermsData(const std::string& google_base_url);
[email protected]375bd7312010-08-30 22:18:1325
[email protected]b37bdfe2012-03-16 20:53:2726 virtual std::string GoogleBaseURLValue() const OVERRIDE;
[email protected]798baa8e2014-06-20 05:42:4427 virtual base::string16 GetRlzParameterValue(
28 bool from_app_list) const OVERRIDE;
29 virtual std::string GetSearchClient() const OVERRIDE;
[email protected]1020fead2014-06-20 13:40:2830 virtual std::string GoogleImageSearchSource() const OVERRIDE;
[email protected]5c3c6e482014-06-23 09:47:1831 virtual bool EnableAnswersInSuggest() const OVERRIDE;
32 virtual bool IsShowingSearchTermsOnSearchResultsPages() const OVERRIDE;
[email protected]1d7727e2014-07-23 07:04:4333 virtual int OmniboxStartMargin() const OVERRIDE;
[email protected]798baa8e2014-06-20 05:42:4434
35 void set_google_base_url(const std::string& google_base_url) {
36 google_base_url_ = google_base_url;
37 }
38 void set_search_client(const std::string& search_client) {
39 search_client_ = search_client;
40 }
[email protected]5c3c6e482014-06-23 09:47:1841 void set_enable_answers_in_suggest(bool enable_answers_in_suggest) {
42 enable_answers_in_suggest_ = enable_answers_in_suggest;
43 }
44 void set_is_showing_search_terms_on_search_results_pages(bool value) {
45 is_showing_search_terms_on_search_results_pages_ = value;
46 }
[email protected]1d7727e2014-07-23 07:04:4347 void set_omnibox_start_margin(int omnibox_start_margin) {
48 omnibox_start_margin_ = omnibox_start_margin;
49 }
[email protected]375bd7312010-08-30 22:18:1350
51 private:
52 std::string google_base_url_;
[email protected]798baa8e2014-06-20 05:42:4453 std::string search_client_;
[email protected]5c3c6e482014-06-23 09:47:1854 bool enable_answers_in_suggest_;
55 bool is_showing_search_terms_on_search_results_pages_;
[email protected]1d7727e2014-07-23 07:04:4356 int omnibox_start_margin_;
[email protected]375bd7312010-08-30 22:18:1357
58 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData);
59};
60
[email protected]b37bdfe2012-03-16 20:53:2761TestSearchTermsData::TestSearchTermsData(const std::string& google_base_url)
[email protected]5c3c6e482014-06-23 09:47:1862 : google_base_url_(google_base_url),
63 enable_answers_in_suggest_(false),
64 is_showing_search_terms_on_search_results_pages_(false) {
[email protected]b37bdfe2012-03-16 20:53:2765}
66
67std::string TestSearchTermsData::GoogleBaseURLValue() const {
68 return google_base_url_;
69}
70
[email protected]798baa8e2014-06-20 05:42:4471base::string16 TestSearchTermsData::GetRlzParameterValue(
72 bool from_app_list) const {
73 return ASCIIToUTF16(
74 from_app_list ? "rlz_parameter_from_app_list" : "rlz_parameter");
75}
76
77std::string TestSearchTermsData::GetSearchClient() const {
78 return search_client_;
79}
80
[email protected]1020fead2014-06-20 13:40:2881std::string TestSearchTermsData::GoogleImageSearchSource() const {
82 return "google_image_search_source";
83}
84
[email protected]5c3c6e482014-06-23 09:47:1885bool TestSearchTermsData::EnableAnswersInSuggest() const {
86 return enable_answers_in_suggest_;
87}
88
89bool TestSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const {
90 return is_showing_search_terms_on_search_results_pages_;
91}
92
[email protected]1d7727e2014-07-23 07:04:4393int TestSearchTermsData::OmniboxStartMargin() const {
94 return omnibox_start_margin_;
95}
96
[email protected]b37bdfe2012-03-16 20:53:2797// TemplateURLTest ------------------------------------------------------------
98
[email protected]583844c2011-08-27 00:38:3599class TemplateURLTest : public testing::Test {
[email protected]d82443b2009-01-15 19:54:56100 public:
[email protected]798baa8e2014-06-20 05:42:44101 TemplateURLTest() : search_terms_data_("http://www.google.com/") {}
[email protected]b37bdfe2012-03-16 20:53:27102 void CheckSuggestBaseURL(const std::string& base_url,
103 const std::string& base_suggest_url) const;
[email protected]ce7ee5f2014-06-16 23:41:19104
[email protected]798baa8e2014-06-20 05:42:44105 TestSearchTermsData search_terms_data_;
[email protected]d82443b2009-01-15 19:54:56106};
107
[email protected]b37bdfe2012-03-16 20:53:27108void TemplateURLTest::CheckSuggestBaseURL(
109 const std::string& base_url,
110 const std::string& base_suggest_url) const {
111 TestSearchTermsData search_terms_data(base_url);
112 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue());
113}
114
115
116// Actual tests ---------------------------------------------------------------
117
[email protected]d82443b2009-01-15 19:54:56118TEST_F(TemplateURLTest, Defaults) {
[email protected]573889f22012-04-07 01:31:54119 TemplateURLData data;
120 EXPECT_FALSE(data.show_in_default_list);
121 EXPECT_FALSE(data.safe_for_autoreplace);
122 EXPECT_EQ(0, data.prepopulate_id);
[email protected]d82443b2009-01-15 19:54:56123}
124
125TEST_F(TemplateURLTest, TestValidWithComplete) {
[email protected]573889f22012-04-07 01:31:54126 TemplateURLData data;
127 data.SetURL("{searchTerms}");
[email protected]168d08722014-06-18 07:13:28128 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19129 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56130}
131
132TEST_F(TemplateURLTest, URLRefTestSearchTerms) {
[email protected]0d2e6a62010-01-15 20:09:19133 struct SearchTermsCase {
[email protected]ddd231e2010-06-29 20:35:19134 const char* url;
[email protected]0085863a2013-12-06 21:19:03135 const base::string16 terms;
[email protected]34e24852012-01-31 18:43:58136 const std::string output;
[email protected]0d2e6a62010-01-15 20:09:19137 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:30138 { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:16139 "http://foosea%20rch/bar" },
[email protected]400b133f2011-01-19 18:32:30140 { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:16141 "http://foosea%20rch/bar?boo=abc" },
[email protected]400b133f2011-01-19 18:32:30142 { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:16143 "http://foo/?boo=sea+rch%2Fbar" },
[email protected]400b133f2011-01-19 18:32:30144 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"),
[email protected]c31a979c2012-05-31 23:57:16145 "http://en.wikipedia.org/wiki/%3F" }
[email protected]0d2e6a62010-01-15 20:09:19146 };
147 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
148 const SearchTermsCase& value = search_term_cases[i];
[email protected]573889f22012-04-07 01:31:54149 TemplateURLData data;
150 data.SetURL(value.url);
[email protected]168d08722014-06-18 07:13:28151 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19152 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
153 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04154 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19155 TemplateURLRef::SearchTermsArgs(value.terms), search_terms_data_));
[email protected]c31a979c2012-05-31 23:57:16156 ASSERT_TRUE(result.is_valid());
157 EXPECT_EQ(value.output, result.spec());
[email protected]0d2e6a62010-01-15 20:09:19158 }
[email protected]d82443b2009-01-15 19:54:56159}
160
161TEST_F(TemplateURLTest, URLRefTestCount) {
[email protected]573889f22012-04-07 01:31:54162 TemplateURLData data;
163 data.SetURL("http://foo{searchTerms}{count?}");
[email protected]168d08722014-06-18 07:13:28164 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19165 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
166 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04167 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19168 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X")), search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56169 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27170 EXPECT_EQ("http://foox/", result.spec());
[email protected]d82443b2009-01-15 19:54:56171}
172
173TEST_F(TemplateURLTest, URLRefTestCount2) {
[email protected]573889f22012-04-07 01:31:54174 TemplateURLData data;
175 data.SetURL("http://foo{searchTerms}{count}");
[email protected]168d08722014-06-18 07:13:28176 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19177 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
178 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04179 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19180 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X")), search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56181 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27182 EXPECT_EQ("http://foox10/", result.spec());
[email protected]d82443b2009-01-15 19:54:56183}
184
185TEST_F(TemplateURLTest, URLRefTestIndices) {
[email protected]573889f22012-04-07 01:31:54186 TemplateURLData data;
187 data.SetURL("http://foo{searchTerms}x{startIndex?}y{startPage?}");
[email protected]168d08722014-06-18 07:13:28188 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19189 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
190 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04191 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19192 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X")), search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56193 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27194 EXPECT_EQ("http://fooxxy/", result.spec());
[email protected]d82443b2009-01-15 19:54:56195}
196
197TEST_F(TemplateURLTest, URLRefTestIndices2) {
[email protected]573889f22012-04-07 01:31:54198 TemplateURLData data;
199 data.SetURL("http://foo{searchTerms}x{startIndex}y{startPage}");
[email protected]168d08722014-06-18 07:13:28200 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19201 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
202 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04203 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19204 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X")), search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56205 ASSERT_TRUE(result.is_valid());
[email protected]405aae22012-03-29 20:36:13206 EXPECT_EQ("http://fooxx1y1/", result.spec());
[email protected]d82443b2009-01-15 19:54:56207}
208
209TEST_F(TemplateURLTest, URLRefTestEncoding) {
[email protected]573889f22012-04-07 01:31:54210 TemplateURLData data;
211 data.SetURL("http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a");
[email protected]168d08722014-06-18 07:13:28212 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19213 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
214 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04215 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19216 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X")), search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56217 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27218 EXPECT_EQ("http://fooxxutf-8ya/", result.spec());
[email protected]d82443b2009-01-15 19:54:56219}
220
[email protected]93b29062013-07-12 03:09:09221TEST_F(TemplateURLTest, URLRefTestImageURLWithPOST) {
222 const char kInvalidPostParamsString[] =
223 "unknown_template={UnknownTemplate},bad_value=bad{value},"
224 "{google:sbiSource}";
225 // List all accpectable parameter format in valid_post_params_string. it is
226 // expected like: "name0=,name1=value1,name2={template1}"
227 const char kValidPostParamsString[] =
228 "image_content={google:imageThumbnail},image_url={google:imageURL},"
229 "sbisrc={google:imageSearchSource},language={language},empty_param=,"
[email protected]2f3bc6512013-08-28 03:56:27230 "constant_param=constant,width={google:imageOriginalWidth}";
[email protected]93b29062013-07-12 03:09:09231 const char KImageSearchURL[] = "http://foo.com/sbi";
232
233 TemplateURLData data;
234 data.image_url = KImageSearchURL;
235
236 // Try to parse invalid post parameters.
237 data.image_url_post_params = kInvalidPostParamsString;
[email protected]168d08722014-06-18 07:13:28238 TemplateURL url_bad(data);
[email protected]ce7ee5f2014-06-16 23:41:19239 ASSERT_FALSE(url_bad.image_url_ref().IsValid(search_terms_data_));
[email protected]93b29062013-07-12 03:09:09240 const TemplateURLRef::PostParams& bad_post_params =
241 url_bad.image_url_ref().post_params_;
242 ASSERT_EQ(2U, bad_post_params.size());
243 EXPECT_EQ("unknown_template", bad_post_params[0].first);
244 EXPECT_EQ("{UnknownTemplate}", bad_post_params[0].second);
245 EXPECT_EQ("bad_value", bad_post_params[1].first);
246 EXPECT_EQ("bad{value}", bad_post_params[1].second);
247
248 // Try to parse valid post parameters.
249 data.image_url_post_params = kValidPostParamsString;
[email protected]168d08722014-06-18 07:13:28250 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19251 ASSERT_TRUE(url.image_url_ref().IsValid(search_terms_data_));
252 ASSERT_FALSE(url.image_url_ref().SupportsReplacement(search_terms_data_));
[email protected]93b29062013-07-12 03:09:09253
254 // Check term replacement.
255 TemplateURLRef::SearchTermsArgs search_args(ASCIIToUTF16("X"));
256 search_args.image_thumbnail_content = "dummy-image-thumbnail";
257 search_args.image_url = GURL("http://dummyimage.com/dummy.jpg");
[email protected]2f3bc6512013-08-28 03:56:27258 search_args.image_original_size = gfx::Size(10, 10);
[email protected]93b29062013-07-12 03:09:09259 // Replacement operation with no post_data buffer should still return
260 // the parsed URL.
[email protected]ce7ee5f2014-06-16 23:41:19261 TestSearchTermsData search_terms_data("http://X");
262 GURL result(url.image_url_ref().ReplaceSearchTerms(
263 search_args, search_terms_data));
[email protected]93b29062013-07-12 03:09:09264 ASSERT_TRUE(result.is_valid());
265 EXPECT_EQ(KImageSearchURL, result.spec());
[email protected]7c2bcc42013-08-01 04:03:48266 TemplateURLRef::PostContent post_content;
[email protected]ce7ee5f2014-06-16 23:41:19267 result = GURL(url.image_url_ref().ReplaceSearchTerms(
[email protected]7c2bcc42013-08-01 04:03:48268 search_args, search_terms_data, &post_content));
[email protected]93b29062013-07-12 03:09:09269 ASSERT_TRUE(result.is_valid());
270 EXPECT_EQ(KImageSearchURL, result.spec());
[email protected]7c2bcc42013-08-01 04:03:48271 ASSERT_FALSE(post_content.first.empty());
272 ASSERT_FALSE(post_content.second.empty());
[email protected]93b29062013-07-12 03:09:09273
274 // Check parsed result of post parameters.
275 const TemplateURLRef::Replacements& replacements =
276 url.image_url_ref().replacements_;
277 const TemplateURLRef::PostParams& post_params =
278 url.image_url_ref().post_params_;
[email protected]2f3bc6512013-08-28 03:56:27279 EXPECT_EQ(7U, post_params.size());
[email protected]93b29062013-07-12 03:09:09280 for (TemplateURLRef::PostParams::const_iterator i = post_params.begin();
281 i != post_params.end(); ++i) {
282 TemplateURLRef::Replacements::const_iterator j = replacements.begin();
283 for (; j != replacements.end(); ++j) {
284 if (j->is_post_param && j->index ==
285 static_cast<size_t>(i - post_params.begin())) {
286 switch (j->type) {
[email protected]2f3bc6512013-08-28 03:56:27287 case TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_WIDTH:
288 EXPECT_EQ("width", i->first);
289 EXPECT_EQ(
290 base::IntToString(search_args.image_original_size.width()),
291 i->second);
292 break;
[email protected]1020fead2014-06-20 13:40:28293 case TemplateURLRef::GOOGLE_IMAGE_SEARCH_SOURCE:
294 EXPECT_EQ("sbisrc", i->first);
295 EXPECT_EQ(search_terms_data.GoogleImageSearchSource(), i->second);
296 break;
[email protected]93b29062013-07-12 03:09:09297 case TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL:
298 EXPECT_EQ("image_content", i->first);
299 EXPECT_EQ(search_args.image_thumbnail_content, i->second);
300 break;
301 case TemplateURLRef::GOOGLE_IMAGE_URL:
302 EXPECT_EQ("image_url", i->first);
303 EXPECT_EQ(search_args.image_url.spec(), i->second);
304 break;
305 case TemplateURLRef::LANGUAGE:
306 EXPECT_EQ("language", i->first);
307 EXPECT_EQ("en", i->second);
308 break;
309 default:
310 ADD_FAILURE(); // Should never go here.
311 }
312 break;
313 }
314 }
315 if (j != replacements.end())
316 continue;
317 if (i->first == "empty_param") {
318 EXPECT_TRUE(i->second.empty());
319 } else if (i->first == "sbisrc") {
[email protected]7c2bcc42013-08-01 04:03:48320 EXPECT_FALSE(i->second.empty());
[email protected]93b29062013-07-12 03:09:09321 } else {
322 EXPECT_EQ("constant_param", i->first);
323 EXPECT_EQ("constant", i->second);
324 }
325 }
326}
327
[email protected]d88cb202011-08-17 20:03:01328// Test that setting the prepopulate ID from TemplateURL causes the stored
329// TemplateURLRef to handle parsing the URL parameters differently.
[email protected]1a257262011-06-28 22:15:44330TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
[email protected]573889f22012-04-07 01:31:54331 TemplateURLData data;
[email protected]243abf32012-05-15 18:28:20332 data.SetURL("http://foo{fhqwhgads}bar");
[email protected]168d08722014-06-18 07:13:28333 TemplateURL url(data);
[email protected]1a257262011-06-28 22:15:44334 TemplateURLRef::Replacements replacements;
335 bool valid = false;
[email protected]243abf32012-05-15 18:28:20336 EXPECT_EQ("http://foo{fhqwhgads}bar", url.url_ref().ParseURL(
[email protected]93b29062013-07-12 03:09:09337 "http://foo{fhqwhgads}bar", &replacements, NULL, &valid));
[email protected]1a257262011-06-28 22:15:44338 EXPECT_TRUE(replacements.empty());
339 EXPECT_TRUE(valid);
340
[email protected]573889f22012-04-07 01:31:54341 data.prepopulate_id = 123;
[email protected]168d08722014-06-18 07:13:28342 TemplateURL url2(data);
[email protected]243abf32012-05-15 18:28:20343 EXPECT_EQ("http://foobar", url2.url_ref().ParseURL("http://foo{fhqwhgads}bar",
[email protected]93b29062013-07-12 03:09:09344 &replacements, NULL,
345 &valid));
[email protected]1a257262011-06-28 22:15:44346 EXPECT_TRUE(replacements.empty());
347 EXPECT_TRUE(valid);
348}
349
[email protected]d82443b2009-01-15 19:54:56350TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
[email protected]573889f22012-04-07 01:31:54351 TemplateURLData data;
352 data.SetURL("http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b");
[email protected]168d08722014-06-18 07:13:28353 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19354 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
355 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04356 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19357 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X")), search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56358 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27359 EXPECT_EQ("http://fooxutf-8axyb/", result.spec());
[email protected]d82443b2009-01-15 19:54:56360}
361
362TEST_F(TemplateURLTest, URLRefTestEncoding2) {
[email protected]573889f22012-04-07 01:31:54363 TemplateURLData data;
364 data.SetURL("http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a");
[email protected]168d08722014-06-18 07:13:28365 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19366 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
367 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04368 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19369 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X")), search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56370 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27371 EXPECT_EQ("http://fooxxutf-8yutf-8a/", result.spec());
[email protected]d82443b2009-01-15 19:54:56372}
373
[email protected]375bd7312010-08-30 22:18:13374TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) {
375 struct SearchTermsCase {
376 const char* url;
[email protected]0085863a2013-12-06 21:19:03377 const base::string16 terms;
[email protected]375bd7312010-08-30 22:18:13378 const char* output;
379 } search_term_cases[] = {
[email protected]0085863a2013-12-06 21:19:03380 { "{google:baseURL}{language}{searchTerms}", base::string16(),
[email protected]b37bdfe2012-03-16 20:53:27381 "http://example.com/e/en" },
[email protected]0085863a2013-12-06 21:19:03382 { "{google:baseSuggestURL}{searchTerms}", base::string16(),
[email protected]014010e2011-10-01 04:12:44383 "http://example.com/complete/" }
[email protected]375bd7312010-08-30 22:18:13384 };
385
386 TestSearchTermsData search_terms_data("http://example.com/e/");
[email protected]573889f22012-04-07 01:31:54387 TemplateURLData data;
[email protected]375bd7312010-08-30 22:18:13388 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
389 const SearchTermsCase& value = search_term_cases[i];
[email protected]573889f22012-04-07 01:31:54390 data.SetURL(value.url);
[email protected]168d08722014-06-18 07:13:28391 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19392 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data));
393 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data));
394 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]93b29062013-07-12 03:09:09395 TemplateURLRef::SearchTermsArgs(value.terms), search_terms_data, NULL));
[email protected]375bd7312010-08-30 22:18:13396 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27397 EXPECT_EQ(value.output, result.spec());
[email protected]375bd7312010-08-30 22:18:13398 }
399}
400
[email protected]d82443b2009-01-15 19:54:56401TEST_F(TemplateURLTest, URLRefTermToWide) {
402 struct ToWideCase {
403 const char* encoded_search_term;
[email protected]0085863a2013-12-06 21:19:03404 const base::string16 expected_decoded_term;
[email protected]d82443b2009-01-15 19:54:56405 } to_wide_cases[] = {
[email protected]400b133f2011-01-19 18:32:30406 {"hello+world", ASCIIToUTF16("hello world")},
[email protected]d82443b2009-01-15 19:54:56407 // Test some big-5 input.
[email protected]f911df52013-12-24 23:24:23408 {"%a7A%A6%6e+to+you", base::WideToUTF16(L"\x4f60\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56409 // Test some UTF-8 input. We should fall back to this when the encoding
410 // doesn't look like big-5. We have a '5' in the middle, which is an invalid
411 // Big-5 trailing byte.
[email protected]f911df52013-12-24 23:24:23412 {"%e4%bd%a05%e5%a5%bd+to+you",
413 base::WideToUTF16(L"\x4f60\x35\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56414 // Undecodable input should stay escaped.
[email protected]f911df52013-12-24 23:24:23415 {"%91%01+abcd", base::WideToUTF16(L"%91%01 abcd")},
[email protected]7df43482009-07-31 19:37:44416 // Make sure we convert %2B to +.
[email protected]400b133f2011-01-19 18:32:30417 {"C%2B%2B", ASCIIToUTF16("C++")},
[email protected]7df43482009-07-31 19:37:44418 // C%2B is escaped as C%252B, make sure we unescape it properly.
[email protected]400b133f2011-01-19 18:32:30419 {"C%252B", ASCIIToUTF16("C%2B")},
[email protected]d82443b2009-01-15 19:54:56420 };
421
[email protected]d82443b2009-01-15 19:54:56422 // Set one input encoding: big-5. This is so we can test fallback to UTF-8.
[email protected]573889f22012-04-07 01:31:54423 TemplateURLData data;
424 data.SetURL("http://foo?q={searchTerms}");
425 data.input_encodings.push_back("big-5");
[email protected]168d08722014-06-18 07:13:28426 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19427 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
428 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]f63ae312009-02-04 17:58:46429 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) {
[email protected]9b74ab52012-03-30 16:08:07430 EXPECT_EQ(to_wide_cases[i].expected_decoded_term,
[email protected]360ba052012-04-04 17:26:13431 url.url_ref().SearchTermToString16(
432 to_wide_cases[i].encoded_search_term));
[email protected]d82443b2009-01-15 19:54:56433 }
434}
435
[email protected]d82443b2009-01-15 19:54:56436TEST_F(TemplateURLTest, DisplayURLToURLRef) {
437 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19438 const std::string url;
[email protected]0085863a2013-12-06 21:19:03439 const base::string16 expected_result;
[email protected]b37bdfe2012-03-16 20:53:27440 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19441 { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a",
[email protected]400b133f2011-01-19 18:32:30442 ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") },
[email protected]ddd231e2010-06-29 20:35:19443 { "http://X",
[email protected]400b133f2011-01-19 18:32:30444 ASCIIToUTF16("http://X") },
[email protected]ddd231e2010-06-29 20:35:19445 { "http://foo{searchTerms",
[email protected]400b133f2011-01-19 18:32:30446 ASCIIToUTF16("http://foo{searchTerms") },
[email protected]ddd231e2010-06-29 20:35:19447 { "http://foo{searchTerms}{language}",
[email protected]400b133f2011-01-19 18:32:30448 ASCIIToUTF16("http://foo%s{language}") },
[email protected]d82443b2009-01-15 19:54:56449 };
[email protected]573889f22012-04-07 01:31:54450 TemplateURLData data;
[email protected]b37bdfe2012-03-16 20:53:27451 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54452 data.SetURL(test_data[i].url);
[email protected]168d08722014-06-18 07:13:28453 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19454 EXPECT_EQ(test_data[i].expected_result,
455 url.url_ref().DisplayURL(search_terms_data_));
[email protected]b37bdfe2012-03-16 20:53:27456 EXPECT_EQ(test_data[i].url,
[email protected]ce7ee5f2014-06-16 23:41:19457 TemplateURLRef::DisplayURLToURLRef(
458 url.url_ref().DisplayURL(search_terms_data_)));
[email protected]d82443b2009-01-15 19:54:56459 }
460}
461
462TEST_F(TemplateURLTest, ReplaceSearchTerms) {
463 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19464 const std::string url;
[email protected]d82443b2009-01-15 19:54:56465 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27466 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19467 { "http://foo/{language}{searchTerms}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56468 "http://foo/{language}XUTF-8" },
[email protected]ddd231e2010-06-29 20:35:19469 { "http://foo/{language}{inputEncoding}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56470 "http://foo/{language}UTF-8X" },
[email protected]ddd231e2010-06-29 20:35:19471 { "http://foo/{searchTerms}{language}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56472 "http://foo/X{language}UTF-8" },
[email protected]ddd231e2010-06-29 20:35:19473 { "http://foo/{searchTerms}{inputEncoding}{language}",
[email protected]d82443b2009-01-15 19:54:56474 "http://foo/XUTF-8{language}" },
[email protected]ddd231e2010-06-29 20:35:19475 { "http://foo/{inputEncoding}{searchTerms}{language}",
[email protected]d82443b2009-01-15 19:54:56476 "http://foo/UTF-8X{language}" },
[email protected]ddd231e2010-06-29 20:35:19477 { "http://foo/{inputEncoding}{language}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56478 "http://foo/UTF-8{language}X" },
[email protected]ddd231e2010-06-29 20:35:19479 { "http://foo/{language}a{searchTerms}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56480 "http://foo/{language}aXaUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19481 { "http://foo/{language}a{inputEncoding}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56482 "http://foo/{language}aUTF-8aXa" },
[email protected]ddd231e2010-06-29 20:35:19483 { "http://foo/{searchTerms}a{language}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56484 "http://foo/Xa{language}aUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19485 { "http://foo/{searchTerms}a{inputEncoding}a{language}a",
[email protected]d82443b2009-01-15 19:54:56486 "http://foo/XaUTF-8a{language}a" },
[email protected]ddd231e2010-06-29 20:35:19487 { "http://foo/{inputEncoding}a{searchTerms}a{language}a",
[email protected]d82443b2009-01-15 19:54:56488 "http://foo/UTF-8aXa{language}a" },
[email protected]ddd231e2010-06-29 20:35:19489 { "http://foo/{inputEncoding}a{language}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56490 "http://foo/UTF-8a{language}aXa" },
491 };
[email protected]573889f22012-04-07 01:31:54492 TemplateURLData data;
493 data.input_encodings.push_back("UTF-8");
[email protected]b37bdfe2012-03-16 20:53:27494 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54495 data.SetURL(test_data[i].url);
[email protected]168d08722014-06-18 07:13:28496 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19497 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
498 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]b37bdfe2012-03-16 20:53:27499 std::string expected_result = test_data[i].expected_result;
[email protected]d82443b2009-01-15 19:54:56500 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}",
[email protected]798baa8e2014-06-20 05:42:44501 search_terms_data_.GetApplicationLocale());
[email protected]bca359b2012-06-24 07:53:04502 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19503 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X")),
504 search_terms_data_));
[email protected]b37bdfe2012-03-16 20:53:27505 ASSERT_TRUE(result.is_valid());
[email protected]d82443b2009-01-15 19:54:56506 EXPECT_EQ(expected_result, result.spec());
507 }
508}
509
510
511// Tests replacing search terms in various encodings and making sure the
512// generated URL matches the expected value.
513TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {
514 struct TestData {
515 const std::string encoding;
[email protected]0085863a2013-12-06 21:19:03516 const base::string16 search_term;
[email protected]ddd231e2010-06-29 20:35:19517 const std::string url;
[email protected]d82443b2009-01-15 19:54:56518 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27519 } test_data[] = {
[email protected]f911df52013-12-24 23:24:23520 { "BIG5", base::WideToUTF16(L"\x60BD"),
[email protected]400b133f2011-01-19 18:32:30521 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17522 "http://foo/?%B1~BIG5" },
[email protected]400b133f2011-01-19 18:32:30523 { "UTF-8", ASCIIToUTF16("blah"),
524 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17525 "http://foo/?blahUTF-8" },
[email protected]f911df52013-12-24 23:24:23526 { "Shift_JIS", base::UTF8ToUTF16("\xe3\x81\x82"),
[email protected]34e24852012-01-31 18:43:58527 "http://foo/{searchTerms}/bar",
528 "http://foo/%82%A0/bar"},
[email protected]f911df52013-12-24 23:24:23529 { "Shift_JIS", base::UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"),
[email protected]34e24852012-01-31 18:43:58530 "http://foo/{searchTerms}/bar",
531 "http://foo/%82%A0%20%82%A2/bar"},
[email protected]d82443b2009-01-15 19:54:56532 };
[email protected]573889f22012-04-07 01:31:54533 TemplateURLData data;
[email protected]b37bdfe2012-03-16 20:53:27534 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54535 data.SetURL(test_data[i].url);
536 data.input_encodings.clear();
537 data.input_encodings.push_back(test_data[i].encoding);
[email protected]168d08722014-06-18 07:13:28538 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19539 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
540 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04541 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19542 TemplateURLRef::SearchTermsArgs(test_data[i].search_term),
543 search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04544 ASSERT_TRUE(result.is_valid());
545 EXPECT_EQ(test_data[i].expected_result, result.spec());
546 }
547}
548
549// Tests replacing assisted query stats (AQS) in various scenarios.
550TEST_F(TemplateURLTest, ReplaceAssistedQueryStats) {
551 struct TestData {
[email protected]0085863a2013-12-06 21:19:03552 const base::string16 search_term;
[email protected]bca359b2012-06-24 07:53:04553 const std::string aqs;
554 const std::string base_url;
555 const std::string url;
556 const std::string expected_result;
557 } test_data[] = {
558 // No HTTPS, no AQS.
559 { ASCIIToUTF16("foo"),
560 "chrome.0.0l6",
561 "http://foo/",
562 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
563 "http://foo/?foo" },
564 // HTTPS available, AQS should be replaced.
565 { ASCIIToUTF16("foo"),
566 "chrome.0.0l6",
567 "https://foo/",
568 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
569 "https://foo/?fooaqs=chrome.0.0l6&" },
570 // HTTPS available, however AQS is empty.
571 { ASCIIToUTF16("foo"),
572 "",
573 "https://foo/",
574 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
575 "https://foo/?foo" },
576 // No {google:baseURL} and protocol is HTTP, we must not substitute AQS.
577 { ASCIIToUTF16("foo"),
578 "chrome.0.0l6",
[email protected]798baa8e2014-06-20 05:42:44579 "http://www.google.com",
[email protected]bca359b2012-06-24 07:53:04580 "http://foo?{searchTerms}{google:assistedQueryStats}",
581 "http://foo/?foo" },
582 // A non-Google search provider with HTTPS should allow AQS.
583 { ASCIIToUTF16("foo"),
584 "chrome.0.0l6",
[email protected]798baa8e2014-06-20 05:42:44585 "https://www.google.com",
[email protected]bca359b2012-06-24 07:53:04586 "https://foo?{searchTerms}{google:assistedQueryStats}",
587 "https://foo/?fooaqs=chrome.0.0l6&" },
588 };
589 TemplateURLData data;
590 data.input_encodings.push_back("UTF-8");
591 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
592 data.SetURL(test_data[i].url);
[email protected]168d08722014-06-18 07:13:28593 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19594 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
595 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04596 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
597 search_terms_args.assisted_query_stats = test_data[i].aqs;
[email protected]798baa8e2014-06-20 05:42:44598 search_terms_data_.set_google_base_url(test_data[i].base_url);
[email protected]ce7ee5f2014-06-16 23:41:19599 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
600 search_terms_data_));
[email protected]b37bdfe2012-03-16 20:53:27601 ASSERT_TRUE(result.is_valid());
602 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56603 }
604}
605
[email protected]00790562012-12-14 09:57:16606// Tests replacing cursor position.
607TEST_F(TemplateURLTest, ReplaceCursorPosition) {
608 struct TestData {
[email protected]0085863a2013-12-06 21:19:03609 const base::string16 search_term;
[email protected]00790562012-12-14 09:57:16610 size_t cursor_position;
611 const std::string url;
612 const std::string expected_result;
613 } test_data[] = {
614 { ASCIIToUTF16("foo"),
[email protected]0085863a2013-12-06 21:19:03615 base::string16::npos,
[email protected]00790562012-12-14 09:57:16616 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
617 "http://www.google.com/?foo&" },
618 { ASCIIToUTF16("foo"),
619 2,
620 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
621 "http://www.google.com/?foo&cp=2&" },
622 { ASCIIToUTF16("foo"),
623 15,
624 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
625 "http://www.google.com/?foo&cp=15&" },
626 };
627 TemplateURLData data;
628 data.input_encodings.push_back("UTF-8");
629 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
630 data.SetURL(test_data[i].url);
[email protected]168d08722014-06-18 07:13:28631 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19632 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
633 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]00790562012-12-14 09:57:16634 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
635 search_terms_args.cursor_position = test_data[i].cursor_position;
[email protected]ce7ee5f2014-06-16 23:41:19636 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
637 search_terms_data_));
[email protected]00790562012-12-14 09:57:16638 ASSERT_TRUE(result.is_valid());
639 EXPECT_EQ(test_data[i].expected_result, result.spec());
640 }
641}
642
[email protected]420472b22014-06-10 13:34:43643// Tests replacing input type (&oit=).
644TEST_F(TemplateURLTest, ReplaceInputType) {
645 struct TestData {
646 const base::string16 search_term;
[email protected]332d17d22014-06-20 16:56:03647 metrics::OmniboxInputType::Type input_type;
[email protected]420472b22014-06-10 13:34:43648 const std::string url;
649 const std::string expected_result;
650 } test_data[] = {
651 { ASCIIToUTF16("foo"),
652 metrics::OmniboxInputType::UNKNOWN,
653 "{google:baseURL}?{searchTerms}&{google:inputType}",
654 "http://www.google.com/?foo&oit=1&" },
655 { ASCIIToUTF16("foo"),
656 metrics::OmniboxInputType::URL,
657 "{google:baseURL}?{searchTerms}&{google:inputType}",
658 "http://www.google.com/?foo&oit=3&" },
659 { ASCIIToUTF16("foo"),
660 metrics::OmniboxInputType::FORCED_QUERY,
661 "{google:baseURL}?{searchTerms}&{google:inputType}",
662 "http://www.google.com/?foo&oit=5&" },
663 };
[email protected]420472b22014-06-10 13:34:43664 TemplateURLData data;
665 data.input_encodings.push_back("UTF-8");
666 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
667 data.SetURL(test_data[i].url);
[email protected]168d08722014-06-18 07:13:28668 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19669 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
670 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]420472b22014-06-10 13:34:43671 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
672 search_terms_args.input_type = test_data[i].input_type;
[email protected]ce7ee5f2014-06-16 23:41:19673 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
674 search_terms_data_));
[email protected]420472b22014-06-10 13:34:43675 ASSERT_TRUE(result.is_valid());
676 EXPECT_EQ(test_data[i].expected_result, result.spec());
677 }
678}
679
[email protected]9b9fa672013-11-07 06:04:52680// Tests replacing currentPageUrl.
681TEST_F(TemplateURLTest, ReplaceCurrentPageUrl) {
[email protected]800569d2013-05-06 07:38:48682 struct TestData {
[email protected]0085863a2013-12-06 21:19:03683 const base::string16 search_term;
[email protected]9b9fa672013-11-07 06:04:52684 const std::string current_page_url;
[email protected]800569d2013-05-06 07:38:48685 const std::string url;
686 const std::string expected_result;
687 } test_data[] = {
688 { ASCIIToUTF16("foo"),
689 "http://www.google.com/",
[email protected]9b9fa672013-11-07 06:04:52690 "{google:baseURL}?{searchTerms}&{google:currentPageUrl}",
[email protected]800569d2013-05-06 07:38:48691 "http://www.google.com/?foo&url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Fwww.google.com%2F&" },
692 { ASCIIToUTF16("foo"),
693 "",
[email protected]9b9fa672013-11-07 06:04:52694 "{google:baseURL}?{searchTerms}&{google:currentPageUrl}",
[email protected]800569d2013-05-06 07:38:48695 "http://www.google.com/?foo&" },
696 { ASCIIToUTF16("foo"),
697 "http://g.com/+-/*&=",
[email protected]9b9fa672013-11-07 06:04:52698 "{google:baseURL}?{searchTerms}&{google:currentPageUrl}",
[email protected]800569d2013-05-06 07:38:48699 "http://www.google.com/?foo&url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Fg.com%2F%2B-%2F*%26%3D&" },
700 };
701 TemplateURLData data;
702 data.input_encodings.push_back("UTF-8");
703 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
704 data.SetURL(test_data[i].url);
[email protected]168d08722014-06-18 07:13:28705 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19706 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
707 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]800569d2013-05-06 07:38:48708 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
[email protected]9b9fa672013-11-07 06:04:52709 search_terms_args.current_page_url = test_data[i].current_page_url;
[email protected]ce7ee5f2014-06-16 23:41:19710 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
711 search_terms_data_));
[email protected]800569d2013-05-06 07:38:48712 ASSERT_TRUE(result.is_valid());
713 EXPECT_EQ(test_data[i].expected_result, result.spec());
714 }
715}
716
[email protected]1d7727e2014-07-23 07:04:43717TEST_F(TemplateURLTest, OmniboxStartmargin) {
718 struct TestData {
719 const bool enable_omnibox_start_margin;
720 const int omnibox_start_margin;
721 const std::string expected_result;
722 } test_data[] = {
723 { false,
724 0,
725 "http://bar/foo?q=foobar" },
726 { true,
727 0,
728 "http://bar/foo?es_sm=0&q=foobar" },
729 { true,
730 42,
731 "http://bar/foo?es_sm=42&q=foobar" },
732 };
733 TemplateURLData data;
734 data.SetURL("http://bar/foo?{google:omniboxStartMarginParameter}"
735 "q={searchTerms}");
736 data.input_encodings.push_back("UTF-8");
737 TemplateURL url(data);
738 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
739 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
740 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
741 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foobar"));
742 search_terms_args.enable_omnibox_start_margin =
743 test_data[i].enable_omnibox_start_margin;
744 search_terms_data_.set_omnibox_start_margin(
745 test_data[i].omnibox_start_margin);
746 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
747 search_terms_data_));
748 ASSERT_TRUE(result.is_valid());
749 EXPECT_EQ(test_data[i].expected_result, result.spec());
750 }
751}
752
[email protected]d82443b2009-01-15 19:54:56753TEST_F(TemplateURLTest, Suggestions) {
754 struct TestData {
755 const int accepted_suggestion;
[email protected]0085863a2013-12-06 21:19:03756 const base::string16 original_query_for_suggestion;
[email protected]d82443b2009-01-15 19:54:56757 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27758 } test_data[] = {
[email protected]0085863a2013-12-06 21:19:03759 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, base::string16(),
[email protected]29653892013-03-02 19:25:37760 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30761 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"),
[email protected]29653892013-03-02 19:25:37762 "http://bar/foo?q=foobar" },
[email protected]0085863a2013-12-06 21:19:03763 { TemplateURLRef::NO_SUGGESTION_CHOSEN, base::string16(),
[email protected]29653892013-03-02 19:25:37764 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30765 { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"),
[email protected]29653892013-03-02 19:25:37766 "http://bar/foo?q=foobar" },
[email protected]0085863a2013-12-06 21:19:03767 { 0, base::string16(), "http://bar/foo?oq=&q=foobar" },
[email protected]29653892013-03-02 19:25:37768 { 1, ASCIIToUTF16("foo"), "http://bar/foo?oq=foo&q=foobar" },
[email protected]d82443b2009-01-15 19:54:56769 };
[email protected]573889f22012-04-07 01:31:54770 TemplateURLData data;
[email protected]29653892013-03-02 19:25:37771 data.SetURL("http://bar/foo?{google:originalQueryForSuggestion}"
772 "q={searchTerms}");
[email protected]573889f22012-04-07 01:31:54773 data.input_encodings.push_back("UTF-8");
[email protected]168d08722014-06-18 07:13:28774 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19775 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
776 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]b37bdfe2012-03-16 20:53:27777 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]bca359b2012-06-24 07:53:04778 TemplateURLRef::SearchTermsArgs search_terms_args(
779 ASCIIToUTF16("foobar"));
780 search_terms_args.accepted_suggestion = test_data[i].accepted_suggestion;
781 search_terms_args.original_query =
782 test_data[i].original_query_for_suggestion;
[email protected]ce7ee5f2014-06-16 23:41:19783 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
784 search_terms_data_));
[email protected]b37bdfe2012-03-16 20:53:27785 ASSERT_TRUE(result.is_valid());
786 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56787 }
788}
789
[email protected]81f808de2009-09-25 01:36:34790TEST_F(TemplateURLTest, RLZ) {
[email protected]798baa8e2014-06-20 05:42:44791 base::string16 rlz_string = search_terms_data_.GetRlzParameterValue(false);
[email protected]d82443b2009-01-15 19:54:56792
[email protected]573889f22012-04-07 01:31:54793 TemplateURLData data;
794 data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
[email protected]168d08722014-06-18 07:13:28795 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19796 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
797 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]bca359b2012-06-24 07:53:04798 GURL result(url.url_ref().ReplaceSearchTerms(
[email protected]ce7ee5f2014-06-16 23:41:19799 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")), search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56800 ASSERT_TRUE(result.is_valid());
[email protected]798baa8e2014-06-20 05:42:44801 EXPECT_EQ("http://bar/?rlz=" + base::UTF16ToUTF8(rlz_string) + "&x",
802 result.spec());
[email protected]d82443b2009-01-15 19:54:56803}
804
[email protected]c8ccc41d2014-04-10 04:42:12805TEST_F(TemplateURLTest, RLZFromAppList) {
[email protected]798baa8e2014-06-20 05:42:44806 base::string16 rlz_string = search_terms_data_.GetRlzParameterValue(true);
[email protected]c8ccc41d2014-04-10 04:42:12807
808 TemplateURLData data;
809 data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
[email protected]168d08722014-06-18 07:13:28810 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19811 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
812 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]c8ccc41d2014-04-10 04:42:12813 TemplateURLRef::SearchTermsArgs args(ASCIIToUTF16("x"));
814 args.from_app_list = true;
[email protected]ce7ee5f2014-06-16 23:41:19815 GURL result(url.url_ref().ReplaceSearchTerms(args, search_terms_data_));
[email protected]c8ccc41d2014-04-10 04:42:12816 ASSERT_TRUE(result.is_valid());
[email protected]798baa8e2014-06-20 05:42:44817 EXPECT_EQ("http://bar/?rlz=" + base::UTF16ToUTF8(rlz_string) + "&x",
818 result.spec());
[email protected]c8ccc41d2014-04-10 04:42:12819}
[email protected]c8ccc41d2014-04-10 04:42:12820
[email protected]d82443b2009-01-15 19:54:56821TEST_F(TemplateURLTest, HostAndSearchTermKey) {
822 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19823 const std::string url;
[email protected]d82443b2009-01-15 19:54:56824 const std::string host;
825 const std::string path;
826 const std::string search_term_key;
[email protected]573889f22012-04-07 01:31:54827 } test_data[] = {
[email protected]7c60f5042013-02-14 03:39:32828 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56829
830 // No query key should result in empty values.
[email protected]7c60f5042013-02-14 03:39:32831 { "http://blah/{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56832
833 // No term should result in empty values.
[email protected]7c60f5042013-02-14 03:39:32834 { "http://blah/", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56835
836 // Multiple terms should result in empty values.
[email protected]7c60f5042013-02-14 03:39:32837 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56838
839 // Term in the host shouldn't match.
[email protected]7c60f5042013-02-14 03:39:32840 { "http://{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56841
[email protected]7c60f5042013-02-14 03:39:32842 { "http://blah/?q={searchTerms}", "blah", "/", "q"},
843 { "https://blah/?q={searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56844
845 // Single term with extra chars in value should match.
[email protected]7c60f5042013-02-14 03:39:32846 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56847 };
848
[email protected]573889f22012-04-07 01:31:54849 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
850 TemplateURLData data;
851 data.SetURL(test_data[i].url);
[email protected]168d08722014-06-18 07:13:28852 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19853 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost(search_terms_data_));
854 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath(search_terms_data_));
855 EXPECT_EQ(test_data[i].search_term_key,
856 url.url_ref().GetSearchTermKey(search_terms_data_));
[email protected]d82443b2009-01-15 19:54:56857 }
858}
859
860TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {
861 static const struct {
[email protected]ddd231e2010-06-29 20:35:19862 const char* const base_url;
863 const char* const base_suggest_url;
[email protected]d82443b2009-01-15 19:54:56864 } data[] = {
[email protected]014010e2011-10-01 04:12:44865 { "http://google.com/", "http://google.com/complete/", },
866 { "http://www.google.com/", "http://www.google.com/complete/", },
867 { "http://www.google.co.uk/", "http://www.google.co.uk/complete/", },
868 { "http://www.google.com.by/", "http://www.google.com.by/complete/", },
869 { "http://google.com/intl/xx/", "http://google.com/complete/", },
[email protected]d82443b2009-01-15 19:54:56870 };
871
[email protected]f63ae312009-02-04 17:58:46872 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i)
[email protected]d82443b2009-01-15 19:54:56873 CheckSuggestBaseURL(data[i].base_url, data[i].base_suggest_url);
874}
875
[email protected]81c6ef62010-01-21 09:58:47876TEST_F(TemplateURLTest, ParseParameterKnown) {
[email protected]ddd231e2010-06-29 20:35:19877 std::string parsed_url("{searchTerms}");
[email protected]573889f22012-04-07 01:31:54878 TemplateURLData data;
879 data.SetURL(parsed_url);
[email protected]168d08722014-06-18 07:13:28880 TemplateURL url(data);
[email protected]81c6ef62010-01-21 09:58:47881 TemplateURLRef::Replacements replacements;
[email protected]360ba052012-04-04 17:26:13882 EXPECT_TRUE(url.url_ref().ParseParameter(0, 12, &parsed_url, &replacements));
[email protected]ddd231e2010-06-29 20:35:19883 EXPECT_EQ(std::string(), parsed_url);
[email protected]81c6ef62010-01-21 09:58:47884 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27885 EXPECT_EQ(0U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47886 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
887}
888
889TEST_F(TemplateURLTest, ParseParameterUnknown) {
[email protected]243abf32012-05-15 18:28:20890 std::string parsed_url("{fhqwhgads}abc");
[email protected]573889f22012-04-07 01:31:54891 TemplateURLData data;
892 data.SetURL(parsed_url);
[email protected]168d08722014-06-18 07:13:28893 TemplateURL url(data);
[email protected]81c6ef62010-01-21 09:58:47894 TemplateURLRef::Replacements replacements;
[email protected]1a257262011-06-28 22:15:44895
896 // By default, TemplateURLRef should not consider itself prepopulated.
897 // Therefore we should not replace the unknown parameter.
[email protected]360ba052012-04-04 17:26:13898 EXPECT_FALSE(url.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]243abf32012-05-15 18:28:20899 EXPECT_EQ("{fhqwhgads}abc", parsed_url);
[email protected]1a257262011-06-28 22:15:44900 EXPECT_TRUE(replacements.empty());
901
902 // If the TemplateURLRef is prepopulated, we should remove unknown parameters.
[email protected]243abf32012-05-15 18:28:20903 parsed_url = "{fhqwhgads}abc";
[email protected]573889f22012-04-07 01:31:54904 data.prepopulate_id = 1;
[email protected]168d08722014-06-18 07:13:28905 TemplateURL url2(data);
[email protected]495c30b2012-05-15 18:48:15906 EXPECT_TRUE(url2.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]243abf32012-05-15 18:28:20907 EXPECT_EQ("abc", parsed_url);
[email protected]81c6ef62010-01-21 09:58:47908 EXPECT_TRUE(replacements.empty());
909}
910
911TEST_F(TemplateURLTest, ParseURLEmpty) {
[email protected]168d08722014-06-18 07:13:28912 TemplateURL url((TemplateURLData()));
[email protected]81c6ef62010-01-21 09:58:47913 TemplateURLRef::Replacements replacements;
914 bool valid = false;
[email protected]b37bdfe2012-03-16 20:53:27915 EXPECT_EQ(std::string(),
[email protected]93b29062013-07-12 03:09:09916 url.url_ref().ParseURL(std::string(), &replacements, NULL, &valid));
[email protected]81c6ef62010-01-21 09:58:47917 EXPECT_TRUE(replacements.empty());
918 EXPECT_TRUE(valid);
919}
920
921TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
[email protected]573889f22012-04-07 01:31:54922 TemplateURLData data;
923 data.SetURL("{");
[email protected]168d08722014-06-18 07:13:28924 TemplateURL url(data);
[email protected]81c6ef62010-01-21 09:58:47925 TemplateURLRef::Replacements replacements;
926 bool valid = false;
[email protected]93b29062013-07-12 03:09:09927 EXPECT_EQ(std::string(), url.url_ref().ParseURL("{", &replacements, NULL,
928 &valid));
[email protected]81c6ef62010-01-21 09:58:47929 EXPECT_TRUE(replacements.empty());
930 EXPECT_FALSE(valid);
931}
932
933TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
[email protected]573889f22012-04-07 01:31:54934 TemplateURLData data;
935 data.SetURL("{}");
[email protected]168d08722014-06-18 07:13:28936 TemplateURL url(data);
[email protected]81c6ef62010-01-21 09:58:47937 TemplateURLRef::Replacements replacements;
938 bool valid = false;
[email protected]93b29062013-07-12 03:09:09939 EXPECT_EQ("{}", url.url_ref().ParseURL("{}", &replacements, NULL, &valid));
[email protected]81c6ef62010-01-21 09:58:47940 EXPECT_TRUE(replacements.empty());
941 EXPECT_TRUE(valid);
942}
943
944TEST_F(TemplateURLTest, ParseURLTwoParameters) {
[email protected]573889f22012-04-07 01:31:54945 TemplateURLData data;
946 data.SetURL("{}{{%s}}");
[email protected]168d08722014-06-18 07:13:28947 TemplateURL url(data);
[email protected]81c6ef62010-01-21 09:58:47948 TemplateURLRef::Replacements replacements;
949 bool valid = false;
[email protected]ddd231e2010-06-29 20:35:19950 EXPECT_EQ("{}{}",
[email protected]93b29062013-07-12 03:09:09951 url.url_ref().ParseURL("{}{{searchTerms}}", &replacements, NULL,
952 &valid));
[email protected]81c6ef62010-01-21 09:58:47953 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27954 EXPECT_EQ(3U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47955 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
956 EXPECT_TRUE(valid);
957}
958
959TEST_F(TemplateURLTest, ParseURLNestedParameter) {
[email protected]573889f22012-04-07 01:31:54960 TemplateURLData data;
961 data.SetURL("{%s");
[email protected]168d08722014-06-18 07:13:28962 TemplateURL url(data);
[email protected]81c6ef62010-01-21 09:58:47963 TemplateURLRef::Replacements replacements;
964 bool valid = false;
[email protected]360ba052012-04-04 17:26:13965 EXPECT_EQ("{",
[email protected]93b29062013-07-12 03:09:09966 url.url_ref().ParseURL("{{searchTerms}", &replacements, NULL,
967 &valid));
[email protected]81c6ef62010-01-21 09:58:47968 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27969 EXPECT_EQ(1U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47970 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
971 EXPECT_TRUE(valid);
972}
[email protected]5b3078752012-10-09 18:54:16973
[email protected]fd6d8822012-12-08 06:56:11974TEST_F(TemplateURLTest, SearchClient) {
975 const std::string base_url_str("http://google.com/?");
976 const std::string terms_str("{searchTerms}&{google:searchClient}");
977 const std::string full_url_str = base_url_str + terms_str;
[email protected]0085863a2013-12-06 21:19:03978 const base::string16 terms(ASCIIToUTF16(terms_str));
[email protected]798baa8e2014-06-20 05:42:44979 search_terms_data_.set_google_base_url(base_url_str);
[email protected]fd6d8822012-12-08 06:56:11980
981 TemplateURLData data;
982 data.SetURL(full_url_str);
[email protected]168d08722014-06-18 07:13:28983 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:19984 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
985 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]fd6d8822012-12-08 06:56:11986 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foobar"));
987
988 // Check that the URL is correct when a client is not present.
[email protected]ce7ee5f2014-06-16 23:41:19989 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
990 search_terms_data_));
[email protected]fd6d8822012-12-08 06:56:11991 ASSERT_TRUE(result.is_valid());
992 EXPECT_EQ("http://google.com/?foobar&", result.spec());
993
994 // Check that the URL is correct when a client is present.
[email protected]798baa8e2014-06-20 05:42:44995 search_terms_data_.set_search_client("search_client");
[email protected]ce7ee5f2014-06-16 23:41:19996 GURL result_2(url.url_ref().ReplaceSearchTerms(search_terms_args,
997 search_terms_data_));
[email protected]fd6d8822012-12-08 06:56:11998 ASSERT_TRUE(result_2.is_valid());
[email protected]798baa8e2014-06-20 05:42:44999 EXPECT_EQ("http://google.com/?foobar&client=search_client&", result_2.spec());
[email protected]fd6d8822012-12-08 06:56:111000}
[email protected]fd6d8822012-12-08 06:56:111001
[email protected]5b3078752012-10-09 18:54:161002TEST_F(TemplateURLTest, GetURLNoInstantURL) {
1003 TemplateURLData data;
1004 data.SetURL("http://google.com/?q={searchTerms}");
1005 data.suggestions_url = "http://google.com/suggest?q={searchTerms}";
1006 data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}");
1007 data.alternate_urls.push_back("{google:baseURL}/alt/#q={searchTerms}");
[email protected]168d08722014-06-18 07:13:281008 TemplateURL url(data);
[email protected]5b3078752012-10-09 18:54:161009 ASSERT_EQ(3U, url.URLCount());
1010 EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0));
1011 EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1));
1012 EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2));
1013}
1014
1015TEST_F(TemplateURLTest, GetURLNoSuggestionsURL) {
1016 TemplateURLData data;
1017 data.SetURL("http://google.com/?q={searchTerms}");
1018 data.instant_url = "http://google.com/instant#q={searchTerms}";
1019 data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}");
1020 data.alternate_urls.push_back("{google:baseURL}/alt/#q={searchTerms}");
[email protected]168d08722014-06-18 07:13:281021 TemplateURL url(data);
[email protected]5b3078752012-10-09 18:54:161022 ASSERT_EQ(3U, url.URLCount());
1023 EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0));
1024 EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1));
1025 EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2));
1026}
1027
1028TEST_F(TemplateURLTest, GetURLOnlyOneURL) {
1029 TemplateURLData data;
1030 data.SetURL("http://www.google.co.uk/");
[email protected]168d08722014-06-18 07:13:281031 TemplateURL url(data);
[email protected]5b3078752012-10-09 18:54:161032 ASSERT_EQ(1U, url.URLCount());
1033 EXPECT_EQ("http://www.google.co.uk/", url.GetURL(0));
1034}
1035
1036TEST_F(TemplateURLTest, ExtractSearchTermsFromURL) {
1037 TemplateURLData data;
1038 data.SetURL("http://google.com/?q={searchTerms}");
1039 data.instant_url = "http://google.com/instant#q={searchTerms}";
1040 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
1041 data.alternate_urls.push_back(
1042 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
[email protected]168d08722014-06-18 07:13:281043 TemplateURL url(data);
[email protected]0085863a2013-12-06 21:19:031044 base::string16 result;
[email protected]5b3078752012-10-09 18:54:161045
1046 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191047 GURL("http://google.com/?q=something"), search_terms_data_, &result));
[email protected]4076ea62013-01-09 01:47:191048 EXPECT_EQ(ASCIIToUTF16("something"), result);
1049
1050 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191051 GURL("http://google.com/?espv&q=something"),
1052 search_terms_data_, &result));
[email protected]4076ea62013-01-09 01:47:191053 EXPECT_EQ(ASCIIToUTF16("something"), result);
1054
1055 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191056 GURL("http://google.com/?espv=1&q=something"),
1057 search_terms_data_, &result));
[email protected]4076ea62013-01-09 01:47:191058 EXPECT_EQ(ASCIIToUTF16("something"), result);
1059
1060 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191061 GURL("http://google.com/?espv=0&q=something"),
1062 search_terms_data_, &result));
[email protected]4076ea62013-01-09 01:47:191063 EXPECT_EQ(ASCIIToUTF16("something"), result);
1064
1065 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191066 GURL("http://google.com/alt/#q=something"),
1067 search_terms_data_, &result));
[email protected]4076ea62013-01-09 01:47:191068 EXPECT_EQ(ASCIIToUTF16("something"), result);
1069
1070 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191071 GURL("http://google.com/alt/#espv&q=something"),
1072 search_terms_data_, &result));
[email protected]4076ea62013-01-09 01:47:191073 EXPECT_EQ(ASCIIToUTF16("something"), result);
1074
1075 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191076 GURL("http://google.com/alt/#espv=1&q=something"),
1077 search_terms_data_, &result));
[email protected]4076ea62013-01-09 01:47:191078 EXPECT_EQ(ASCIIToUTF16("something"), result);
1079
1080 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191081 GURL("http://google.com/alt/#espv=0&q=something"),
1082 search_terms_data_, &result));
[email protected]5b3078752012-10-09 18:54:161083 EXPECT_EQ(ASCIIToUTF16("something"), result);
1084
1085 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191086 GURL("http://google.ca/?q=something"), search_terms_data_, &result));
[email protected]b959d7d42013-12-13 17:26:371087 EXPECT_EQ(base::string16(), result);
[email protected]5b3078752012-10-09 18:54:161088
1089 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191090 GURL("http://google.ca/?q=something&q=anything"),
1091 search_terms_data_, &result));
[email protected]b959d7d42013-12-13 17:26:371092 EXPECT_EQ(base::string16(), result);
[email protected]67d8b752013-04-03 17:33:271093
1094 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191095 GURL("http://google.com/foo/?q=foo"), search_terms_data_, &result));
[email protected]b959d7d42013-12-13 17:26:371096 EXPECT_EQ(base::string16(), result);
[email protected]5b3078752012-10-09 18:54:161097
[email protected]32e2d81b2012-10-16 19:03:251098 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191099 GURL("https://google.com/?q=foo"), search_terms_data_, &result));
[email protected]32e2d81b2012-10-16 19:03:251100 EXPECT_EQ(ASCIIToUTF16("foo"), result);
[email protected]5b3078752012-10-09 18:54:161101
1102 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191103 GURL("http://google.com:8080/?q=foo"), search_terms_data_, &result));
[email protected]b959d7d42013-12-13 17:26:371104 EXPECT_EQ(base::string16(), result);
[email protected]5b3078752012-10-09 18:54:161105
1106 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191107 GURL("http://google.com/?q=1+2+3&b=456"), search_terms_data_, &result));
[email protected]5b3078752012-10-09 18:54:161108 EXPECT_EQ(ASCIIToUTF16("1 2 3"), result);
1109
1110 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191111 GURL("http://google.com/alt/?q=123#q=456"),
1112 search_terms_data_, &result));
[email protected]5b3078752012-10-09 18:54:161113 EXPECT_EQ(ASCIIToUTF16("456"), result);
1114
1115 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191116 GURL("http://google.com/alt/?a=012&q=123&b=456#f=789"),
1117 search_terms_data_, &result));
[email protected]5b3078752012-10-09 18:54:161118 EXPECT_EQ(ASCIIToUTF16("123"), result);
1119
1120 EXPECT_TRUE(url.ExtractSearchTermsFromURL(GURL(
[email protected]ce7ee5f2014-06-16 23:41:191121 "http://google.com/alt/?a=012&q=123&b=456#j=abc&q=789&h=def9"),
1122 search_terms_data_, &result));
[email protected]5b3078752012-10-09 18:54:161123 EXPECT_EQ(ASCIIToUTF16("789"), result);
1124
1125 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191126 GURL("http://google.com/alt/?q="), search_terms_data_, &result));
[email protected]b959d7d42013-12-13 17:26:371127 EXPECT_EQ(base::string16(), result);
[email protected]5b3078752012-10-09 18:54:161128
1129 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191130 GURL("http://google.com/alt/?#q="), search_terms_data_, &result));
[email protected]b959d7d42013-12-13 17:26:371131 EXPECT_EQ(base::string16(), result);
[email protected]5b3078752012-10-09 18:54:161132
1133 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191134 GURL("http://google.com/alt/?q=#q="), search_terms_data_, &result));
[email protected]b959d7d42013-12-13 17:26:371135 EXPECT_EQ(base::string16(), result);
[email protected]5b3078752012-10-09 18:54:161136
1137 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191138 GURL("http://google.com/alt/?q=123#q="), search_terms_data_, &result));
[email protected]b959d7d42013-12-13 17:26:371139 EXPECT_EQ(base::string16(), result);
[email protected]5b3078752012-10-09 18:54:161140
1141 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]ce7ee5f2014-06-16 23:41:191142 GURL("http://google.com/alt/?q=#q=123"), search_terms_data_, &result));
[email protected]5b3078752012-10-09 18:54:161143 EXPECT_EQ(ASCIIToUTF16("123"), result);
1144}
[email protected]4076ea62013-01-09 01:47:191145
1146TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) {
1147 TemplateURLData data;
1148 data.SetURL("http://google.com/?q={searchTerms}");
1149 data.instant_url = "http://google.com/instant#q={searchTerms}";
1150 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
1151 data.alternate_urls.push_back(
1152 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
1153 data.search_terms_replacement_key = "espv";
[email protected]168d08722014-06-18 07:13:281154 TemplateURL url(data);
[email protected]4076ea62013-01-09 01:47:191155
1156 // Test with instant enabled required.
1157 EXPECT_FALSE(url.HasSearchTermsReplacementKey(
1158 GURL("http://google.com/")));
1159
1160 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1161 GURL("http://google.com/?espv")));
1162
1163 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1164 GURL("http://google.com/#espv")));
1165
1166 EXPECT_FALSE(url.HasSearchTermsReplacementKey(
1167 GURL("http://google.com/?q=something")));
1168
1169 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1170 GURL("http://google.com/?q=something&espv")));
1171
1172 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1173 GURL("http://google.com/?q=something&espv=1")));
1174
1175 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1176 GURL("http://google.com/?q=something&espv=0")));
1177
1178 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1179 GURL("http://google.com/?espv&q=something")));
1180
1181 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1182 GURL("http://google.com/?espv=1&q=something")));
1183
1184 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1185 GURL("http://google.com/?espv=0&q=something")));
1186
1187 EXPECT_FALSE(url.HasSearchTermsReplacementKey(
1188 GURL("http://google.com/alt/#q=something")));
1189
1190 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1191 GURL("http://google.com/alt/#q=something&espv")));
1192
1193 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1194 GURL("http://google.com/alt/#q=something&espv=1")));
1195
1196 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1197 GURL("http://google.com/alt/#q=something&espv=0")));
1198
1199 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1200 GURL("http://google.com/alt/#espv&q=something")));
1201
1202 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1203 GURL("http://google.com/alt/#espv=1&q=something")));
1204
1205 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1206 GURL("http://google.com/alt/#espv=0&q=something")));
1207
1208 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1209 GURL("http://google.com/?espv#q=something")));
1210
1211 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1212 GURL("http://google.com/?espv=1#q=something")));
1213
1214 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1215 GURL("http://google.com/?q=something#espv")));
1216
1217 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1218 GURL("http://google.com/?q=something#espv=1")));
1219
1220 // This does not ensure the domain matches.
1221 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1222 GURL("http://bing.com/?espv")));
1223
1224 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
1225 GURL("http://bing.com/#espv")));
1226}
[email protected]f62e30f52013-03-23 03:45:151227
1228TEST_F(TemplateURLTest, ReplaceSearchTermsInURL) {
1229 TemplateURLData data;
1230 data.SetURL("http://google.com/?q={searchTerms}");
1231 data.instant_url = "http://google.com/instant#q={searchTerms}";
1232 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
1233 data.alternate_urls.push_back(
1234 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
[email protected]168d08722014-06-18 07:13:281235 TemplateURL url(data);
[email protected]f62e30f52013-03-23 03:45:151236 TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("Bob Morane"));
1237 GURL result;
1238
1239 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191240 GURL("http://google.com/?q=something"), search_terms,
1241 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151242 EXPECT_EQ(GURL("http://google.com/?q=Bob%20Morane"), result);
1243
1244 result = GURL("http://should.not.change.com");
1245 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191246 GURL("http://google.ca/?q=something"), search_terms,
1247 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151248 EXPECT_EQ(GURL("http://should.not.change.com"), result);
1249
1250 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191251 GURL("http://google.com/foo/?q=foo"), search_terms,
1252 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151253
1254 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191255 GURL("https://google.com/?q=foo"), search_terms,
1256 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151257 EXPECT_EQ(GURL("https://google.com/?q=Bob%20Morane"), result);
1258
1259 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191260 GURL("http://google.com:8080/?q=foo"), search_terms,
1261 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151262
1263 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191264 GURL("http://google.com/?q=1+2+3&b=456"), search_terms,
1265 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151266 EXPECT_EQ(GURL("http://google.com/?q=Bob%20Morane&b=456"), result);
1267
1268 // Note: Spaces in REF parameters are not escaped. See TryEncoding() in
1269 // template_url.cc for details.
1270 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191271 GURL("http://google.com/alt/?q=123#q=456"), search_terms,
1272 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151273 EXPECT_EQ(GURL("http://google.com/alt/?q=123#q=Bob Morane"), result);
1274
1275 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
1276 GURL("http://google.com/alt/?a=012&q=123&b=456#f=789"), search_terms,
[email protected]ce7ee5f2014-06-16 23:41:191277 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151278 EXPECT_EQ(GURL("http://google.com/alt/?a=012&q=Bob%20Morane&b=456#f=789"),
1279 result);
1280
1281 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
1282 GURL("http://google.com/alt/?a=012&q=123&b=456#j=abc&q=789&h=def9"),
[email protected]ce7ee5f2014-06-16 23:41:191283 search_terms, search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151284 EXPECT_EQ(GURL("http://google.com/alt/?a=012&q=123&b=456"
1285 "#j=abc&q=Bob Morane&h=def9"), result);
1286
1287 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191288 GURL("http://google.com/alt/?q="), search_terms,
1289 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151290
1291 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191292 GURL("http://google.com/alt/?#q="), search_terms,
1293 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151294
1295 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191296 GURL("http://google.com/alt/?q=#q="), search_terms,
1297 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151298
1299 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191300 GURL("http://google.com/alt/?q=123#q="), search_terms,
1301 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151302
1303 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
[email protected]ce7ee5f2014-06-16 23:41:191304 GURL("http://google.com/alt/?q=#q=123"), search_terms,
1305 search_terms_data_, &result));
[email protected]f62e30f52013-03-23 03:45:151306 EXPECT_EQ(GURL("http://google.com/alt/?q=#q=Bob Morane"), result);
1307}
[email protected]56fa29592013-07-02 20:25:531308
[email protected]621ade062013-10-28 06:27:431309// Test the |suggest_query_params| field of SearchTermsArgs.
1310TEST_F(TemplateURLTest, SuggestQueryParams) {
[email protected]621ade062013-10-28 06:27:431311 TemplateURLData data;
1312 // Pick a URL with replacements before, during, and after the query, to ensure
1313 // we don't goof up any of them.
1314 data.SetURL("{google:baseURL}search?q={searchTerms}"
1315 "#{google:originalQueryForSuggestion}x");
[email protected]168d08722014-06-18 07:13:281316 TemplateURL url(data);
[email protected]621ade062013-10-28 06:27:431317
1318 // Baseline: no |suggest_query_params| field.
1319 TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("abc"));
1320 search_terms.original_query = ASCIIToUTF16("def");
1321 search_terms.accepted_suggestion = 0;
1322 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x",
[email protected]ce7ee5f2014-06-16 23:41:191323 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_));
[email protected]621ade062013-10-28 06:27:431324
1325 // Set the suggest_query_params.
1326 search_terms.suggest_query_params = "pq=xyz";
1327 EXPECT_EQ("http://www.google.com/search?pq=xyz&q=abc#oq=def&x",
[email protected]ce7ee5f2014-06-16 23:41:191328 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_));
[email protected]621ade062013-10-28 06:27:431329
1330 // Add extra_query_params in the mix, and ensure it works.
1331 search_terms.append_extra_query_params = true;
1332 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1333 switches::kExtraSearchQueryParams, "a=b");
1334 EXPECT_EQ("http://www.google.com/search?a=b&pq=xyz&q=abc#oq=def&x",
[email protected]ce7ee5f2014-06-16 23:41:191335 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_));
[email protected]621ade062013-10-28 06:27:431336}
1337
[email protected]56fa29592013-07-02 20:25:531338// Test the |append_extra_query_params| field of SearchTermsArgs.
1339TEST_F(TemplateURLTest, ExtraQueryParams) {
[email protected]56fa29592013-07-02 20:25:531340 TemplateURLData data;
1341 // Pick a URL with replacements before, during, and after the query, to ensure
1342 // we don't goof up any of them.
1343 data.SetURL("{google:baseURL}search?q={searchTerms}"
1344 "#{google:originalQueryForSuggestion}x");
[email protected]168d08722014-06-18 07:13:281345 TemplateURL url(data);
[email protected]56fa29592013-07-02 20:25:531346
1347 // Baseline: no command-line args, no |append_extra_query_params| flag.
1348 TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("abc"));
1349 search_terms.original_query = ASCIIToUTF16("def");
1350 search_terms.accepted_suggestion = 0;
1351 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x",
[email protected]ce7ee5f2014-06-16 23:41:191352 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_));
[email protected]56fa29592013-07-02 20:25:531353
1354 // Set the flag. Since there are no command-line args, this should have no
1355 // effect.
1356 search_terms.append_extra_query_params = true;
1357 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x",
[email protected]ce7ee5f2014-06-16 23:41:191358 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_));
[email protected]56fa29592013-07-02 20:25:531359
1360 // Now append the command-line arg. This should be inserted into the query.
1361 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1362 switches::kExtraSearchQueryParams, "a=b");
1363 EXPECT_EQ("http://www.google.com/search?a=b&q=abc#oq=def&x",
[email protected]ce7ee5f2014-06-16 23:41:191364 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_));
[email protected]56fa29592013-07-02 20:25:531365
1366 // Turn off the flag. Now the command-line arg should be ignored again.
1367 search_terms.append_extra_query_params = false;
1368 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x",
[email protected]ce7ee5f2014-06-16 23:41:191369 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_));
[email protected]56fa29592013-07-02 20:25:531370}
[email protected]d5015ca2013-08-08 22:04:181371
1372// Tests replacing pageClassification.
[email protected]57ac99b92013-11-13 01:30:171373TEST_F(TemplateURLTest, ReplacePageClassification) {
[email protected]d5015ca2013-08-08 22:04:181374 TemplateURLData data;
1375 data.input_encodings.push_back("UTF-8");
1376 data.SetURL("{google:baseURL}?{google:pageClassification}q={searchTerms}");
[email protected]168d08722014-06-18 07:13:281377 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:191378 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
1379 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]d5015ca2013-08-08 22:04:181380 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
1381
[email protected]ce7ee5f2014-06-16 23:41:191382 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1383 search_terms_data_);
[email protected]d5015ca2013-08-08 22:04:181384 EXPECT_EQ("http://www.google.com/?q=foo", result);
1385
[email protected]332d17d22014-06-20 16:56:031386 search_terms_args.page_classification = metrics::OmniboxEventProto::NTP;
[email protected]ce7ee5f2014-06-16 23:41:191387 result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1388 search_terms_data_);
[email protected]d5015ca2013-08-08 22:04:181389 EXPECT_EQ("http://www.google.com/?pgcl=1&q=foo", result);
1390
1391 search_terms_args.page_classification =
[email protected]332d17d22014-06-20 16:56:031392 metrics::OmniboxEventProto::HOME_PAGE;
[email protected]ce7ee5f2014-06-16 23:41:191393 result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1394 search_terms_data_);
[email protected]d5015ca2013-08-08 22:04:181395 EXPECT_EQ("http://www.google.com/?pgcl=3&q=foo", result);
1396}
[email protected]2328ee22013-08-08 23:00:191397
1398// Test the IsSearchResults function.
1399TEST_F(TemplateURLTest, IsSearchResults) {
1400 TemplateURLData data;
1401 data.SetURL("http://bar/search?q={searchTerms}");
1402 data.instant_url = "http://bar/instant#q={searchTerms}";
[email protected]2767c0fd2013-08-16 17:44:161403 data.new_tab_url = "http://bar/newtab";
[email protected]2328ee22013-08-08 23:00:191404 data.alternate_urls.push_back("http://bar/?q={searchTerms}");
1405 data.alternate_urls.push_back("http://bar/#q={searchTerms}");
1406 data.alternate_urls.push_back("http://bar/search#q{searchTerms}");
1407 data.alternate_urls.push_back("http://bar/webhp#q={searchTerms}");
[email protected]168d08722014-06-18 07:13:281408 TemplateURL search_provider(data);
[email protected]2328ee22013-08-08 23:00:191409
1410 const struct {
1411 const char* const url;
1412 bool result;
1413 } url_data[] = {
1414 { "http://bar/search?q=foo&oq=foo", true, },
1415 { "http://bar/?q=foo&oq=foo", true, },
1416 { "http://bar/#output=search&q=foo&oq=foo", true, },
1417 { "http://bar/webhp#q=foo&oq=foo", true, },
1418 { "http://bar/#q=foo&oq=foo", true, },
1419 { "http://bar/?ext=foo&q=foo#ref=bar", true, },
1420 { "http://bar/url?url=http://www.foo.com/&q=foo#ref=bar", false, },
1421 { "http://bar/", false, },
1422 { "http://foo/", false, },
[email protected]2767c0fd2013-08-16 17:44:161423 { "http://bar/newtab", false, },
[email protected]2328ee22013-08-08 23:00:191424 };
1425
1426 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_data); ++i) {
1427 EXPECT_EQ(url_data[i].result,
[email protected]ce7ee5f2014-06-16 23:41:191428 search_provider.IsSearchURL(GURL(url_data[i].url),
1429 search_terms_data_));
[email protected]2328ee22013-08-08 23:00:191430 }
1431}
[email protected]a048de8a2013-10-02 18:30:061432
1433TEST_F(TemplateURLTest, ReflectsBookmarkBarPinned) {
1434 TemplateURLData data;
1435 data.input_encodings.push_back("UTF-8");
1436 data.SetURL("{google:baseURL}?{google:bookmarkBarPinned}q={searchTerms}");
[email protected]168d08722014-06-18 07:13:281437 TemplateURL url(data);
[email protected]ce7ee5f2014-06-16 23:41:191438 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
1439 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
[email protected]a048de8a2013-10-02 18:30:061440 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
1441
1442 // Do not add the param when InstantExtended is suppressed on SRPs.
[email protected]5c3c6e482014-06-23 09:47:181443 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(false);
[email protected]ce7ee5f2014-06-16 23:41:191444 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1445 search_terms_data_);
[email protected]a048de8a2013-10-02 18:30:061446 EXPECT_EQ("http://www.google.com/?q=foo", result);
1447
1448 // Add the param when InstantExtended is not suppressed on SRPs.
[email protected]5c3c6e482014-06-23 09:47:181449 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(true);
[email protected]a048de8a2013-10-02 18:30:061450 search_terms_args.bookmark_bar_pinned = false;
[email protected]ce7ee5f2014-06-16 23:41:191451 result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1452 search_terms_data_);
[email protected]a048de8a2013-10-02 18:30:061453 EXPECT_EQ("http://www.google.com/?bmbp=0&q=foo", result);
1454
[email protected]5c3c6e482014-06-23 09:47:181455 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(true);
[email protected]a048de8a2013-10-02 18:30:061456 search_terms_args.bookmark_bar_pinned = true;
[email protected]ce7ee5f2014-06-16 23:41:191457 result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1458 search_terms_data_);
[email protected]a048de8a2013-10-02 18:30:061459 EXPECT_EQ("http://www.google.com/?bmbp=1&q=foo", result);
1460}
[email protected]9d70de12014-05-10 02:15:311461
[email protected]9d70de12014-05-10 02:15:311462TEST_F(TemplateURLTest, AnswersHasVersion) {
1463 TemplateURLData data;
[email protected]798baa8e2014-06-20 05:42:441464 search_terms_data_.set_google_base_url("http://bar/");
[email protected]9d70de12014-05-10 02:15:311465 data.SetURL("http://bar/search?q={searchTerms}&{google:searchVersion}xssi=t");
1466
[email protected]168d08722014-06-18 07:13:281467 TemplateURL url(data);
[email protected]9d70de12014-05-10 02:15:311468 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
[email protected]ce7ee5f2014-06-16 23:41:191469 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1470 search_terms_data_);
[email protected]9d70de12014-05-10 02:15:311471 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result);
1472
[email protected]5c3c6e482014-06-23 09:47:181473 search_terms_data_.set_enable_answers_in_suggest(true);
[email protected]168d08722014-06-18 07:13:281474 TemplateURL url2(data);
[email protected]ce7ee5f2014-06-16 23:41:191475 result = url2.url_ref().ReplaceSearchTerms(search_terms_args,
1476 search_terms_data_);
[email protected]9d70de12014-05-10 02:15:311477 EXPECT_EQ("http://bar/search?q=foo&gs_rn=42&xssi=t", result);
1478}
[email protected]20184242014-05-14 02:57:421479
1480TEST_F(TemplateURLTest, SessionToken) {
1481 TemplateURLData data;
[email protected]798baa8e2014-06-20 05:42:441482 search_terms_data_.set_google_base_url("http://bar/");
[email protected]20184242014-05-14 02:57:421483 data.SetURL("http://bar/search?q={searchTerms}&{google:sessionToken}xssi=t");
1484
[email protected]168d08722014-06-18 07:13:281485 TemplateURL url(data);
[email protected]20184242014-05-14 02:57:421486 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
1487 search_terms_args.session_token = "SESSIONTOKENGOESHERE";
[email protected]ce7ee5f2014-06-16 23:41:191488 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1489 search_terms_data_);
[email protected]20184242014-05-14 02:57:421490 EXPECT_EQ("http://bar/search?q=foo&psi=SESSIONTOKENGOESHERE&xssi=t", result);
1491
[email protected]168d08722014-06-18 07:13:281492 TemplateURL url2(data);
[email protected]20184242014-05-14 02:57:421493 search_terms_args.session_token = "";
[email protected]ce7ee5f2014-06-16 23:41:191494 result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1495 search_terms_data_);
[email protected]20184242014-05-14 02:57:421496 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result);
1497}
[email protected]448b17f52014-06-13 01:08:031498
1499TEST_F(TemplateURLTest, ContextualSearchParameters) {
1500 TemplateURLData data;
[email protected]798baa8e2014-06-20 05:42:441501 search_terms_data_.set_google_base_url("http://bar/");
[email protected]448b17f52014-06-13 01:08:031502 data.SetURL("http://bar/_/contextualsearch?"
1503 "{google:contextualSearchVersion}"
1504 "{google:contextualSearchContextData}");
1505
[email protected]168d08722014-06-18 07:13:281506 TemplateURL url(data);
[email protected]448b17f52014-06-13 01:08:031507 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
[email protected]ce7ee5f2014-06-16 23:41:191508 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1509 search_terms_data_);
[email protected]52e02aa2014-08-06 05:36:091510 EXPECT_EQ("http://bar/_/contextualsearch?ctxsl_resolve=1", result);
[email protected]448b17f52014-06-13 01:08:031511
1512 TemplateURLRef::SearchTermsArgs::ContextualSearchParams params(
1513 1, 6, 11, "allen", "woody+allen+movies", "www.wikipedia.org",
[email protected]52e02aa2014-08-06 05:36:091514 "utf-8", true);
[email protected]448b17f52014-06-13 01:08:031515 search_terms_args.contextual_search_params = params;
[email protected]ce7ee5f2014-06-16 23:41:191516 result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1517 search_terms_data_);
[email protected]448b17f52014-06-13 01:08:031518 EXPECT_EQ("http://bar/_/contextualsearch?"
1519 "ctxs=1&"
1520 "ctxs_start=6&"
1521 "ctxs_end=11&"
1522 "q=allen&"
1523 "ctxs_content=woody+allen+movies&"
[email protected]52e02aa2014-08-06 05:36:091524 "ctxsl_url=www.wikipedia.org&"
1525 "ctxs_encoding=utf-8&"
1526 "ctxsl_resolve=1",
1527 result);
[email protected]448b17f52014-06-13 01:08:031528}
[email protected]44ccc9f2014-06-20 17:36:211529
1530TEST_F(TemplateURLTest, GenerateKeyword) {
1531 ASSERT_EQ(ASCIIToUTF16("foo"),
1532 TemplateURL::GenerateKeyword(GURL("http://foo")));
1533 // www. should be stripped.
1534 ASSERT_EQ(ASCIIToUTF16("foo"),
1535 TemplateURL::GenerateKeyword(GURL("http://www.foo")));
1536 // Make sure we don't get a trailing '/'.
1537 ASSERT_EQ(ASCIIToUTF16("blah"),
1538 TemplateURL::GenerateKeyword(GURL("http://blah/")));
1539 // Don't generate the empty string.
1540 ASSERT_EQ(ASCIIToUTF16("www"),
1541 TemplateURL::GenerateKeyword(GURL("http://www.")));
1542}
1543
1544TEST_F(TemplateURLTest, GenerateSearchURL) {
1545 struct GenerateSearchURLCase {
1546 const char* test_name;
1547 const char* url;
1548 const char* expected;
1549 } generate_url_cases[] = {
1550 { "invalid URL", "foo{searchTerms}", "" },
1551 { "URL with no replacements", "http://foo/", "http://foo/" },
1552 { "basic functionality", "http://foo/{searchTerms}",
1553 "http://foo/blah.blah.blah.blah.blah" }
1554 };
1555
1556 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) {
1557 TemplateURLData data;
1558 data.SetURL(generate_url_cases[i].url);
1559 TemplateURL t_url(data);
1560 EXPECT_EQ(t_url.GenerateSearchURL(search_terms_data_).spec(),
1561 generate_url_cases[i].expected)
1562 << generate_url_cases[i].test_name << " failed.";
1563 }
1564}
[email protected]9e9130ce2014-06-23 23:20:511565
1566TEST_F(TemplateURLTest, PrefetchQueryParameters) {
1567 TemplateURLData data;
1568 search_terms_data_.set_google_base_url("http://bar/");
1569 data.SetURL("http://bar/search?q={searchTerms}&{google:prefetchQuery}xssi=t");
1570
1571 TemplateURL url(data);
1572 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
1573 search_terms_args.prefetch_query = "full query text";
1574 search_terms_args.prefetch_query_type = "2338";
1575 std::string result =
1576 url.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_);
1577 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t",
1578 result);
1579
1580 TemplateURL url2(data);
1581 search_terms_args.prefetch_query.clear();
1582 search_terms_args.prefetch_query_type.clear();
1583 result =
1584 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_);
1585 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result);
1586}