blob: 089c1a1dab00494425ae7a3afceb7df39a2337a2 [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;
[email protected]0d2e6a62010-01-15 20:09:1979 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:3080 { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:1681 "http://foosea%20rch/bar" },
[email protected]400b133f2011-01-19 18:32:3082 { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:1683 "http://foosea%20rch/bar?boo=abc" },
[email protected]400b133f2011-01-19 18:32:3084 { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"),
[email protected]c31a979c2012-05-31 23:57:1685 "http://foo/?boo=sea+rch%2Fbar" },
[email protected]400b133f2011-01-19 18:32:3086 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"),
[email protected]c31a979c2012-05-31 23:57:1687 "http://en.wikipedia.org/wiki/%3F" }
[email protected]0d2e6a62010-01-15 20:09:1988 };
89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
90 const SearchTermsCase& value = search_term_cases[i];
[email protected]573889f22012-04-07 01:31:5491 TemplateURLData data;
92 data.SetURL(value.url);
[email protected]16fca9b82012-04-23 18:40:2693 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:1394 EXPECT_TRUE(url.url_ref().IsValid());
95 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:0496 GURL result(url.url_ref().ReplaceSearchTerms(
97 TemplateURLRef::SearchTermsArgs(value.terms)));
[email protected]c31a979c2012-05-31 23:57:1698 ASSERT_TRUE(result.is_valid());
99 EXPECT_EQ(value.output, result.spec());
[email protected]0d2e6a62010-01-15 20:09:19100 }
[email protected]d82443b2009-01-15 19:54:56101}
102
103TEST_F(TemplateURLTest, URLRefTestCount) {
[email protected]573889f22012-04-07 01:31:54104 TemplateURLData data;
105 data.SetURL("http://foo{searchTerms}{count?}");
[email protected]16fca9b82012-04-23 18:40:26106 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13107 EXPECT_TRUE(url.url_ref().IsValid());
108 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04109 GURL result(url.url_ref().ReplaceSearchTerms(
110 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56111 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27112 EXPECT_EQ("http://foox/", result.spec());
[email protected]d82443b2009-01-15 19:54:56113}
114
115TEST_F(TemplateURLTest, URLRefTestCount2) {
[email protected]573889f22012-04-07 01:31:54116 TemplateURLData data;
117 data.SetURL("http://foo{searchTerms}{count}");
[email protected]16fca9b82012-04-23 18:40:26118 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13119 EXPECT_TRUE(url.url_ref().IsValid());
120 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04121 GURL result(url.url_ref().ReplaceSearchTerms(
122 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56123 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27124 EXPECT_EQ("http://foox10/", result.spec());
[email protected]d82443b2009-01-15 19:54:56125}
126
127TEST_F(TemplateURLTest, URLRefTestIndices) {
[email protected]573889f22012-04-07 01:31:54128 TemplateURLData data;
129 data.SetURL("http://foo{searchTerms}x{startIndex?}y{startPage?}");
[email protected]16fca9b82012-04-23 18:40:26130 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13131 EXPECT_TRUE(url.url_ref().IsValid());
132 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04133 GURL result(url.url_ref().ReplaceSearchTerms(
134 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56135 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27136 EXPECT_EQ("http://fooxxy/", result.spec());
[email protected]d82443b2009-01-15 19:54:56137}
138
139TEST_F(TemplateURLTest, URLRefTestIndices2) {
[email protected]573889f22012-04-07 01:31:54140 TemplateURLData data;
141 data.SetURL("http://foo{searchTerms}x{startIndex}y{startPage}");
[email protected]16fca9b82012-04-23 18:40:26142 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13143 EXPECT_TRUE(url.url_ref().IsValid());
144 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04145 GURL result(url.url_ref().ReplaceSearchTerms(
146 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56147 ASSERT_TRUE(result.is_valid());
[email protected]405aae22012-03-29 20:36:13148 EXPECT_EQ("http://fooxx1y1/", result.spec());
[email protected]d82443b2009-01-15 19:54:56149}
150
151TEST_F(TemplateURLTest, URLRefTestEncoding) {
[email protected]573889f22012-04-07 01:31:54152 TemplateURLData data;
153 data.SetURL("http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a");
[email protected]16fca9b82012-04-23 18:40:26154 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13155 EXPECT_TRUE(url.url_ref().IsValid());
156 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04157 GURL result(url.url_ref().ReplaceSearchTerms(
158 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56159 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27160 EXPECT_EQ("http://fooxxutf-8ya/", result.spec());
[email protected]d82443b2009-01-15 19:54:56161}
162
[email protected]d88cb202011-08-17 20:03:01163// Test that setting the prepopulate ID from TemplateURL causes the stored
164// TemplateURLRef to handle parsing the URL parameters differently.
[email protected]1a257262011-06-28 22:15:44165TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
[email protected]573889f22012-04-07 01:31:54166 TemplateURLData data;
[email protected]243abf32012-05-15 18:28:20167 data.SetURL("http://foo{fhqwhgads}bar");
[email protected]16fca9b82012-04-23 18:40:26168 TemplateURL url(NULL, data);
[email protected]1a257262011-06-28 22:15:44169 TemplateURLRef::Replacements replacements;
170 bool valid = false;
[email protected]243abf32012-05-15 18:28:20171 EXPECT_EQ("http://foo{fhqwhgads}bar", url.url_ref().ParseURL(
172 "http://foo{fhqwhgads}bar", &replacements, &valid));
[email protected]1a257262011-06-28 22:15:44173 EXPECT_TRUE(replacements.empty());
174 EXPECT_TRUE(valid);
175
[email protected]573889f22012-04-07 01:31:54176 data.prepopulate_id = 123;
[email protected]16fca9b82012-04-23 18:40:26177 TemplateURL url2(NULL, data);
[email protected]243abf32012-05-15 18:28:20178 EXPECT_EQ("http://foobar", url2.url_ref().ParseURL("http://foo{fhqwhgads}bar",
179 &replacements, &valid));
[email protected]1a257262011-06-28 22:15:44180 EXPECT_TRUE(replacements.empty());
181 EXPECT_TRUE(valid);
182}
183
[email protected]d82443b2009-01-15 19:54:56184TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
[email protected]573889f22012-04-07 01:31:54185 TemplateURLData data;
186 data.SetURL("http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b");
[email protected]16fca9b82012-04-23 18:40:26187 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13188 EXPECT_TRUE(url.url_ref().IsValid());
189 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04190 GURL result(url.url_ref().ReplaceSearchTerms(
191 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56192 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27193 EXPECT_EQ("http://fooxutf-8axyb/", result.spec());
[email protected]d82443b2009-01-15 19:54:56194}
195
196TEST_F(TemplateURLTest, URLRefTestEncoding2) {
[email protected]573889f22012-04-07 01:31:54197 TemplateURLData data;
198 data.SetURL("http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a");
[email protected]16fca9b82012-04-23 18:40:26199 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13200 EXPECT_TRUE(url.url_ref().IsValid());
201 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04202 GURL result(url.url_ref().ReplaceSearchTerms(
203 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]d82443b2009-01-15 19:54:56204 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27205 EXPECT_EQ("http://fooxxutf-8yutf-8a/", result.spec());
[email protected]d82443b2009-01-15 19:54:56206}
207
[email protected]375bd7312010-08-30 22:18:13208TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) {
209 struct SearchTermsCase {
210 const char* url;
[email protected]400b133f2011-01-19 18:32:30211 const string16 terms;
[email protected]375bd7312010-08-30 22:18:13212 const char* output;
213 } search_term_cases[] = {
[email protected]400b133f2011-01-19 18:32:30214 { "{google:baseURL}{language}{searchTerms}", string16(),
[email protected]b37bdfe2012-03-16 20:53:27215 "http://example.com/e/en" },
[email protected]400b133f2011-01-19 18:32:30216 { "{google:baseSuggestURL}{searchTerms}", string16(),
[email protected]014010e2011-10-01 04:12:44217 "http://example.com/complete/" }
[email protected]375bd7312010-08-30 22:18:13218 };
219
220 TestSearchTermsData search_terms_data("http://example.com/e/");
[email protected]573889f22012-04-07 01:31:54221 TemplateURLData data;
[email protected]375bd7312010-08-30 22:18:13222 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
223 const SearchTermsCase& value = search_term_cases[i];
[email protected]573889f22012-04-07 01:31:54224 data.SetURL(value.url);
[email protected]16fca9b82012-04-23 18:40:26225 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13226 EXPECT_TRUE(url.url_ref().IsValid());
227 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04228 GURL result(url.url_ref().ReplaceSearchTermsUsingTermsData(
229 TemplateURLRef::SearchTermsArgs(value.terms), search_terms_data));
[email protected]375bd7312010-08-30 22:18:13230 ASSERT_TRUE(result.is_valid());
[email protected]b37bdfe2012-03-16 20:53:27231 EXPECT_EQ(value.output, result.spec());
[email protected]375bd7312010-08-30 22:18:13232 }
233}
234
[email protected]d82443b2009-01-15 19:54:56235TEST_F(TemplateURLTest, URLRefTermToWide) {
236 struct ToWideCase {
237 const char* encoded_search_term;
[email protected]400b133f2011-01-19 18:32:30238 const string16 expected_decoded_term;
[email protected]d82443b2009-01-15 19:54:56239 } to_wide_cases[] = {
[email protected]400b133f2011-01-19 18:32:30240 {"hello+world", ASCIIToUTF16("hello world")},
[email protected]d82443b2009-01-15 19:54:56241 // Test some big-5 input.
[email protected]400b133f2011-01-19 18:32:30242 {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56243 // Test some UTF-8 input. We should fall back to this when the encoding
244 // doesn't look like big-5. We have a '5' in the middle, which is an invalid
245 // Big-5 trailing byte.
[email protected]400b133f2011-01-19 18:32:30246 {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")},
[email protected]d82443b2009-01-15 19:54:56247 // Undecodable input should stay escaped.
[email protected]400b133f2011-01-19 18:32:30248 {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")},
[email protected]7df43482009-07-31 19:37:44249 // Make sure we convert %2B to +.
[email protected]400b133f2011-01-19 18:32:30250 {"C%2B%2B", ASCIIToUTF16("C++")},
[email protected]7df43482009-07-31 19:37:44251 // C%2B is escaped as C%252B, make sure we unescape it properly.
[email protected]400b133f2011-01-19 18:32:30252 {"C%252B", ASCIIToUTF16("C%2B")},
[email protected]d82443b2009-01-15 19:54:56253 };
254
[email protected]d82443b2009-01-15 19:54:56255 // Set one input encoding: big-5. This is so we can test fallback to UTF-8.
[email protected]573889f22012-04-07 01:31:54256 TemplateURLData data;
257 data.SetURL("http://foo?q={searchTerms}");
258 data.input_encodings.push_back("big-5");
[email protected]16fca9b82012-04-23 18:40:26259 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13260 EXPECT_TRUE(url.url_ref().IsValid());
261 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]f63ae312009-02-04 17:58:46262 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) {
[email protected]9b74ab52012-03-30 16:08:07263 EXPECT_EQ(to_wide_cases[i].expected_decoded_term,
[email protected]360ba052012-04-04 17:26:13264 url.url_ref().SearchTermToString16(
265 to_wide_cases[i].encoded_search_term));
[email protected]d82443b2009-01-15 19:54:56266 }
267}
268
[email protected]d82443b2009-01-15 19:54:56269TEST_F(TemplateURLTest, DisplayURLToURLRef) {
270 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19271 const std::string url;
[email protected]400b133f2011-01-19 18:32:30272 const string16 expected_result;
[email protected]b37bdfe2012-03-16 20:53:27273 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19274 { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a",
[email protected]400b133f2011-01-19 18:32:30275 ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") },
[email protected]ddd231e2010-06-29 20:35:19276 { "http://X",
[email protected]400b133f2011-01-19 18:32:30277 ASCIIToUTF16("http://X") },
[email protected]ddd231e2010-06-29 20:35:19278 { "http://foo{searchTerms",
[email protected]400b133f2011-01-19 18:32:30279 ASCIIToUTF16("http://foo{searchTerms") },
[email protected]ddd231e2010-06-29 20:35:19280 { "http://foo{searchTerms}{language}",
[email protected]400b133f2011-01-19 18:32:30281 ASCIIToUTF16("http://foo%s{language}") },
[email protected]d82443b2009-01-15 19:54:56282 };
[email protected]573889f22012-04-07 01:31:54283 TemplateURLData data;
[email protected]b37bdfe2012-03-16 20:53:27284 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54285 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26286 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13287 EXPECT_EQ(test_data[i].expected_result, url.url_ref().DisplayURL());
[email protected]b37bdfe2012-03-16 20:53:27288 EXPECT_EQ(test_data[i].url,
[email protected]360ba052012-04-04 17:26:13289 TemplateURLRef::DisplayURLToURLRef(url.url_ref().DisplayURL()));
[email protected]d82443b2009-01-15 19:54:56290 }
291}
292
293TEST_F(TemplateURLTest, ReplaceSearchTerms) {
294 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19295 const std::string url;
[email protected]d82443b2009-01-15 19:54:56296 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27297 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19298 { "http://foo/{language}{searchTerms}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56299 "http://foo/{language}XUTF-8" },
[email protected]ddd231e2010-06-29 20:35:19300 { "http://foo/{language}{inputEncoding}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56301 "http://foo/{language}UTF-8X" },
[email protected]ddd231e2010-06-29 20:35:19302 { "http://foo/{searchTerms}{language}{inputEncoding}",
[email protected]d82443b2009-01-15 19:54:56303 "http://foo/X{language}UTF-8" },
[email protected]ddd231e2010-06-29 20:35:19304 { "http://foo/{searchTerms}{inputEncoding}{language}",
[email protected]d82443b2009-01-15 19:54:56305 "http://foo/XUTF-8{language}" },
[email protected]ddd231e2010-06-29 20:35:19306 { "http://foo/{inputEncoding}{searchTerms}{language}",
[email protected]d82443b2009-01-15 19:54:56307 "http://foo/UTF-8X{language}" },
[email protected]ddd231e2010-06-29 20:35:19308 { "http://foo/{inputEncoding}{language}{searchTerms}",
[email protected]d82443b2009-01-15 19:54:56309 "http://foo/UTF-8{language}X" },
[email protected]ddd231e2010-06-29 20:35:19310 { "http://foo/{language}a{searchTerms}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56311 "http://foo/{language}aXaUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19312 { "http://foo/{language}a{inputEncoding}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56313 "http://foo/{language}aUTF-8aXa" },
[email protected]ddd231e2010-06-29 20:35:19314 { "http://foo/{searchTerms}a{language}a{inputEncoding}a",
[email protected]d82443b2009-01-15 19:54:56315 "http://foo/Xa{language}aUTF-8a" },
[email protected]ddd231e2010-06-29 20:35:19316 { "http://foo/{searchTerms}a{inputEncoding}a{language}a",
[email protected]d82443b2009-01-15 19:54:56317 "http://foo/XaUTF-8a{language}a" },
[email protected]ddd231e2010-06-29 20:35:19318 { "http://foo/{inputEncoding}a{searchTerms}a{language}a",
[email protected]d82443b2009-01-15 19:54:56319 "http://foo/UTF-8aXa{language}a" },
[email protected]ddd231e2010-06-29 20:35:19320 { "http://foo/{inputEncoding}a{language}a{searchTerms}a",
[email protected]d82443b2009-01-15 19:54:56321 "http://foo/UTF-8a{language}aXa" },
322 };
[email protected]573889f22012-04-07 01:31:54323 TemplateURLData data;
324 data.input_encodings.push_back("UTF-8");
[email protected]b37bdfe2012-03-16 20:53:27325 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54326 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26327 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13328 EXPECT_TRUE(url.url_ref().IsValid());
[email protected]3954c3a2012-04-10 20:17:55329 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27330 std::string expected_result = test_data[i].expected_result;
[email protected]d82443b2009-01-15 19:54:56331 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}",
[email protected]d70539de2009-06-24 22:17:06332 g_browser_process->GetApplicationLocale());
[email protected]bca359b2012-06-24 07:53:04333 GURL result(url.url_ref().ReplaceSearchTerms(
334 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("X"))));
[email protected]b37bdfe2012-03-16 20:53:27335 ASSERT_TRUE(result.is_valid());
[email protected]d82443b2009-01-15 19:54:56336 EXPECT_EQ(expected_result, result.spec());
337 }
338}
339
340
341// Tests replacing search terms in various encodings and making sure the
342// generated URL matches the expected value.
343TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {
344 struct TestData {
345 const std::string encoding;
[email protected]400b133f2011-01-19 18:32:30346 const string16 search_term;
[email protected]ddd231e2010-06-29 20:35:19347 const std::string url;
[email protected]d82443b2009-01-15 19:54:56348 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27349 } test_data[] = {
[email protected]400b133f2011-01-19 18:32:30350 { "BIG5", WideToUTF16(L"\x60BD"),
351 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17352 "http://foo/?%B1~BIG5" },
[email protected]400b133f2011-01-19 18:32:30353 { "UTF-8", ASCIIToUTF16("blah"),
354 "http://foo/?{searchTerms}{inputEncoding}",
[email protected]3c75f0d2010-03-02 05:51:17355 "http://foo/?blahUTF-8" },
[email protected]34e24852012-01-31 18:43:58356 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"),
357 "http://foo/{searchTerms}/bar",
358 "http://foo/%82%A0/bar"},
359 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"),
360 "http://foo/{searchTerms}/bar",
361 "http://foo/%82%A0%20%82%A2/bar"},
[email protected]d82443b2009-01-15 19:54:56362 };
[email protected]573889f22012-04-07 01:31:54363 TemplateURLData data;
[email protected]b37bdfe2012-03-16 20:53:27364 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]573889f22012-04-07 01:31:54365 data.SetURL(test_data[i].url);
366 data.input_encodings.clear();
367 data.input_encodings.push_back(test_data[i].encoding);
[email protected]16fca9b82012-04-23 18:40:26368 TemplateURL url(NULL, data);
[email protected]3954c3a2012-04-10 20:17:55369 EXPECT_TRUE(url.url_ref().IsValid());
370 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04371 GURL result(url.url_ref().ReplaceSearchTerms(
372 TemplateURLRef::SearchTermsArgs(test_data[i].search_term)));
373 ASSERT_TRUE(result.is_valid());
374 EXPECT_EQ(test_data[i].expected_result, result.spec());
375 }
376}
377
378// Tests replacing assisted query stats (AQS) in various scenarios.
379TEST_F(TemplateURLTest, ReplaceAssistedQueryStats) {
380 struct TestData {
381 const string16 search_term;
382 const std::string aqs;
383 const std::string base_url;
384 const std::string url;
385 const std::string expected_result;
386 } test_data[] = {
387 // No HTTPS, no AQS.
388 { ASCIIToUTF16("foo"),
389 "chrome.0.0l6",
390 "http://foo/",
391 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
392 "http://foo/?foo" },
393 // HTTPS available, AQS should be replaced.
394 { ASCIIToUTF16("foo"),
395 "chrome.0.0l6",
396 "https://foo/",
397 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
398 "https://foo/?fooaqs=chrome.0.0l6&" },
399 // HTTPS available, however AQS is empty.
400 { ASCIIToUTF16("foo"),
401 "",
402 "https://foo/",
403 "{google:baseURL}?{searchTerms}{google:assistedQueryStats}",
404 "https://foo/?foo" },
405 // No {google:baseURL} and protocol is HTTP, we must not substitute AQS.
406 { ASCIIToUTF16("foo"),
407 "chrome.0.0l6",
408 "",
409 "http://foo?{searchTerms}{google:assistedQueryStats}",
410 "http://foo/?foo" },
411 // A non-Google search provider with HTTPS should allow AQS.
412 { ASCIIToUTF16("foo"),
413 "chrome.0.0l6",
414 "",
415 "https://foo?{searchTerms}{google:assistedQueryStats}",
416 "https://foo/?fooaqs=chrome.0.0l6&" },
417 };
418 TemplateURLData data;
419 data.input_encodings.push_back("UTF-8");
420 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
421 data.SetURL(test_data[i].url);
422 TemplateURL url(NULL, data);
423 EXPECT_TRUE(url.url_ref().IsValid());
424 ASSERT_TRUE(url.url_ref().SupportsReplacement());
425 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
426 search_terms_args.assisted_query_stats = test_data[i].aqs;
427 UIThreadSearchTermsData::SetGoogleBaseURL(test_data[i].base_url);
428 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
[email protected]b37bdfe2012-03-16 20:53:27429 ASSERT_TRUE(result.is_valid());
430 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56431 }
432}
433
434TEST_F(TemplateURLTest, Suggestions) {
435 struct TestData {
436 const int accepted_suggestion;
[email protected]400b133f2011-01-19 18:32:30437 const string16 original_query_for_suggestion;
[email protected]d82443b2009-01-15 19:54:56438 const std::string expected_result;
[email protected]b37bdfe2012-03-16 20:53:27439 } test_data[] = {
[email protected]400b133f2011-01-19 18:32:30440 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
[email protected]d82443b2009-01-15 19:54:56441 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30442 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"),
[email protected]d82443b2009-01-15 19:54:56443 "http://bar/foo?q=foobar" },
[email protected]400b133f2011-01-19 18:32:30444 { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(),
[email protected]d82443b2009-01-15 19:54:56445 "http://bar/foo?aq=f&q=foobar" },
[email protected]400b133f2011-01-19 18:32:30446 { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"),
[email protected]d82443b2009-01-15 19:54:56447 "http://bar/foo?aq=f&q=foobar" },
[email protected]400b133f2011-01-19 18:32:30448 { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" },
449 { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" },
[email protected]d82443b2009-01-15 19:54:56450 };
[email protected]573889f22012-04-07 01:31:54451 TemplateURLData data;
452 data.SetURL("http://bar/foo?{google:acceptedSuggestion}"
453 "{google:originalQueryForSuggestion}q={searchTerms}");
454 data.input_encodings.push_back("UTF-8");
[email protected]16fca9b82012-04-23 18:40:26455 TemplateURL url(NULL, data);
[email protected]3954c3a2012-04-10 20:17:55456 EXPECT_TRUE(url.url_ref().IsValid());
[email protected]360ba052012-04-04 17:26:13457 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]b37bdfe2012-03-16 20:53:27458 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
[email protected]bca359b2012-06-24 07:53:04459 TemplateURLRef::SearchTermsArgs search_terms_args(
460 ASCIIToUTF16("foobar"));
461 search_terms_args.accepted_suggestion = test_data[i].accepted_suggestion;
462 search_terms_args.original_query =
463 test_data[i].original_query_for_suggestion;
464 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
[email protected]b37bdfe2012-03-16 20:53:27465 ASSERT_TRUE(result.is_valid());
466 EXPECT_EQ(test_data[i].expected_result, result.spec());
[email protected]d82443b2009-01-15 19:54:56467 }
468}
469
[email protected]81d9b72d2012-03-26 22:29:17470#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]81f808de2009-09-25 01:36:34471TEST_F(TemplateURLTest, RLZ) {
[email protected]400b133f2011-01-19 18:32:30472 string16 rlz_string;
[email protected]81d9b72d2012-03-26 22:29:17473#if defined(ENABLE_RLZ)
474 std::string brand;
475 if (google_util::GetBrand(&brand) && !brand.empty() &&
476 !google_util::IsOrganic(brand)) {
477 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string);
478 }
[email protected]58b64332010-08-13 16:09:39479#endif
[email protected]d82443b2009-01-15 19:54:56480
[email protected]573889f22012-04-07 01:31:54481 TemplateURLData data;
482 data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
[email protected]16fca9b82012-04-23 18:40:26483 TemplateURL url(NULL, data);
[email protected]360ba052012-04-04 17:26:13484 EXPECT_TRUE(url.url_ref().IsValid());
485 ASSERT_TRUE(url.url_ref().SupportsReplacement());
[email protected]bca359b2012-06-24 07:53:04486 GURL result(url.url_ref().ReplaceSearchTerms(
487 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x"))));
[email protected]d82443b2009-01-15 19:54:56488 ASSERT_TRUE(result.is_valid());
[email protected]12bd05872009-03-17 19:25:06489 std::string expected_url = "http://bar/?";
[email protected]b37bdfe2012-03-16 20:53:27490 if (!rlz_string.empty())
[email protected]8ead4c022012-03-17 02:09:50491 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&";
[email protected]12bd05872009-03-17 19:25:06492 expected_url += "x";
[email protected]b37bdfe2012-03-16 20:53:27493 EXPECT_EQ(expected_url, result.spec());
[email protected]d82443b2009-01-15 19:54:56494}
[email protected]81f808de2009-09-25 01:36:34495#endif
[email protected]d82443b2009-01-15 19:54:56496
497TEST_F(TemplateURLTest, HostAndSearchTermKey) {
498 struct TestData {
[email protected]ddd231e2010-06-29 20:35:19499 const std::string url;
[email protected]d82443b2009-01-15 19:54:56500 const std::string host;
501 const std::string path;
502 const std::string search_term_key;
[email protected]573889f22012-04-07 01:31:54503 } test_data[] = {
[email protected]ddd231e2010-06-29 20:35:19504 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56505
506 // No query key should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19507 { "http://blah/{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56508
509 // No term should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19510 { "http://blah/", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56511
512 // Multiple terms should result in empty values.
[email protected]ddd231e2010-06-29 20:35:19513 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56514
515 // Term in the host shouldn't match.
[email protected]ddd231e2010-06-29 20:35:19516 { "http://{searchTerms}", "", "", ""},
[email protected]d82443b2009-01-15 19:54:56517
[email protected]ddd231e2010-06-29 20:35:19518 { "http://blah/?q={searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56519
520 // Single term with extra chars in value should match.
[email protected]ddd231e2010-06-29 20:35:19521 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
[email protected]d82443b2009-01-15 19:54:56522 };
523
[email protected]573889f22012-04-07 01:31:54524 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
525 TemplateURLData data;
526 data.SetURL(test_data[i].url);
[email protected]16fca9b82012-04-23 18:40:26527 TemplateURL url(NULL, data);
[email protected]573889f22012-04-07 01:31:54528 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost());
529 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath());
530 EXPECT_EQ(test_data[i].search_term_key, url.url_ref().GetSearchTermKey());
[email protected]d82443b2009-01-15 19:54:56531 }
532}
533
534TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {
535 static const struct {
[email protected]ddd231e2010-06-29 20:35:19536 const char* const base_url;
537 const char* const base_suggest_url;
[email protected]d82443b2009-01-15 19:54:56538 } data[] = {
[email protected]014010e2011-10-01 04:12:44539 { "http://google.com/", "http://google.com/complete/", },
540 { "http://www.google.com/", "http://www.google.com/complete/", },
541 { "http://www.google.co.uk/", "http://www.google.co.uk/complete/", },
542 { "http://www.google.com.by/", "http://www.google.com.by/complete/", },
543 { "http://google.com/intl/xx/", "http://google.com/complete/", },
[email protected]d82443b2009-01-15 19:54:56544 };
545
[email protected]f63ae312009-02-04 17:58:46546 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i)
[email protected]d82443b2009-01-15 19:54:56547 CheckSuggestBaseURL(data[i].base_url, data[i].base_suggest_url);
548}
549
[email protected]81c6ef62010-01-21 09:58:47550TEST_F(TemplateURLTest, ParseParameterKnown) {
[email protected]ddd231e2010-06-29 20:35:19551 std::string parsed_url("{searchTerms}");
[email protected]573889f22012-04-07 01:31:54552 TemplateURLData data;
553 data.SetURL(parsed_url);
[email protected]16fca9b82012-04-23 18:40:26554 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47555 TemplateURLRef::Replacements replacements;
[email protected]360ba052012-04-04 17:26:13556 EXPECT_TRUE(url.url_ref().ParseParameter(0, 12, &parsed_url, &replacements));
[email protected]ddd231e2010-06-29 20:35:19557 EXPECT_EQ(std::string(), parsed_url);
[email protected]81c6ef62010-01-21 09:58:47558 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27559 EXPECT_EQ(0U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47560 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
561}
562
563TEST_F(TemplateURLTest, ParseParameterUnknown) {
[email protected]243abf32012-05-15 18:28:20564 std::string parsed_url("{fhqwhgads}abc");
[email protected]573889f22012-04-07 01:31:54565 TemplateURLData data;
566 data.SetURL(parsed_url);
[email protected]16fca9b82012-04-23 18:40:26567 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47568 TemplateURLRef::Replacements replacements;
[email protected]1a257262011-06-28 22:15:44569
570 // By default, TemplateURLRef should not consider itself prepopulated.
571 // Therefore we should not replace the unknown parameter.
[email protected]360ba052012-04-04 17:26:13572 EXPECT_FALSE(url.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]243abf32012-05-15 18:28:20573 EXPECT_EQ("{fhqwhgads}abc", parsed_url);
[email protected]1a257262011-06-28 22:15:44574 EXPECT_TRUE(replacements.empty());
575
576 // If the TemplateURLRef is prepopulated, we should remove unknown parameters.
[email protected]243abf32012-05-15 18:28:20577 parsed_url = "{fhqwhgads}abc";
[email protected]573889f22012-04-07 01:31:54578 data.prepopulate_id = 1;
[email protected]16fca9b82012-04-23 18:40:26579 TemplateURL url2(NULL, data);
[email protected]495c30b2012-05-15 18:48:15580 EXPECT_TRUE(url2.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
[email protected]243abf32012-05-15 18:28:20581 EXPECT_EQ("abc", parsed_url);
[email protected]81c6ef62010-01-21 09:58:47582 EXPECT_TRUE(replacements.empty());
583}
584
585TEST_F(TemplateURLTest, ParseURLEmpty) {
[email protected]16fca9b82012-04-23 18:40:26586 TemplateURL url(NULL, TemplateURLData());
[email protected]81c6ef62010-01-21 09:58:47587 TemplateURLRef::Replacements replacements;
588 bool valid = false;
[email protected]b37bdfe2012-03-16 20:53:27589 EXPECT_EQ(std::string(),
[email protected]360ba052012-04-04 17:26:13590 url.url_ref().ParseURL(std::string(), &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47591 EXPECT_TRUE(replacements.empty());
592 EXPECT_TRUE(valid);
593}
594
595TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
[email protected]573889f22012-04-07 01:31:54596 TemplateURLData data;
597 data.SetURL("{");
[email protected]16fca9b82012-04-23 18:40:26598 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47599 TemplateURLRef::Replacements replacements;
600 bool valid = false;
[email protected]360ba052012-04-04 17:26:13601 EXPECT_EQ(std::string(), url.url_ref().ParseURL("{", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47602 EXPECT_TRUE(replacements.empty());
603 EXPECT_FALSE(valid);
604}
605
606TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
[email protected]573889f22012-04-07 01:31:54607 TemplateURLData data;
608 data.SetURL("{}");
[email protected]16fca9b82012-04-23 18:40:26609 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47610 TemplateURLRef::Replacements replacements;
611 bool valid = false;
[email protected]360ba052012-04-04 17:26:13612 EXPECT_EQ("{}", url.url_ref().ParseURL("{}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47613 EXPECT_TRUE(replacements.empty());
614 EXPECT_TRUE(valid);
615}
616
617TEST_F(TemplateURLTest, ParseURLTwoParameters) {
[email protected]573889f22012-04-07 01:31:54618 TemplateURLData data;
619 data.SetURL("{}{{%s}}");
[email protected]16fca9b82012-04-23 18:40:26620 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47621 TemplateURLRef::Replacements replacements;
622 bool valid = false;
[email protected]ddd231e2010-06-29 20:35:19623 EXPECT_EQ("{}{}",
[email protected]360ba052012-04-04 17:26:13624 url.url_ref().ParseURL("{}{{searchTerms}}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47625 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27626 EXPECT_EQ(3U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47627 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
628 EXPECT_TRUE(valid);
629}
630
631TEST_F(TemplateURLTest, ParseURLNestedParameter) {
[email protected]573889f22012-04-07 01:31:54632 TemplateURLData data;
633 data.SetURL("{%s");
[email protected]16fca9b82012-04-23 18:40:26634 TemplateURL url(NULL, data);
[email protected]81c6ef62010-01-21 09:58:47635 TemplateURLRef::Replacements replacements;
636 bool valid = false;
[email protected]360ba052012-04-04 17:26:13637 EXPECT_EQ("{",
638 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid));
[email protected]81c6ef62010-01-21 09:58:47639 ASSERT_EQ(1U, replacements.size());
[email protected]b37bdfe2012-03-16 20:53:27640 EXPECT_EQ(1U, replacements[0].index);
[email protected]81c6ef62010-01-21 09:58:47641 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
642 EXPECT_TRUE(valid);
643}