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

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

Issue 120983002: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/rlz/rlz.h" 11 #include "chrome/browser/rlz/rlz.h"
12 #include "chrome/browser/search_engines/search_terms_data.h" 12 #include "chrome/browser/search_engines/search_terms_data.h"
13 #include "chrome/browser/search_engines/template_url.h" 13 #include "chrome/browser/search_engines/template_url.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/chrome_version_info.h" 15 #include "chrome/common/chrome_version_info.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 #if defined(ENABLE_RLZ) 18 #if defined(ENABLE_RLZ)
19 #include "chrome/browser/google/google_util.h" 19 #include "chrome/browser/google/google_util.h"
20 #endif 20 #endif
21 21
22 #if defined(OS_ANDROID) 22 #if defined(OS_ANDROID)
23 #include "chrome/browser/search_engines/search_terms_data_android.h" 23 #include "chrome/browser/search_engines/search_terms_data_android.h"
24 #endif 24 #endif
25 25
26 using base::ASCIIToUTF16;
27
26 // TestSearchTermsData -------------------------------------------------------- 28 // TestSearchTermsData --------------------------------------------------------
27 29
28 // Simple implementation of SearchTermsData. 30 // Simple implementation of SearchTermsData.
29 class TestSearchTermsData : public SearchTermsData { 31 class TestSearchTermsData : public SearchTermsData {
30 public: 32 public:
31 explicit TestSearchTermsData(const std::string& google_base_url); 33 explicit TestSearchTermsData(const std::string& google_base_url);
32 34
33 virtual std::string GoogleBaseURLValue() const OVERRIDE; 35 virtual std::string GoogleBaseURLValue() const OVERRIDE;
34 36
35 private: 37 private:
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 344 }
343 } 345 }
344 346
345 TEST_F(TemplateURLTest, URLRefTermToWide) { 347 TEST_F(TemplateURLTest, URLRefTermToWide) {
346 struct ToWideCase { 348 struct ToWideCase {
347 const char* encoded_search_term; 349 const char* encoded_search_term;
348 const base::string16 expected_decoded_term; 350 const base::string16 expected_decoded_term;
349 } to_wide_cases[] = { 351 } to_wide_cases[] = {
350 {"hello+world", ASCIIToUTF16("hello world")}, 352 {"hello+world", ASCIIToUTF16("hello world")},
351 // Test some big-5 input. 353 // Test some big-5 input.
352 {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")}, 354 {"%a7A%A6%6e+to+you", base::WideToUTF16(L"\x4f60\x597d to you")},
353 // Test some UTF-8 input. We should fall back to this when the encoding 355 // Test some UTF-8 input. We should fall back to this when the encoding
354 // doesn't look like big-5. We have a '5' in the middle, which is an invalid 356 // doesn't look like big-5. We have a '5' in the middle, which is an invalid
355 // Big-5 trailing byte. 357 // Big-5 trailing byte.
356 {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")}, 358 {"%e4%bd%a05%e5%a5%bd+to+you",
359 base::WideToUTF16(L"\x4f60\x35\x597d to you")},
357 // Undecodable input should stay escaped. 360 // Undecodable input should stay escaped.
358 {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")}, 361 {"%91%01+abcd", base::WideToUTF16(L"%91%01 abcd")},
359 // Make sure we convert %2B to +. 362 // Make sure we convert %2B to +.
360 {"C%2B%2B", ASCIIToUTF16("C++")}, 363 {"C%2B%2B", ASCIIToUTF16("C++")},
361 // C%2B is escaped as C%252B, make sure we unescape it properly. 364 // C%2B is escaped as C%252B, make sure we unescape it properly.
362 {"C%252B", ASCIIToUTF16("C%2B")}, 365 {"C%252B", ASCIIToUTF16("C%2B")},
363 }; 366 };
364 367
365 // Set one input encoding: big-5. This is so we can test fallback to UTF-8. 368 // Set one input encoding: big-5. This is so we can test fallback to UTF-8.
366 TemplateURLData data; 369 TemplateURLData data;
367 data.SetURL("http://foo?q={searchTerms}"); 370 data.SetURL("http://foo?q={searchTerms}");
368 data.input_encodings.push_back("big-5"); 371 data.input_encodings.push_back("big-5");
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 453
451 // Tests replacing search terms in various encodings and making sure the 454 // Tests replacing search terms in various encodings and making sure the
452 // generated URL matches the expected value. 455 // generated URL matches the expected value.
453 TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { 456 TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {
454 struct TestData { 457 struct TestData {
455 const std::string encoding; 458 const std::string encoding;
456 const base::string16 search_term; 459 const base::string16 search_term;
457 const std::string url; 460 const std::string url;
458 const std::string expected_result; 461 const std::string expected_result;
459 } test_data[] = { 462 } test_data[] = {
460 { "BIG5", WideToUTF16(L"\x60BD"), 463 { "BIG5", base::WideToUTF16(L"\x60BD"),
461 "http://foo/?{searchTerms}{inputEncoding}", 464 "http://foo/?{searchTerms}{inputEncoding}",
462 "http://foo/?%B1~BIG5" }, 465 "http://foo/?%B1~BIG5" },
463 { "UTF-8", ASCIIToUTF16("blah"), 466 { "UTF-8", ASCIIToUTF16("blah"),
464 "http://foo/?{searchTerms}{inputEncoding}", 467 "http://foo/?{searchTerms}{inputEncoding}",
465 "http://foo/?blahUTF-8" }, 468 "http://foo/?blahUTF-8" },
466 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82"), 469 { "Shift_JIS", base::UTF8ToUTF16("\xe3\x81\x82"),
467 "http://foo/{searchTerms}/bar", 470 "http://foo/{searchTerms}/bar",
468 "http://foo/%82%A0/bar"}, 471 "http://foo/%82%A0/bar"},
469 { "Shift_JIS", UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"), 472 { "Shift_JIS", base::UTF8ToUTF16("\xe3\x81\x82 \xe3\x81\x84"),
470 "http://foo/{searchTerms}/bar", 473 "http://foo/{searchTerms}/bar",
471 "http://foo/%82%A0%20%82%A2/bar"}, 474 "http://foo/%82%A0%20%82%A2/bar"},
472 }; 475 };
473 TemplateURLData data; 476 TemplateURLData data;
474 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 477 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
475 data.SetURL(test_data[i].url); 478 data.SetURL(test_data[i].url);
476 data.input_encodings.clear(); 479 data.input_encodings.clear();
477 data.input_encodings.push_back(test_data[i].encoding); 480 data.input_encodings.push_back(test_data[i].encoding);
478 TemplateURL url(NULL, data); 481 TemplateURL url(NULL, data);
479 EXPECT_TRUE(url.url_ref().IsValid()); 482 EXPECT_TRUE(url.url_ref().IsValid());
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 TemplateURLData data; 669 TemplateURLData data;
667 data.SetURL("http://bar/?{google:RLZ}{searchTerms}"); 670 data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
668 TemplateURL url(NULL, data); 671 TemplateURL url(NULL, data);
669 EXPECT_TRUE(url.url_ref().IsValid()); 672 EXPECT_TRUE(url.url_ref().IsValid());
670 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 673 ASSERT_TRUE(url.url_ref().SupportsReplacement());
671 GURL result(url.url_ref().ReplaceSearchTerms( 674 GURL result(url.url_ref().ReplaceSearchTerms(
672 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")))); 675 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x"))));
673 ASSERT_TRUE(result.is_valid()); 676 ASSERT_TRUE(result.is_valid());
674 std::string expected_url = "http://bar/?"; 677 std::string expected_url = "http://bar/?";
675 if (!rlz_string.empty()) 678 if (!rlz_string.empty())
676 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&"; 679 expected_url += "rlz=" + base::UTF16ToUTF8(rlz_string) + "&";
677 expected_url += "x"; 680 expected_url += "x";
678 EXPECT_EQ(expected_url, result.spec()); 681 EXPECT_EQ(expected_url, result.spec());
679 } 682 }
680 683
681 TEST_F(TemplateURLTest, HostAndSearchTermKey) { 684 TEST_F(TemplateURLTest, HostAndSearchTermKey) {
682 struct TestData { 685 struct TestData {
683 const std::string url; 686 const std::string url;
684 const std::string host; 687 const std::string host;
685 const std::string path; 688 const std::string path;
686 const std::string search_term_key; 689 const std::string search_term_key;
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 url.url_ref_.showing_search_terms_ = true; 1286 url.url_ref_.showing_search_terms_ = true;
1284 search_terms_args.bookmark_bar_pinned = false; 1287 search_terms_args.bookmark_bar_pinned = false;
1285 result = url.url_ref().ReplaceSearchTerms(search_terms_args); 1288 result = url.url_ref().ReplaceSearchTerms(search_terms_args);
1286 EXPECT_EQ("http://www.google.com/?bmbp=0&q=foo", result); 1289 EXPECT_EQ("http://www.google.com/?bmbp=0&q=foo", result);
1287 1290
1288 url.url_ref_.showing_search_terms_ = true; 1291 url.url_ref_.showing_search_terms_ = true;
1289 search_terms_args.bookmark_bar_pinned = true; 1292 search_terms_args.bookmark_bar_pinned = true;
1290 result = url.url_ref().ReplaceSearchTerms(search_terms_args); 1293 result = url.url_ref().ReplaceSearchTerms(search_terms_args);
1291 EXPECT_EQ("http://www.google.com/?bmbp=1&q=foo", result); 1294 EXPECT_EQ("http://www.google.com/?bmbp=1&q=foo", result);
1292 } 1295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698