Chromium Code Reviews| 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 ASSERT_TRUE(url.url_ref().SupportsReplacement()); | 424 ASSERT_TRUE(url.url_ref().SupportsReplacement()); |
| 425 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); | 425 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); |
| 426 search_terms_args.assisted_query_stats = test_data[i].aqs; | 426 search_terms_args.assisted_query_stats = test_data[i].aqs; |
| 427 UIThreadSearchTermsData::SetGoogleBaseURL(test_data[i].base_url); | 427 UIThreadSearchTermsData::SetGoogleBaseURL(test_data[i].base_url); |
| 428 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args)); | 428 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args)); |
| 429 ASSERT_TRUE(result.is_valid()); | 429 ASSERT_TRUE(result.is_valid()); |
| 430 EXPECT_EQ(test_data[i].expected_result, result.spec()); | 430 EXPECT_EQ(test_data[i].expected_result, result.spec()); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 // Tests replacing cursor position. | |
| 435 TEST_F(TemplateURLTest, ReplaceCursorPosition) { | |
| 436 struct TestData { | |
| 437 const string16 search_term; | |
| 438 size_t cursor_position; | |
| 439 const std::string url; | |
|
Peter Kasting
2012/12/05 20:49:38
Nit: Indenting
Bart N.
2012/12/06 21:43:32
Done.
| |
| 440 const std::string expected_result; | |
| 441 } test_data[] = { | |
| 442 { ASCIIToUTF16("foo"), | |
| 443 string16::npos, | |
| 444 "{google:baseURL}?{searchTerms}&{google:cursorPosition}", | |
| 445 "http://www.google.com/?foo&" }, | |
| 446 { ASCIIToUTF16("foo"), | |
| 447 2, | |
| 448 "{google:baseURL}?{searchTerms}&{google:cursorPosition}", | |
| 449 "http://www.google.com/?foo&cp=2&" }, | |
| 450 { ASCIIToUTF16("foo"), | |
| 451 15, | |
| 452 "{google:baseURL}?{searchTerms}&{google:cursorPosition}", | |
| 453 "http://www.google.com/?foo&cp=15&" }, | |
| 454 }; | |
| 455 TemplateURLData data; | |
| 456 data.input_encodings.push_back("UTF-8"); | |
| 457 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | |
| 458 data.SetURL(test_data[i].url); | |
| 459 TemplateURL url(NULL, data); | |
| 460 EXPECT_TRUE(url.url_ref().IsValid()); | |
| 461 ASSERT_TRUE(url.url_ref().SupportsReplacement()); | |
| 462 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); | |
| 463 search_terms_args.cursor_position = test_data[i].cursor_position; | |
| 464 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args)); | |
| 465 ASSERT_TRUE(result.is_valid()); | |
| 466 EXPECT_EQ(test_data[i].expected_result, result.spec()); | |
| 467 } | |
| 468 } | |
| 469 | |
| 434 TEST_F(TemplateURLTest, Suggestions) { | 470 TEST_F(TemplateURLTest, Suggestions) { |
| 435 struct TestData { | 471 struct TestData { |
| 436 const int accepted_suggestion; | 472 const int accepted_suggestion; |
| 437 const string16 original_query_for_suggestion; | 473 const string16 original_query_for_suggestion; |
| 438 const std::string expected_result; | 474 const std::string expected_result; |
| 439 } test_data[] = { | 475 } test_data[] = { |
| 440 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), | 476 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), |
| 441 "http://bar/foo?q=foobar" }, | 477 "http://bar/foo?q=foobar" }, |
| 442 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), | 478 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), |
| 443 "http://bar/foo?q=foobar" }, | 479 "http://bar/foo?q=foobar" }, |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 EXPECT_EQ(string16(), result); | 769 EXPECT_EQ(string16(), result); |
| 734 | 770 |
| 735 EXPECT_FALSE(url.ExtractSearchTermsFromURL( | 771 EXPECT_FALSE(url.ExtractSearchTermsFromURL( |
| 736 GURL("http://google.com/alt/?q=123#q="), &result)); | 772 GURL("http://google.com/alt/?q=123#q="), &result)); |
| 737 EXPECT_EQ(string16(), result); | 773 EXPECT_EQ(string16(), result); |
| 738 | 774 |
| 739 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | 775 EXPECT_TRUE(url.ExtractSearchTermsFromURL( |
| 740 GURL("http://google.com/alt/?q=#q=123"), &result)); | 776 GURL("http://google.com/alt/?q=#q=123"), &result)); |
| 741 EXPECT_EQ(ASCIIToUTF16("123"), result); | 777 EXPECT_EQ(ASCIIToUTF16("123"), result); |
| 742 } | 778 } |
| OLD | NEW |