blob: c06406d8b59f4094599016936075d3e167ca6f3e [file] [log] [blame]
[email protected]34e24852012-01-31 18:43:581// Copyright (c) 2012 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]d82443b2009-01-15 19:54:566#include "base/string_util.h"
[email protected]64048bd2010-03-08 23:28:587#include "base/utf_string_conversions.h"
[email protected]d82443b2009-01-15 19:54:568#include "chrome/browser/browser_process.h"
9#include "chrome/browser/rlz/rlz.h"
[email protected]375bd7312010-08-30 22:18:1310#include "chrome/browser/search_engines/search_terms_data.h"
[email protected]d54e03a52009-01-16 00:31:0411#include "chrome/browser/search_engines/template_url.h"
[email protected]d82443b2009-01-15 19:54:5612#include "testing/gtest/include/gtest/gtest.h"
13
[email protected]81d9b72d2012-03-26 22:29:1714#if defined(ENABLE_RLZ)
15#include "chrome/browser/google/google_util.h"
16#endif
17
[email protected]fd6d8822012-12-08 06:56:1118#if defined(OS_ANDROID)
19#include "chrome/browser/search_engines/search_terms_data_android.h"
20#endif
21
[email protected]b37bdfe2012-03-16 20:53:2722// TestSearchTermsData --------------------------------------------------------
23
[email protected]375bd7312010-08-30 22:18:1324// Simple implementation of SearchTermsData.
25class TestSearchTermsData : public SearchTermsData {
26 public:
[email protected]b37bdfe2012-03-16 20:53:2727 explicit TestSearchTermsData(const std::string& google_base_url);
[email protected]375bd7312010-08-30 22:18:1328
[email protected]b37bdfe2012-03-16 20:53:2729 virtual std::string GoogleBaseURLValue() const OVERRIDE;
[email protected]375bd7312010-08-30 22:18:1330
31 private:
32 std::string google_base_url_;
33
34 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData);
35};
36
[email protected]b37bdfe2012-03-16 20:53:2737TestSearchTermsData::TestSearchTermsData(const std::string& google_base_url)
38 : google_base_url_(google_base_url) {
39}
40
41std::string TestSearchTermsData::GoogleBaseURLValue() const {
42 return google_base_url_;
43}
44
45
46// TemplateURLTest ------------------------------------------------------------
47
[email protected]583844c2011-08-27 00:38:3548class TemplateURLTest : public testing::Test {
[email protected]d82443b2009-01-15 19:54:5649 public:
[email protected]b37bdfe2012-03-16 20:53:2750 void CheckSuggestBaseURL(const std::string& base_url,
51 const std::string& base_suggest_url) const;
[email protected]d82443b2009-01-15 19:54:5652};
53
[email protected]b37bdfe2012-03-16 20:53:2754void TemplateURLTest::CheckSuggestBaseURL(
55 const std::string& base_url,
56 const std::string& base_suggest_url) const {
57 TestSearchTermsData search_terms_data(base_url);
58 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue());
59}
60
61
62// Actual tests ---------------------------------------------------------------
63
[email protected]d82443b2009-01-15 19:54:5664TEST_F(TemplateURLTest, Defaults) {
[email protected]573889f22012-04-07 01:31:5465 TemplateURLData data;
66 EXPECT_FALSE(data.show_in_default_list);
67 EXPECT_FALSE(data.safe_for_autoreplace);
68 EXPECT_EQ(0, data.prepopulate_id);
[email protected]d82443b2009-01-15 19:54:5669}
70
71TEST_F(TemplateURLTest, TestValidWithComplete) {
[email protected]573889f22012-04-07 01:31:5472 TemplateURLData data;
73 data.SetURL("{searchTerms}");
[email protected]16fca9b82012-04-23 18:40:2674 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:1375 EXPECT_TRUE(url.url_ref().IsValid());
[email protected]d82443b2009-01-15 19:54:5676}
77
78TEST_F(TemplateURLTest, URLRefTestSearchTerms) {
[email protected]0d2e6a62010-01-15 20:09:1979 struct SearchTermsCase {
[email protected]ddd231e2010-06-29 20:35:1980 const char* url;
[email protected]400b133f2011-01-19 18:32:3081 const string16 terms;
[email protected]34e24852012-01-31 18:43:5882 const std::string output;
[email protected]0d2e6a62010-01-15 20:09:1983 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:3084 { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:1685 "http://foosea%20rch/bar" },
[email protected]400b133f2011-01-19 18:32:3086 { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:1687 "http://foosea%20rch/bar?boo=abc" },
[email protected]400b133f2011-01-19 18:32:3088 { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:1689 "http://foo/?boo=sea+rch%2Fbar" },
[email protected]400b133f2011-01-19 18:32:3090 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"),
[email protected]c31a979c2012-05-31 23:57:1691 "http://en.wikipedia.org/wiki/%3F" }
[email protected]0d2e6a62010-01-15 20:09:1992 };
93 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
94 const SearchTermsCase& value = search_term_cases[i];
[email protected]573889f22012-04-07 01:31:5495 TemplateURLData data;
96 data.SetURL(value.url);
[email protected]16fca9b82012-04-23 18:40:2697 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:1398 EXPECT_TRUE(url.url_ref().IsValid());
99 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04100 GURL result(url.url_ref().ReplaceSearchTerms(
101 TemplateURLRef::SearchTermsArgs(value.terms)));
[email protected]c31a979c2012-05-31 23:57:16102 ASSERT_TRUE(result.is_valid());
103 EXPECT_EQ(value.output, result.spec());
[email protected]0d2e6a62010-01-15 20:09:19104 }
[email protected]d82443b2009-01-15 19:54:56105}
106
107TEST_F(TemplateURLTest, URLRefTestCount) {
[email protected]573889f22012-04-07 01:31:54108 TemplateURLData data;
109 data.SetURL("http://foo{searchTerms}{count?}");
[email protected]16fca9b82012-04-23 18:40:26110 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13111 EXPECT_TRUE(url.url_ref().IsValid());
112 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04113 GURL result(url.url_ref().ReplaceSearchTerms(
114 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56115 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27116 EXPECT_EQ("http://foox/", result.spec());
[email protected]d82443b2009-01-15 19:54:56117}
118
119TEST_F(TemplateURLTest, URLRefTestCount2) {
[email protected]573889f22012-04-07 01:31:54120 TemplateURLData data;
121 data.SetURL("http://foo{searchTerms}{count}");
[email protected]16fca9b82012-04-23 18:40:26122 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13123 EXPECT_TRUE(url.url_ref().IsValid());
124 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04125 GURL result(url.url_ref().ReplaceSearchTerms(
126 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56127 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27128 EXPECT_EQ("http://foox10/", result.spec());
[email protected]d82443b2009-01-15 19:54:56129}
130
131TEST_F(TemplateURLTest, URLRefTestIndices) {
[email protected]573889f22012-04-07 01:31:54132 TemplateURLData data;
133 data.SetURL("http://foo{searchTerms}x{startIndex?}y{startPage?}");
[email protected]16fca9b82012-04-23 18:40:26134 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13135 EXPECT_TRUE(url.url_ref().IsValid());
136 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04137 GURL result(url.url_ref().ReplaceSearchTerms(
138 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56139 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27140 EXPECT_EQ("http://fooxxy/", result.spec());
[email protected]d82443b2009-01-15 19:54:56141}
142
143TEST_F(TemplateURLTest, URLRefTestIndices2) {
[email protected]573889f22012-04-07 01:31:54144 TemplateURLData data;
145 data.SetURL("http://foo{searchTerms}x{startIndex}y{startPage}");
[email protected]16fca9b82012-04-23 18:40:26146 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13147 EXPECT_TRUE(url.url_ref().IsValid());
148 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04149 GURL result(url.url_ref().ReplaceSearchTerms(
150 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56151 ASSERT_TRUE(result.is_valid());
[email protected]405aae22012-03-29 20:36:13152 EXPECT_EQ("http://fooxx1y1/", result.spec());
[email protected]d82443b2009-01-15 19:54:56153}
154
155TEST_F(TemplateURLTest, URLRefTestEncoding) {
[email protected]573889f22012-04-07 01:31:54156 TemplateURLData data;
157 data.SetURL("http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a");
[email protected]16fca9b82012-04-23 18:40:26158 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13159 EXPECT_TRUE(url.url_ref().IsValid());
160 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04161 GURL result(url.url_ref().ReplaceSearchTerms(
162 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56163 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27164 EXPECT_EQ("http://fooxxutf-8ya/", result.spec());
[email protected]d82443b2009-01-15 19:54:56165}
166
[email protected]d88cb202011-08-17 20:03:01167// Test that setting the prepopulate ID from TemplateURL causes the stored
168// TemplateURLRef to handle parsing the URL parameters differently.
[email protected]1a257262011-06-28 22:15:44169TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
[email protected]573889f22012-04-07 01:31:54170 TemplateURLData data;
[email protected]243abf32012-05-15 18:28:20171 data.SetURL("http://foo{fhqwhgads}bar");
[email protected]16fca9b82012-04-23 18:40:26172 TemplateURL url(NULL, data);
[email protected]1a257262011-06-28 22:15:44173 TemplateURLRef::Replacements replacements;
174 bool valid = false;
[email protected]243abf32012-05-15 18:28:20175 EXPECT_EQ("http://foo{fhqwhgads}bar", url.url_ref().ParseURL(
176 "http://foo{fhqwhgads}bar", &replacements, &valid));
[email protected]1a257262011-06-28 22:15:44177 EXPECT_TRUE(replacements.empty());
178 EXPECT_TRUE(valid);
179
[email protected]573889f22012-04-07 01:31:54180 data.prepopulate_id = 123;
[email protected]16fca9b82012-04-23 18:40:26181 TemplateURL url2(NULL, data);
[email protected]243abf32012-05-15 18:28:20182 EXPECT_EQ("http://foobar", url2.url_ref().ParseURL("http://foo{fhqwhgads}bar",
183 &replacements, &valid));
[email protected]1a257262011-06-28 22:15:44184 EXPECT_TRUE(replacements.empty());
185 EXPECT_TRUE(valid);
186}
187
[email protected]d82443b2009-01-15 19:54:56188TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
[email protected]573889f22012-04-07 01:31:54189 TemplateURLData data;
190 data.SetURL("http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b");
[email protected]16fca9b82012-04-23 18:40:26191 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13192 EXPECT_TRUE(url.url_ref().IsValid());
193 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04194 GURL result(url.url_ref().ReplaceSearchTerms(
195 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56196 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27197 EXPECT_EQ("http://fooxutf-8axyb/", result.spec());
[email protected]d82443b2009-01-15 19:54:56198}
199
200TEST_F(TemplateURLTest, URLRefTestEncoding2) {
[email protected]573889f22012-04-07 01:31:54201 TemplateURLData data;
202 data.SetURL("http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a");
[email protected]16fca9b82012-04-23 18:40:26203 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13204 EXPECT_TRUE(url.url_ref().IsValid());
205 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04206 GURL result(url.url_ref().ReplaceSearchTerms(
207 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56208 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27209 EXPECT_EQ("http://fooxxutf-8yutf-8a/", result.spec());
[email protected]d82443b2009-01-15 19:54:56210}
211
[email protected]375bd7312010-08-30 22:18:13212TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) {
213 struct SearchTermsCase {
214 const char* url;
[email protected]400b133f2011-01-19 18:32:30215 const string16 terms;
[email protected]375bd7312010-08-30 22:18:13216 const char* output;
217 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:30218 { "{google:baseURL}{language}{searchTerms}", string16(),
[email protected]b37bdfe2012-03-16 20:53:27219 "http://example.com/e/en" },
[email protected]400b133f2011-01-19 18:32:30220 { "{google:baseSuggestURL}{searchTerms}", string16(),
[email protected]014010e2011-10-01 04:12:44221 "http://example.com/complete/" }
[email protected]375bd7312010-08-30 22:18:13222 };
223
224 TestSearchTermsData search_terms_data("http://example.com/e/");
[email protected]573889f22012-04-07 01:31:54225 TemplateURLData data;
[email protected]375bd7312010-08-30 22:18:13226 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
227 const SearchTermsCase& value = search_term_cases[i];
[email protected]573889f22012-04-07 01:31:54228 data.SetURL(value.url);
[email protected]16fca9b82012-04-23 18:40:26229 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13230 EXPECT_TRUE(url.url_ref().IsValid());
231 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04232 GURL result(url.url_ref().ReplaceSearchTermsUsingTermsData(
233 TemplateURLRef::SearchTermsArgs(value.terms), search_terms_data));
[email protected]375bd7312010-08-30 22:18:13234 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27235 EXPECT_EQ(value.output, result.spec());
[email protected]375bd7312010-08-30 22:18:13236 }
237}
238
[email protected]d82443b2009-01-15 19:54:56239TEST_F(TemplateURLTest, URLRefTermToWide) {
240 struct ToWideCase {
241 const char* encoded_search_term;
[email protected]400b133f2011-01-19 18:32:30242 const string16 expected_decoded_term;
[email protected]d82443b2009-01-15 19:54:56243 } to_wide_cases[] = {
[email protected]400b133f2011-01-19 18:32:30244 {"hello+world", ASCIIToUTF16("hello world")},
[email protected]d82443b2009-01-15 19:54:56245 // Test some big-5 input.
[email protected]47e870b2013-02-24 21:14:53246 {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56247 // Test some UTF-8 input. We should fall back to this when the encoding
248 // doesn't look like big-5. We have a '5' in the middle, which is an invalid
249 // Big-5 trailing byte.
[email protected]47e870b2013-02-24 21:14:53250 {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56251 // Undecodable input should stay escaped.
[email protected]47e870b2013-02-24 21:14:53252 {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")},
[email protected]7df43482009-07-31 19:37:44253 // Make sure we convert %2B to +.
[email protected]400b133f2011-01-19 18:32:30254 {"C%2B%2B", ASCIIToUTF16("C++")},
[email protected]7df43482009-07-31 19:37:44255 // C%2B is escaped as C%252B, make sure we unescape it properly.
[email protected]400b133f2011-01-19 18:32:30256 {"C%252B", ASCIIToUTF16("C%2B")},
[email protected]d82443b2009-01-15 19:54:56257 };
258
[email protected]d82443b2009-01-15 19:54:56259 // Set one input encoding: big-5. This is so we can test fallback to UTF-8.
[email protected]573889f22012-04-07 01:31:54260 TemplateURLData data;
261 data.SetURL("http://foo?q={searchTerms}");
262 data.input_encodings.push_back("big-5");
[email protected]16fca9b82012-04-23 18:40:26263 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13264 EXPECT_TRUE(url.url_ref().IsValid());
265 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]f63ae312009-02-04 17:58:46266 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) {
[email protected]9b74ab52012-03-30 16:08:07267 EXPECT_EQ(to_wide_cases[i].expected_decoded_term,
[email protected]360ba052012-04-04 17:26:13268 url.url_ref().SearchTermToString16(
269 to_wide_cases[i].encoded_search_term));
[email protected]d82443b2009-01-15 19:54:56270 }
271}
272
[email protected]d82443b2009-01-15 19:54:56273TEST_F(TemplateURLTest, DisplayURLToURLRef) {
274 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19275 const std::string url;
[email protected]400b133f2011-01-19 18:32:30276 const string16 expected_result;
[email protected]b37bdfe2012-03-16 20:53:27277 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19278 { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a",
[email protected]400b133f2011-01-19 18:32:30279 ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") },
[email protected]ddd231e2010-06-29 20:35:19280 { "http://X",
[email protected]400b133f2011-01-19 18:32:30281 ASCIIToUTF16("http://X") },
[email protected]ddd231e2010-06-29 20:35:19282 { "http://foo{searchTerms",
[email protected]400b133f2011-01-19 18:32:30283 ASCIIToUTF16("http://foo{searchTerms") },
[email protected]ddd231e2010-06-29 20:35:19284 { "http://foo{searchTerms}{language}",
[email protected]400b133f2011-01-19 18:32:30285 ASCIIToUTF16("http://foo%s{language}") },
[email protected]d82443b2009-01-15 19:54:56286 };
[email protected]573889f22012-04-07 01:31:54287 TemplateURLData data;
[email protected]b37bdfe2012-03-16 20:53:27288 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54289 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26290 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13291 EXPECT_EQ(test_data[i].expected_result, url.url_ref().DisplayURL());
[email protected]b37bdfe2012-03-16 20:53:27292 EXPECT_EQ(test_data[i].url,
[email protected]360ba052012-04-04 17:26:13293 TemplateURLRef::DisplayURLToURLRef(url.url_ref().DisplayURL()));
[email protected]d82443b2009-01-15 19:54:56294 }
295}
296
297TEST_F(TemplateURLTest, ReplaceSearchTerms) {
298 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19299 const std::string url;
[email protected]d82443b2009-01-15 19:54:56300 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27301 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19302 { "http://foo/{language}{searchTerms}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56303 "http://foo/{language}XUTF-8" },
[email protected]ddd231e2010-06-29 20:35:19304 { "http://foo/{language}{inputEncoding}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56305 "http://foo/{language}UTF-8X" },
[email protected]ddd231e2010-06-29 20:35:19306 { "http://foo/{searchTerms}{language}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56307 "http://foo/X{language}UTF-8" },
[email protected]ddd231e2010-06-29 20:35:19308 { "http://foo/{searchTerms}{inputEncoding}{language}",
[email protected]d82443b2009-01-15 19:54:56309 "http://foo/XUTF-8{language}" },
[email protected]ddd231e2010-06-29 20:35:19310 { "http://foo/{inputEncoding}{searchTerms}{language}",
[email protected]d82443b2009-01-15 19:54:56311 "http://foo/UTF-8X{language}" },
[email protected]ddd231e2010-06-29 20:35:19312 { "http://foo/{inputEncoding}{language}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56313 "http://foo/UTF-8{language}X" },
[email protected]ddd231e2010-06-29 20:35:19314 { "http://foo/{language}a{searchTerms}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56315 "http://foo/{language}aXaUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19316 { "http://foo/{language}a{inputEncoding}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56317 "http://foo/{language}aUTF-8aXa" },
[email protected]ddd231e2010-06-29 20:35:19318 { "http://foo/{searchTerms}a{language}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56319 "http://foo/Xa{language}aUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19320 { "http://foo/{searchTerms}a{inputEncoding}a{language}a",
[email protected]d82443b2009-01-15 19:54:56321 "http://foo/XaUTF-8a{language}a" },
[email protected]ddd231e2010-06-29 20:35:19322 { "http://foo/{inputEncoding}a{searchTerms}a{language}a",
[email protected]d82443b2009-01-15 19:54:56323 "http://foo/UTF-8aXa{language}a" },
[email protected]ddd231e2010-06-29 20:35:19324 { "http://foo/{inputEncoding}a{language}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56325 "http://foo/UTF-8a{language}aXa" },
326 };
[email protected]573889f22012-04-07 01:31:54327 TemplateURLData data;
328 data.input_encodings.push_back("UTF-8");
[email protected]b37bdfe2012-03-16 20:53:27329 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54330 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26331 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13332 EXPECT_TRUE(url.url_ref().IsValid());
[email protected]3954c3a2012-04-10 20:17:55333 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27334 std::string expected_result = test_data[i].expected_result;
[email protected]d82443b2009-01-15 19:54:56335 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}",
[email protected]d70539de2009-06-24 22:17:06336 g_browser_process->GetApplicationLocale());
[email protected]bca359b2012-06-24 07:53:04337 GURL result(url.url_ref().ReplaceSearchTerms(
338 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]b37bdfe2012-03-16 20:53:27339 ASSERT_TRUE(result.is_valid());
[email protected]d82443b2009-01-15 19:54:56340 EXPECT_EQ(expected_result, result.spec());
341 }
342}
343
344
345// Tests replacing search terms in various encodings and making sure the
346// generated URL matches the expected value.
347TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {
348 struct TestData {
349 const std::string encoding;
[email protected]400b133f2011-01-19 18:32:30350 const string16 search_term;
[email protected]ddd231e2010-06-29 20:35:19351 const std::string url;
[email protected]d82443b2009-01-15 19:54:56352 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27353 } test_data[] = {
[email protected]47e870b2013-02-24 21:14:53354 { "BIG5", WideToUTF16(L"\x60BD"),
[email protected]400b133f2011-01-19 18:32:30355 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17356 "http://foo/?%B1~BIG5" },
[email protected]400b133f2011-01-19 18:32:30357 { "UTF-8", ASCIIToUTF16("blah"),
358 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17359 "http://foo/?blahUTF-8" },
[email protected]34e24852012-01-31 18:43:58360 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"),
361 "http://foo/{searchTerms}/bar",
362 "http://foo/%82%A0/bar"},
363 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"),
364 "http://foo/{searchTerms}/bar",
365 "http://foo/%82%A0%20%82%A2/bar"},
[email protected]d82443b2009-01-15 19:54:56366 };
[email protected]573889f22012-04-07 01:31:54367 TemplateURLData data;
[email protected]b37bdfe2012-03-16 20:53:27368 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54369 data.SetURL(test_data[i].url);
370 data.input_encodings.clear();
371 data.input_encodings.push_back(test_data[i].encoding);
[email protected]16fca9b82012-04-23 18:40:26372 TemplateURL url(NULL, data);
[email protected]3954c3a2012-04-10 20:17:55373 EXPECT_TRUE(url.url_ref().IsValid());
374 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04375 GURL result(url.url_ref().ReplaceSearchTerms(
376 TemplateURLRef::SearchTermsArgs(test_data[i].search_term)));
377 ASSERT_TRUE(result.is_valid());
378 EXPECT_EQ(test_data[i].expected_result, result.spec());
379 }
380}
381
382// Tests replacing assisted query stats (AQS) in various scenarios.
383TEST_F(TemplateURLTest, ReplaceAssistedQueryStats) {
384 struct TestData {
385 const string16 search_term;
386 const std::string aqs;
387 const std::string base_url;
388 const std::string url;
389 const std::string expected_result;
390 } test_data[] = {
391 // No HTTPS, no AQS.
392 { ASCIIToUTF16("foo"),
393 "chrome.0.0l6",
394 "http://foo/",
395 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
396 "http://foo/?foo" },
397 // HTTPS available, AQS should be replaced.
398 { ASCIIToUTF16("foo"),
399 "chrome.0.0l6",
400 "https://foo/",
401 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
402 "https://foo/?fooaqs=chrome.0.0l6&" },
403 // HTTPS available, however AQS is empty.
404 { ASCIIToUTF16("foo"),
405 "",
406 "https://foo/",
407 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
408 "https://foo/?foo" },
409 // No {google:baseURL} and protocol is HTTP, we must not substitute AQS.
410 { ASCIIToUTF16("foo"),
411 "chrome.0.0l6",
412 "",
413 "http://foo?{searchTerms}{google:assistedQueryStats}",
414 "http://foo/?foo" },
415 // A non-Google search provider with HTTPS should allow AQS.
416 { ASCIIToUTF16("foo"),
417 "chrome.0.0l6",
418 "",
419 "https://foo?{searchTerms}{google:assistedQueryStats}",
420 "https://foo/?fooaqs=chrome.0.0l6&" },
421 };
422 TemplateURLData data;
423 data.input_encodings.push_back("UTF-8");
424 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
425 data.SetURL(test_data[i].url);
426 TemplateURL url(NULL, data);
427 EXPECT_TRUE(url.url_ref().IsValid());
428 ASSERT_TRUE(url.url_ref().SupportsReplacement());
429 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
430 search_terms_args.assisted_query_stats = test_data[i].aqs;
431 UIThreadSearchTermsData::SetGoogleBaseURL(test_data[i].base_url);
432 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
[email protected]b37bdfe2012-03-16 20:53:27433 ASSERT_TRUE(result.is_valid());
434 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56435 }
436}
437
[email protected]00790562012-12-14 09:57:16438// Tests replacing cursor position.
439TEST_F(TemplateURLTest, ReplaceCursorPosition) {
440 struct TestData {
441 const string16 search_term;
442 size_t cursor_position;
443 const std::string url;
444 const std::string expected_result;
445 } test_data[] = {
446 { ASCIIToUTF16("foo"),
447 string16::npos,
448 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
449 "http://www.google.com/?foo&" },
450 { ASCIIToUTF16("foo"),
451 2,
452 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
453 "http://www.google.com/?foo&cp=2&" },
454 { ASCIIToUTF16("foo"),
455 15,
456 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
457 "http://www.google.com/?foo&cp=15&" },
458 };
459 TemplateURLData data;
460 data.input_encodings.push_back("UTF-8");
461 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
462 data.SetURL(test_data[i].url);
463 TemplateURL url(NULL, data);
464 EXPECT_TRUE(url.url_ref().IsValid());
465 ASSERT_TRUE(url.url_ref().SupportsReplacement());
466 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
467 search_terms_args.cursor_position = test_data[i].cursor_position;
468 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
469 ASSERT_TRUE(result.is_valid());
470 EXPECT_EQ(test_data[i].expected_result, result.spec());
471 }
472}
473
[email protected]d82443b2009-01-15 19:54:56474TEST_F(TemplateURLTest, Suggestions) {
475 struct TestData {
476 const int accepted_suggestion;
[email protected]400b133f2011-01-19 18:32:30477 const string16 original_query_for_suggestion;
[email protected]d82443b2009-01-15 19:54:56478 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27479 } test_data[] = {
[email protected]400b133f2011-01-19 18:32:30480 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
[email protected]29653892013-03-02 19:25:37481 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30482 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"),
[email protected]29653892013-03-02 19:25:37483 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30484 { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(),
[email protected]29653892013-03-02 19:25:37485 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30486 { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"),
[email protected]29653892013-03-02 19:25:37487 "http://bar/foo?q=foobar" },
488 { 0, string16(), "http://bar/foo?oq=&q=foobar" },
489 { 1, ASCIIToUTF16("foo"), "http://bar/foo?oq=foo&q=foobar" },
[email protected]d82443b2009-01-15 19:54:56490 };
[email protected]573889f22012-04-07 01:31:54491 TemplateURLData data;
[email protected]29653892013-03-02 19:25:37492 data.SetURL("http://bar/foo?{google:originalQueryForSuggestion}"
493 "q={searchTerms}");
[email protected]573889f22012-04-07 01:31:54494 data.input_encodings.push_back("UTF-8");
[email protected]16fca9b82012-04-23 18:40:26495 TemplateURL url(NULL, data);
[email protected]3954c3a2012-04-10 20:17:55496 EXPECT_TRUE(url.url_ref().IsValid());
[email protected]360ba052012-04-04 17:26:13497 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27498 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]bca359b2012-06-24 07:53:04499 TemplateURLRef::SearchTermsArgs search_terms_args(
500 ASCIIToUTF16("foobar"));
501 search_terms_args.accepted_suggestion = test_data[i].accepted_suggestion;
502 search_terms_args.original_query =
503 test_data[i].original_query_for_suggestion;
504 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
[email protected]b37bdfe2012-03-16 20:53:27505 ASSERT_TRUE(result.is_valid());
506 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56507 }
508}
509
[email protected]81f808de2009-09-25 01:36:34510TEST_F(TemplateURLTest, RLZ) {
[email protected]400b133f2011-01-19 18:32:30511 string16 rlz_string;
[email protected]81d9b72d2012-03-26 22:29:17512#if defined(ENABLE_RLZ)
513 std::string brand;
514 if (google_util::GetBrand(&brand) && !brand.empty() &&
515 !google_util::IsOrganic(brand)) {
[email protected]7e6f4ed5c2012-10-31 21:10:34516 RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz_string);
[email protected]81d9b72d2012-03-26 22:29:17517 }
[email protected]fd6d8822012-12-08 06:56:11518#elif defined(OS_ANDROID)
519 SearchTermsDataAndroid::rlz_parameter_value_.Get() =
520 ASCIIToUTF16("android_test");
521 rlz_string = SearchTermsDataAndroid::rlz_parameter_value_.Get();
[email protected]58b64332010-08-13 16:09:39522#endif
[email protected]d82443b2009-01-15 19:54:56523
[email protected]573889f22012-04-07 01:31:54524 TemplateURLData data;
525 data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
[email protected]16fca9b82012-04-23 18:40:26526 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13527 EXPECT_TRUE(url.url_ref().IsValid());
528 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04529 GURL result(url.url_ref().ReplaceSearchTerms(
530 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x"))));
[email protected]d82443b2009-01-15 19:54:56531 ASSERT_TRUE(result.is_valid());
[email protected]12bd05872009-03-17 19:25:06532 std::string expected_url = "http://bar/?";
[email protected]b37bdfe2012-03-16 20:53:27533 if (!rlz_string.empty())
[email protected]8ead4c022012-03-17 02:09:50534 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&";
[email protected]12bd05872009-03-17 19:25:06535 expected_url += "x";
[email protected]b37bdfe2012-03-16 20:53:27536 EXPECT_EQ(expected_url, result.spec());
[email protected]d82443b2009-01-15 19:54:56537}
538
539TEST_F(TemplateURLTest, HostAndSearchTermKey) {
540 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19541 const std::string url;
[email protected]d82443b2009-01-15 19:54:56542 const std::string host;
543 const std::string path;
544 const std::string search_term_key;
[email protected]573889f22012-04-07 01:31:54545 } test_data[] = {
[email protected]7c60f5042013-02-14 03:39:32546 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56547
548 // No query key should result in empty values.
[email protected]7c60f5042013-02-14 03:39:32549 { "http://blah/{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56550
551 // No term should result in empty values.
[email protected]7c60f5042013-02-14 03:39:32552 { "http://blah/", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56553
554 // Multiple terms should result in empty values.
[email protected]7c60f5042013-02-14 03:39:32555 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56556
557 // Term in the host shouldn't match.
[email protected]7c60f5042013-02-14 03:39:32558 { "http://{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56559
[email protected]7c60f5042013-02-14 03:39:32560 { "http://blah/?q={searchTerms}", "blah", "/", "q"},
561 { "https://blah/?q={searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56562
563 // Single term with extra chars in value should match.
[email protected]7c60f5042013-02-14 03:39:32564 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56565 };
566
[email protected]573889f22012-04-07 01:31:54567 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
568 TemplateURLData data;
569 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26570 TemplateURL url(NULL, data);
[email protected]573889f22012-04-07 01:31:54571 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost());
572 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath());
573 EXPECT_EQ(test_data[i].search_term_key, url.url_ref().GetSearchTermKey());
[email protected]d82443b2009-01-15 19:54:56574 }
575}
576
577TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {
578 static const struct {
[email protected]ddd231e2010-06-29 20:35:19579 const char* const base_url;
580 const char* const base_suggest_url;
[email protected]d82443b2009-01-15 19:54:56581 } data[] = {
[email protected]014010e2011-10-01 04:12:44582 { "http://google.com/", "http://google.com/complete/", },
583 { "http://www.google.com/", "http://www.google.com/complete/", },
584 { "http://www.google.co.uk/", "http://www.google.co.uk/complete/", },
585 { "http://www.google.com.by/", "http://www.google.com.by/complete/", },
586 { "http://google.com/intl/xx/", "http://google.com/complete/", },
[email protected]d82443b2009-01-15 19:54:56587 };
588
[email protected]f63ae312009-02-04 17:58:46589 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i)
[email protected]d82443b2009-01-15 19:54:56590 CheckSuggestBaseURL(data[i].base_url, data[i].base_suggest_url);
591}
592
[email protected]81c6ef62010-01-21 09:58:47593TEST_F(TemplateURLTest, ParseParameterKnown) {
[email protected]ddd231e2010-06-29 20:35:19594 std::string parsed_url("{searchTerms}");
[email protected]573889f22012-04-07 01:31:54595 TemplateURLData data;
596 data.SetURL(parsed_url);
[email protected]16fca9b82012-04-23 18:40:26597 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47598 TemplateURLRef::Replacements replacements;
[email protected]360ba052012-04-04 17:26:13599 EXPECT_TRUE(url.url_ref().ParseParameter(0, 12, &parsed_url, &replacements));
[email protected]ddd231e2010-06-29 20:35:19600 EXPECT_EQ(std::string(), parsed_url);
[email protected]81c6ef62010-01-21 09:58:47601 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27602 EXPECT_EQ(0U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47603 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
604}
605
606TEST_F(TemplateURLTest, ParseParameterUnknown) {
[email protected]243abf32012-05-15 18:28:20607 std::string parsed_url("{fhqwhgads}abc");
[email protected]573889f22012-04-07 01:31:54608 TemplateURLData data;
609 data.SetURL(parsed_url);
[email protected]16fca9b82012-04-23 18:40:26610 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47611 TemplateURLRef::Replacements replacements;
[email protected]1a257262011-06-28 22:15:44612
613 // By default, TemplateURLRef should not consider itself prepopulated.
614 // Therefore we should not replace the unknown parameter.
[email protected]360ba052012-04-04 17:26:13615 EXPECT_FALSE(url.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]243abf32012-05-15 18:28:20616 EXPECT_EQ("{fhqwhgads}abc", parsed_url);
[email protected]1a257262011-06-28 22:15:44617 EXPECT_TRUE(replacements.empty());
618
619 // If the TemplateURLRef is prepopulated, we should remove unknown parameters.
[email protected]243abf32012-05-15 18:28:20620 parsed_url = "{fhqwhgads}abc";
[email protected]573889f22012-04-07 01:31:54621 data.prepopulate_id = 1;
[email protected]16fca9b82012-04-23 18:40:26622 TemplateURL url2(NULL, data);
[email protected]495c30b2012-05-15 18:48:15623 EXPECT_TRUE(url2.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]243abf32012-05-15 18:28:20624 EXPECT_EQ("abc", parsed_url);
[email protected]81c6ef62010-01-21 09:58:47625 EXPECT_TRUE(replacements.empty());
626}
627
628TEST_F(TemplateURLTest, ParseURLEmpty) {
[email protected]16fca9b82012-04-23 18:40:26629 TemplateURL url(NULL, TemplateURLData());
[email protected]81c6ef62010-01-21 09:58:47630 TemplateURLRef::Replacements replacements;
631 bool valid = false;
[email protected]b37bdfe2012-03-16 20:53:27632 EXPECT_EQ(std::string(),
[email protected]360ba052012-04-04 17:26:13633 url.url_ref().ParseURL(std::string(), &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47634 EXPECT_TRUE(replacements.empty());
635 EXPECT_TRUE(valid);
636}
637
638TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
[email protected]573889f22012-04-07 01:31:54639 TemplateURLData data;
640 data.SetURL("{");
[email protected]16fca9b82012-04-23 18:40:26641 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47642 TemplateURLRef::Replacements replacements;
643 bool valid = false;
[email protected]360ba052012-04-04 17:26:13644 EXPECT_EQ(std::string(), url.url_ref().ParseURL("{", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47645 EXPECT_TRUE(replacements.empty());
646 EXPECT_FALSE(valid);
647}
648
649TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
[email protected]573889f22012-04-07 01:31:54650 TemplateURLData data;
651 data.SetURL("{}");
[email protected]16fca9b82012-04-23 18:40:26652 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47653 TemplateURLRef::Replacements replacements;
654 bool valid = false;
[email protected]360ba052012-04-04 17:26:13655 EXPECT_EQ("{}", url.url_ref().ParseURL("{}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47656 EXPECT_TRUE(replacements.empty());
657 EXPECT_TRUE(valid);
658}
659
660TEST_F(TemplateURLTest, ParseURLTwoParameters) {
[email protected]573889f22012-04-07 01:31:54661 TemplateURLData data;
662 data.SetURL("{}{{%s}}");
[email protected]16fca9b82012-04-23 18:40:26663 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47664 TemplateURLRef::Replacements replacements;
665 bool valid = false;
[email protected]ddd231e2010-06-29 20:35:19666 EXPECT_EQ("{}{}",
[email protected]360ba052012-04-04 17:26:13667 url.url_ref().ParseURL("{}{{searchTerms}}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47668 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27669 EXPECT_EQ(3U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47670 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
671 EXPECT_TRUE(valid);
672}
673
674TEST_F(TemplateURLTest, ParseURLNestedParameter) {
[email protected]573889f22012-04-07 01:31:54675 TemplateURLData data;
676 data.SetURL("{%s");
[email protected]16fca9b82012-04-23 18:40:26677 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47678 TemplateURLRef::Replacements replacements;
679 bool valid = false;
[email protected]360ba052012-04-04 17:26:13680 EXPECT_EQ("{",
681 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47682 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27683 EXPECT_EQ(1U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47684 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
685 EXPECT_TRUE(valid);
686}
[email protected]5b3078752012-10-09 18:54:16687
[email protected]fd6d8822012-12-08 06:56:11688#if defined(OS_ANDROID)
689TEST_F(TemplateURLTest, SearchClient) {
690 const std::string base_url_str("http://google.com/?");
691 const std::string terms_str("{searchTerms}&{google:searchClient}");
692 const std::string full_url_str = base_url_str + terms_str;
693 const string16 terms(ASCIIToUTF16(terms_str));
694 UIThreadSearchTermsData::SetGoogleBaseURL(base_url_str);
695
696 TemplateURLData data;
697 data.SetURL(full_url_str);
698 TemplateURL url(NULL, data);
699 EXPECT_TRUE(url.url_ref().IsValid());
700 ASSERT_TRUE(url.url_ref().SupportsReplacement());
701 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foobar"));
702
703 // Check that the URL is correct when a client is not present.
704 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
705 ASSERT_TRUE(result.is_valid());
706 EXPECT_EQ("http://google.com/?foobar&", result.spec());
707
708 // Check that the URL is correct when a client is present.
709 SearchTermsDataAndroid::search_client_.Get() = "android_test";
710 GURL result_2(url.url_ref().ReplaceSearchTerms(search_terms_args));
711 ASSERT_TRUE(result_2.is_valid());
712 EXPECT_EQ("http://google.com/?foobar&client=android_test&", result_2.spec());
713}
714#endif
715
[email protected]5b3078752012-10-09 18:54:16716TEST_F(TemplateURLTest, GetURLNoInstantURL) {
717 TemplateURLData data;
718 data.SetURL("http://google.com/?q={searchTerms}");
719 data.suggestions_url = "http://google.com/suggest?q={searchTerms}";
720 data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}");
721 data.alternate_urls.push_back("{google:baseURL}/alt/#q={searchTerms}");
722 TemplateURL url(NULL, data);
723 ASSERT_EQ(3U, url.URLCount());
724 EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0));
725 EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1));
726 EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2));
727}
728
729TEST_F(TemplateURLTest, GetURLNoSuggestionsURL) {
730 TemplateURLData data;
731 data.SetURL("http://google.com/?q={searchTerms}");
732 data.instant_url = "http://google.com/instant#q={searchTerms}";
733 data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}");
734 data.alternate_urls.push_back("{google:baseURL}/alt/#q={searchTerms}");
735 TemplateURL url(NULL, data);
736 ASSERT_EQ(3U, url.URLCount());
737 EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0));
738 EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1));
739 EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2));
740}
741
742TEST_F(TemplateURLTest, GetURLOnlyOneURL) {
743 TemplateURLData data;
744 data.SetURL("http://www.google.co.uk/");
745 TemplateURL url(NULL, data);
746 ASSERT_EQ(1U, url.URLCount());
747 EXPECT_EQ("http://www.google.co.uk/", url.GetURL(0));
748}
749
750TEST_F(TemplateURLTest, ExtractSearchTermsFromURL) {
751 TemplateURLData data;
752 data.SetURL("http://google.com/?q={searchTerms}");
753 data.instant_url = "http://google.com/instant#q={searchTerms}";
754 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
755 data.alternate_urls.push_back(
756 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
757 TemplateURL url(NULL, data);
758 string16 result;
759
760 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
761 GURL("http://google.com/?q=something"), &result));
[email protected]4076ea62013-01-09 01:47:19762 EXPECT_EQ(ASCIIToUTF16("something"), result);
763
764 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
765 GURL("http://google.com/?espv&q=something"), &result));
766 EXPECT_EQ(ASCIIToUTF16("something"), result);
767
768 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
769 GURL("http://google.com/?espv=1&q=something"), &result));
770 EXPECT_EQ(ASCIIToUTF16("something"), result);
771
772 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
773 GURL("http://google.com/?espv=0&q=something"), &result));
774 EXPECT_EQ(ASCIIToUTF16("something"), result);
775
776 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
777 GURL("http://google.com/alt/#q=something"), &result));
778 EXPECT_EQ(ASCIIToUTF16("something"), result);
779
780 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
781 GURL("http://google.com/alt/#espv&q=something"), &result));
782 EXPECT_EQ(ASCIIToUTF16("something"), result);
783
784 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
785 GURL("http://google.com/alt/#espv=1&q=something"), &result));
786 EXPECT_EQ(ASCIIToUTF16("something"), result);
787
788 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
789 GURL("http://google.com/alt/#espv=0&q=something"), &result));
[email protected]5b3078752012-10-09 18:54:16790 EXPECT_EQ(ASCIIToUTF16("something"), result);
791
792 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
793 GURL("http://google.ca/?q=something"), &result));
794 EXPECT_EQ(string16(), result);
795
796 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]67d8b752013-04-03 17:33:27797 GURL("http://google.ca/?q=something&q=anything"), &result));
798 EXPECT_EQ(string16(), result);
799
800 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
[email protected]5b3078752012-10-09 18:54:16801 GURL("http://google.com/foo/?q=foo"), &result));
802 EXPECT_EQ(string16(), result);
803
[email protected]32e2d81b2012-10-16 19:03:25804 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
[email protected]5b3078752012-10-09 18:54:16805 GURL("https://google.com/?q=foo"), &result));
[email protected]32e2d81b2012-10-16 19:03:25806 EXPECT_EQ(ASCIIToUTF16("foo"), result);
[email protected]5b3078752012-10-09 18:54:16807
808 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
809 GURL("http://google.com:8080/?q=foo"), &result));
810 EXPECT_EQ(string16(), result);
811
812 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
813 GURL("http://google.com/?q=1+2+3&b=456"), &result));
814 EXPECT_EQ(ASCIIToUTF16("1 2 3"), result);
815
816 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
817 GURL("http://google.com/alt/?q=123#q=456"), &result));
818 EXPECT_EQ(ASCIIToUTF16("456"), result);
819
820 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
821 GURL("http://google.com/alt/?a=012&q=123&b=456#f=789"), &result));
822 EXPECT_EQ(ASCIIToUTF16("123"), result);
823
824 EXPECT_TRUE(url.ExtractSearchTermsFromURL(GURL(
825 "http://google.com/alt/?a=012&q=123&b=456#j=abc&q=789&h=def9"), &result));
826 EXPECT_EQ(ASCIIToUTF16("789"), result);
827
828 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
829 GURL("http://google.com/alt/?q="), &result));
830 EXPECT_EQ(string16(), result);
831
832 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
833 GURL("http://google.com/alt/?#q="), &result));
834 EXPECT_EQ(string16(), result);
835
836 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
837 GURL("http://google.com/alt/?q=#q="), &result));
838 EXPECT_EQ(string16(), result);
839
840 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
841 GURL("http://google.com/alt/?q=123#q="), &result));
842 EXPECT_EQ(string16(), result);
843
844 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
845 GURL("http://google.com/alt/?q=#q=123"), &result));
846 EXPECT_EQ(ASCIIToUTF16("123"), result);
847}
[email protected]4076ea62013-01-09 01:47:19848
849TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) {
850 TemplateURLData data;
851 data.SetURL("http://google.com/?q={searchTerms}");
852 data.instant_url = "http://google.com/instant#q={searchTerms}";
853 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
854 data.alternate_urls.push_back(
855 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
856 data.search_terms_replacement_key = "espv";
857 TemplateURL url(NULL, data);
858
859 // Test with instant enabled required.
860 EXPECT_FALSE(url.HasSearchTermsReplacementKey(
861 GURL("http://google.com/")));
862
863 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
864 GURL("http://google.com/?espv")));
865
866 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
867 GURL("http://google.com/#espv")));
868
869 EXPECT_FALSE(url.HasSearchTermsReplacementKey(
870 GURL("http://google.com/?q=something")));
871
872 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
873 GURL("http://google.com/?q=something&espv")));
874
875 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
876 GURL("http://google.com/?q=something&espv=1")));
877
878 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
879 GURL("http://google.com/?q=something&espv=0")));
880
881 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
882 GURL("http://google.com/?espv&q=something")));
883
884 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
885 GURL("http://google.com/?espv=1&q=something")));
886
887 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
888 GURL("http://google.com/?espv=0&q=something")));
889
890 EXPECT_FALSE(url.HasSearchTermsReplacementKey(
891 GURL("http://google.com/alt/#q=something")));
892
893 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
894 GURL("http://google.com/alt/#q=something&espv")));
895
896 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
897 GURL("http://google.com/alt/#q=something&espv=1")));
898
899 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
900 GURL("http://google.com/alt/#q=something&espv=0")));
901
902 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
903 GURL("http://google.com/alt/#espv&q=something")));
904
905 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
906 GURL("http://google.com/alt/#espv=1&q=something")));
907
908 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
909 GURL("http://google.com/alt/#espv=0&q=something")));
910
911 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
912 GURL("http://google.com/?espv#q=something")));
913
914 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
915 GURL("http://google.com/?espv=1#q=something")));
916
917 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
918 GURL("http://google.com/?q=something#espv")));
919
920 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
921 GURL("http://google.com/?q=something#espv=1")));
922
923 // This does not ensure the domain matches.
924 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
925 GURL("http://bing.com/?espv")));
926
927 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
928 GURL("http://bing.com/#espv")));
929}
[email protected]f62e30f52013-03-23 03:45:15930
931TEST_F(TemplateURLTest, ReplaceSearchTermsInURL) {
932 TemplateURLData data;
933 data.SetURL("http://google.com/?q={searchTerms}");
934 data.instant_url = "http://google.com/instant#q={searchTerms}";
935 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
936 data.alternate_urls.push_back(
937 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
938 TemplateURL url(NULL, data);
939 TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("Bob Morane"));
940 GURL result;
941
942 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
943 GURL("http://google.com/?q=something"), search_terms, &result));
944 EXPECT_EQ(GURL("http://google.com/?q=Bob%20Morane"), result);
945
946 result = GURL("http://should.not.change.com");
947 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
948 GURL("http://google.ca/?q=something"), search_terms, &result));
949 EXPECT_EQ(GURL("http://should.not.change.com"), result);
950
951 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
952 GURL("http://google.com/foo/?q=foo"), search_terms, &result));
953
954 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
955 GURL("https://google.com/?q=foo"), search_terms, &result));
956 EXPECT_EQ(GURL("https://google.com/?q=Bob%20Morane"), result);
957
958 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
959 GURL("http://google.com:8080/?q=foo"), search_terms, &result));
960
961 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
962 GURL("http://google.com/?q=1+2+3&b=456"), search_terms, &result));
963 EXPECT_EQ(GURL("http://google.com/?q=Bob%20Morane&b=456"), result);
964
965 // Note: Spaces in REF parameters are not escaped. See TryEncoding() in
966 // template_url.cc for details.
967 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
968 GURL("http://google.com/alt/?q=123#q=456"), search_terms, &result));
969 EXPECT_EQ(GURL("http://google.com/alt/?q=123#q=Bob Morane"), result);
970
971 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
972 GURL("http://google.com/alt/?a=012&q=123&b=456#f=789"), search_terms,
973 &result));
974 EXPECT_EQ(GURL("http://google.com/alt/?a=012&q=Bob%20Morane&b=456#f=789"),
975 result);
976
977 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
978 GURL("http://google.com/alt/?a=012&q=123&b=456#j=abc&q=789&h=def9"),
979 search_terms, &result));
980 EXPECT_EQ(GURL("http://google.com/alt/?a=012&q=123&b=456"
981 "#j=abc&q=Bob Morane&h=def9"), result);
982
983 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
984 GURL("http://google.com/alt/?q="), search_terms, &result));
985
986 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
987 GURL("http://google.com/alt/?#q="), search_terms, &result));
988
989 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
990 GURL("http://google.com/alt/?q=#q="), search_terms, &result));
991
992 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
993 GURL("http://google.com/alt/?q=123#q="), search_terms, &result));
994
995 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
996 GURL("http://google.com/alt/?q=#q=123"), search_terms, &result));
997 EXPECT_EQ(GURL("http://google.com/alt/?q=#q=Bob Morane"), result);
998}