OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "chrome/browser/search_engines/template_url.h" | 11 #include "chrome/browser/search_engines/template_url.h" |
12 #include "chrome/test/base/testing_profile.h" | |
12 #include "chrome/test/testing_browser_process_test.h" | 13 #include "chrome/test/testing_browser_process_test.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 // Simple implementation of SearchTermsData. | 16 // Simple implementation of SearchTermsData. |
16 class TestSearchTermsData : public SearchTermsData { | 17 class TestSearchTermsData : public SearchTermsData { |
17 public: | 18 public: |
18 explicit TestSearchTermsData(const char* google_base_url) | 19 explicit TestSearchTermsData(const char* google_base_url) |
19 : google_base_url_(google_base_url) { | 20 : google_base_url_(google_base_url) { |
20 } | 21 } |
21 | 22 |
(...skipping 23 matching lines...) Expand all Loading... | |
45 virtual void TearDown() { | 46 virtual void TearDown() { |
46 TemplateURLRef::SetGoogleBaseURL(NULL); | 47 TemplateURLRef::SetGoogleBaseURL(NULL); |
47 } | 48 } |
48 | 49 |
49 void CheckSuggestBaseURL(const char* base_url, | 50 void CheckSuggestBaseURL(const char* base_url, |
50 const char* base_suggest_url) const { | 51 const char* base_suggest_url) const { |
51 TestSearchTermsData search_terms_data(base_url); | 52 TestSearchTermsData search_terms_data(base_url); |
52 EXPECT_STREQ(base_suggest_url, | 53 EXPECT_STREQ(base_suggest_url, |
53 search_terms_data.GoogleBaseSuggestURLValue().c_str()); | 54 search_terms_data.GoogleBaseSuggestURLValue().c_str()); |
54 } | 55 } |
56 | |
57 protected: | |
58 TestingProfile profile_; | |
55 }; | 59 }; |
56 | 60 |
57 TEST_F(TemplateURLTest, Defaults) { | 61 TEST_F(TemplateURLTest, Defaults) { |
58 TemplateURL url; | 62 TemplateURL url; |
59 ASSERT_FALSE(url.show_in_default_list()); | 63 ASSERT_FALSE(url.show_in_default_list()); |
60 ASSERT_FALSE(url.safe_for_autoreplace()); | 64 ASSERT_FALSE(url.safe_for_autoreplace()); |
61 ASSERT_EQ(0, url.prepopulate_id()); | 65 ASSERT_EQ(0, url.prepopulate_id()); |
62 } | 66 } |
63 | 67 |
64 TEST_F(TemplateURLTest, TestValidWithComplete) { | 68 TEST_F(TemplateURLTest, TestValidWithComplete) { |
(...skipping 16 matching lines...) Expand all Loading... | |
81 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"), | 85 { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"), |
82 "http://en.wikipedia.org/wiki/%3F" } | 86 "http://en.wikipedia.org/wiki/%3F" } |
83 }; | 87 }; |
84 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { | 88 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { |
85 const SearchTermsCase& value = search_term_cases[i]; | 89 const SearchTermsCase& value = search_term_cases[i]; |
86 TemplateURL t_url; | 90 TemplateURL t_url; |
87 TemplateURLRef ref(value.url, 0, 0); | 91 TemplateURLRef ref(value.url, 0, 0); |
88 ASSERT_TRUE(ref.IsValid()); | 92 ASSERT_TRUE(ref.IsValid()); |
89 | 93 |
90 ASSERT_TRUE(ref.SupportsReplacement()); | 94 ASSERT_TRUE(ref.SupportsReplacement()); |
91 GURL result = GURL(ref.ReplaceSearchTerms(t_url, value.terms, | 95 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, t_url, value.terms, |
Peter Kasting
2011/08/10 20:54:06
Again, these can all pass NULL as you don't care a
| |
92 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 96 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
93 ASSERT_TRUE(result.is_valid()); | 97 ASSERT_TRUE(result.is_valid()); |
94 ASSERT_EQ(value.output, result.spec()); | 98 ASSERT_EQ(value.output, result.spec()); |
95 } | 99 } |
96 } | 100 } |
97 | 101 |
98 TEST_F(TemplateURLTest, URLRefTestCount) { | 102 TEST_F(TemplateURLTest, URLRefTestCount) { |
99 TemplateURL t_url; | 103 TemplateURL t_url; |
100 TemplateURLRef ref("http://foo{searchTerms}{count?}", 0, 0); | 104 TemplateURLRef ref("http://foo{searchTerms}{count?}", 0, 0); |
101 ASSERT_TRUE(ref.IsValid()); | 105 ASSERT_TRUE(ref.IsValid()); |
102 ASSERT_TRUE(ref.SupportsReplacement()); | 106 ASSERT_TRUE(ref.SupportsReplacement()); |
103 GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), | 107 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, t_url, ASCIIToUTF16("X"), |
104 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 108 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
105 ASSERT_TRUE(result.is_valid()); | 109 ASSERT_TRUE(result.is_valid()); |
106 ASSERT_EQ("http://foox/", result.spec()); | 110 ASSERT_EQ("http://foox/", result.spec()); |
107 } | 111 } |
108 | 112 |
109 TEST_F(TemplateURLTest, URLRefTestCount2) { | 113 TEST_F(TemplateURLTest, URLRefTestCount2) { |
110 TemplateURL t_url; | 114 TemplateURL t_url; |
111 TemplateURLRef ref("http://foo{searchTerms}{count}", 0, 0); | 115 TemplateURLRef ref("http://foo{searchTerms}{count}", 0, 0); |
112 ASSERT_TRUE(ref.IsValid()); | 116 ASSERT_TRUE(ref.IsValid()); |
113 ASSERT_TRUE(ref.SupportsReplacement()); | 117 ASSERT_TRUE(ref.SupportsReplacement()); |
114 GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), | 118 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, t_url, ASCIIToUTF16("X"), |
115 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 119 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
116 ASSERT_TRUE(result.is_valid()); | 120 ASSERT_TRUE(result.is_valid()); |
117 ASSERT_EQ("http://foox10/", result.spec()); | 121 ASSERT_EQ("http://foox10/", result.spec()); |
118 } | 122 } |
119 | 123 |
120 TEST_F(TemplateURLTest, URLRefTestIndices) { | 124 TEST_F(TemplateURLTest, URLRefTestIndices) { |
121 TemplateURL t_url; | 125 TemplateURL t_url; |
122 TemplateURLRef ref("http://foo{searchTerms}x{startIndex?}y{startPage?}", | 126 TemplateURLRef ref("http://foo{searchTerms}x{startIndex?}y{startPage?}", |
123 1, 2); | 127 1, 2); |
124 ASSERT_TRUE(ref.IsValid()); | 128 ASSERT_TRUE(ref.IsValid()); |
125 ASSERT_TRUE(ref.SupportsReplacement()); | 129 ASSERT_TRUE(ref.SupportsReplacement()); |
126 GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), | 130 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, t_url, ASCIIToUTF16("X"), |
127 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 131 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
128 ASSERT_TRUE(result.is_valid()); | 132 ASSERT_TRUE(result.is_valid()); |
129 ASSERT_EQ("http://fooxxy/", result.spec()); | 133 ASSERT_EQ("http://fooxxy/", result.spec()); |
130 } | 134 } |
131 | 135 |
132 TEST_F(TemplateURLTest, URLRefTestIndices2) { | 136 TEST_F(TemplateURLTest, URLRefTestIndices2) { |
133 TemplateURL t_url; | 137 TemplateURL t_url; |
134 TemplateURLRef ref("http://foo{searchTerms}x{startIndex}y{startPage}", 1, 2); | 138 TemplateURLRef ref("http://foo{searchTerms}x{startIndex}y{startPage}", 1, 2); |
135 ASSERT_TRUE(ref.IsValid()); | 139 ASSERT_TRUE(ref.IsValid()); |
136 ASSERT_TRUE(ref.SupportsReplacement()); | 140 ASSERT_TRUE(ref.SupportsReplacement()); |
137 GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), | 141 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, t_url, ASCIIToUTF16("X"), |
138 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 142 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
139 ASSERT_TRUE(result.is_valid()); | 143 ASSERT_TRUE(result.is_valid()); |
140 ASSERT_EQ("http://fooxx1y2/", result.spec()); | 144 ASSERT_EQ("http://fooxx1y2/", result.spec()); |
141 } | 145 } |
142 | 146 |
143 TEST_F(TemplateURLTest, URLRefTestEncoding) { | 147 TEST_F(TemplateURLTest, URLRefTestEncoding) { |
144 TemplateURL t_url; | 148 TemplateURL t_url; |
145 TemplateURLRef ref( | 149 TemplateURLRef ref( |
146 "http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a", 1, 2); | 150 "http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a", 1, 2); |
147 ASSERT_TRUE(ref.IsValid()); | 151 ASSERT_TRUE(ref.IsValid()); |
148 ASSERT_TRUE(ref.SupportsReplacement()); | 152 ASSERT_TRUE(ref.SupportsReplacement()); |
149 GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), | 153 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, t_url, ASCIIToUTF16("X"), |
150 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 154 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
151 ASSERT_TRUE(result.is_valid()); | 155 ASSERT_TRUE(result.is_valid()); |
152 ASSERT_EQ("http://fooxxutf-8ya/", result.spec()); | 156 ASSERT_EQ("http://fooxxutf-8ya/", result.spec()); |
153 } | 157 } |
154 | 158 |
155 TEST_F(TemplateURLTest, SetPrepopulatedAndParse) { | 159 TEST_F(TemplateURLTest, SetPrepopulatedAndParse) { |
156 TemplateURL t_url; | 160 TemplateURL t_url; |
157 t_url.SetURL("http://foo{fhqwhgads}", 0, 0); | 161 t_url.SetURL("http://foo{fhqwhgads}", 0, 0); |
158 TemplateURLRef::Replacements replacements; | 162 TemplateURLRef::Replacements replacements; |
159 bool valid = false; | 163 bool valid = false; |
(...skipping 14 matching lines...) Expand all Loading... | |
174 EXPECT_TRUE(replacements.empty()); | 178 EXPECT_TRUE(replacements.empty()); |
175 EXPECT_TRUE(valid); | 179 EXPECT_TRUE(valid); |
176 } | 180 } |
177 | 181 |
178 TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) { | 182 TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) { |
179 TemplateURL t_url; | 183 TemplateURL t_url; |
180 TemplateURLRef ref( | 184 TemplateURLRef ref( |
181 "http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b", 1, 2); | 185 "http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b", 1, 2); |
182 ASSERT_TRUE(ref.IsValid()); | 186 ASSERT_TRUE(ref.IsValid()); |
183 ASSERT_TRUE(ref.SupportsReplacement()); | 187 ASSERT_TRUE(ref.SupportsReplacement()); |
184 GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), | 188 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, t_url, ASCIIToUTF16("X"), |
185 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 189 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
186 ASSERT_TRUE(result.is_valid()); | 190 ASSERT_TRUE(result.is_valid()); |
187 ASSERT_EQ("http://fooxutf-8axyb/", result.spec()); | 191 ASSERT_EQ("http://fooxutf-8axyb/", result.spec()); |
188 } | 192 } |
189 | 193 |
190 TEST_F(TemplateURLTest, URLRefTestEncoding2) { | 194 TEST_F(TemplateURLTest, URLRefTestEncoding2) { |
191 TemplateURL t_url; | 195 TemplateURL t_url; |
192 TemplateURLRef ref( | 196 TemplateURLRef ref( |
193 "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 1, 2); | 197 "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 1, 2); |
194 ASSERT_TRUE(ref.IsValid()); | 198 ASSERT_TRUE(ref.IsValid()); |
195 ASSERT_TRUE(ref.SupportsReplacement()); | 199 ASSERT_TRUE(ref.SupportsReplacement()); |
196 GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), | 200 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, t_url, ASCIIToUTF16("X"), |
197 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 201 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
198 ASSERT_TRUE(result.is_valid()); | 202 ASSERT_TRUE(result.is_valid()); |
199 ASSERT_EQ("http://fooxxutf-8yutf-8a/", result.spec()); | 203 ASSERT_EQ("http://fooxxutf-8yutf-8a/", result.spec()); |
200 } | 204 } |
201 | 205 |
202 TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { | 206 TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { |
203 struct SearchTermsCase { | 207 struct SearchTermsCase { |
204 const char* url; | 208 const char* url; |
205 const string16 terms; | 209 const string16 terms; |
206 const char* output; | 210 const char* output; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 }; | 338 }; |
335 TemplateURL turl; | 339 TemplateURL turl; |
336 turl.add_input_encoding("UTF-8"); | 340 turl.add_input_encoding("UTF-8"); |
337 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 341 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
338 TemplateURLRef ref(data[i].url, 1, 2); | 342 TemplateURLRef ref(data[i].url, 1, 2); |
339 EXPECT_TRUE(ref.IsValid()); | 343 EXPECT_TRUE(ref.IsValid()); |
340 EXPECT_TRUE(ref.SupportsReplacement()); | 344 EXPECT_TRUE(ref.SupportsReplacement()); |
341 std::string expected_result = data[i].expected_result; | 345 std::string expected_result = data[i].expected_result; |
342 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}", | 346 ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}", |
343 g_browser_process->GetApplicationLocale()); | 347 g_browser_process->GetApplicationLocale()); |
344 GURL result = GURL(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("X"), | 348 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, turl, |
345 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 349 ASCIIToUTF16("X"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, |
350 string16())); | |
346 EXPECT_TRUE(result.is_valid()); | 351 EXPECT_TRUE(result.is_valid()); |
347 EXPECT_EQ(expected_result, result.spec()); | 352 EXPECT_EQ(expected_result, result.spec()); |
348 } | 353 } |
349 } | 354 } |
350 | 355 |
351 | 356 |
352 // Tests replacing search terms in various encodings and making sure the | 357 // Tests replacing search terms in various encodings and making sure the |
353 // generated URL matches the expected value. | 358 // generated URL matches the expected value. |
354 TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { | 359 TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { |
355 struct TestData { | 360 struct TestData { |
356 const std::string encoding; | 361 const std::string encoding; |
357 const string16 search_term; | 362 const string16 search_term; |
358 const std::string url; | 363 const std::string url; |
359 const std::string expected_result; | 364 const std::string expected_result; |
360 } data[] = { | 365 } data[] = { |
361 { "BIG5", WideToUTF16(L"\x60BD"), | 366 { "BIG5", WideToUTF16(L"\x60BD"), |
362 "http://foo/?{searchTerms}{inputEncoding}", | 367 "http://foo/?{searchTerms}{inputEncoding}", |
363 "http://foo/?%B1~BIG5" }, | 368 "http://foo/?%B1~BIG5" }, |
364 { "UTF-8", ASCIIToUTF16("blah"), | 369 { "UTF-8", ASCIIToUTF16("blah"), |
365 "http://foo/?{searchTerms}{inputEncoding}", | 370 "http://foo/?{searchTerms}{inputEncoding}", |
366 "http://foo/?blahUTF-8" }, | 371 "http://foo/?blahUTF-8" }, |
367 }; | 372 }; |
368 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 373 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
369 TemplateURL turl; | 374 TemplateURL turl; |
370 turl.add_input_encoding(data[i].encoding); | 375 turl.add_input_encoding(data[i].encoding); |
371 TemplateURLRef ref(data[i].url, 1, 2); | 376 TemplateURLRef ref(data[i].url, 1, 2); |
372 GURL result = GURL(ref.ReplaceSearchTerms(turl, | 377 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, turl, |
373 data[i].search_term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, | 378 data[i].search_term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, |
374 string16())); | 379 string16())); |
375 EXPECT_TRUE(result.is_valid()); | 380 EXPECT_TRUE(result.is_valid()); |
376 EXPECT_EQ(data[i].expected_result, result.spec()); | 381 EXPECT_EQ(data[i].expected_result, result.spec()); |
377 } | 382 } |
378 } | 383 } |
379 | 384 |
380 TEST_F(TemplateURLTest, Suggestions) { | 385 TEST_F(TemplateURLTest, Suggestions) { |
381 struct TestData { | 386 struct TestData { |
382 const int accepted_suggestion; | 387 const int accepted_suggestion; |
(...skipping 11 matching lines...) Expand all Loading... | |
394 { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" }, | 399 { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" }, |
395 { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" }, | 400 { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" }, |
396 }; | 401 }; |
397 TemplateURL turl; | 402 TemplateURL turl; |
398 turl.add_input_encoding("UTF-8"); | 403 turl.add_input_encoding("UTF-8"); |
399 TemplateURLRef ref("http://bar/foo?{google:acceptedSuggestion}" | 404 TemplateURLRef ref("http://bar/foo?{google:acceptedSuggestion}" |
400 "{google:originalQueryForSuggestion}q={searchTerms}", 1, 2); | 405 "{google:originalQueryForSuggestion}q={searchTerms}", 1, 2); |
401 ASSERT_TRUE(ref.IsValid()); | 406 ASSERT_TRUE(ref.IsValid()); |
402 ASSERT_TRUE(ref.SupportsReplacement()); | 407 ASSERT_TRUE(ref.SupportsReplacement()); |
403 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 408 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
404 GURL result = GURL(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("foobar"), | 409 GURL result = GURL(ref.ReplaceSearchTerms(&profile_, turl, |
405 data[i].accepted_suggestion, data[i].original_query_for_suggestion)); | 410 ASCIIToUTF16("foobar"), data[i].accepted_suggestion, |
411 data[i].original_query_for_suggestion)); | |
406 EXPECT_TRUE(result.is_valid()); | 412 EXPECT_TRUE(result.is_valid()); |
407 EXPECT_EQ(data[i].expected_result, result.spec()); | 413 EXPECT_EQ(data[i].expected_result, result.spec()); |
408 } | 414 } |
409 } | 415 } |
410 | 416 |
411 #if defined(OS_WIN) | 417 #if defined(OS_WIN) |
412 TEST_F(TemplateURLTest, RLZ) { | 418 TEST_F(TemplateURLTest, RLZ) { |
413 string16 rlz_string; | 419 string16 rlz_string; |
414 #if defined(GOOGLE_CHROME_BUILD) | 420 #if defined(GOOGLE_CHROME_BUILD) |
415 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string); | 421 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string); |
416 #endif | 422 #endif |
417 | 423 |
418 TemplateURL t_url; | 424 TemplateURL t_url; |
419 TemplateURLRef ref("http://bar/?{google:RLZ}{searchTerms}", 1, 2); | 425 TemplateURLRef ref("http://bar/?{google:RLZ}{searchTerms}", 1, 2); |
420 ASSERT_TRUE(ref.IsValid()); | 426 ASSERT_TRUE(ref.IsValid()); |
421 ASSERT_TRUE(ref.SupportsReplacement()); | 427 ASSERT_TRUE(ref.SupportsReplacement()); |
422 GURL result(ref.ReplaceSearchTerms(t_url, L"x", | 428 GURL result(ref.ReplaceSearchTerms(&profile_, t_url, L"x", |
423 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 429 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
424 ASSERT_TRUE(result.is_valid()); | 430 ASSERT_TRUE(result.is_valid()); |
425 std::string expected_url = "http://bar/?"; | 431 std::string expected_url = "http://bar/?"; |
426 if (!rlz_string.empty()) { | 432 if (!rlz_string.empty()) { |
427 expected_url += "rlz=" + WideToUTF8(rlz_string) + "&"; | 433 expected_url += "rlz=" + WideToUTF8(rlz_string) + "&"; |
428 } | 434 } |
429 expected_url += "x"; | 435 expected_url += "x"; |
430 ASSERT_EQ(expected_url, result.spec()); | 436 ASSERT_EQ(expected_url, result.spec()); |
431 } | 437 } |
432 #endif | 438 #endif |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 TEST_F(TemplateURLTest, ParseURLNestedParameter) { | 576 TEST_F(TemplateURLTest, ParseURLNestedParameter) { |
571 TemplateURLRef url_ref("{%s", 0, 0); | 577 TemplateURLRef url_ref("{%s", 0, 0); |
572 TemplateURLRef::Replacements replacements; | 578 TemplateURLRef::Replacements replacements; |
573 bool valid = false; | 579 bool valid = false; |
574 EXPECT_EQ("{", url_ref.ParseURL("{{searchTerms}", &replacements, &valid)); | 580 EXPECT_EQ("{", url_ref.ParseURL("{{searchTerms}", &replacements, &valid)); |
575 ASSERT_EQ(1U, replacements.size()); | 581 ASSERT_EQ(1U, replacements.size()); |
576 EXPECT_EQ(static_cast<size_t>(1), replacements[0].index); | 582 EXPECT_EQ(static_cast<size_t>(1), replacements[0].index); |
577 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); | 583 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); |
578 EXPECT_TRUE(valid); | 584 EXPECT_TRUE(valid); |
579 } | 585 } |
OLD | NEW |