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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/metrics/field_trial.h" | 6 #include "base/metrics/field_trial.h" |
7 #include "base/metrics/histogram_base.h" | 7 #include "base/metrics/histogram_base.h" |
8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 TemplateURLService* template_url_service = | 50 TemplateURLService* template_url_service = |
51 TemplateURLServiceFactory::GetForProfile(profile()); | 51 TemplateURLServiceFactory::GetForProfile(profile()); |
52 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); | 52 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); |
53 SetSearchProvider(true, false); | 53 SetSearchProvider(true, false); |
54 } | 54 } |
55 | 55 |
56 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) { | 56 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) { |
57 TemplateURLService* template_url_service = | 57 TemplateURLService* template_url_service = |
58 TemplateURLServiceFactory::GetForProfile(profile()); | 58 TemplateURLServiceFactory::GetForProfile(profile()); |
59 TemplateURLData data; | 59 TemplateURLData data; |
| 60 data.SetShortName(base::ASCIIToUTF16("foo.com")); |
60 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 61 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
61 data.instant_url = "http://foo.com/instant?" | 62 data.instant_url = "http://foo.com/instant?" |
62 "{google:forceInstantResults}foo=foo#foo=foo&strk"; | 63 "{google:forceInstantResults}foo=foo#foo=foo&strk"; |
63 if (set_ntp_url) { | 64 if (set_ntp_url) { |
64 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + | 65 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + |
65 std::string("://foo.com/newtab?strk"); | 66 std::string("://foo.com/newtab?strk"); |
66 } | 67 } |
67 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); | 68 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); |
68 data.search_terms_replacement_key = "strk"; | 69 data.search_terms_replacement_key = "strk"; |
69 | 70 |
70 TemplateURL* template_url = new TemplateURL(data); | 71 TemplateURL* template_url = new TemplateURL(data); |
71 // Takes ownership of |template_url|. | 72 // Takes ownership of |template_url|. |
72 template_url_service->Add(template_url); | 73 template_url_service->Add(template_url); |
73 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 74 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
74 } | 75 } |
75 | 76 |
76 // Build an Instant URL with or without a valid search terms replacement key | 77 // Build an Instant URL with or without a valid search terms replacement key |
77 // as per |has_search_term_replacement_key|. Set that URL as the instant URL | 78 // as per |has_search_term_replacement_key|. Set that URL as the instant URL |
78 // for the default search provider. | 79 // for the default search provider. |
79 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) { | 80 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) { |
80 TemplateURLService* template_url_service = | 81 TemplateURLService* template_url_service = |
81 TemplateURLServiceFactory::GetForProfile(profile()); | 82 TemplateURLServiceFactory::GetForProfile(profile()); |
82 | 83 |
83 static const char kInstantURLWithStrk[] = | 84 static const char kInstantURLWithStrk[] = |
84 "http://foo.com/instant?foo=foo#foo=foo&strk"; | 85 "http://foo.com/instant?foo=foo#foo=foo&strk"; |
85 static const char kInstantURLNoStrk[] = | 86 static const char kInstantURLNoStrk[] = |
86 "http://foo.com/instant?foo=foo#foo=foo"; | 87 "http://foo.com/instant?foo=foo#foo=foo"; |
87 | 88 |
88 TemplateURLData data; | 89 TemplateURLData data; |
| 90 data.SetShortName(base::ASCIIToUTF16("foo.com")); |
89 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 91 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
90 data.instant_url = (has_search_term_replacement_key ? | 92 data.instant_url = (has_search_term_replacement_key ? |
91 kInstantURLWithStrk : kInstantURLNoStrk); | 93 kInstantURLWithStrk : kInstantURLNoStrk); |
92 data.search_terms_replacement_key = "strk"; | 94 data.search_terms_replacement_key = "strk"; |
93 | 95 |
94 TemplateURL* template_url = new TemplateURL(data); | 96 TemplateURL* template_url = new TemplateURL(data); |
95 // Takes ownership of |template_url|. | 97 // Takes ownership of |template_url|. |
96 template_url_service->Add(template_url); | 98 template_url_service->Add(template_url); |
97 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 99 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
98 } | 100 } |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 GetInstantURL(profile(), true)); | 506 GetInstantURL(profile(), true)); |
505 } | 507 } |
506 | 508 |
507 TEST_F(SearchTest, CommandLineOverrides) { | 509 TEST_F(SearchTest, CommandLineOverrides) { |
508 GURL local_instant_url(GetLocalInstantURL(profile())); | 510 GURL local_instant_url(GetLocalInstantURL(profile())); |
509 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); | 511 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); |
510 | 512 |
511 TemplateURLService* template_url_service = | 513 TemplateURLService* template_url_service = |
512 TemplateURLServiceFactory::GetForProfile(profile()); | 514 TemplateURLServiceFactory::GetForProfile(profile()); |
513 TemplateURLData data; | 515 TemplateURLData data; |
| 516 data.SetShortName(base::ASCIIToUTF16("Google")); |
514 data.SetURL("{google:baseURL}search?q={searchTerms}"); | 517 data.SetURL("{google:baseURL}search?q={searchTerms}"); |
515 data.instant_url = "{google:baseURL}webhp?strk"; | 518 data.instant_url = "{google:baseURL}webhp?strk"; |
516 data.search_terms_replacement_key = "strk"; | 519 data.search_terms_replacement_key = "strk"; |
517 TemplateURL* template_url = new TemplateURL(data); | 520 TemplateURL* template_url = new TemplateURL(data); |
518 // Takes ownership of |template_url|. | 521 // Takes ownership of |template_url|. |
519 template_url_service->Add(template_url); | 522 template_url_service->Add(template_url); |
520 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 523 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
521 | 524 |
522 // By default, Instant Extended forces the instant URL to be HTTPS, so even if | 525 // By default, Instant Extended forces the instant URL to be HTTPS, so even if |
523 // we set a Google base URL that is HTTP, we should get an HTTPS URL. | 526 // we set a Google base URL that is HTTP, we should get an HTTPS URL. |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 << test.url << " " << test.comment; | 759 << test.url << " " << test.comment; |
757 } | 760 } |
758 } | 761 } |
759 | 762 |
760 class SearchURLTest : public SearchTest { | 763 class SearchURLTest : public SearchTest { |
761 protected: | 764 protected: |
762 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) override { | 765 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) override { |
763 TemplateURLService* template_url_service = | 766 TemplateURLService* template_url_service = |
764 TemplateURLServiceFactory::GetForProfile(profile()); | 767 TemplateURLServiceFactory::GetForProfile(profile()); |
765 TemplateURLData data; | 768 TemplateURLData data; |
| 769 data.SetShortName(base::ASCIIToUTF16("Google")); |
766 data.SetURL("{google:baseURL}search?" | 770 data.SetURL("{google:baseURL}search?" |
767 "{google:instantExtendedEnabledParameter}q={searchTerms}"); | 771 "{google:instantExtendedEnabledParameter}q={searchTerms}"); |
768 data.search_terms_replacement_key = "espv"; | 772 data.search_terms_replacement_key = "espv"; |
769 template_url_ = new TemplateURL(data); | 773 template_url_ = new TemplateURL(data); |
770 // |template_url_service| takes ownership of |template_url_|. | 774 // |template_url_service| takes ownership of |template_url_|. |
771 template_url_service->Add(template_url_); | 775 template_url_service->Add(template_url_); |
772 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_); | 776 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_); |
773 } | 777 } |
774 | 778 |
775 TemplateURL* template_url_; | 779 TemplateURL* template_url_; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) { | 874 TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) { |
871 EnableQueryExtractionForTesting(); | 875 EnableQueryExtractionForTesting(); |
872 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 876 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
873 "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); | 877 "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); |
874 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 878 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
875 EXPECT_TRUE(IsQueryExtractionEnabled()); | 879 EXPECT_TRUE(IsQueryExtractionEnabled()); |
876 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | 880 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
877 } | 881 } |
878 | 882 |
879 } // namespace chrome | 883 } // namespace chrome |
OLD | NEW |