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