blob: 656e7b87ceb654aaf806619305028d3db7a506f8 [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]b37bdfe2012-03-16 20:53:2718// TestSearchTermsData --------------------------------------------------------
19
[email protected]375bd7312010-08-30 22:18:1320// Simple implementation of SearchTermsData.
21class TestSearchTermsData : public SearchTermsData {
22 public:
[email protected]b37bdfe2012-03-16 20:53:2723 explicit TestSearchTermsData(const std::string& google_base_url);
[email protected]375bd7312010-08-30 22:18:1324
[email protected]b37bdfe2012-03-16 20:53:2725 virtual std::string GoogleBaseURLValue() const OVERRIDE;
[email protected]375bd7312010-08-30 22:18:1326
27 private:
28 std::string google_base_url_;
29
30 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData);
31};
32
[email protected]b37bdfe2012-03-16 20:53:2733TestSearchTermsData::TestSearchTermsData(const std::string& google_base_url)
34 : google_base_url_(google_base_url) {
35}
36
37std::string TestSearchTermsData::GoogleBaseURLValue() const {
38 return google_base_url_;
39}
40
41
42// TemplateURLTest ------------------------------------------------------------
43
[email protected]583844c2011-08-27 00:38:3544class TemplateURLTest : public testing::Test {
[email protected]d82443b2009-01-15 19:54:5645 public:
[email protected]b37bdfe2012-03-16 20:53:2746 void CheckSuggestBaseURL(const std::string& base_url,
47 const std::string& base_suggest_url) const;
[email protected]d82443b2009-01-15 19:54:5648};
49
[email protected]b37bdfe2012-03-16 20:53:2750void TemplateURLTest::CheckSuggestBaseURL(
51 const std::string& base_url,
52 const std::string& base_suggest_url) const {
53 TestSearchTermsData search_terms_data(base_url);
54 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue());
55}
56
57
58// Actual tests ---------------------------------------------------------------
59
[email protected]d82443b2009-01-15 19:54:5660TEST_F(TemplateURLTest, Defaults) {
[email protected]573889f22012-04-07 01:31:5461 TemplateURLData data;
62 EXPECT_FALSE(data.show_in_default_list);
63 EXPECT_FALSE(data.safe_for_autoreplace);
64 EXPECT_EQ(0, data.prepopulate_id);
[email protected]d82443b2009-01-15 19:54:5665}
66
67TEST_F(TemplateURLTest, TestValidWithComplete) {
[email protected]573889f22012-04-07 01:31:5468 TemplateURLData data;
69 data.SetURL("{searchTerms}");
[email protected]16fca9b82012-04-23 18:40:2670 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:1371 EXPECT_TRUE(url.url_ref().IsValid());
[email protected]d82443b2009-01-15 19:54:5672}
73
74TEST_F(TemplateURLTest, URLRefTestSearchTerms) {
[email protected]0d2e6a62010-01-15 20:09:1975 struct SearchTermsCase {
[email protected]ddd231e2010-06-29 20:35:1976 const char* url;
[email protected]400b133f2011-01-19 18:32:3077 const string16 terms;
[email protected]34e24852012-01-31 18:43:5878 const std::string output;
79 bool valid_url;
[email protected]0d2e6a62010-01-15 20:09:1980 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:3081 { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]34e24852012-01-31 18:43:5882 "http://foosea%20rch%2Fbar", false },
[email protected]400b133f2011-01-19 18:32:3083 { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"),
[email protected]34e24852012-01-31 18:43:5884 "http://foosea%20rch%2Fbar?boo=abc", false },
[email protected]400b133f2011-01-19 18:32:3085 { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]34e24852012-01-31 18:43:5886 "http://foo/?boo=sea+rch%2Fbar", true },
[email protected]400b133f2011-01-19 18:32:3087 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"),
[email protected]34e24852012-01-31 18:43:5888 "http://en.wikipedia.org/wiki%2F%3F", true }
[email protected]0d2e6a62010-01-15 20:09:1989 };
90 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
91 const SearchTermsCase& value = search_term_cases[i];
[email protected]573889f22012-04-07 01:31:5492 TemplateURLData data;
93 data.SetURL(value.url);
[email protected]16fca9b82012-04-23 18:40:2694 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:1395 EXPECT_TRUE(url.url_ref().IsValid());
96 ASSERT_TRUE(url.url_ref().SupportsReplacement());
97 std::string result = url.url_ref().ReplaceSearchTerms(value.terms,
[email protected]34e24852012-01-31 18:43:5898 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16());
[email protected]360ba052012-04-04 17:26:1399 EXPECT_EQ(value.output, result);
[email protected]b37bdfe2012-03-16 20:53:27100 GURL result_url(result);
[email protected]360ba052012-04-04 17:26:13101 EXPECT_EQ(value.valid_url, result_url.is_valid());
[email protected]0d2e6a62010-01-15 20:09:19102 }
[email protected]d82443b2009-01-15 19:54:56103}
104
105TEST_F(TemplateURLTest, URLRefTestCount) {
[email protected]573889f22012-04-07 01:31:54106 TemplateURLData data;
107 data.SetURL("http://foo{searchTerms}{count?}");
[email protected]16fca9b82012-04-23 18:40:26108 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13109 EXPECT_TRUE(url.url_ref().IsValid());
110 ASSERT_TRUE(url.url_ref().SupportsReplacement());
111 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30112 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56113 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27114 EXPECT_EQ("http://foox/", result.spec());
[email protected]d82443b2009-01-15 19:54:56115}
116
117TEST_F(TemplateURLTest, URLRefTestCount2) {
[email protected]573889f22012-04-07 01:31:54118 TemplateURLData data;
119 data.SetURL("http://foo{searchTerms}{count}");
[email protected]16fca9b82012-04-23 18:40:26120 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13121 EXPECT_TRUE(url.url_ref().IsValid());
122 ASSERT_TRUE(url.url_ref().SupportsReplacement());
123 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30124 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56125 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27126 EXPECT_EQ("http://foox10/", result.spec());
[email protected]d82443b2009-01-15 19:54:56127}
128
129TEST_F(TemplateURLTest, URLRefTestIndices) {
[email protected]573889f22012-04-07 01:31:54130 TemplateURLData data;
131 data.SetURL("http://foo{searchTerms}x{startIndex?}y{startPage?}");
[email protected]16fca9b82012-04-23 18:40:26132 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13133 EXPECT_TRUE(url.url_ref().IsValid());
134 ASSERT_TRUE(url.url_ref().SupportsReplacement());
135 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30136 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56137 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27138 EXPECT_EQ("http://fooxxy/", result.spec());
[email protected]d82443b2009-01-15 19:54:56139}
140
141TEST_F(TemplateURLTest, URLRefTestIndices2) {
[email protected]573889f22012-04-07 01:31:54142 TemplateURLData data;
143 data.SetURL("http://foo{searchTerms}x{startIndex}y{startPage}");
[email protected]16fca9b82012-04-23 18:40:26144 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13145 EXPECT_TRUE(url.url_ref().IsValid());
146 ASSERT_TRUE(url.url_ref().SupportsReplacement());
147 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30148 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56149 ASSERT_TRUE(result.is_valid());
[email protected]405aae22012-03-29 20:36:13150 EXPECT_EQ("http://fooxx1y1/", result.spec());
[email protected]d82443b2009-01-15 19:54:56151}
152
153TEST_F(TemplateURLTest, URLRefTestEncoding) {
[email protected]573889f22012-04-07 01:31:54154 TemplateURLData data;
155 data.SetURL("http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a");
[email protected]16fca9b82012-04-23 18:40:26156 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13157 EXPECT_TRUE(url.url_ref().IsValid());
158 ASSERT_TRUE(url.url_ref().SupportsReplacement());
159 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30160 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56161 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27162 EXPECT_EQ("http://fooxxutf-8ya/", result.spec());
[email protected]d82443b2009-01-15 19:54:56163}
164
[email protected]d88cb202011-08-17 20:03:01165// Test that setting the prepopulate ID from TemplateURL causes the stored
166// TemplateURLRef to handle parsing the URL parameters differently.
[email protected]1a257262011-06-28 22:15:44167TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
[email protected]573889f22012-04-07 01:31:54168 TemplateURLData data;
[email protected]243abf32012-05-15 18:28:20169 data.SetURL("http://foo{fhqwhgads}bar");
[email protected]16fca9b82012-04-23 18:40:26170 TemplateURL url(NULL, data);
[email protected]1a257262011-06-28 22:15:44171 TemplateURLRef::Replacements replacements;
172 bool valid = false;
[email protected]243abf32012-05-15 18:28:20173 EXPECT_EQ("http://foo{fhqwhgads}bar", url.url_ref().ParseURL(
174 "http://foo{fhqwhgads}bar", &replacements, &valid));
[email protected]1a257262011-06-28 22:15:44175 EXPECT_TRUE(replacements.empty());
176 EXPECT_TRUE(valid);
177
[email protected]573889f22012-04-07 01:31:54178 data.prepopulate_id = 123;
[email protected]16fca9b82012-04-23 18:40:26179 TemplateURL url2(NULL, data);
[email protected]243abf32012-05-15 18:28:20180 EXPECT_EQ("http://foobar", url2.url_ref().ParseURL("http://foo{fhqwhgads}bar",
181 &replacements, &valid));
[email protected]1a257262011-06-28 22:15:44182 EXPECT_TRUE(replacements.empty());
183 EXPECT_TRUE(valid);
184}
185
[email protected]d82443b2009-01-15 19:54:56186TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
[email protected]573889f22012-04-07 01:31:54187 TemplateURLData data;
188 data.SetURL("http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b");
[email protected]16fca9b82012-04-23 18:40:26189 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13190 EXPECT_TRUE(url.url_ref().IsValid());
191 ASSERT_TRUE(url.url_ref().SupportsReplacement());
192 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30193 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56194 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27195 EXPECT_EQ("http://fooxutf-8axyb/", result.spec());
[email protected]d82443b2009-01-15 19:54:56196}
197
198TEST_F(TemplateURLTest, URLRefTestEncoding2) {
[email protected]573889f22012-04-07 01:31:54199 TemplateURLData data;
200 data.SetURL("http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a");
[email protected]16fca9b82012-04-23 18:40:26201 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13202 EXPECT_TRUE(url.url_ref().IsValid());
203 ASSERT_TRUE(url.url_ref().SupportsReplacement());
204 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30205 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56206 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27207 EXPECT_EQ("http://fooxxutf-8yutf-8a/", result.spec());
[email protected]d82443b2009-01-15 19:54:56208}
209
[email protected]375bd7312010-08-30 22:18:13210TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) {
211 struct SearchTermsCase {
212 const char* url;
[email protected]400b133f2011-01-19 18:32:30213 const string16 terms;
[email protected]375bd7312010-08-30 22:18:13214 const char* output;
215 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:30216 { "{google:baseURL}{language}{searchTerms}", string16(),
[email protected]b37bdfe2012-03-16 20:53:27217 "http://example.com/e/en" },
[email protected]400b133f2011-01-19 18:32:30218 { "{google:baseSuggestURL}{searchTerms}", string16(),
[email protected]014010e2011-10-01 04:12:44219 "http://example.com/complete/" }
[email protected]375bd7312010-08-30 22:18:13220 };
221
222 TestSearchTermsData search_terms_data("http://example.com/e/");
[email protected]573889f22012-04-07 01:31:54223 TemplateURLData data;
[email protected]375bd7312010-08-30 22:18:13224 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
225 const SearchTermsCase& value = search_term_cases[i];
[email protected]573889f22012-04-07 01:31:54226 data.SetURL(value.url);
[email protected]16fca9b82012-04-23 18:40:26227 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13228 EXPECT_TRUE(url.url_ref().IsValid());
229 ASSERT_TRUE(url.url_ref().SupportsReplacement());
230 GURL result(url.url_ref().ReplaceSearchTermsUsingTermsData(value.terms,
[email protected]400b133f2011-01-19 18:32:30231 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
[email protected]375bd7312010-08-30 22:18:13232 search_terms_data));
233 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27234 EXPECT_EQ(value.output, result.spec());
[email protected]375bd7312010-08-30 22:18:13235 }
236}
237
[email protected]d82443b2009-01-15 19:54:56238TEST_F(TemplateURLTest, URLRefTermToWide) {
239 struct ToWideCase {
240 const char* encoded_search_term;
[email protected]400b133f2011-01-19 18:32:30241 const string16 expected_decoded_term;
[email protected]d82443b2009-01-15 19:54:56242 } to_wide_cases[] = {
[email protected]400b133f2011-01-19 18:32:30243 {"hello+world", ASCIIToUTF16("hello world")},
[email protected]d82443b2009-01-15 19:54:56244 // Test some big-5 input.
[email protected]400b133f2011-01-19 18:32:30245 {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56246 // Test some UTF-8 input. We should fall back to this when the encoding
247 // doesn't look like big-5. We have a '5' in the middle, which is an invalid
248 // Big-5 trailing byte.
[email protected]400b133f2011-01-19 18:32:30249 {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56250 // Undecodable input should stay escaped.
[email protected]400b133f2011-01-19 18:32:30251 {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")},
[email protected]7df43482009-07-31 19:37:44252 // Make sure we convert %2B to +.
[email protected]400b133f2011-01-19 18:32:30253 {"C%2B%2B", ASCIIToUTF16("C++")},
[email protected]7df43482009-07-31 19:37:44254 // C%2B is escaped as C%252B, make sure we unescape it properly.
[email protected]400b133f2011-01-19 18:32:30255 {"C%252B", ASCIIToUTF16("C%2B")},
[email protected]d82443b2009-01-15 19:54:56256 };
257
[email protected]d82443b2009-01-15 19:54:56258 // Set one input encoding: big-5. This is so we can test fallback to UTF-8.
[email protected]573889f22012-04-07 01:31:54259 TemplateURLData data;
260 data.SetURL("http://foo?q={searchTerms}");
261 data.input_encodings.push_back("big-5");
[email protected]16fca9b82012-04-23 18:40:26262 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13263 EXPECT_TRUE(url.url_ref().IsValid());
264 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]f63ae312009-02-04 17:58:46265 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) {
[email protected]9b74ab52012-03-30 16:08:07266 EXPECT_EQ(to_wide_cases[i].expected_decoded_term,
[email protected]360ba052012-04-04 17:26:13267 url.url_ref().SearchTermToString16(
268 to_wide_cases[i].encoded_search_term));
[email protected]d82443b2009-01-15 19:54:56269 }
270}
271
[email protected]d82443b2009-01-15 19:54:56272TEST_F(TemplateURLTest, DisplayURLToURLRef) {
273 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19274 const std::string url;
[email protected]400b133f2011-01-19 18:32:30275 const string16 expected_result;
[email protected]b37bdfe2012-03-16 20:53:27276 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19277 { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a",
[email protected]400b133f2011-01-19 18:32:30278 ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") },
[email protected]ddd231e2010-06-29 20:35:19279 { "http://X",
[email protected]400b133f2011-01-19 18:32:30280 ASCIIToUTF16("http://X") },
[email protected]ddd231e2010-06-29 20:35:19281 { "http://foo{searchTerms",
[email protected]400b133f2011-01-19 18:32:30282 ASCIIToUTF16("http://foo{searchTerms") },
[email protected]ddd231e2010-06-29 20:35:19283 { "http://foo{searchTerms}{language}",
[email protected]400b133f2011-01-19 18:32:30284 ASCIIToUTF16("http://foo%s{language}") },
[email protected]d82443b2009-01-15 19:54:56285 };
[email protected]573889f22012-04-07 01:31:54286 TemplateURLData data;
[email protected]b37bdfe2012-03-16 20:53:27287 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54288 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26289 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13290 EXPECT_EQ(test_data[i].expected_result, url.url_ref().DisplayURL());
[email protected]b37bdfe2012-03-16 20:53:27291 EXPECT_EQ(test_data[i].url,
[email protected]360ba052012-04-04 17:26:13292 TemplateURLRef::DisplayURLToURLRef(url.url_ref().DisplayURL()));
[email protected]d82443b2009-01-15 19:54:56293 }
294}
295
296TEST_F(TemplateURLTest, ReplaceSearchTerms) {
297 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19298 const std::string url;
[email protected]d82443b2009-01-15 19:54:56299 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27300 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19301 { "http://foo/{language}{searchTerms}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56302 "http://foo/{language}XUTF-8" },
[email protected]ddd231e2010-06-29 20:35:19303 { "http://foo/{language}{inputEncoding}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56304 "http://foo/{language}UTF-8X" },
[email protected]ddd231e2010-06-29 20:35:19305 { "http://foo/{searchTerms}{language}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56306 "http://foo/X{language}UTF-8" },
[email protected]ddd231e2010-06-29 20:35:19307 { "http://foo/{searchTerms}{inputEncoding}{language}",
[email protected]d82443b2009-01-15 19:54:56308 "http://foo/XUTF-8{language}" },
[email protected]ddd231e2010-06-29 20:35:19309 { "http://foo/{inputEncoding}{searchTerms}{language}",
[email protected]d82443b2009-01-15 19:54:56310 "http://foo/UTF-8X{language}" },
[email protected]ddd231e2010-06-29 20:35:19311 { "http://foo/{inputEncoding}{language}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56312 "http://foo/UTF-8{language}X" },
[email protected]ddd231e2010-06-29 20:35:19313 { "http://foo/{language}a{searchTerms}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56314 "http://foo/{language}aXaUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19315 { "http://foo/{language}a{inputEncoding}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56316 "http://foo/{language}aUTF-8aXa" },
[email protected]ddd231e2010-06-29 20:35:19317 { "http://foo/{searchTerms}a{language}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56318 "http://foo/Xa{language}aUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19319 { "http://foo/{searchTerms}a{inputEncoding}a{language}a",
[email protected]d82443b2009-01-15 19:54:56320 "http://foo/XaUTF-8a{language}a" },
[email protected]ddd231e2010-06-29 20:35:19321 { "http://foo/{inputEncoding}a{searchTerms}a{language}a",
[email protected]d82443b2009-01-15 19:54:56322 "http://foo/UTF-8aXa{language}a" },
[email protected]ddd231e2010-06-29 20:35:19323 { "http://foo/{inputEncoding}a{language}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56324 "http://foo/UTF-8a{language}aXa" },
325 };
[email protected]573889f22012-04-07 01:31:54326 TemplateURLData data;
327 data.input_encodings.push_back("UTF-8");
[email protected]b37bdfe2012-03-16 20:53:27328 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54329 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26330 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13331 EXPECT_TRUE(url.url_ref().IsValid());
[email protected]3954c3a2012-04-10 20:17:55332 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27333 std::string expected_result = test_data[i].expected_result;
[email protected]d82443b2009-01-15 19:54:56334 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}",
[email protected]d70539de2009-06-24 22:17:06335 g_browser_process->GetApplicationLocale());
[email protected]360ba052012-04-04 17:26:13336 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30337 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]b37bdfe2012-03-16 20:53:27338 ASSERT_TRUE(result.is_valid());
[email protected]d82443b2009-01-15 19:54:56339 EXPECT_EQ(expected_result, result.spec());
340 }
341}
342
343
344// Tests replacing search terms in various encodings and making sure the
345// generated URL matches the expected value.
346TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {
347 struct TestData {
348 const std::string encoding;
[email protected]400b133f2011-01-19 18:32:30349 const string16 search_term;
[email protected]ddd231e2010-06-29 20:35:19350 const std::string url;
[email protected]d82443b2009-01-15 19:54:56351 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27352 } test_data[] = {
[email protected]400b133f2011-01-19 18:32:30353 { "BIG5", WideToUTF16(L"\x60BD"),
354 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17355 "http://foo/?%B1~BIG5" },
[email protected]400b133f2011-01-19 18:32:30356 { "UTF-8", ASCIIToUTF16("blah"),
357 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17358 "http://foo/?blahUTF-8" },
[email protected]34e24852012-01-31 18:43:58359 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"),
360 "http://foo/{searchTerms}/bar",
361 "http://foo/%82%A0/bar"},
362 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"),
363 "http://foo/{searchTerms}/bar",
364 "http://foo/%82%A0%20%82%A2/bar"},
[email protected]d82443b2009-01-15 19:54:56365 };
[email protected]573889f22012-04-07 01:31:54366 TemplateURLData data;
[email protected]b37bdfe2012-03-16 20:53:27367 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54368 data.SetURL(test_data[i].url);
369 data.input_encodings.clear();
370 data.input_encodings.push_back(test_data[i].encoding);
[email protected]16fca9b82012-04-23 18:40:26371 TemplateURL url(NULL, data);
[email protected]3954c3a2012-04-10 20:17:55372 EXPECT_TRUE(url.url_ref().IsValid());
373 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]360ba052012-04-04 17:26:13374 GURL result(url.url_ref().ReplaceSearchTerms(test_data[i].search_term,
[email protected]b37bdfe2012-03-16 20:53:27375 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
376 ASSERT_TRUE(result.is_valid());
377 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56378 }
379}
380
381TEST_F(TemplateURLTest, Suggestions) {
382 struct TestData {
383 const int accepted_suggestion;
[email protected]400b133f2011-01-19 18:32:30384 const string16 original_query_for_suggestion;
[email protected]d82443b2009-01-15 19:54:56385 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27386 } test_data[] = {
[email protected]400b133f2011-01-19 18:32:30387 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
[email protected]d82443b2009-01-15 19:54:56388 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30389 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"),
[email protected]d82443b2009-01-15 19:54:56390 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30391 { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(),
[email protected]d82443b2009-01-15 19:54:56392 "http://bar/foo?aq=f&q=foobar" },
[email protected]400b133f2011-01-19 18:32:30393 { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"),
[email protected]d82443b2009-01-15 19:54:56394 "http://bar/foo?aq=f&q=foobar" },
[email protected]400b133f2011-01-19 18:32:30395 { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" },
396 { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" },
[email protected]d82443b2009-01-15 19:54:56397 };
[email protected]573889f22012-04-07 01:31:54398 TemplateURLData data;
399 data.SetURL("http://bar/foo?{google:acceptedSuggestion}"
400 "{google:originalQueryForSuggestion}q={searchTerms}");
401 data.input_encodings.push_back("UTF-8");
[email protected]16fca9b82012-04-23 18:40:26402 TemplateURL url(NULL, data);
[email protected]3954c3a2012-04-10 20:17:55403 EXPECT_TRUE(url.url_ref().IsValid());
[email protected]360ba052012-04-04 17:26:13404 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27405 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]360ba052012-04-04 17:26:13406 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("foobar"),
[email protected]b37bdfe2012-03-16 20:53:27407 test_data[i].accepted_suggestion,
408 test_data[i].original_query_for_suggestion));
409 ASSERT_TRUE(result.is_valid());
410 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56411 }
412}
413
[email protected]81d9b72d2012-03-26 22:29:17414#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]81f808de2009-09-25 01:36:34415TEST_F(TemplateURLTest, RLZ) {
[email protected]400b133f2011-01-19 18:32:30416 string16 rlz_string;
[email protected]81d9b72d2012-03-26 22:29:17417#if defined(ENABLE_RLZ)
418 std::string brand;
419 if (google_util::GetBrand(&brand) && !brand.empty() &&
420 !google_util::IsOrganic(brand)) {
421 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string);
422 }
[email protected]58b64332010-08-13 16:09:39423#endif
[email protected]d82443b2009-01-15 19:54:56424
[email protected]573889f22012-04-07 01:31:54425 TemplateURLData data;
426 data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
[email protected]16fca9b82012-04-23 18:40:26427 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13428 EXPECT_TRUE(url.url_ref().IsValid());
429 ASSERT_TRUE(url.url_ref().SupportsReplacement());
430 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"),
[email protected]400b133f2011-01-19 18:32:30431 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56432 ASSERT_TRUE(result.is_valid());
[email protected]12bd05872009-03-17 19:25:06433 std::string expected_url = "http://bar/?";
[email protected]b37bdfe2012-03-16 20:53:27434 if (!rlz_string.empty())
[email protected]8ead4c022012-03-17 02:09:50435 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&";
[email protected]12bd05872009-03-17 19:25:06436 expected_url += "x";
[email protected]b37bdfe2012-03-16 20:53:27437 EXPECT_EQ(expected_url, result.spec());
[email protected]d82443b2009-01-15 19:54:56438}
[email protected]81f808de2009-09-25 01:36:34439#endif
[email protected]d82443b2009-01-15 19:54:56440
441TEST_F(TemplateURLTest, HostAndSearchTermKey) {
442 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19443 const std::string url;
[email protected]d82443b2009-01-15 19:54:56444 const std::string host;
445 const std::string path;
446 const std::string search_term_key;
[email protected]573889f22012-04-07 01:31:54447 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19448 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56449
450 // No query key should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19451 { "http://blah/{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56452
453 // No term should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19454 { "http://blah/", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56455
456 // Multiple terms should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19457 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56458
459 // Term in the host shouldn't match.
[email protected]ddd231e2010-06-29 20:35:19460 { "http://{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56461
[email protected]ddd231e2010-06-29 20:35:19462 { "http://blah/?q={searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56463
464 // Single term with extra chars in value should match.
[email protected]ddd231e2010-06-29 20:35:19465 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56466 };
467
[email protected]573889f22012-04-07 01:31:54468 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
469 TemplateURLData data;
470 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26471 TemplateURL url(NULL, data);
[email protected]573889f22012-04-07 01:31:54472 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost());
473 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath());
474 EXPECT_EQ(test_data[i].search_term_key, url.url_ref().GetSearchTermKey());
[email protected]d82443b2009-01-15 19:54:56475 }
476}
477
478TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {
479 static const struct {
[email protected]ddd231e2010-06-29 20:35:19480 const char* const base_url;
481 const char* const base_suggest_url;
[email protected]d82443b2009-01-15 19:54:56482 } data[] = {
[email protected]014010e2011-10-01 04:12:44483 { "http://google.com/", "http://google.com/complete/", },
484 { "http://www.google.com/", "http://www.google.com/complete/", },
485 { "http://www.google.co.uk/", "http://www.google.co.uk/complete/", },
486 { "http://www.google.com.by/", "http://www.google.com.by/complete/", },
487 { "http://google.com/intl/xx/", "http://google.com/complete/", },
[email protected]d82443b2009-01-15 19:54:56488 };
489
[email protected]f63ae312009-02-04 17:58:46490 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i)
[email protected]d82443b2009-01-15 19:54:56491 CheckSuggestBaseURL(data[i].base_url, data[i].base_suggest_url);
492}
493
[email protected]81c6ef62010-01-21 09:58:47494TEST_F(TemplateURLTest, ParseParameterKnown) {
[email protected]ddd231e2010-06-29 20:35:19495 std::string parsed_url("{searchTerms}");
[email protected]573889f22012-04-07 01:31:54496 TemplateURLData data;
497 data.SetURL(parsed_url);
[email protected]16fca9b82012-04-23 18:40:26498 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47499 TemplateURLRef::Replacements replacements;
[email protected]360ba052012-04-04 17:26:13500 EXPECT_TRUE(url.url_ref().ParseParameter(0, 12, &parsed_url, &replacements));
[email protected]ddd231e2010-06-29 20:35:19501 EXPECT_EQ(std::string(), parsed_url);
[email protected]81c6ef62010-01-21 09:58:47502 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27503 EXPECT_EQ(0U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47504 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
505}
506
507TEST_F(TemplateURLTest, ParseParameterUnknown) {
[email protected]243abf32012-05-15 18:28:20508 std::string parsed_url("{fhqwhgads}abc");
[email protected]573889f22012-04-07 01:31:54509 TemplateURLData data;
510 data.SetURL(parsed_url);
[email protected]16fca9b82012-04-23 18:40:26511 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47512 TemplateURLRef::Replacements replacements;
[email protected]1a257262011-06-28 22:15:44513
514 // By default, TemplateURLRef should not consider itself prepopulated.
515 // Therefore we should not replace the unknown parameter.
[email protected]360ba052012-04-04 17:26:13516 EXPECT_FALSE(url.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]243abf32012-05-15 18:28:20517 EXPECT_EQ("{fhqwhgads}abc", parsed_url);
[email protected]1a257262011-06-28 22:15:44518 EXPECT_TRUE(replacements.empty());
519
520 // If the TemplateURLRef is prepopulated, we should remove unknown parameters.
[email protected]243abf32012-05-15 18:28:20521 parsed_url = "{fhqwhgads}abc";
[email protected]573889f22012-04-07 01:31:54522 data.prepopulate_id = 1;
[email protected]16fca9b82012-04-23 18:40:26523 TemplateURL url2(NULL, data);
[email protected]495c30b2012-05-15 18:48:15524 EXPECT_TRUE(url2.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]243abf32012-05-15 18:28:20525 EXPECT_EQ("abc", parsed_url);
[email protected]81c6ef62010-01-21 09:58:47526 EXPECT_TRUE(replacements.empty());
527}
528
529TEST_F(TemplateURLTest, ParseURLEmpty) {
[email protected]16fca9b82012-04-23 18:40:26530 TemplateURL url(NULL, TemplateURLData());
[email protected]81c6ef62010-01-21 09:58:47531 TemplateURLRef::Replacements replacements;
532 bool valid = false;
[email protected]b37bdfe2012-03-16 20:53:27533 EXPECT_EQ(std::string(),
[email protected]360ba052012-04-04 17:26:13534 url.url_ref().ParseURL(std::string(), &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47535 EXPECT_TRUE(replacements.empty());
536 EXPECT_TRUE(valid);
537}
538
539TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
[email protected]573889f22012-04-07 01:31:54540 TemplateURLData data;
541 data.SetURL("{");
[email protected]16fca9b82012-04-23 18:40:26542 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47543 TemplateURLRef::Replacements replacements;
544 bool valid = false;
[email protected]360ba052012-04-04 17:26:13545 EXPECT_EQ(std::string(), url.url_ref().ParseURL("{", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47546 EXPECT_TRUE(replacements.empty());
547 EXPECT_FALSE(valid);
548}
549
550TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
[email protected]573889f22012-04-07 01:31:54551 TemplateURLData data;
552 data.SetURL("{}");
[email protected]16fca9b82012-04-23 18:40:26553 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47554 TemplateURLRef::Replacements replacements;
555 bool valid = false;
[email protected]360ba052012-04-04 17:26:13556 EXPECT_EQ("{}", url.url_ref().ParseURL("{}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47557 EXPECT_TRUE(replacements.empty());
558 EXPECT_TRUE(valid);
559}
560
561TEST_F(TemplateURLTest, ParseURLTwoParameters) {
[email protected]573889f22012-04-07 01:31:54562 TemplateURLData data;
563 data.SetURL("{}{{%s}}");
[email protected]16fca9b82012-04-23 18:40:26564 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47565 TemplateURLRef::Replacements replacements;
566 bool valid = false;
[email protected]ddd231e2010-06-29 20:35:19567 EXPECT_EQ("{}{}",
[email protected]360ba052012-04-04 17:26:13568 url.url_ref().ParseURL("{}{{searchTerms}}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47569 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27570 EXPECT_EQ(3U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47571 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
572 EXPECT_TRUE(valid);
573}
574
575TEST_F(TemplateURLTest, ParseURLNestedParameter) {
[email protected]573889f22012-04-07 01:31:54576 TemplateURLData data;
577 data.SetURL("{%s");
[email protected]16fca9b82012-04-23 18:40:26578 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47579 TemplateURLRef::Replacements replacements;
580 bool valid = false;
[email protected]360ba052012-04-04 17:26:13581 EXPECT_EQ("{",
582 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47583 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27584 EXPECT_EQ(1U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47585 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
586 EXPECT_TRUE(valid);
587}