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

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

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

Powered by Google App Engine
This is Rietveld 408576698