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

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

Issue 396583002: Stop depending on InstantService from BaseSearchProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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 "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/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); 168 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
169 SetSearchProvider(true, false); 169 SetSearchProvider(true, false);
170 } 170 }
171 171
172 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) { 172 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) {
173 TemplateURLService* template_url_service = 173 TemplateURLService* template_url_service =
174 TemplateURLServiceFactory::GetForProfile(profile()); 174 TemplateURLServiceFactory::GetForProfile(profile());
175 TemplateURLData data; 175 TemplateURLData data;
176 data.SetURL("http://foo.com/url?bar={searchTerms}"); 176 data.SetURL("http://foo.com/url?bar={searchTerms}");
177 data.instant_url = "http://foo.com/instant?" 177 data.instant_url = "http://foo.com/instant?"
178 "{google:omniboxStartMarginParameter}{google:forceInstantResults}" 178 "{google:forceInstantResults}foo=foo#foo=foo&strk";
179 "foo=foo#foo=foo&strk";
180 if (set_ntp_url) { 179 if (set_ntp_url) {
181 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + 180 data.new_tab_url = (insecure_ntp_url ? "http" : "https") +
182 std::string("://foo.com/newtab?strk"); 181 std::string("://foo.com/newtab?strk");
183 } 182 }
184 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); 183 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
185 data.search_terms_replacement_key = "strk"; 184 data.search_terms_replacement_key = "strk";
186 185
187 TemplateURL* template_url = new TemplateURL(data); 186 TemplateURL* template_url = new TemplateURL(data);
188 // Takes ownership of |template_url|. 187 // Takes ownership of |template_url|.
189 template_url_service->Add(template_url); 188 template_url_service->Add(template_url);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) { 491 TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) {
493 AddTab(browser(), GURL("chrome://blank")); 492 AddTab(browser(), GURL("chrome://blank"));
494 content::WebContents* contents = 493 content::WebContents* contents =
495 browser()->tab_strip_model()->GetWebContentsAt(0); 494 browser()->tab_strip_model()->GetWebContentsAt(0);
496 content::NavigationController& controller = contents->GetController(); 495 content::NavigationController& controller = contents->GetController();
497 // Local NTP. 496 // Local NTP.
498 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 497 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
499 EXPECT_TRUE(NavEntryIsInstantNTP(contents, 498 EXPECT_TRUE(NavEntryIsInstantNTP(contents,
500 controller.GetLastCommittedEntry())); 499 controller.GetLastCommittedEntry()));
501 // Instant page is not cacheable NTP. 500 // Instant page is not cacheable NTP.
502 NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin, 501 NavigateAndCommitActiveTab(GetInstantURL(profile(), false));
503 false));
504 EXPECT_FALSE(NavEntryIsInstantNTP(contents, 502 EXPECT_FALSE(NavEntryIsInstantNTP(contents,
505 controller.GetLastCommittedEntry())); 503 controller.GetLastCommittedEntry()));
506 // Test Cacheable NTP 504 // Test Cacheable NTP
507 NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile())); 505 NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile()));
508 EXPECT_TRUE(NavEntryIsInstantNTP(contents, 506 EXPECT_TRUE(NavEntryIsInstantNTP(contents,
509 controller.GetLastCommittedEntry())); 507 controller.GetLastCommittedEntry()));
510 } 508 }
511 509
512 TEST_F(SearchTest, InstantCacheableNTPNavigationEntryNewProfile) { 510 TEST_F(SearchTest, InstantCacheableNTPNavigationEntryNewProfile) {
513 SetSearchProvider(false, false); 511 SetSearchProvider(false, false);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 supervised_user_service->GetURLFilterForUIThread(); 558 supervised_user_service->GetURLFilterForUIThread();
561 std::map<std::string, bool> hosts; 559 std::map<std::string, bool> hosts;
562 hosts["foo.com"] = false; 560 hosts["foo.com"] = false;
563 url_filter->SetManualHosts(&hosts); 561 url_filter->SetManualHosts(&hosts);
564 562
565 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 563 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
566 chrome::GetNewTabPageURL(profile())); 564 chrome::GetNewTabPageURL(profile()));
567 GURL new_tab_url(chrome::kChromeUINewTabURL); 565 GURL new_tab_url(chrome::kChromeUINewTabURL);
568 EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile())); 566 EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile()));
569 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url); 567 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url);
570 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); 568 EXPECT_EQ(GURL(), GetInstantURL(profile(), false));
571 } 569 }
572 570
573 TEST_F(SearchTest, GetInstantURL) { 571 TEST_F(SearchTest, GetInstantURL) {
574 // No Instant URL because "strk" is missing. 572 // No Instant URL because "strk" is missing.
575 SetDefaultInstantTemplateUrl(false); 573 SetDefaultInstantTemplateUrl(false);
576 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); 574 EXPECT_EQ(GURL(), GetInstantURL(profile(), false));
577 575
578 // Set an Instant URL with a valid search terms replacement key. 576 // Set an Instant URL with a valid search terms replacement key.
579 SetDefaultInstantTemplateUrl(true); 577 SetDefaultInstantTemplateUrl(true);
580 578
581 // Now there should be a valid Instant URL. Note the HTTPS "upgrade". 579 // Now there should be a valid Instant URL. Note the HTTPS "upgrade".
582 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), 580 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
583 GetInstantURL(profile(), kDisableStartMargin, false)); 581 GetInstantURL(profile(), false));
584 582
585 // Enable suggest. No difference. 583 // Enable suggest. No difference.
586 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); 584 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
587 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), 585 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
588 GetInstantURL(profile(), kDisableStartMargin, false)); 586 GetInstantURL(profile(), false));
589 587
590 // Disable suggest. No Instant URL. 588 // Disable suggest. No Instant URL.
591 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); 589 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false);
592 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); 590 EXPECT_EQ(GURL(), GetInstantURL(profile(), false));
593 591
594 // Use alternate Instant search base URL. 592 // Use alternate Instant search base URL.
595 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); 593 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
596 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 594 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
597 "EmbeddedSearch", "Group1 espv:8 use_alternate_instant_url:1")); 595 "EmbeddedSearch", "Group1 espv:8 use_alternate_instant_url:1"));
598 EXPECT_EQ(GURL("https://foo.com/search?foo=foo&qbp=1#foo=foo&strk"), 596 EXPECT_EQ(GURL("https://foo.com/search?foo=foo&qbp=1#foo=foo&strk"),
599 GetInstantURL(profile(), kDisableStartMargin, false)); 597 GetInstantURL(profile(), false));
600 }
601
602 TEST_F(SearchTest, StartMarginCGI) {
603 // No margin.
604 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
605
606 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
607 GetInstantURL(profile(), kDisableStartMargin, false));
608
609 // With start margin.
610 EXPECT_EQ(GURL("https://foo.com/instant?es_sm=10&foo=foo#foo=foo&strk"),
611 GetInstantURL(profile(), 10, false));
612 } 598 }
613 599
614 TEST_F(SearchTest, InstantSearchEnabledCGI) { 600 TEST_F(SearchTest, InstantSearchEnabledCGI) {
615 // Disable Instant Search. 601 // Disable Instant Search.
616 // Make sure {google:forceInstantResults} is not set in the Instant URL. 602 // Make sure {google:forceInstantResults} is not set in the Instant URL.
617 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), 603 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
618 GetInstantURL(profile(), kDisableStartMargin, false)); 604 GetInstantURL(profile(), false));
619 605
620 // Enable Instant Search. 606 // Enable Instant Search.
621 // Make sure {google:forceInstantResults} is set in the Instant URL. 607 // Make sure {google:forceInstantResults} is set in the Instant URL.
622 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), 608 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"),
623 GetInstantURL(profile(), kDisableStartMargin, true)); 609 GetInstantURL(profile(), true));
624 } 610 }
625 611
626 TEST_F(SearchTest, CommandLineOverrides) { 612 TEST_F(SearchTest, CommandLineOverrides) {
627 GURL local_instant_url(GetLocalInstantURL(profile())); 613 GURL local_instant_url(GetLocalInstantURL(profile()));
628 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); 614 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url);
629 615
630 TemplateURLService* template_url_service = 616 TemplateURLService* template_url_service =
631 TemplateURLServiceFactory::GetForProfile(profile()); 617 TemplateURLServiceFactory::GetForProfile(profile());
632 TemplateURLData data; 618 TemplateURLData data;
633 data.SetURL("{google:baseURL}search?q={searchTerms}"); 619 data.SetURL("{google:baseURL}search?q={searchTerms}");
634 data.instant_url = "{google:baseURL}webhp?strk"; 620 data.instant_url = "{google:baseURL}webhp?strk";
635 data.search_terms_replacement_key = "strk"; 621 data.search_terms_replacement_key = "strk";
636 TemplateURL* template_url = new TemplateURL(data); 622 TemplateURL* template_url = new TemplateURL(data);
637 // Takes ownership of |template_url|. 623 // Takes ownership of |template_url|.
638 template_url_service->Add(template_url); 624 template_url_service->Add(template_url);
639 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 625 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
640 626
641 // By default, Instant Extended forces the instant URL to be HTTPS, so even if 627 // By default, Instant Extended forces the instant URL to be HTTPS, so even if
642 // we set a Google base URL that is HTTP, we should get an HTTPS URL. 628 // we set a Google base URL that is HTTP, we should get an HTTPS URL.
643 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); 629 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/");
644 GURL instant_url(GetInstantURL(profile(), kDisableStartMargin, false)); 630 GURL instant_url(GetInstantURL(profile(), false));
645 ASSERT_TRUE(instant_url.is_valid()); 631 ASSERT_TRUE(instant_url.is_valid());
646 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); 632 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec());
647 633
648 // However, if the Google base URL is specified on the command line, the 634 // However, if the Google base URL is specified on the command line, the
649 // instant URL should just use it, even if it's HTTP. 635 // instant URL should just use it, even if it's HTTP.
650 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); 636 UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
651 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, 637 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
652 "http://www.bar.com/"); 638 "http://www.bar.com/");
653 instant_url = GetInstantURL(profile(), kDisableStartMargin, false); 639 instant_url = GetInstantURL(profile(), false);
654 ASSERT_TRUE(instant_url.is_valid()); 640 ASSERT_TRUE(instant_url.is_valid());
655 EXPECT_EQ("http://www.bar.com/webhp?strk", instant_url.spec()); 641 EXPECT_EQ("http://www.bar.com/webhp?strk", instant_url.spec());
656 642
657 // Similarly, setting a Google base URL on the command line should allow you 643 // Similarly, setting a Google base URL on the command line should allow you
658 // to get the Google version of the local NTP, even though search provider's 644 // to get the Google version of the local NTP, even though search provider's
659 // URL doesn't contain "google". 645 // URL doesn't contain "google".
660 local_instant_url = GetLocalInstantURL(profile()); 646 local_instant_url = GetLocalInstantURL(profile());
661 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); 647 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url);
662 648
663 // If we specify extra search query params, they should be inserted into the 649 // If we specify extra search query params, they should be inserted into the
664 // query portion of the instant URL. 650 // query portion of the instant URL.
665 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 651 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
666 switches::kExtraSearchQueryParams, "a=b"); 652 switches::kExtraSearchQueryParams, "a=b");
667 instant_url = GetInstantURL(profile(), kDisableStartMargin, false); 653 instant_url = GetInstantURL(profile(), false);
668 ASSERT_TRUE(instant_url.is_valid()); 654 ASSERT_TRUE(instant_url.is_valid());
669 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); 655 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec());
670 } 656 }
671 657
672 TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) { 658 TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
673 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 659 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
674 "EmbeddedSearch", 660 "EmbeddedSearch",
675 "Group1 espv:2 prefetch_results:1")); 661 "Group1 espv:2 prefetch_results:1"));
676 EXPECT_TRUE(ShouldPrefetchSearchResults()); 662 EXPECT_TRUE(ShouldPrefetchSearchResults());
677 #if defined(OS_IOS) || defined(OS_ANDROID) 663 #if defined(OS_IOS) || defined(OS_ANDROID)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 816
831 TEST_F(SearchTest, IsNTPURL) { 817 TEST_F(SearchTest, IsNTPURL) {
832 GURL invalid_url; 818 GURL invalid_url;
833 GURL ntp_url(chrome::kChromeUINewTabURL); 819 GURL ntp_url(chrome::kChromeUINewTabURL);
834 GURL local_ntp_url(GetLocalInstantURL(profile())); 820 GURL local_ntp_url(GetLocalInstantURL(profile()));
835 821
836 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile())); 822 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile()));
837 // No margin. 823 // No margin.
838 EnableQueryExtractionForTesting(); 824 EnableQueryExtractionForTesting();
839 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); 825 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
840 GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin, false)); 826 GURL remote_ntp_url(GetInstantURL(profile(), false));
841 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); 827 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc");
842 GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); 828 GURL search_url_without_search_terms("https://foo.com/url?strk&bar");
843 829
844 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile())); 830 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile()));
845 EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile())); 831 EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile()));
846 EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile())); 832 EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile()));
847 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile())); 833 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile()));
848 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); 834 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile()));
849 835
850 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL)); 836 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL));
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1199 }
1214 1200
1215 TEST_F(OriginChipTest, CommandLineOnSrp) { 1201 TEST_F(OriginChipTest, CommandLineOnSrp) {
1216 CommandLine::ForCurrentProcess()->AppendSwitch( 1202 CommandLine::ForCurrentProcess()->AppendSwitch(
1217 switches::kEnableOriginChipOnSrp); 1203 switches::kEnableOriginChipOnSrp);
1218 EXPECT_TRUE(ShouldDisplayOriginChip()); 1204 EXPECT_TRUE(ShouldDisplayOriginChip());
1219 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); 1205 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition());
1220 } 1206 }
1221 1207
1222 } // namespace chrome 1208 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/search_engines/ui_thread_search_terms_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698