Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: chrome/browser/search_engines/template_url_unittest.cc

Issue 9982018: Move most TemplateURL data members to a new struct, TemplateURLData. This allows us to eliminate t… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/rlz/rlz.h" 9 #include "chrome/browser/rlz/rlz.h"
10 #include "chrome/browser/search_engines/search_terms_data.h" 10 #include "chrome/browser/search_engines/search_terms_data.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 const std::string& base_url, 51 const std::string& base_url,
52 const std::string& base_suggest_url) const { 52 const std::string& base_suggest_url) const {
53 TestSearchTermsData search_terms_data(base_url); 53 TestSearchTermsData search_terms_data(base_url);
54 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue()); 54 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue());
55 } 55 }
56 56
57 57
58 // Actual tests --------------------------------------------------------------- 58 // Actual tests ---------------------------------------------------------------
59 59
60 TEST_F(TemplateURLTest, Defaults) { 60 TEST_F(TemplateURLTest, Defaults) {
61 TemplateURL url; 61 TemplateURLData data;
62 EXPECT_FALSE(url.show_in_default_list()); 62 EXPECT_FALSE(data.show_in_default_list);
63 EXPECT_FALSE(url.safe_for_autoreplace()); 63 EXPECT_FALSE(data.safe_for_autoreplace);
64 EXPECT_EQ(0, url.prepopulate_id()); 64 EXPECT_EQ(0, data.prepopulate_id);
65 } 65 }
66 66
67 TEST_F(TemplateURLTest, TestValidWithComplete) { 67 TEST_F(TemplateURLTest, TestValidWithComplete) {
68 TemplateURL url; 68 TemplateURLData data;
69 url.SetURL("{searchTerms}"); 69 data.SetURL("{searchTerms}");
70 TemplateURL url(data);
70 EXPECT_TRUE(url.url_ref().IsValid()); 71 EXPECT_TRUE(url.url_ref().IsValid());
71 } 72 }
72 73
73 TEST_F(TemplateURLTest, URLRefTestSearchTerms) { 74 TEST_F(TemplateURLTest, URLRefTestSearchTerms) {
74 struct SearchTermsCase { 75 struct SearchTermsCase {
75 const char* url; 76 const char* url;
76 const string16 terms; 77 const string16 terms;
77 const std::string output; 78 const std::string output;
78 bool valid_url; 79 bool valid_url;
79 } search_term_cases[] = { 80 } search_term_cases[] = {
80 { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"), 81 { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"),
81 "http://foosea%20rch%2Fbar", false }, 82 "http://foosea%20rch%2Fbar", false },
82 { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"), 83 { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"),
83 "http://foosea%20rch%2Fbar?boo=abc", false }, 84 "http://foosea%20rch%2Fbar?boo=abc", false },
84 { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"), 85 { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"),
85 "http://foo/?boo=sea+rch%2Fbar", true }, 86 "http://foo/?boo=sea+rch%2Fbar", true },
86 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"), 87 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"),
87 "http://en.wikipedia.org/wiki%2F%3F", true } 88 "http://en.wikipedia.org/wiki%2F%3F", true }
88 }; 89 };
89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { 90 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
90 const SearchTermsCase& value = search_term_cases[i]; 91 const SearchTermsCase& value = search_term_cases[i];
91 TemplateURL url; 92 TemplateURLData data;
92 url.SetURL(value.url); 93 data.SetURL(value.url);
94 TemplateURL url(data);
93 EXPECT_TRUE(url.url_ref().IsValid()); 95 EXPECT_TRUE(url.url_ref().IsValid());
94 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 96 ASSERT_TRUE(url.url_ref().SupportsReplacement());
95 std::string result = url.url_ref().ReplaceSearchTerms(value.terms, 97 std::string result = url.url_ref().ReplaceSearchTerms(value.terms,
96 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()); 98 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16());
97 EXPECT_EQ(value.output, result); 99 EXPECT_EQ(value.output, result);
98 GURL result_url(result); 100 GURL result_url(result);
99 EXPECT_EQ(value.valid_url, result_url.is_valid()); 101 EXPECT_EQ(value.valid_url, result_url.is_valid());
100 } 102 }
101 } 103 }
102 104
103 TEST_F(TemplateURLTest, URLRefTestCount) { 105 TEST_F(TemplateURLTest, URLRefTestCount) {
104 TemplateURL url; 106 TemplateURLData data;
105 url.SetURL("http://foo{searchTerms}{count?}"); 107 data.SetURL("http://foo{searchTerms}{count?}");
108 TemplateURL url(data);
106 EXPECT_TRUE(url.url_ref().IsValid()); 109 EXPECT_TRUE(url.url_ref().IsValid());
107 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 110 ASSERT_TRUE(url.url_ref().SupportsReplacement());
108 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"), 111 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
109 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 112 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
110 ASSERT_TRUE(result.is_valid()); 113 ASSERT_TRUE(result.is_valid());
111 EXPECT_EQ("http://foox/", result.spec()); 114 EXPECT_EQ("http://foox/", result.spec());
112 } 115 }
113 116
114 TEST_F(TemplateURLTest, URLRefTestCount2) { 117 TEST_F(TemplateURLTest, URLRefTestCount2) {
115 TemplateURL url; 118 TemplateURLData data;
116 url.SetURL("http://foo{searchTerms}{count}"); 119 data.SetURL("http://foo{searchTerms}{count}");
120 TemplateURL url(data);
117 EXPECT_TRUE(url.url_ref().IsValid()); 121 EXPECT_TRUE(url.url_ref().IsValid());
118 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 122 ASSERT_TRUE(url.url_ref().SupportsReplacement());
119 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"), 123 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
120 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 124 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
121 ASSERT_TRUE(result.is_valid()); 125 ASSERT_TRUE(result.is_valid());
122 EXPECT_EQ("http://foox10/", result.spec()); 126 EXPECT_EQ("http://foox10/", result.spec());
123 } 127 }
124 128
125 TEST_F(TemplateURLTest, URLRefTestIndices) { 129 TEST_F(TemplateURLTest, URLRefTestIndices) {
126 TemplateURL url; 130 TemplateURLData data;
127 url.SetURL("http://foo{searchTerms}x{startIndex?}y{startPage?}"); 131 data.SetURL("http://foo{searchTerms}x{startIndex?}y{startPage?}");
132 TemplateURL url(data);
128 EXPECT_TRUE(url.url_ref().IsValid()); 133 EXPECT_TRUE(url.url_ref().IsValid());
129 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 134 ASSERT_TRUE(url.url_ref().SupportsReplacement());
130 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"), 135 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
131 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 136 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
132 ASSERT_TRUE(result.is_valid()); 137 ASSERT_TRUE(result.is_valid());
133 EXPECT_EQ("http://fooxxy/", result.spec()); 138 EXPECT_EQ("http://fooxxy/", result.spec());
134 } 139 }
135 140
136 TEST_F(TemplateURLTest, URLRefTestIndices2) { 141 TEST_F(TemplateURLTest, URLRefTestIndices2) {
137 TemplateURL url; 142 TemplateURLData data;
138 url.SetURL("http://foo{searchTerms}x{startIndex}y{startPage}"); 143 data.SetURL("http://foo{searchTerms}x{startIndex}y{startPage}");
144 TemplateURL url(data);
139 EXPECT_TRUE(url.url_ref().IsValid()); 145 EXPECT_TRUE(url.url_ref().IsValid());
140 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 146 ASSERT_TRUE(url.url_ref().SupportsReplacement());
141 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"), 147 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
142 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 148 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
143 ASSERT_TRUE(result.is_valid()); 149 ASSERT_TRUE(result.is_valid());
144 EXPECT_EQ("http://fooxx1y1/", result.spec()); 150 EXPECT_EQ("http://fooxx1y1/", result.spec());
145 } 151 }
146 152
147 TEST_F(TemplateURLTest, URLRefTestEncoding) { 153 TEST_F(TemplateURLTest, URLRefTestEncoding) {
148 TemplateURL url; 154 TemplateURLData data;
149 url.SetURL("http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a"); 155 data.SetURL("http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a");
156 TemplateURL url(data);
150 EXPECT_TRUE(url.url_ref().IsValid()); 157 EXPECT_TRUE(url.url_ref().IsValid());
151 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 158 ASSERT_TRUE(url.url_ref().SupportsReplacement());
152 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"), 159 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
153 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 160 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
154 ASSERT_TRUE(result.is_valid()); 161 ASSERT_TRUE(result.is_valid());
155 EXPECT_EQ("http://fooxxutf-8ya/", result.spec()); 162 EXPECT_EQ("http://fooxxutf-8ya/", result.spec());
156 } 163 }
157 164
158 // Test that setting the prepopulate ID from TemplateURL causes the stored 165 // Test that setting the prepopulate ID from TemplateURL causes the stored
159 // TemplateURLRef to handle parsing the URL parameters differently. 166 // TemplateURLRef to handle parsing the URL parameters differently.
160 TEST_F(TemplateURLTest, SetPrepopulatedAndParse) { 167 TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
161 TemplateURL url; 168 TemplateURLData data;
162 url.SetURL("http://foo{fhqwhgads}"); 169 data.SetURL("http://foo{fhqwhgads}");
170 TemplateURL url(data);
163 TemplateURLRef::Replacements replacements; 171 TemplateURLRef::Replacements replacements;
164 bool valid = false; 172 bool valid = false;
165 EXPECT_EQ("http://foo{fhqwhgads}", 173 EXPECT_EQ("http://foo{fhqwhgads}",
166 url.url_ref().ParseURL("http://foo{fhqwhgads}", &replacements, &valid)); 174 url.url_ref().ParseURL("http://foo{fhqwhgads}", &replacements, &valid));
167 EXPECT_TRUE(replacements.empty()); 175 EXPECT_TRUE(replacements.empty());
168 EXPECT_TRUE(valid); 176 EXPECT_TRUE(valid);
169 177
170 url.SetPrepopulateId(123); 178 data.prepopulate_id = 123;
171 EXPECT_EQ("http://foo", 179 TemplateURL url2(data);
172 url.url_ref().ParseURL("http://foo{fhqwhgads}", &replacements, &valid)); 180 EXPECT_EQ("http://foo", url2.url_ref().ParseURL("http://foo{fhqwhgads}",
181 &replacements, &valid));
173 EXPECT_TRUE(replacements.empty()); 182 EXPECT_TRUE(replacements.empty());
174 EXPECT_TRUE(valid); 183 EXPECT_TRUE(valid);
175 } 184 }
176 185
177 TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) { 186 TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
178 TemplateURL url; 187 TemplateURLData data;
179 url.SetURL("http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b"); 188 data.SetURL("http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b");
189 TemplateURL url(data);
180 EXPECT_TRUE(url.url_ref().IsValid()); 190 EXPECT_TRUE(url.url_ref().IsValid());
181 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 191 ASSERT_TRUE(url.url_ref().SupportsReplacement());
182 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"), 192 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
183 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 193 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
184 ASSERT_TRUE(result.is_valid()); 194 ASSERT_TRUE(result.is_valid());
185 EXPECT_EQ("http://fooxutf-8axyb/", result.spec()); 195 EXPECT_EQ("http://fooxutf-8axyb/", result.spec());
186 } 196 }
187 197
188 TEST_F(TemplateURLTest, URLRefTestEncoding2) { 198 TEST_F(TemplateURLTest, URLRefTestEncoding2) {
189 TemplateURL url; 199 TemplateURLData data;
190 url.SetURL("http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a"); 200 data.SetURL("http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a");
201 TemplateURL url(data);
191 EXPECT_TRUE(url.url_ref().IsValid()); 202 EXPECT_TRUE(url.url_ref().IsValid());
192 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 203 ASSERT_TRUE(url.url_ref().SupportsReplacement());
193 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"), 204 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
194 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 205 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
195 ASSERT_TRUE(result.is_valid()); 206 ASSERT_TRUE(result.is_valid());
196 EXPECT_EQ("http://fooxxutf-8yutf-8a/", result.spec()); 207 EXPECT_EQ("http://fooxxutf-8yutf-8a/", result.spec());
197 } 208 }
198 209
199 TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { 210 TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) {
200 struct SearchTermsCase { 211 struct SearchTermsCase {
201 const char* url; 212 const char* url;
202 const string16 terms; 213 const string16 terms;
203 const char* output; 214 const char* output;
204 } search_term_cases[] = { 215 } search_term_cases[] = {
205 { "{google:baseURL}{language}{searchTerms}", string16(), 216 { "{google:baseURL}{language}{searchTerms}", string16(),
206 "http://example.com/e/en" }, 217 "http://example.com/e/en" },
207 { "{google:baseSuggestURL}{searchTerms}", string16(), 218 { "{google:baseSuggestURL}{searchTerms}", string16(),
208 "http://example.com/complete/" } 219 "http://example.com/complete/" }
209 }; 220 };
210 221
211 TestSearchTermsData search_terms_data("http://example.com/e/"); 222 TestSearchTermsData search_terms_data("http://example.com/e/");
212 TemplateURL url; 223 TemplateURLData data;
213 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { 224 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
214 const SearchTermsCase& value = search_term_cases[i]; 225 const SearchTermsCase& value = search_term_cases[i];
215 url.SetURL(value.url); 226 data.SetURL(value.url);
227 TemplateURL url(data);
216 EXPECT_TRUE(url.url_ref().IsValid()); 228 EXPECT_TRUE(url.url_ref().IsValid());
217 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 229 ASSERT_TRUE(url.url_ref().SupportsReplacement());
218 GURL result(url.url_ref().ReplaceSearchTermsUsingTermsData(value.terms, 230 GURL result(url.url_ref().ReplaceSearchTermsUsingTermsData(value.terms,
219 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), 231 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
220 search_terms_data)); 232 search_terms_data));
221 ASSERT_TRUE(result.is_valid()); 233 ASSERT_TRUE(result.is_valid());
222 EXPECT_EQ(value.output, result.spec()); 234 EXPECT_EQ(value.output, result.spec());
223 } 235 }
224 } 236 }
225 237
(...skipping 11 matching lines...) Expand all
237 {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")}, 249 {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")},
238 // Undecodable input should stay escaped. 250 // Undecodable input should stay escaped.
239 {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")}, 251 {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")},
240 // Make sure we convert %2B to +. 252 // Make sure we convert %2B to +.
241 {"C%2B%2B", ASCIIToUTF16("C++")}, 253 {"C%2B%2B", ASCIIToUTF16("C++")},
242 // C%2B is escaped as C%252B, make sure we unescape it properly. 254 // C%2B is escaped as C%252B, make sure we unescape it properly.
243 {"C%252B", ASCIIToUTF16("C%2B")}, 255 {"C%252B", ASCIIToUTF16("C%2B")},
244 }; 256 };
245 257
246 // Set one input encoding: big-5. This is so we can test fallback to UTF-8. 258 // Set one input encoding: big-5. This is so we can test fallback to UTF-8.
247 TemplateURL url; 259 TemplateURLData data;
248 url.SetURL("http://foo?q={searchTerms}"); 260 data.SetURL("http://foo?q={searchTerms}");
249 url.add_input_encoding("big-5"); 261 data.input_encodings.push_back("big-5");
262 TemplateURL url(data);
250 EXPECT_TRUE(url.url_ref().IsValid()); 263 EXPECT_TRUE(url.url_ref().IsValid());
251 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 264 ASSERT_TRUE(url.url_ref().SupportsReplacement());
252 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) { 265 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) {
253 EXPECT_EQ(to_wide_cases[i].expected_decoded_term, 266 EXPECT_EQ(to_wide_cases[i].expected_decoded_term,
254 url.url_ref().SearchTermToString16( 267 url.url_ref().SearchTermToString16(
255 to_wide_cases[i].encoded_search_term)); 268 to_wide_cases[i].encoded_search_term));
256 } 269 }
257 } 270 }
258 271
259 TEST_F(TemplateURLTest, DisplayURLToURLRef) { 272 TEST_F(TemplateURLTest, DisplayURLToURLRef) {
260 struct TestData { 273 struct TestData {
261 const std::string url; 274 const std::string url;
262 const string16 expected_result; 275 const string16 expected_result;
263 } test_data[] = { 276 } test_data[] = {
264 { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 277 { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a",
265 ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") }, 278 ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") },
266 { "http://X", 279 { "http://X",
267 ASCIIToUTF16("http://X") }, 280 ASCIIToUTF16("http://X") },
268 { "http://foo{searchTerms", 281 { "http://foo{searchTerms",
269 ASCIIToUTF16("http://foo{searchTerms") }, 282 ASCIIToUTF16("http://foo{searchTerms") },
270 { "http://foo{searchTerms}{language}", 283 { "http://foo{searchTerms}{language}",
271 ASCIIToUTF16("http://foo%s{language}") }, 284 ASCIIToUTF16("http://foo%s{language}") },
272 }; 285 };
286 TemplateURLData data;
273 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 287 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
274 TemplateURL url; 288 data.SetURL(test_data[i].url);
275 url.SetURL(test_data[i].url); 289 TemplateURL url(data);
276 EXPECT_EQ(test_data[i].expected_result, url.url_ref().DisplayURL()); 290 EXPECT_EQ(test_data[i].expected_result, url.url_ref().DisplayURL());
277 EXPECT_EQ(test_data[i].url, 291 EXPECT_EQ(test_data[i].url,
278 TemplateURLRef::DisplayURLToURLRef(url.url_ref().DisplayURL())); 292 TemplateURLRef::DisplayURLToURLRef(url.url_ref().DisplayURL()));
279 } 293 }
280 } 294 }
281 295
282 TEST_F(TemplateURLTest, ReplaceSearchTerms) { 296 TEST_F(TemplateURLTest, ReplaceSearchTerms) {
283 struct TestData { 297 struct TestData {
284 const std::string url; 298 const std::string url;
285 const std::string expected_result; 299 const std::string expected_result;
(...skipping 16 matching lines...) Expand all
302 "http://foo/{language}aUTF-8aXa" }, 316 "http://foo/{language}aUTF-8aXa" },
303 { "http://foo/{searchTerms}a{language}a{inputEncoding}a", 317 { "http://foo/{searchTerms}a{language}a{inputEncoding}a",
304 "http://foo/Xa{language}aUTF-8a" }, 318 "http://foo/Xa{language}aUTF-8a" },
305 { "http://foo/{searchTerms}a{inputEncoding}a{language}a", 319 { "http://foo/{searchTerms}a{inputEncoding}a{language}a",
306 "http://foo/XaUTF-8a{language}a" }, 320 "http://foo/XaUTF-8a{language}a" },
307 { "http://foo/{inputEncoding}a{searchTerms}a{language}a", 321 { "http://foo/{inputEncoding}a{searchTerms}a{language}a",
308 "http://foo/UTF-8aXa{language}a" }, 322 "http://foo/UTF-8aXa{language}a" },
309 { "http://foo/{inputEncoding}a{language}a{searchTerms}a", 323 { "http://foo/{inputEncoding}a{language}a{searchTerms}a",
310 "http://foo/UTF-8a{language}aXa" }, 324 "http://foo/UTF-8a{language}aXa" },
311 }; 325 };
312 TemplateURL url; 326 TemplateURLData data;
313 url.add_input_encoding("UTF-8"); 327 data.input_encodings.push_back("UTF-8");
314 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 328 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
315 url.SetURL(test_data[i].url); 329 data.SetURL(test_data[i].url);
330 TemplateURL url(data);
316 EXPECT_TRUE(url.url_ref().IsValid()); 331 EXPECT_TRUE(url.url_ref().IsValid());
317 EXPECT_TRUE(url.url_ref().SupportsReplacement()); 332 EXPECT_TRUE(url.url_ref().SupportsReplacement());
318 std::string expected_result = test_data[i].expected_result; 333 std::string expected_result = test_data[i].expected_result;
319 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}", 334 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}",
320 g_browser_process->GetApplicationLocale()); 335 g_browser_process->GetApplicationLocale());
321 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"), 336 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
322 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 337 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
323 ASSERT_TRUE(result.is_valid()); 338 ASSERT_TRUE(result.is_valid());
324 EXPECT_EQ(expected_result, result.spec()); 339 EXPECT_EQ(expected_result, result.spec());
325 } 340 }
(...skipping 15 matching lines...) Expand all
341 { "UTF-8", ASCIIToUTF16("blah"), 356 { "UTF-8", ASCIIToUTF16("blah"),
342 "http://foo/?{searchTerms}{inputEncoding}", 357 "http://foo/?{searchTerms}{inputEncoding}",
343 "http://foo/?blahUTF-8" }, 358 "http://foo/?blahUTF-8" },
344 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"), 359 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"),
345 "http://foo/{searchTerms}/bar", 360 "http://foo/{searchTerms}/bar",
346 "http://foo/%82%A0/bar"}, 361 "http://foo/%82%A0/bar"},
347 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"), 362 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"),
348 "http://foo/{searchTerms}/bar", 363 "http://foo/{searchTerms}/bar",
349 "http://foo/%82%A0%20%82%A2/bar"}, 364 "http://foo/%82%A0%20%82%A2/bar"},
350 }; 365 };
366 TemplateURLData data;
351 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 367 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
352 TemplateURL url; 368 data.SetURL(test_data[i].url);
353 url.SetURL(test_data[i].url); 369 data.input_encodings.clear();
354 url.add_input_encoding(test_data[i].encoding); 370 data.input_encodings.push_back(test_data[i].encoding);
371 TemplateURL url(data);
355 GURL result(url.url_ref().ReplaceSearchTerms(test_data[i].search_term, 372 GURL result(url.url_ref().ReplaceSearchTerms(test_data[i].search_term,
356 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 373 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
357 ASSERT_TRUE(result.is_valid()); 374 ASSERT_TRUE(result.is_valid());
358 EXPECT_EQ(test_data[i].expected_result, result.spec()); 375 EXPECT_EQ(test_data[i].expected_result, result.spec());
359 } 376 }
360 } 377 }
361 378
362 TEST_F(TemplateURLTest, Suggestions) { 379 TEST_F(TemplateURLTest, Suggestions) {
363 struct TestData { 380 struct TestData {
364 const int accepted_suggestion; 381 const int accepted_suggestion;
365 const string16 original_query_for_suggestion; 382 const string16 original_query_for_suggestion;
366 const std::string expected_result; 383 const std::string expected_result;
367 } test_data[] = { 384 } test_data[] = {
368 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), 385 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
369 "http://bar/foo?q=foobar" }, 386 "http://bar/foo?q=foobar" },
370 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), 387 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"),
371 "http://bar/foo?q=foobar" }, 388 "http://bar/foo?q=foobar" },
372 { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(), 389 { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(),
373 "http://bar/foo?aq=f&q=foobar" }, 390 "http://bar/foo?aq=f&q=foobar" },
374 { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"), 391 { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"),
375 "http://bar/foo?aq=f&q=foobar" }, 392 "http://bar/foo?aq=f&q=foobar" },
376 { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" }, 393 { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" },
377 { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" }, 394 { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" },
378 }; 395 };
379 TemplateURL url; 396 TemplateURLData data;
380 url.add_input_encoding("UTF-8"); 397 data.SetURL("http://bar/foo?{google:acceptedSuggestion}"
381 url.SetURL("http://bar/foo?{google:acceptedSuggestion}" 398 "{google:originalQueryForSuggestion}q={searchTerms}");
382 "{google:originalQueryForSuggestion}q={searchTerms}"); 399 data.input_encodings.push_back("UTF-8");
400 TemplateURL url(data);
383 ASSERT_TRUE(url.url_ref().IsValid()); 401 ASSERT_TRUE(url.url_ref().IsValid());
384 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 402 ASSERT_TRUE(url.url_ref().SupportsReplacement());
385 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 403 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
386 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("foobar"), 404 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("foobar"),
387 test_data[i].accepted_suggestion, 405 test_data[i].accepted_suggestion,
388 test_data[i].original_query_for_suggestion)); 406 test_data[i].original_query_for_suggestion));
389 ASSERT_TRUE(result.is_valid()); 407 ASSERT_TRUE(result.is_valid());
390 EXPECT_EQ(test_data[i].expected_result, result.spec()); 408 EXPECT_EQ(test_data[i].expected_result, result.spec());
391 } 409 }
392 } 410 }
393 411
394 #if defined(OS_WIN) || defined(OS_MACOSX) 412 #if defined(OS_WIN) || defined(OS_MACOSX)
395 TEST_F(TemplateURLTest, RLZ) { 413 TEST_F(TemplateURLTest, RLZ) {
396 string16 rlz_string; 414 string16 rlz_string;
397 #if defined(ENABLE_RLZ) 415 #if defined(ENABLE_RLZ)
398 std::string brand; 416 std::string brand;
399 if (google_util::GetBrand(&brand) && !brand.empty() && 417 if (google_util::GetBrand(&brand) && !brand.empty() &&
400 !google_util::IsOrganic(brand)) { 418 !google_util::IsOrganic(brand)) {
401 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string); 419 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string);
402 } 420 }
403 #endif 421 #endif
404 422
405 TemplateURL url; 423 TemplateURLData data;
406 url.SetURL("http://bar/?{google:RLZ}{searchTerms}"); 424 data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
425 TemplateURL url(data);
407 EXPECT_TRUE(url.url_ref().IsValid()); 426 EXPECT_TRUE(url.url_ref().IsValid());
408 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 427 ASSERT_TRUE(url.url_ref().SupportsReplacement());
409 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"), 428 GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"),
410 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 429 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
411 ASSERT_TRUE(result.is_valid()); 430 ASSERT_TRUE(result.is_valid());
412 std::string expected_url = "http://bar/?"; 431 std::string expected_url = "http://bar/?";
413 if (!rlz_string.empty()) 432 if (!rlz_string.empty())
414 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&"; 433 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&";
415 expected_url += "x"; 434 expected_url += "x";
416 EXPECT_EQ(expected_url, result.spec()); 435 EXPECT_EQ(expected_url, result.spec());
417 } 436 }
418 #endif 437 #endif
419 438
420 TEST_F(TemplateURLTest, HostAndSearchTermKey) { 439 TEST_F(TemplateURLTest, HostAndSearchTermKey) {
421 struct TestData { 440 struct TestData {
422 const std::string url; 441 const std::string url;
423 const std::string host; 442 const std::string host;
424 const std::string path; 443 const std::string path;
425 const std::string search_term_key; 444 const std::string search_term_key;
426 } data[] = { 445 } test_data[] = {
427 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"}, 446 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
428 447
429 // No query key should result in empty values. 448 // No query key should result in empty values.
430 { "http://blah/{searchTerms}", "", "", ""}, 449 { "http://blah/{searchTerms}", "", "", ""},
431 450
432 // No term should result in empty values. 451 // No term should result in empty values.
433 { "http://blah/", "", "", ""}, 452 { "http://blah/", "", "", ""},
434 453
435 // Multiple terms should result in empty values. 454 // Multiple terms should result in empty values.
436 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""}, 455 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
437 456
438 // Term in the host shouldn't match. 457 // Term in the host shouldn't match.
439 { "http://{searchTerms}", "", "", ""}, 458 { "http://{searchTerms}", "", "", ""},
440 459
441 { "http://blah/?q={searchTerms}", "blah", "/", "q"}, 460 { "http://blah/?q={searchTerms}", "blah", "/", "q"},
442 461
443 // Single term with extra chars in value should match. 462 // Single term with extra chars in value should match.
444 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"}, 463 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
445 }; 464 };
446 465
447 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 466 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
448 TemplateURL url; 467 TemplateURLData data;
449 url.SetURL(data[i].url); 468 data.SetURL(test_data[i].url);
450 EXPECT_EQ(data[i].host, url.url_ref().GetHost()); 469 TemplateURL url(data);
451 EXPECT_EQ(data[i].path, url.url_ref().GetPath()); 470 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost());
452 EXPECT_EQ(data[i].search_term_key, url.url_ref().GetSearchTermKey()); 471 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath());
472 EXPECT_EQ(test_data[i].search_term_key, url.url_ref().GetSearchTermKey());
453 } 473 }
454 } 474 }
455 475
456 TEST_F(TemplateURLTest, GoogleBaseSuggestURL) { 476 TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {
457 static const struct { 477 static const struct {
458 const char* const base_url; 478 const char* const base_url;
459 const char* const base_suggest_url; 479 const char* const base_suggest_url;
460 } data[] = { 480 } data[] = {
461 { "http://google.com/", "http://google.com/complete/", }, 481 { "http://google.com/", "http://google.com/complete/", },
462 { "http://www.google.com/", "http://www.google.com/complete/", }, 482 { "http://www.google.com/", "http://www.google.com/complete/", },
463 { "http://www.google.co.uk/", "http://www.google.co.uk/complete/", }, 483 { "http://www.google.co.uk/", "http://www.google.co.uk/complete/", },
464 { "http://www.google.com.by/", "http://www.google.com.by/complete/", }, 484 { "http://www.google.com.by/", "http://www.google.com.by/complete/", },
465 { "http://google.com/intl/xx/", "http://google.com/complete/", }, 485 { "http://google.com/intl/xx/", "http://google.com/complete/", },
466 }; 486 };
467 487
468 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) 488 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i)
469 CheckSuggestBaseURL(data[i].base_url, data[i].base_suggest_url); 489 CheckSuggestBaseURL(data[i].base_url, data[i].base_suggest_url);
470 } 490 }
471 491
472 TEST_F(TemplateURLTest, Keyword) { 492 TEST_F(TemplateURLTest, Keyword) {
473 TemplateURL url; 493 TemplateURLData data;
474 url.SetURL("http://www.google.com/search"); 494 data.SetURL("http://www.google.com/search");
475 EXPECT_FALSE(url.autogenerate_keyword()); 495 EXPECT_FALSE(data.autogenerate_keyword());
476 url.set_keyword(ASCIIToUTF16("foo")); 496 data.SetKeyword(ASCIIToUTF16("foo"));
477 EXPECT_EQ(ASCIIToUTF16("foo"), url.keyword()); 497 EXPECT_EQ(ASCIIToUTF16("foo"), TemplateURL(data).keyword());
478 url.set_autogenerate_keyword(true); 498 data.SetAutogenerateKeyword(true);
479 EXPECT_TRUE(url.autogenerate_keyword()); 499 EXPECT_TRUE(data.autogenerate_keyword());
480 EXPECT_EQ(ASCIIToUTF16("google.com"), url.keyword()); 500 EXPECT_EQ(ASCIIToUTF16("google.com"), TemplateURL(data).keyword());
481 url.set_keyword(ASCIIToUTF16("foo")); 501 data.SetKeyword(ASCIIToUTF16("foo"));
482 EXPECT_FALSE(url.autogenerate_keyword()); 502 EXPECT_FALSE(data.autogenerate_keyword());
483 EXPECT_EQ(ASCIIToUTF16("foo"), url.keyword()); 503 EXPECT_EQ(ASCIIToUTF16("foo"), TemplateURL(data).keyword());
484 } 504 }
485 505
486 TEST_F(TemplateURLTest, ParseParameterKnown) { 506 TEST_F(TemplateURLTest, ParseParameterKnown) {
487 std::string parsed_url("{searchTerms}"); 507 std::string parsed_url("{searchTerms}");
488 TemplateURL url; 508 TemplateURLData data;
489 url.SetURL(parsed_url); 509 data.SetURL(parsed_url);
510 TemplateURL url(data);
490 TemplateURLRef::Replacements replacements; 511 TemplateURLRef::Replacements replacements;
491 EXPECT_TRUE(url.url_ref().ParseParameter(0, 12, &parsed_url, &replacements)); 512 EXPECT_TRUE(url.url_ref().ParseParameter(0, 12, &parsed_url, &replacements));
492 EXPECT_EQ(std::string(), parsed_url); 513 EXPECT_EQ(std::string(), parsed_url);
493 ASSERT_EQ(1U, replacements.size()); 514 ASSERT_EQ(1U, replacements.size());
494 EXPECT_EQ(0U, replacements[0].index); 515 EXPECT_EQ(0U, replacements[0].index);
495 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); 516 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
496 } 517 }
497 518
498 TEST_F(TemplateURLTest, ParseParameterUnknown) { 519 TEST_F(TemplateURLTest, ParseParameterUnknown) {
499 std::string parsed_url("{fhqwhgads}"); 520 std::string parsed_url("{fhqwhgads}");
500 TemplateURL url; 521 TemplateURLData data;
501 url.SetURL(parsed_url); 522 data.SetURL(parsed_url);
523 TemplateURL url(data);
502 TemplateURLRef::Replacements replacements; 524 TemplateURLRef::Replacements replacements;
503 525
504 // By default, TemplateURLRef should not consider itself prepopulated. 526 // By default, TemplateURLRef should not consider itself prepopulated.
505 // Therefore we should not replace the unknown parameter. 527 // Therefore we should not replace the unknown parameter.
506 EXPECT_FALSE(url.url_ref().ParseParameter(0, 10, &parsed_url, &replacements)); 528 EXPECT_FALSE(url.url_ref().ParseParameter(0, 10, &parsed_url, &replacements));
507 EXPECT_EQ("{fhqwhgads}", parsed_url); 529 EXPECT_EQ("{fhqwhgads}", parsed_url);
508 EXPECT_TRUE(replacements.empty()); 530 EXPECT_TRUE(replacements.empty());
509 531
510 // If the TemplateURLRef is prepopulated, we should remove unknown parameters. 532 // If the TemplateURLRef is prepopulated, we should remove unknown parameters.
511 parsed_url = "{fhqwhgads}"; 533 parsed_url = "{fhqwhgads}";
512 url.SetPrepopulateId(1); 534 data.prepopulate_id = 1;
513 EXPECT_FALSE(url.url_ref().ParseParameter(0, 10, &parsed_url, &replacements)); 535 TemplateURL url2(data);
536 EXPECT_FALSE(url2.url_ref().ParseParameter(0, 10, &parsed_url,
537 &replacements));
514 EXPECT_EQ(std::string(), parsed_url); 538 EXPECT_EQ(std::string(), parsed_url);
515 EXPECT_TRUE(replacements.empty()); 539 EXPECT_TRUE(replacements.empty());
516 } 540 }
517 541
518 TEST_F(TemplateURLTest, ParseURLEmpty) { 542 TEST_F(TemplateURLTest, ParseURLEmpty) {
519 TemplateURL url; 543 TemplateURLData data;
544 TemplateURL url(data);
520 TemplateURLRef::Replacements replacements; 545 TemplateURLRef::Replacements replacements;
521 bool valid = false; 546 bool valid = false;
522 EXPECT_EQ(std::string(), 547 EXPECT_EQ(std::string(),
523 url.url_ref().ParseURL(std::string(), &replacements, &valid)); 548 url.url_ref().ParseURL(std::string(), &replacements, &valid));
524 EXPECT_TRUE(replacements.empty()); 549 EXPECT_TRUE(replacements.empty());
525 EXPECT_TRUE(valid); 550 EXPECT_TRUE(valid);
526 } 551 }
527 552
528 TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) { 553 TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
529 TemplateURL url; 554 TemplateURLData data;
530 url.SetURL("{"); 555 data.SetURL("{");
556 TemplateURL url(data);
531 TemplateURLRef::Replacements replacements; 557 TemplateURLRef::Replacements replacements;
532 bool valid = false; 558 bool valid = false;
533 EXPECT_EQ(std::string(), url.url_ref().ParseURL("{", &replacements, &valid)); 559 EXPECT_EQ(std::string(), url.url_ref().ParseURL("{", &replacements, &valid));
534 EXPECT_TRUE(replacements.empty()); 560 EXPECT_TRUE(replacements.empty());
535 EXPECT_FALSE(valid); 561 EXPECT_FALSE(valid);
536 } 562 }
537 563
538 TEST_F(TemplateURLTest, ParseURLNoKnownParameters) { 564 TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
539 TemplateURL url; 565 TemplateURLData data;
540 url.SetURL("{}"); 566 data.SetURL("{}");
567 TemplateURL url(data);
541 TemplateURLRef::Replacements replacements; 568 TemplateURLRef::Replacements replacements;
542 bool valid = false; 569 bool valid = false;
543 EXPECT_EQ("{}", url.url_ref().ParseURL("{}", &replacements, &valid)); 570 EXPECT_EQ("{}", url.url_ref().ParseURL("{}", &replacements, &valid));
544 EXPECT_TRUE(replacements.empty()); 571 EXPECT_TRUE(replacements.empty());
545 EXPECT_TRUE(valid); 572 EXPECT_TRUE(valid);
546 } 573 }
547 574
548 TEST_F(TemplateURLTest, ParseURLTwoParameters) { 575 TEST_F(TemplateURLTest, ParseURLTwoParameters) {
549 TemplateURL url; 576 TemplateURLData data;
550 url.SetURL("{}{{%s}}"); 577 data.SetURL("{}{{%s}}");
578 TemplateURL url(data);
551 TemplateURLRef::Replacements replacements; 579 TemplateURLRef::Replacements replacements;
552 bool valid = false; 580 bool valid = false;
553 EXPECT_EQ("{}{}", 581 EXPECT_EQ("{}{}",
554 url.url_ref().ParseURL("{}{{searchTerms}}", &replacements, &valid)); 582 url.url_ref().ParseURL("{}{{searchTerms}}", &replacements, &valid));
555 ASSERT_EQ(1U, replacements.size()); 583 ASSERT_EQ(1U, replacements.size());
556 EXPECT_EQ(3U, replacements[0].index); 584 EXPECT_EQ(3U, replacements[0].index);
557 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); 585 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
558 EXPECT_TRUE(valid); 586 EXPECT_TRUE(valid);
559 } 587 }
560 588
561 TEST_F(TemplateURLTest, ParseURLNestedParameter) { 589 TEST_F(TemplateURLTest, ParseURLNestedParameter) {
562 TemplateURL url; 590 TemplateURLData data;
563 url.SetURL("{%s"); 591 data.SetURL("{%s");
592 TemplateURL url(data);
564 TemplateURLRef::Replacements replacements; 593 TemplateURLRef::Replacements replacements;
565 bool valid = false; 594 bool valid = false;
566 EXPECT_EQ("{", 595 EXPECT_EQ("{",
567 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid)); 596 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid));
568 ASSERT_EQ(1U, replacements.size()); 597 ASSERT_EQ(1U, replacements.size());
569 EXPECT_EQ(1U, replacements[0].index); 598 EXPECT_EQ(1U, replacements[0].index);
570 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); 599 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
571 EXPECT_TRUE(valid); 600 EXPECT_TRUE(valid);
572 } 601 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service_unittest.cc ('k') | chrome/browser/search_engines/util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698