blob: 594978cbce11e9e1d3310ef77b7ac3717242d5ff [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]b37bdfe2012-03-16 20:53:2714// TestSearchTermsData --------------------------------------------------------
15
[email protected]375bd7312010-08-30 22:18:1316// Simple implementation of SearchTermsData.
17class TestSearchTermsData : public SearchTermsData {
18 public:
[email protected]b37bdfe2012-03-16 20:53:2719 explicit TestSearchTermsData(const std::string& google_base_url);
[email protected]375bd7312010-08-30 22:18:1320
[email protected]b37bdfe2012-03-16 20:53:2721 virtual std::string GoogleBaseURLValue() const OVERRIDE;
[email protected]375bd7312010-08-30 22:18:1322
23 private:
24 std::string google_base_url_;
25
26 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData);
27};
28
[email protected]b37bdfe2012-03-16 20:53:2729TestSearchTermsData::TestSearchTermsData(const std::string& google_base_url)
30 : google_base_url_(google_base_url) {
31}
32
33std::string TestSearchTermsData::GoogleBaseURLValue() const {
34 return google_base_url_;
35}
36
37
38// TemplateURLTest ------------------------------------------------------------
39
[email protected]583844c2011-08-27 00:38:3540class TemplateURLTest : public testing::Test {
[email protected]d82443b2009-01-15 19:54:5641 public:
[email protected]b37bdfe2012-03-16 20:53:2742 void CheckSuggestBaseURL(const std::string& base_url,
43 const std::string& base_suggest_url) const;
[email protected]d82443b2009-01-15 19:54:5644};
45
[email protected]b37bdfe2012-03-16 20:53:2746void TemplateURLTest::CheckSuggestBaseURL(
47 const std::string& base_url,
48 const std::string& base_suggest_url) const {
49 TestSearchTermsData search_terms_data(base_url);
50 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue());
51}
52
53
54// Actual tests ---------------------------------------------------------------
55
[email protected]d82443b2009-01-15 19:54:5656TEST_F(TemplateURLTest, Defaults) {
57 TemplateURL url;
[email protected]9ca2d122012-03-22 19:41:2258 EXPECT_FALSE(url.show_in_default_list());
59 EXPECT_FALSE(url.safe_for_autoreplace());
60 EXPECT_EQ(0, url.prepopulate_id());
[email protected]d82443b2009-01-15 19:54:5661}
62
63TEST_F(TemplateURLTest, TestValidWithComplete) {
[email protected]ddd231e2010-06-29 20:35:1964 TemplateURLRef ref("{searchTerms}", 0, 0);
[email protected]9ca2d122012-03-22 19:41:2265 EXPECT_TRUE(ref.IsValid());
[email protected]d82443b2009-01-15 19:54:5666}
67
68TEST_F(TemplateURLTest, URLRefTestSearchTerms) {
[email protected]0d2e6a62010-01-15 20:09:1969 struct SearchTermsCase {
[email protected]ddd231e2010-06-29 20:35:1970 const char* url;
[email protected]400b133f2011-01-19 18:32:3071 const string16 terms;
[email protected]34e24852012-01-31 18:43:5872 const std::string output;
73 bool valid_url;
[email protected]0d2e6a62010-01-15 20:09:1974 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:3075 { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]34e24852012-01-31 18:43:5876 "http://foosea%20rch%2Fbar", false },
[email protected]400b133f2011-01-19 18:32:3077 { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"),
[email protected]34e24852012-01-31 18:43:5878 "http://foosea%20rch%2Fbar?boo=abc", false },
[email protected]400b133f2011-01-19 18:32:3079 { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]34e24852012-01-31 18:43:5880 "http://foo/?boo=sea+rch%2Fbar", true },
[email protected]400b133f2011-01-19 18:32:3081 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"),
[email protected]34e24852012-01-31 18:43:5882 "http://en.wikipedia.org/wiki%2F%3F", true }
[email protected]0d2e6a62010-01-15 20:09:1983 };
84 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
85 const SearchTermsCase& value = search_term_cases[i];
86 TemplateURL t_url;
87 TemplateURLRef ref(value.url, 0, 0);
88 ASSERT_TRUE(ref.IsValid());
[email protected]d82443b2009-01-15 19:54:5689
[email protected]0d2e6a62010-01-15 20:09:1990 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]34e24852012-01-31 18:43:5891 std::string result = ref.ReplaceSearchTerms(t_url, value.terms,
92 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16());
93 ASSERT_EQ(value.output, result);
[email protected]b37bdfe2012-03-16 20:53:2794 GURL result_url(result);
[email protected]34e24852012-01-31 18:43:5895 ASSERT_EQ(value.valid_url, result_url.is_valid());
[email protected]0d2e6a62010-01-15 20:09:1996 }
[email protected]d82443b2009-01-15 19:54:5697}
98
99TEST_F(TemplateURLTest, URLRefTestCount) {
100 TemplateURL t_url;
[email protected]ddd231e2010-06-29 20:35:19101 TemplateURLRef ref("http://foo{searchTerms}{count?}", 0, 0);
[email protected]d82443b2009-01-15 19:54:56102 ASSERT_TRUE(ref.IsValid());
103 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27104 GURL result(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30105 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56106 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27107 EXPECT_EQ("http://foox/", result.spec());
[email protected]d82443b2009-01-15 19:54:56108}
109
110TEST_F(TemplateURLTest, URLRefTestCount2) {
111 TemplateURL t_url;
[email protected]ddd231e2010-06-29 20:35:19112 TemplateURLRef ref("http://foo{searchTerms}{count}", 0, 0);
[email protected]d82443b2009-01-15 19:54:56113 ASSERT_TRUE(ref.IsValid());
114 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27115 GURL result(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30116 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56117 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27118 EXPECT_EQ("http://foox10/", result.spec());
[email protected]d82443b2009-01-15 19:54:56119}
120
121TEST_F(TemplateURLTest, URLRefTestIndices) {
122 TemplateURL t_url;
[email protected]ddd231e2010-06-29 20:35:19123 TemplateURLRef ref("http://foo{searchTerms}x{startIndex?}y{startPage?}",
[email protected]d82443b2009-01-15 19:54:56124 1, 2);
125 ASSERT_TRUE(ref.IsValid());
126 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27127 GURL result(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30128 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56129 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27130 EXPECT_EQ("http://fooxxy/", result.spec());
[email protected]d82443b2009-01-15 19:54:56131}
132
133TEST_F(TemplateURLTest, URLRefTestIndices2) {
134 TemplateURL t_url;
[email protected]ddd231e2010-06-29 20:35:19135 TemplateURLRef ref("http://foo{searchTerms}x{startIndex}y{startPage}", 1, 2);
[email protected]d82443b2009-01-15 19:54:56136 ASSERT_TRUE(ref.IsValid());
137 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27138 GURL result(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30139 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56140 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27141 EXPECT_EQ("http://fooxx1y2/", result.spec());
[email protected]d82443b2009-01-15 19:54:56142}
143
144TEST_F(TemplateURLTest, URLRefTestEncoding) {
145 TemplateURL t_url;
146 TemplateURLRef ref(
[email protected]ddd231e2010-06-29 20:35:19147 "http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a", 1, 2);
[email protected]d82443b2009-01-15 19:54:56148 ASSERT_TRUE(ref.IsValid());
149 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27150 GURL result(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30151 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56152 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27153 EXPECT_EQ("http://fooxxutf-8ya/", result.spec());
[email protected]d82443b2009-01-15 19:54:56154}
155
[email protected]d88cb202011-08-17 20:03:01156// Test that setting the prepopulate ID from TemplateURL causes the stored
157// TemplateURLRef to handle parsing the URL parameters differently.
[email protected]1a257262011-06-28 22:15:44158TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
159 TemplateURL t_url;
160 t_url.SetURL("http://foo{fhqwhgads}", 0, 0);
161 TemplateURLRef::Replacements replacements;
162 bool valid = false;
[email protected]1a257262011-06-28 22:15:44163 EXPECT_EQ("http://foo{fhqwhgads}",
[email protected]b37bdfe2012-03-16 20:53:27164 t_url.url()->ParseURL("http://foo{fhqwhgads}", &replacements, &valid));
[email protected]1a257262011-06-28 22:15:44165 EXPECT_TRUE(replacements.empty());
166 EXPECT_TRUE(valid);
167
168 t_url.SetPrepopulateId(123);
169 EXPECT_EQ("http://foo",
[email protected]b37bdfe2012-03-16 20:53:27170 t_url.url()->ParseURL("http://foo{fhqwhgads}", &replacements, &valid));
[email protected]1a257262011-06-28 22:15:44171 EXPECT_TRUE(replacements.empty());
172 EXPECT_TRUE(valid);
173}
174
[email protected]d82443b2009-01-15 19:54:56175TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
176 TemplateURL t_url;
177 TemplateURLRef ref(
[email protected]ddd231e2010-06-29 20:35:19178 "http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b", 1, 2);
[email protected]d82443b2009-01-15 19:54:56179 ASSERT_TRUE(ref.IsValid());
180 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27181 GURL result(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30182 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56183 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27184 EXPECT_EQ("http://fooxutf-8axyb/", result.spec());
[email protected]d82443b2009-01-15 19:54:56185}
186
187TEST_F(TemplateURLTest, URLRefTestEncoding2) {
188 TemplateURL t_url;
189 TemplateURLRef ref(
[email protected]ddd231e2010-06-29 20:35:19190 "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 1, 2);
[email protected]d82443b2009-01-15 19:54:56191 ASSERT_TRUE(ref.IsValid());
192 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27193 GURL result(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30194 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56195 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27196 EXPECT_EQ("http://fooxxutf-8yutf-8a/", result.spec());
[email protected]d82443b2009-01-15 19:54:56197}
198
[email protected]375bd7312010-08-30 22:18:13199TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) {
200 struct SearchTermsCase {
201 const char* url;
[email protected]400b133f2011-01-19 18:32:30202 const string16 terms;
[email protected]375bd7312010-08-30 22:18:13203 const char* output;
204 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:30205 { "{google:baseURL}{language}{searchTerms}", string16(),
[email protected]b37bdfe2012-03-16 20:53:27206 "http://example.com/e/en" },
[email protected]400b133f2011-01-19 18:32:30207 { "{google:baseSuggestURL}{searchTerms}", string16(),
[email protected]014010e2011-10-01 04:12:44208 "http://example.com/complete/" }
[email protected]375bd7312010-08-30 22:18:13209 };
210
211 TestSearchTermsData search_terms_data("http://example.com/e/");
[email protected]b37bdfe2012-03-16 20:53:27212 TemplateURL t_url;
[email protected]375bd7312010-08-30 22:18:13213 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
214 const SearchTermsCase& value = search_term_cases[i];
[email protected]375bd7312010-08-30 22:18:13215 TemplateURLRef ref(value.url, 0, 0);
216 ASSERT_TRUE(ref.IsValid());
217
218 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27219 GURL result(ref.ReplaceSearchTermsUsingTermsData(t_url, value.terms,
[email protected]400b133f2011-01-19 18:32:30220 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
[email protected]375bd7312010-08-30 22:18:13221 search_terms_data));
222 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27223 EXPECT_EQ(value.output, result.spec());
[email protected]375bd7312010-08-30 22:18:13224 }
225}
226
[email protected]d82443b2009-01-15 19:54:56227TEST_F(TemplateURLTest, URLRefTermToWide) {
228 struct ToWideCase {
229 const char* encoded_search_term;
[email protected]400b133f2011-01-19 18:32:30230 const string16 expected_decoded_term;
[email protected]d82443b2009-01-15 19:54:56231 } to_wide_cases[] = {
[email protected]400b133f2011-01-19 18:32:30232 {"hello+world", ASCIIToUTF16("hello world")},
[email protected]d82443b2009-01-15 19:54:56233 // Test some big-5 input.
[email protected]400b133f2011-01-19 18:32:30234 {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56235 // Test some UTF-8 input. We should fall back to this when the encoding
236 // doesn't look like big-5. We have a '5' in the middle, which is an invalid
237 // Big-5 trailing byte.
[email protected]400b133f2011-01-19 18:32:30238 {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56239 // Undecodable input should stay escaped.
[email protected]400b133f2011-01-19 18:32:30240 {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")},
[email protected]7df43482009-07-31 19:37:44241 // Make sure we convert %2B to +.
[email protected]400b133f2011-01-19 18:32:30242 {"C%2B%2B", ASCIIToUTF16("C++")},
[email protected]7df43482009-07-31 19:37:44243 // C%2B is escaped as C%252B, make sure we unescape it properly.
[email protected]400b133f2011-01-19 18:32:30244 {"C%252B", ASCIIToUTF16("C%2B")},
[email protected]d82443b2009-01-15 19:54:56245 };
246
[email protected]d82443b2009-01-15 19:54:56247 // Set one input encoding: big-5. This is so we can test fallback to UTF-8.
[email protected]b37bdfe2012-03-16 20:53:27248 TemplateURL t_url;
[email protected]d82443b2009-01-15 19:54:56249 std::vector<std::string> encodings;
250 encodings.push_back("big-5");
251 t_url.set_input_encodings(encodings);
252
[email protected]ddd231e2010-06-29 20:35:19253 TemplateURLRef ref("http://foo?q={searchTerms}", 1, 2);
[email protected]d82443b2009-01-15 19:54:56254 ASSERT_TRUE(ref.IsValid());
255 ASSERT_TRUE(ref.SupportsReplacement());
256
[email protected]f63ae312009-02-04 17:58:46257 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) {
[email protected]400b133f2011-01-19 18:32:30258 string16 result = ref.SearchTermToString16(t_url,
[email protected]d82443b2009-01-15 19:54:56259 to_wide_cases[i].encoded_search_term);
260
[email protected]400b133f2011-01-19 18:32:30261 EXPECT_EQ(to_wide_cases[i].expected_decoded_term, result);
[email protected]d82443b2009-01-15 19:54:56262 }
263}
264
[email protected]59762552011-03-15 14:51:02265TEST_F(TemplateURLTest, SetFavicon) {
[email protected]d82443b2009-01-15 19:54:56266 GURL favicon_url("http://favicon.url");
[email protected]b37bdfe2012-03-16 20:53:27267 TemplateURL url;
[email protected]59762552011-03-15 14:51:02268 url.SetFaviconURL(favicon_url);
[email protected]9ca2d122012-03-22 19:41:22269 EXPECT_EQ(1U, url.image_refs().size());
270 EXPECT_EQ(favicon_url, url.GetFaviconURL());
[email protected]d82443b2009-01-15 19:54:56271
272 GURL favicon_url2("http://favicon2.url");
[email protected]59762552011-03-15 14:51:02273 url.SetFaviconURL(favicon_url2);
[email protected]b37bdfe2012-03-16 20:53:27274 EXPECT_EQ(1U, url.image_refs().size());
275 EXPECT_EQ(favicon_url2, url.GetFaviconURL());
[email protected]d82443b2009-01-15 19:54:56276}
277
278TEST_F(TemplateURLTest, DisplayURLToURLRef) {
279 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19280 const std::string url;
[email protected]400b133f2011-01-19 18:32:30281 const string16 expected_result;
[email protected]b37bdfe2012-03-16 20:53:27282 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19283 { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a",
[email protected]400b133f2011-01-19 18:32:30284 ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") },
[email protected]ddd231e2010-06-29 20:35:19285 { "http://X",
[email protected]400b133f2011-01-19 18:32:30286 ASCIIToUTF16("http://X") },
[email protected]ddd231e2010-06-29 20:35:19287 { "http://foo{searchTerms",
[email protected]400b133f2011-01-19 18:32:30288 ASCIIToUTF16("http://foo{searchTerms") },
[email protected]ddd231e2010-06-29 20:35:19289 { "http://foo{searchTerms}{language}",
[email protected]400b133f2011-01-19 18:32:30290 ASCIIToUTF16("http://foo%s{language}") },
[email protected]d82443b2009-01-15 19:54:56291 };
[email protected]b37bdfe2012-03-16 20:53:27292 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
293 TemplateURLRef ref(test_data[i].url, 1, 2);
294 EXPECT_EQ(test_data[i].expected_result, ref.DisplayURL());
295 EXPECT_EQ(test_data[i].url,
[email protected]d82443b2009-01-15 19:54:56296 TemplateURLRef::DisplayURLToURLRef(ref.DisplayURL()));
297 }
298}
299
300TEST_F(TemplateURLTest, ReplaceSearchTerms) {
301 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19302 const std::string url;
[email protected]d82443b2009-01-15 19:54:56303 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27304 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19305 { "http://foo/{language}{searchTerms}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56306 "http://foo/{language}XUTF-8" },
[email protected]ddd231e2010-06-29 20:35:19307 { "http://foo/{language}{inputEncoding}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56308 "http://foo/{language}UTF-8X" },
[email protected]ddd231e2010-06-29 20:35:19309 { "http://foo/{searchTerms}{language}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56310 "http://foo/X{language}UTF-8" },
[email protected]ddd231e2010-06-29 20:35:19311 { "http://foo/{searchTerms}{inputEncoding}{language}",
[email protected]d82443b2009-01-15 19:54:56312 "http://foo/XUTF-8{language}" },
[email protected]ddd231e2010-06-29 20:35:19313 { "http://foo/{inputEncoding}{searchTerms}{language}",
[email protected]d82443b2009-01-15 19:54:56314 "http://foo/UTF-8X{language}" },
[email protected]ddd231e2010-06-29 20:35:19315 { "http://foo/{inputEncoding}{language}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56316 "http://foo/UTF-8{language}X" },
[email protected]ddd231e2010-06-29 20:35:19317 { "http://foo/{language}a{searchTerms}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56318 "http://foo/{language}aXaUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19319 { "http://foo/{language}a{inputEncoding}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56320 "http://foo/{language}aUTF-8aXa" },
[email protected]ddd231e2010-06-29 20:35:19321 { "http://foo/{searchTerms}a{language}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56322 "http://foo/Xa{language}aUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19323 { "http://foo/{searchTerms}a{inputEncoding}a{language}a",
[email protected]d82443b2009-01-15 19:54:56324 "http://foo/XaUTF-8a{language}a" },
[email protected]ddd231e2010-06-29 20:35:19325 { "http://foo/{inputEncoding}a{searchTerms}a{language}a",
[email protected]d82443b2009-01-15 19:54:56326 "http://foo/UTF-8aXa{language}a" },
[email protected]ddd231e2010-06-29 20:35:19327 { "http://foo/{inputEncoding}a{language}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56328 "http://foo/UTF-8a{language}aXa" },
329 };
330 TemplateURL turl;
331 turl.add_input_encoding("UTF-8");
[email protected]b37bdfe2012-03-16 20:53:27332 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
333 TemplateURLRef ref(test_data[i].url, 1, 2);
[email protected]d82443b2009-01-15 19:54:56334 EXPECT_TRUE(ref.IsValid());
335 EXPECT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27336 std::string expected_result = test_data[i].expected_result;
[email protected]d82443b2009-01-15 19:54:56337 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}",
[email protected]d70539de2009-06-24 22:17:06338 g_browser_process->GetApplicationLocale());
[email protected]b37bdfe2012-03-16 20:53:27339 GURL result(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("X"),
[email protected]400b133f2011-01-19 18:32:30340 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]b37bdfe2012-03-16 20:53:27341 ASSERT_TRUE(result.is_valid());
[email protected]d82443b2009-01-15 19:54:56342 EXPECT_EQ(expected_result, result.spec());
343 }
344}
345
346
347// Tests replacing search terms in various encodings and making sure the
348// generated URL matches the expected value.
349TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {
350 struct TestData {
351 const std::string encoding;
[email protected]400b133f2011-01-19 18:32:30352 const string16 search_term;
[email protected]ddd231e2010-06-29 20:35:19353 const std::string url;
[email protected]d82443b2009-01-15 19:54:56354 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27355 } test_data[] = {
[email protected]400b133f2011-01-19 18:32:30356 { "BIG5", WideToUTF16(L"\x60BD"),
357 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17358 "http://foo/?%B1~BIG5" },
[email protected]400b133f2011-01-19 18:32:30359 { "UTF-8", ASCIIToUTF16("blah"),
360 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17361 "http://foo/?blahUTF-8" },
[email protected]34e24852012-01-31 18:43:58362 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"),
363 "http://foo/{searchTerms}/bar",
364 "http://foo/%82%A0/bar"},
365 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"),
366 "http://foo/{searchTerms}/bar",
367 "http://foo/%82%A0%20%82%A2/bar"},
[email protected]d82443b2009-01-15 19:54:56368 };
[email protected]b37bdfe2012-03-16 20:53:27369 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]d82443b2009-01-15 19:54:56370 TemplateURL turl;
[email protected]b37bdfe2012-03-16 20:53:27371 turl.add_input_encoding(test_data[i].encoding);
372 TemplateURLRef ref(test_data[i].url, 1, 2);
373 GURL result(ref.ReplaceSearchTerms(turl, test_data[i].search_term,
374 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
375 ASSERT_TRUE(result.is_valid());
376 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56377 }
378}
379
380TEST_F(TemplateURLTest, Suggestions) {
381 struct TestData {
382 const int accepted_suggestion;
[email protected]400b133f2011-01-19 18:32:30383 const string16 original_query_for_suggestion;
[email protected]d82443b2009-01-15 19:54:56384 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27385 } test_data[] = {
[email protected]400b133f2011-01-19 18:32:30386 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
[email protected]d82443b2009-01-15 19:54:56387 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30388 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"),
[email protected]d82443b2009-01-15 19:54:56389 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30390 { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(),
[email protected]d82443b2009-01-15 19:54:56391 "http://bar/foo?aq=f&q=foobar" },
[email protected]400b133f2011-01-19 18:32:30392 { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"),
[email protected]d82443b2009-01-15 19:54:56393 "http://bar/foo?aq=f&q=foobar" },
[email protected]400b133f2011-01-19 18:32:30394 { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" },
395 { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" },
[email protected]d82443b2009-01-15 19:54:56396 };
397 TemplateURL turl;
398 turl.add_input_encoding("UTF-8");
[email protected]ddd231e2010-06-29 20:35:19399 TemplateURLRef ref("http://bar/foo?{google:acceptedSuggestion}"
400 "{google:originalQueryForSuggestion}q={searchTerms}", 1, 2);
[email protected]d82443b2009-01-15 19:54:56401 ASSERT_TRUE(ref.IsValid());
402 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27403 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
404 GURL result(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("foobar"),
405 test_data[i].accepted_suggestion,
406 test_data[i].original_query_for_suggestion));
407 ASSERT_TRUE(result.is_valid());
408 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56409 }
410}
411
[email protected]12bd05872009-03-17 19:25:06412#if defined(OS_WIN)
[email protected]81f808de2009-09-25 01:36:34413TEST_F(TemplateURLTest, RLZ) {
[email protected]400b133f2011-01-19 18:32:30414 string16 rlz_string;
[email protected]58b64332010-08-13 16:09:39415#if defined(GOOGLE_CHROME_BUILD)
[email protected]1c262172010-06-10 15:25:46416 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string);
[email protected]58b64332010-08-13 16:09:39417#endif
[email protected]d82443b2009-01-15 19:54:56418
419 TemplateURL t_url;
[email protected]ddd231e2010-06-29 20:35:19420 TemplateURLRef ref("http://bar/?{google:RLZ}{searchTerms}", 1, 2);
[email protected]d82443b2009-01-15 19:54:56421 ASSERT_TRUE(ref.IsValid());
422 ASSERT_TRUE(ref.SupportsReplacement());
[email protected]8ead4c022012-03-17 02:09:50423 GURL result(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("x"),
[email protected]400b133f2011-01-19 18:32:30424 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
[email protected]d82443b2009-01-15 19:54:56425 ASSERT_TRUE(result.is_valid());
[email protected]12bd05872009-03-17 19:25:06426 std::string expected_url = "http://bar/?";
[email protected]b37bdfe2012-03-16 20:53:27427 if (!rlz_string.empty())
[email protected]8ead4c022012-03-17 02:09:50428 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&";
[email protected]12bd05872009-03-17 19:25:06429 expected_url += "x";
[email protected]b37bdfe2012-03-16 20:53:27430 EXPECT_EQ(expected_url, result.spec());
[email protected]d82443b2009-01-15 19:54:56431}
[email protected]81f808de2009-09-25 01:36:34432#endif
[email protected]d82443b2009-01-15 19:54:56433
434TEST_F(TemplateURLTest, HostAndSearchTermKey) {
435 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19436 const std::string url;
[email protected]d82443b2009-01-15 19:54:56437 const std::string host;
438 const std::string path;
439 const std::string search_term_key;
440 } data[] = {
[email protected]ddd231e2010-06-29 20:35:19441 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56442
443 // No query key should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19444 { "http://blah/{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56445
446 // No term should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19447 { "http://blah/", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56448
449 // Multiple terms should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19450 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56451
452 // Term in the host shouldn't match.
[email protected]ddd231e2010-06-29 20:35:19453 { "http://{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56454
[email protected]ddd231e2010-06-29 20:35:19455 { "http://blah/?q={searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56456
457 // Single term with extra chars in value should match.
[email protected]ddd231e2010-06-29 20:35:19458 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56459 };
460
[email protected]f63ae312009-02-04 17:58:46461 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
[email protected]b37bdfe2012-03-16 20:53:27462 TemplateURL t_url;
[email protected]d82443b2009-01-15 19:54:56463 t_url.SetURL(data[i].url, 0, 0);
464 EXPECT_EQ(data[i].host, t_url.url()->GetHost());
465 EXPECT_EQ(data[i].path, t_url.url()->GetPath());
466 EXPECT_EQ(data[i].search_term_key, t_url.url()->GetSearchTermKey());
467 }
468}
469
470TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {
471 static const struct {
[email protected]ddd231e2010-06-29 20:35:19472 const char* const base_url;
473 const char* const base_suggest_url;
[email protected]d82443b2009-01-15 19:54:56474 } data[] = {
[email protected]014010e2011-10-01 04:12:44475 { "http://google.com/", "http://google.com/complete/", },
476 { "http://www.google.com/", "http://www.google.com/complete/", },
477 { "http://www.google.co.uk/", "http://www.google.co.uk/complete/", },
478 { "http://www.google.com.by/", "http://www.google.com.by/complete/", },
479 { "http://google.com/intl/xx/", "http://google.com/complete/", },
[email protected]d82443b2009-01-15 19:54:56480 };
481
[email protected]f63ae312009-02-04 17:58:46482 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i)
[email protected]d82443b2009-01-15 19:54:56483 CheckSuggestBaseURL(data[i].base_url, data[i].base_suggest_url);
484}
485
486TEST_F(TemplateURLTest, Keyword) {
487 TemplateURL t_url;
[email protected]ddd231e2010-06-29 20:35:19488 t_url.SetURL("http://www.google.com/search", 0, 0);
[email protected]d82443b2009-01-15 19:54:56489 EXPECT_FALSE(t_url.autogenerate_keyword());
[email protected]400b133f2011-01-19 18:32:30490 t_url.set_keyword(ASCIIToUTF16("foo"));
491 EXPECT_EQ(ASCIIToUTF16("foo"), t_url.keyword());
[email protected]d82443b2009-01-15 19:54:56492 t_url.set_autogenerate_keyword(true);
493 EXPECT_TRUE(t_url.autogenerate_keyword());
[email protected]400b133f2011-01-19 18:32:30494 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url.keyword());
495 t_url.set_keyword(ASCIIToUTF16("foo"));
[email protected]d82443b2009-01-15 19:54:56496 EXPECT_FALSE(t_url.autogenerate_keyword());
[email protected]400b133f2011-01-19 18:32:30497 EXPECT_EQ(ASCIIToUTF16("foo"), t_url.keyword());
[email protected]d82443b2009-01-15 19:54:56498}
[email protected]81c6ef62010-01-21 09:58:47499
500TEST_F(TemplateURLTest, ParseParameterKnown) {
[email protected]ddd231e2010-06-29 20:35:19501 std::string parsed_url("{searchTerms}");
[email protected]81c6ef62010-01-21 09:58:47502 TemplateURLRef url_ref(parsed_url, 0, 0);
503 TemplateURLRef::Replacements replacements;
504 EXPECT_TRUE(url_ref.ParseParameter(0, 12, &parsed_url, &replacements));
[email protected]ddd231e2010-06-29 20:35:19505 EXPECT_EQ(std::string(), parsed_url);
[email protected]81c6ef62010-01-21 09:58:47506 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27507 EXPECT_EQ(0U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47508 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
509}
510
511TEST_F(TemplateURLTest, ParseParameterUnknown) {
[email protected]1a257262011-06-28 22:15:44512 std::string parsed_url("{fhqwhgads}");
[email protected]81c6ef62010-01-21 09:58:47513 TemplateURLRef url_ref(parsed_url, 0, 0);
514 TemplateURLRef::Replacements replacements;
[email protected]1a257262011-06-28 22:15:44515
516 // By default, TemplateURLRef should not consider itself prepopulated.
517 // Therefore we should not replace the unknown parameter.
518 EXPECT_FALSE(url_ref.ParseParameter(0, 10, &parsed_url, &replacements));
519 EXPECT_EQ("{fhqwhgads}", parsed_url);
520 EXPECT_TRUE(replacements.empty());
521
522 // If the TemplateURLRef is prepopulated, we should remove unknown parameters.
523 parsed_url = "{fhqwhgads}";
[email protected]b37bdfe2012-03-16 20:53:27524 url_ref.prepopulated_ = true;
[email protected]1a257262011-06-28 22:15:44525 EXPECT_FALSE(url_ref.ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]b37bdfe2012-03-16 20:53:27526 EXPECT_EQ(std::string(), parsed_url);
[email protected]81c6ef62010-01-21 09:58:47527 EXPECT_TRUE(replacements.empty());
528}
529
530TEST_F(TemplateURLTest, ParseURLEmpty) {
[email protected]9ca2d122012-03-22 19:41:22531 TemplateURLRef url_ref(std::string(), 0, 0);
[email protected]81c6ef62010-01-21 09:58:47532 TemplateURLRef::Replacements replacements;
533 bool valid = false;
[email protected]b37bdfe2012-03-16 20:53:27534 EXPECT_EQ(std::string(),
535 url_ref.ParseURL(std::string(), &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47536 EXPECT_TRUE(replacements.empty());
537 EXPECT_TRUE(valid);
538}
539
540TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
[email protected]ddd231e2010-06-29 20:35:19541 TemplateURLRef url_ref("{", 0, 0);
[email protected]81c6ef62010-01-21 09:58:47542 TemplateURLRef::Replacements replacements;
543 bool valid = false;
[email protected]ddd231e2010-06-29 20:35:19544 EXPECT_EQ(std::string(), url_ref.ParseURL("{", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47545 EXPECT_TRUE(replacements.empty());
546 EXPECT_FALSE(valid);
547}
548
549TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
[email protected]ddd231e2010-06-29 20:35:19550 TemplateURLRef url_ref("{}", 0, 0);
[email protected]81c6ef62010-01-21 09:58:47551 TemplateURLRef::Replacements replacements;
552 bool valid = false;
[email protected]ddd231e2010-06-29 20:35:19553 EXPECT_EQ("{}", url_ref.ParseURL("{}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47554 EXPECT_TRUE(replacements.empty());
555 EXPECT_TRUE(valid);
556}
557
558TEST_F(TemplateURLTest, ParseURLTwoParameters) {
[email protected]ddd231e2010-06-29 20:35:19559 TemplateURLRef url_ref("{}{{%s}}", 0, 0);
[email protected]81c6ef62010-01-21 09:58:47560 TemplateURLRef::Replacements replacements;
561 bool valid = false;
[email protected]ddd231e2010-06-29 20:35:19562 EXPECT_EQ("{}{}",
563 url_ref.ParseURL("{}{{searchTerms}}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47564 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27565 EXPECT_EQ(3U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47566 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
567 EXPECT_TRUE(valid);
568}
569
570TEST_F(TemplateURLTest, ParseURLNestedParameter) {
[email protected]ddd231e2010-06-29 20:35:19571 TemplateURLRef url_ref("{%s", 0, 0);
[email protected]81c6ef62010-01-21 09:58:47572 TemplateURLRef::Replacements replacements;
573 bool valid = false;
[email protected]ddd231e2010-06-29 20:35:19574 EXPECT_EQ("{", url_ref.ParseURL("{{searchTerms}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47575 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27576 EXPECT_EQ(1U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47577 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
578 EXPECT_TRUE(valid);
579}