| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 } | 550 } |
| 551 | 551 |
| 552 TEST_F(SearchTest, GetSearchURLs) { | 552 TEST_F(SearchTest, GetSearchURLs) { |
| 553 std::vector<GURL> search_urls = GetSearchURLs(profile()); | 553 std::vector<GURL> search_urls = GetSearchURLs(profile()); |
| 554 EXPECT_EQ(2U, search_urls.size()); | 554 EXPECT_EQ(2U, search_urls.size()); |
| 555 EXPECT_EQ("http://foo.com/alt#quux=", search_urls[0].spec()); | 555 EXPECT_EQ("http://foo.com/alt#quux=", search_urls[0].spec()); |
| 556 EXPECT_EQ("http://foo.com/url?bar=", search_urls[1].spec()); | 556 EXPECT_EQ("http://foo.com/url?bar=", search_urls[1].spec()); |
| 557 } | 557 } |
| 558 | 558 |
| 559 TEST_F(SearchTest, GetSearchResultPrefetchBaseURL) { | 559 TEST_F(SearchTest, GetSearchResultPrefetchBaseURL) { |
| 560 EXPECT_TRUE(ShouldPrefetchSearchResults()); | |
| 561 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), | 560 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), |
| 562 GetSearchResultPrefetchBaseURL(profile())); | 561 GetSearchResultPrefetchBaseURL(profile())); |
| 563 } | 562 } |
| 564 | 563 |
| 565 struct ExtractSearchTermsTestCase { | 564 struct ExtractSearchTermsTestCase { |
| 566 const char* url; | 565 const char* url; |
| 567 const char* expected_result; | 566 const char* expected_result; |
| 568 const char* comment; | 567 const char* comment; |
| 569 }; | 568 }; |
| 570 | 569 |
| 571 TEST_F(SearchTest, ExtractSearchTermsFromURL) { | 570 TEST_F(SearchTest, ExtractSearchTermsFromURL) { |
| 572 const ExtractSearchTermsTestCase kTestCases[] = { | 571 const ExtractSearchTermsTestCase kTestCases[] = { |
| 573 {chrome::kChromeSearchLocalNtpUrl, "", "NTP url"}, | 572 {chrome::kChromeSearchLocalNtpUrl, "", "NTP url"}, |
| 574 {"https://foo.com/instant?strk", "", "Invalid search url"}, | 573 {"https://foo.com/instant?strk", "", "Invalid search url"}, |
| 575 {"https://foo.com/instant#strk", "", "Invalid search url"}, | 574 {"https://foo.com/instant#strk", "", "Invalid search url"}, |
| 576 {"https://foo.com/alt#quux=foo", "foo", "Valid search url"}, | 575 {"https://foo.com/alt#quux=foo", "foo", "Valid search url"}, |
| 577 {"https://foo.com/alt#quux=foo&strk", "foo", "Valid search url"} | 576 {"https://foo.com/alt#quux=foo&strk", "foo", "Valid search url"} |
| 578 }; | 577 }; |
| 579 | 578 |
| 580 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 579 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 581 const ExtractSearchTermsTestCase& test = kTestCases[i]; | 580 const ExtractSearchTermsTestCase& test = kTestCases[i]; |
| 582 EXPECT_EQ(test.expected_result, | 581 EXPECT_EQ(test.expected_result, |
| 583 base::UTF16ToASCII( | 582 base::UTF16ToASCII( |
| 584 ExtractSearchTermsFromURL(profile(), GURL(test.url)))) | 583 ExtractSearchTermsFromURL(profile(), GURL(test.url)))) |
| 585 << test.url << " " << test.comment; | 584 << test.url << " " << test.comment; |
| 586 } | 585 } |
| 587 } | 586 } |
| 588 | 587 |
| 589 struct QueryExtractionAllowedTestCase { | |
| 590 const char* url; | |
| 591 bool expected_result; | |
| 592 const char* comment; | |
| 593 }; | |
| 594 | |
| 595 TEST_F(SearchTest, IsQueryExtractionAllowedForURL) { | |
| 596 const QueryExtractionAllowedTestCase kTestCases[] = { | |
| 597 {"http://foo.com/instant?strk", false, "HTTP URL"}, | |
| 598 {"https://foo.com/instant?strk", true, "Valid URL"}, | |
| 599 {"https://foo.com/instant?", false, | |
| 600 "No search terms replacement key"}, | |
| 601 {"https://foo.com/alt#quux=foo", false, | |
| 602 "No search terms replacement key"}, | |
| 603 {"https://foo.com/alt#quux=foo&strk", true, "Valid search url"} | |
| 604 }; | |
| 605 | |
| 606 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
| 607 const QueryExtractionAllowedTestCase& test = kTestCases[i]; | |
| 608 EXPECT_EQ(test.expected_result, | |
| 609 IsQueryExtractionAllowedForURL(profile(), GURL(test.url))) | |
| 610 << test.url << " " << test.comment; | |
| 611 } | |
| 612 } | |
| 613 | |
| 614 // Regression test for https://crbug.com/605720: Set up a search provider backed | 588 // Regression test for https://crbug.com/605720: Set up a search provider backed |
| 615 // by localhost on a specific port, like browsertests do. The chrome-search:// | 589 // by localhost on a specific port, like browsertests do. The chrome-search:// |
| 616 // URLs generated in this mode should not have ports. | 590 // URLs generated in this mode should not have ports. |
| 617 TEST_F(SearchTest, SearchProviderWithPort) { | 591 TEST_F(SearchTest, SearchProviderWithPort) { |
| 618 TemplateURLService* template_url_service = | 592 TemplateURLService* template_url_service = |
| 619 TemplateURLServiceFactory::GetForProfile(profile()); | 593 TemplateURLServiceFactory::GetForProfile(profile()); |
| 620 TemplateURLData data; | 594 TemplateURLData data; |
| 621 data.SetShortName(base::ASCIIToUTF16("localhost")); | 595 data.SetShortName(base::ASCIIToUTF16("localhost")); |
| 622 data.SetURL("https://[::1]:1993/url?bar={searchTerms}"); | 596 data.SetURL("https://[::1]:1993/url?bar={searchTerms}"); |
| 623 data.instant_url = | 597 data.instant_url = |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); | 642 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); |
| 669 GURL result(template_url_->url_ref().ReplaceSearchTerms( | 643 GURL result(template_url_->url_ref().ReplaceSearchTerms( |
| 670 search_terms_args, UIThreadSearchTermsData(profile()))); | 644 search_terms_args, UIThreadSearchTermsData(profile()))); |
| 671 ASSERT_TRUE(result.is_valid()); | 645 ASSERT_TRUE(result.is_valid()); |
| 672 // Query extraction is disabled. Make sure | 646 // Query extraction is disabled. Make sure |
| 673 // {google:instantExtendedEnabledParameter} is not set in the search URL. | 647 // {google:instantExtendedEnabledParameter} is not set in the search URL. |
| 674 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec()); | 648 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec()); |
| 675 } | 649 } |
| 676 | 650 |
| 677 } // namespace search | 651 } // namespace search |
| OLD | NEW |