| 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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram_base.h" | 10 #include "base/metrics/histogram_base.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 {"chrome-search://local-ntp", true, "Local NTP"}, | 178 {"chrome-search://local-ntp", true, "Local NTP"}, |
| 179 {"chrome-search://remote-ntp", true, "Remote NTP"}, | 179 {"chrome-search://remote-ntp", true, "Remote NTP"}, |
| 180 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, | 180 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, |
| 181 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, | 181 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, |
| 182 {"chrome-search://foo.com", false, "Search result page"}, | 182 {"chrome-search://foo.com", false, "Search result page"}, |
| 183 {"https://foo.com/instant?strk", false, ""}, | 183 {"https://foo.com/instant?strk", false, ""}, |
| 184 {"https://foo.com/instant#strk", false, ""}, | 184 {"https://foo.com/instant#strk", false, ""}, |
| 185 {"https://foo.com/instant?strk=0", false, ""}, | 185 {"https://foo.com/instant?strk=0", false, ""}, |
| 186 {"https://foo.com/url?strk", false, ""}, | 186 {"https://foo.com/url?strk", false, ""}, |
| 187 {"https://foo.com/alt?strk", false, ""}, | 187 {"https://foo.com/alt?strk", false, ""}, |
| 188 {"https://foo.com:80/instant", false, "HTTPS with port"}, |
| 188 {"http://foo.com/instant", false, "Non-HTTPS"}, | 189 {"http://foo.com/instant", false, "Non-HTTPS"}, |
| 189 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, | 190 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, |
| 190 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, | 191 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, |
| 192 {"http://foo.com:443/instant", false, "Non-HTTPS"}, |
| 191 {"https://foo.com/instant", false, "No search terms replacement"}, | 193 {"https://foo.com/instant", false, "No search terms replacement"}, |
| 192 {"https://foo.com/?strk", false, "Non-exact path"}, | 194 {"https://foo.com/?strk", false, "Non-exact path"}, |
| 193 }; | 195 }; |
| 194 | 196 |
| 195 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 197 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 196 const SearchTestCase& test = kTestCases[i]; | 198 const SearchTestCase& test = kTestCases[i]; |
| 197 EXPECT_EQ(test.expected_result, | 199 EXPECT_EQ(test.expected_result, |
| 198 ShouldUseProcessPerSiteForInstantURL(GURL(test.url), profile())) | 200 ShouldUseProcessPerSiteForInstantURL(GURL(test.url), profile())) |
| 199 << test.url << " " << test.comment; | 201 << test.url << " " << test.comment; |
| 200 } | 202 } |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 TEST_F(SearchTest, | 589 TEST_F(SearchTest, |
| 588 ShouldPrerenderInstantUrlOnOmniboxFocus_EnabledViaFieldTrial) { | 590 ShouldPrerenderInstantUrlOnOmniboxFocus_EnabledViaFieldTrial) { |
| 589 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 591 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 590 "EmbeddedSearch", | 592 "EmbeddedSearch", |
| 591 "Group1 espv:80 prerender_instant_url_on_omnibox_focus:1")); | 593 "Group1 espv:80 prerender_instant_url_on_omnibox_focus:1")); |
| 592 EXPECT_TRUE(ShouldPrerenderInstantUrlOnOmniboxFocus()); | 594 EXPECT_TRUE(ShouldPrerenderInstantUrlOnOmniboxFocus()); |
| 593 EXPECT_EQ(80ul, EmbeddedSearchPageVersion()); | 595 EXPECT_EQ(80ul, EmbeddedSearchPageVersion()); |
| 594 } | 596 } |
| 595 | 597 |
| 596 | 598 |
| 597 | |
| 598 TEST_F(SearchTest, ShouldShowGoogleLocalNTP_Default) { | 599 TEST_F(SearchTest, ShouldShowGoogleLocalNTP_Default) { |
| 599 EXPECT_TRUE(ShouldShowGoogleLocalNTP()); | 600 EXPECT_TRUE(ShouldShowGoogleLocalNTP()); |
| 600 } | 601 } |
| 601 | 602 |
| 602 TEST_F(SearchTest, ShouldShowGoogleLocalNTP_EnabledViaFinch) { | 603 TEST_F(SearchTest, ShouldShowGoogleLocalNTP_EnabledViaFinch) { |
| 603 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 604 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 604 "EmbeddedSearch", "Group1 espv:2 google_local_ntp:1")); | 605 "EmbeddedSearch", "Group1 espv:2 google_local_ntp:1")); |
| 605 EXPECT_TRUE(ShouldShowGoogleLocalNTP()); | 606 EXPECT_TRUE(ShouldShowGoogleLocalNTP()); |
| 606 } | 607 } |
| 607 | 608 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 }; | 694 }; |
| 694 | 695 |
| 695 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 696 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 696 const QueryExtractionAllowedTestCase& test = kTestCases[i]; | 697 const QueryExtractionAllowedTestCase& test = kTestCases[i]; |
| 697 EXPECT_EQ(test.expected_result, | 698 EXPECT_EQ(test.expected_result, |
| 698 IsQueryExtractionAllowedForURL(profile(), GURL(test.url))) | 699 IsQueryExtractionAllowedForURL(profile(), GURL(test.url))) |
| 699 << test.url << " " << test.comment; | 700 << test.url << " " << test.comment; |
| 700 } | 701 } |
| 701 } | 702 } |
| 702 | 703 |
| 704 // Regression test for https://crbug.com/605720: Set up a search provider backed |
| 705 // by localhost on a specific port, like browsertests do. The chrome-search:// |
| 706 // URLs generated in this mode should not have ports. |
| 707 TEST_F(SearchTest, SearchProviderWithPort) { |
| 708 TemplateURLService* template_url_service = |
| 709 TemplateURLServiceFactory::GetForProfile(profile()); |
| 710 TemplateURLData data; |
| 711 data.SetShortName(base::ASCIIToUTF16("localhost")); |
| 712 data.SetURL("https://[::1]:1993/url?bar={searchTerms}"); |
| 713 data.instant_url = |
| 714 "https://[::1]:1993/instant?" |
| 715 "{google:forceInstantResults}foo=foo#foo=foo&strk"; |
| 716 data.new_tab_url = "https://[::1]:1993/newtab?strk"; |
| 717 data.alternate_urls.push_back("https://[::1]:1993/alt#quux={searchTerms}"); |
| 718 data.search_terms_replacement_key = "strk"; |
| 719 |
| 720 TemplateURL* template_url = new TemplateURL(data); |
| 721 template_url_service->Add(template_url); // Takes ownership of |template_url|. |
| 722 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
| 723 |
| 724 EXPECT_TRUE(ShouldAssignURLToInstantRenderer( |
| 725 GURL("https://[::1]:1993/newtab?lala"), profile())); |
| 726 EXPECT_FALSE(ShouldAssignURLToInstantRenderer( |
| 727 GURL("https://[::1]:1992/newtab?lala"), profile())); |
| 728 EXPECT_EQ(GURL("chrome-search://remote-ntp/newtab?lala"), |
| 729 GetEffectiveURLForInstant(GURL("https://[::1]:1993/newtab?lala"), |
| 730 profile())); |
| 731 EXPECT_EQ(GURL("chrome-search://[::1]/instant?strk"), |
| 732 GetEffectiveURLForInstant(GURL("https://[::1]:1993/instant?strk"), |
| 733 profile())); |
| 734 EXPECT_FALSE(ShouldAssignURLToInstantRenderer( |
| 735 GURL("https://[::1]:1993/unregistered-path?strk"), profile())); |
| 736 } |
| 737 |
| 703 class SearchURLTest : public SearchTest { | 738 class SearchURLTest : public SearchTest { |
| 704 protected: | 739 protected: |
| 705 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) override { | 740 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) override { |
| 706 TemplateURLService* template_url_service = | 741 TemplateURLService* template_url_service = |
| 707 TemplateURLServiceFactory::GetForProfile(profile()); | 742 TemplateURLServiceFactory::GetForProfile(profile()); |
| 708 TemplateURLData data; | 743 TemplateURLData data; |
| 709 data.SetShortName(base::ASCIIToUTF16("Google")); | 744 data.SetShortName(base::ASCIIToUTF16("Google")); |
| 710 data.SetURL("{google:baseURL}search?" | 745 data.SetURL("{google:baseURL}search?" |
| 711 "{google:instantExtendedEnabledParameter}q={searchTerms}"); | 746 "{google:instantExtendedEnabledParameter}q={searchTerms}"); |
| 712 data.search_terms_replacement_key = "espv"; | 747 data.search_terms_replacement_key = "espv"; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 738 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); | 773 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); |
| 739 GURL result(template_url_->url_ref().ReplaceSearchTerms( | 774 GURL result(template_url_->url_ref().ReplaceSearchTerms( |
| 740 search_terms_args, UIThreadSearchTermsData(profile()))); | 775 search_terms_args, UIThreadSearchTermsData(profile()))); |
| 741 ASSERT_TRUE(result.is_valid()); | 776 ASSERT_TRUE(result.is_valid()); |
| 742 // Query extraction is disabled. Make sure | 777 // Query extraction is disabled. Make sure |
| 743 // {google:instantExtendedEnabledParameter} is not set in the search URL. | 778 // {google:instantExtendedEnabledParameter} is not set in the search URL. |
| 744 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec()); | 779 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec()); |
| 745 } | 780 } |
| 746 | 781 |
| 747 } // namespace search | 782 } // namespace search |
| OLD | NEW |