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

Side by Side Diff: chrome/browser/search/search_unittest.cc

Issue 2290503003: Remove use of stl_util in search_engines. (Closed)
Patch Set: ios for reals Created 4 years, 3 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
OLDNEW
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/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram_base.h" 11 #include "base/metrics/histogram_base.h"
11 #include "base/metrics/histogram_samples.h" 12 #include "base/metrics/histogram_samples.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "chrome/browser/search/instant_service.h" 15 #include "chrome/browser/search/instant_service.h"
15 #include "chrome/browser/search/instant_service_factory.h" 16 #include "chrome/browser/search/instant_service_factory.h"
16 #include "chrome/browser/search/search.h" 17 #include "chrome/browser/search/search.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 19 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 data.instant_url = "http://foo.com/instant?" 68 data.instant_url = "http://foo.com/instant?"
68 "{google:forceInstantResults}foo=foo#foo=foo&strk"; 69 "{google:forceInstantResults}foo=foo#foo=foo&strk";
69 if (set_ntp_url) { 70 if (set_ntp_url) {
70 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + 71 data.new_tab_url = (insecure_ntp_url ? "http" : "https") +
71 std::string("://foo.com/newtab?strk"); 72 std::string("://foo.com/newtab?strk");
72 } 73 }
73 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); 74 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
74 data.search_terms_replacement_key = "strk"; 75 data.search_terms_replacement_key = "strk";
75 76
76 TemplateURL* template_url = new TemplateURL(data); 77 TemplateURL* template_url = new TemplateURL(data);
77 // Takes ownership of |template_url|. 78 // Takes ownership of |template_url|.
Peter Kasting 2016/08/31 04:12:55 Nit: Comment is now redundant.
Avi (use Gerrit) 2016/09/01 00:34:26 Done.
78 template_url_service->Add(template_url); 79 template_url_service->Add(base::WrapUnique(template_url));
79 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 80 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
80 } 81 }
81 82
82 // Build an Instant URL with or without a valid search terms replacement key 83 // Build an Instant URL with or without a valid search terms replacement key
83 // as per |has_search_term_replacement_key|. Set that URL as the instant URL 84 // as per |has_search_term_replacement_key|. Set that URL as the instant URL
84 // for the default search provider. 85 // for the default search provider.
85 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) { 86 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) {
86 TemplateURLService* template_url_service = 87 TemplateURLService* template_url_service =
87 TemplateURLServiceFactory::GetForProfile(profile()); 88 TemplateURLServiceFactory::GetForProfile(profile());
88 89
89 static const char kInstantURLWithStrk[] = 90 static const char kInstantURLWithStrk[] =
90 "http://foo.com/instant?foo=foo#foo=foo&strk"; 91 "http://foo.com/instant?foo=foo#foo=foo&strk";
91 static const char kInstantURLNoStrk[] = 92 static const char kInstantURLNoStrk[] =
92 "http://foo.com/instant?foo=foo#foo=foo"; 93 "http://foo.com/instant?foo=foo#foo=foo";
93 94
94 TemplateURLData data; 95 TemplateURLData data;
95 data.SetShortName(base::ASCIIToUTF16("foo.com")); 96 data.SetShortName(base::ASCIIToUTF16("foo.com"));
96 data.SetURL("http://foo.com/url?bar={searchTerms}"); 97 data.SetURL("http://foo.com/url?bar={searchTerms}");
97 data.instant_url = (has_search_term_replacement_key ? 98 data.instant_url = (has_search_term_replacement_key ?
98 kInstantURLWithStrk : kInstantURLNoStrk); 99 kInstantURLWithStrk : kInstantURLNoStrk);
99 data.search_terms_replacement_key = "strk"; 100 data.search_terms_replacement_key = "strk";
100 101
101 TemplateURL* template_url = new TemplateURL(data); 102 TemplateURL* template_url = new TemplateURL(data);
102 // Takes ownership of |template_url|. 103 template_url_service->Add(base::WrapUnique(template_url));
103 template_url_service->Add(template_url);
104 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 104 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
105 } 105 }
106 106
107 bool InInstantProcess(const content::WebContents* contents) { 107 bool InInstantProcess(const content::WebContents* contents) {
108 InstantService* instant_service = 108 InstantService* instant_service =
109 InstantServiceFactory::GetForProfile(profile()); 109 InstantServiceFactory::GetForProfile(profile());
110 return instant_service->IsInstantProcess( 110 return instant_service->IsInstantProcess(
111 contents->GetRenderProcessHost()->GetID()); 111 contents->GetRenderProcessHost()->GetID());
112 } 112 }
113 113
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 489
490 TEST_F(SearchTest, CommandLineOverrides) { 490 TEST_F(SearchTest, CommandLineOverrides) {
491 TemplateURLService* template_url_service = 491 TemplateURLService* template_url_service =
492 TemplateURLServiceFactory::GetForProfile(profile()); 492 TemplateURLServiceFactory::GetForProfile(profile());
493 TemplateURLData data; 493 TemplateURLData data;
494 data.SetShortName(base::ASCIIToUTF16("Google")); 494 data.SetShortName(base::ASCIIToUTF16("Google"));
495 data.SetURL("{google:baseURL}search?q={searchTerms}"); 495 data.SetURL("{google:baseURL}search?q={searchTerms}");
496 data.instant_url = "{google:baseURL}webhp?strk"; 496 data.instant_url = "{google:baseURL}webhp?strk";
497 data.search_terms_replacement_key = "strk"; 497 data.search_terms_replacement_key = "strk";
498 TemplateURL* template_url = new TemplateURL(data); 498 TemplateURL* template_url = new TemplateURL(data);
499 // Takes ownership of |template_url|. 499 template_url_service->Add(base::WrapUnique(template_url));
500 template_url_service->Add(template_url);
501 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 500 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
502 501
503 // By default, Instant Extended forces the instant URL to be HTTPS, so even if 502 // By default, Instant Extended forces the instant URL to be HTTPS, so even if
504 // we set a Google base URL that is HTTP, we should get an HTTPS URL. 503 // we set a Google base URL that is HTTP, we should get an HTTPS URL.
505 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); 504 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/");
506 GURL instant_url(GetInstantURL(profile(), false)); 505 GURL instant_url(GetInstantURL(profile(), false));
507 ASSERT_TRUE(instant_url.is_valid()); 506 ASSERT_TRUE(instant_url.is_valid());
508 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); 507 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec());
509 508
510 // However, if the Google base URL is specified on the command line, the 509 // However, if the Google base URL is specified on the command line, the
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 data.SetShortName(base::ASCIIToUTF16("localhost")); 621 data.SetShortName(base::ASCIIToUTF16("localhost"));
623 data.SetURL("https://[::1]:1993/url?bar={searchTerms}"); 622 data.SetURL("https://[::1]:1993/url?bar={searchTerms}");
624 data.instant_url = 623 data.instant_url =
625 "https://[::1]:1993/instant?" 624 "https://[::1]:1993/instant?"
626 "{google:forceInstantResults}foo=foo#foo=foo&strk"; 625 "{google:forceInstantResults}foo=foo#foo=foo&strk";
627 data.new_tab_url = "https://[::1]:1993/newtab?strk"; 626 data.new_tab_url = "https://[::1]:1993/newtab?strk";
628 data.alternate_urls.push_back("https://[::1]:1993/alt#quux={searchTerms}"); 627 data.alternate_urls.push_back("https://[::1]:1993/alt#quux={searchTerms}");
629 data.search_terms_replacement_key = "strk"; 628 data.search_terms_replacement_key = "strk";
630 629
631 TemplateURL* template_url = new TemplateURL(data); 630 TemplateURL* template_url = new TemplateURL(data);
632 template_url_service->Add(template_url); // Takes ownership of |template_url|. 631 template_url_service->Add(base::WrapUnique(template_url));
633 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 632 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
634 633
635 EXPECT_TRUE(ShouldAssignURLToInstantRenderer( 634 EXPECT_TRUE(ShouldAssignURLToInstantRenderer(
636 GURL("https://[::1]:1993/newtab?lala"), profile())); 635 GURL("https://[::1]:1993/newtab?lala"), profile()));
637 EXPECT_FALSE(ShouldAssignURLToInstantRenderer( 636 EXPECT_FALSE(ShouldAssignURLToInstantRenderer(
638 GURL("https://[::1]:1992/newtab?lala"), profile())); 637 GURL("https://[::1]:1992/newtab?lala"), profile()));
639 EXPECT_EQ(GURL("chrome-search://remote-ntp/newtab?lala"), 638 EXPECT_EQ(GURL("chrome-search://remote-ntp/newtab?lala"),
640 GetEffectiveURLForInstant(GURL("https://[::1]:1993/newtab?lala"), 639 GetEffectiveURLForInstant(GURL("https://[::1]:1993/newtab?lala"),
641 profile())); 640 profile()));
642 EXPECT_EQ(GURL("chrome-search://[::1]/instant?strk"), 641 EXPECT_EQ(GURL("chrome-search://[::1]/instant?strk"),
643 GetEffectiveURLForInstant(GURL("https://[::1]:1993/instant?strk"), 642 GetEffectiveURLForInstant(GURL("https://[::1]:1993/instant?strk"),
644 profile())); 643 profile()));
645 EXPECT_FALSE(ShouldAssignURLToInstantRenderer( 644 EXPECT_FALSE(ShouldAssignURLToInstantRenderer(
646 GURL("https://[::1]:1993/unregistered-path?strk"), profile())); 645 GURL("https://[::1]:1993/unregistered-path?strk"), profile()));
647 } 646 }
648 647
649 class SearchURLTest : public SearchTest { 648 class SearchURLTest : public SearchTest {
650 protected: 649 protected:
651 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) override { 650 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) override {
652 TemplateURLService* template_url_service = 651 TemplateURLService* template_url_service =
653 TemplateURLServiceFactory::GetForProfile(profile()); 652 TemplateURLServiceFactory::GetForProfile(profile());
654 TemplateURLData data; 653 TemplateURLData data;
655 data.SetShortName(base::ASCIIToUTF16("Google")); 654 data.SetShortName(base::ASCIIToUTF16("Google"));
656 data.SetURL("{google:baseURL}search?" 655 data.SetURL("{google:baseURL}search?"
657 "{google:instantExtendedEnabledParameter}q={searchTerms}"); 656 "{google:instantExtendedEnabledParameter}q={searchTerms}");
658 data.search_terms_replacement_key = "espv"; 657 data.search_terms_replacement_key = "espv";
659 template_url_ = new TemplateURL(data); 658 template_url_ = new TemplateURL(data);
660 // |template_url_service| takes ownership of |template_url_|. 659 // |template_url_service| takes ownership of |template_url_|.
Peter Kasting 2016/08/31 04:12:55 Nit: Comment is now redundant.
Avi (use Gerrit) 2016/09/01 00:34:26 Done.
661 template_url_service->Add(template_url_); 660 template_url_service->Add(base::WrapUnique(template_url_));
662 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_); 661 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_);
663 } 662 }
664 663
665 TemplateURL* template_url_; 664 TemplateURL* template_url_;
666 }; 665 };
667 666
668 TEST_F(SearchURLTest, QueryExtractionDisabled) { 667 TEST_F(SearchURLTest, QueryExtractionDisabled) {
669 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/"); 668 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/");
670 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); 669 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo"));
671 GURL result(template_url_->url_ref().ReplaceSearchTerms( 670 GURL result(template_url_->url_ref().ReplaceSearchTerms(
672 search_terms_args, UIThreadSearchTermsData(profile()))); 671 search_terms_args, UIThreadSearchTermsData(profile())));
673 ASSERT_TRUE(result.is_valid()); 672 ASSERT_TRUE(result.is_valid());
674 // Query extraction is disabled. Make sure 673 // Query extraction is disabled. Make sure
675 // {google:instantExtendedEnabledParameter} is not set in the search URL. 674 // {google:instantExtendedEnabledParameter} is not set in the search URL.
676 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec()); 675 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec());
677 } 676 }
678 677
679 } // namespace search 678 } // namespace search
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698