OLD | NEW |
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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 TEST_F(TemplateURLTest, URLRefTermToWide) { | 239 TEST_F(TemplateURLTest, URLRefTermToWide) { |
240 struct ToWideCase { | 240 struct ToWideCase { |
241 const char* encoded_search_term; | 241 const char* encoded_search_term; |
242 const string16 expected_decoded_term; | 242 const string16 expected_decoded_term; |
243 } to_wide_cases[] = { | 243 } to_wide_cases[] = { |
244 {"hello+world", ASCIIToUTF16("hello world")}, | 244 {"hello+world", ASCIIToUTF16("hello world")}, |
245 // Test some big-5 input. | 245 // Test some big-5 input. |
246 {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")}, | 246 {"%a7A%A6%6e+to+you", base::WideToUTF16(L"\x4f60\x597d to you")}, |
247 // Test some UTF-8 input. We should fall back to this when the encoding | 247 // Test some UTF-8 input. We should fall back to this when the encoding |
248 // doesn't look like big-5. We have a '5' in the middle, which is an invalid | 248 // doesn't look like big-5. We have a '5' in the middle, which is an invalid |
249 // Big-5 trailing byte. | 249 // Big-5 trailing byte. |
250 {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")}, | 250 {"%e4%bd%a05%e5%a5%bd+to+you", |
| 251 base::WideToUTF16(L"\x4f60\x35\x597d to you")}, |
251 // Undecodable input should stay escaped. | 252 // Undecodable input should stay escaped. |
252 {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")}, | 253 {"%91%01+abcd", base::WideToUTF16(L"%91%01 abcd")}, |
253 // Make sure we convert %2B to +. | 254 // Make sure we convert %2B to +. |
254 {"C%2B%2B", ASCIIToUTF16("C++")}, | 255 {"C%2B%2B", ASCIIToUTF16("C++")}, |
255 // C%2B is escaped as C%252B, make sure we unescape it properly. | 256 // C%2B is escaped as C%252B, make sure we unescape it properly. |
256 {"C%252B", ASCIIToUTF16("C%2B")}, | 257 {"C%252B", ASCIIToUTF16("C%2B")}, |
257 }; | 258 }; |
258 | 259 |
259 // Set one input encoding: big-5. This is so we can test fallback to UTF-8. | 260 // Set one input encoding: big-5. This is so we can test fallback to UTF-8. |
260 TemplateURLData data; | 261 TemplateURLData data; |
261 data.SetURL("http://foo?q={searchTerms}"); | 262 data.SetURL("http://foo?q={searchTerms}"); |
262 data.input_encodings.push_back("big-5"); | 263 data.input_encodings.push_back("big-5"); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 345 |
345 // Tests replacing search terms in various encodings and making sure the | 346 // Tests replacing search terms in various encodings and making sure the |
346 // generated URL matches the expected value. | 347 // generated URL matches the expected value. |
347 TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { | 348 TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { |
348 struct TestData { | 349 struct TestData { |
349 const std::string encoding; | 350 const std::string encoding; |
350 const string16 search_term; | 351 const string16 search_term; |
351 const std::string url; | 352 const std::string url; |
352 const std::string expected_result; | 353 const std::string expected_result; |
353 } test_data[] = { | 354 } test_data[] = { |
354 { "BIG5", WideToUTF16(L"\x60BD"), | 355 { "BIG5", base::WideToUTF16(L"\x60BD"), |
355 "http://foo/?{searchTerms}{inputEncoding}", | 356 "http://foo/?{searchTerms}{inputEncoding}", |
356 "http://foo/?%B1~BIG5" }, | 357 "http://foo/?%B1~BIG5" }, |
357 { "UTF-8", ASCIIToUTF16("blah"), | 358 { "UTF-8", ASCIIToUTF16("blah"), |
358 "http://foo/?{searchTerms}{inputEncoding}", | 359 "http://foo/?{searchTerms}{inputEncoding}", |
359 "http://foo/?blahUTF-8" }, | 360 "http://foo/?blahUTF-8" }, |
360 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"), | 361 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"), |
361 "http://foo/{searchTerms}/bar", | 362 "http://foo/{searchTerms}/bar", |
362 "http://foo/%82%A0/bar"}, | 363 "http://foo/%82%A0/bar"}, |
363 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"), | 364 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"), |
364 "http://foo/{searchTerms}/bar", | 365 "http://foo/{searchTerms}/bar", |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | 919 EXPECT_TRUE(url.HasSearchTermsReplacementKey( |
919 GURL("http://google.com/?q=something#espv=1"))); | 920 GURL("http://google.com/?q=something#espv=1"))); |
920 | 921 |
921 // This does not ensure the domain matches. | 922 // This does not ensure the domain matches. |
922 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | 923 EXPECT_TRUE(url.HasSearchTermsReplacementKey( |
923 GURL("http://bing.com/?espv"))); | 924 GURL("http://bing.com/?espv"))); |
924 | 925 |
925 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | 926 EXPECT_TRUE(url.HasSearchTermsReplacementKey( |
926 GURL("http://bing.com/#espv"))); | 927 GURL("http://bing.com/#espv"))); |
927 } | 928 } |
OLD | NEW |