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

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

Issue 141893009: Create a new helper function to extract search terms from the URL irrespective of the availablility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 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
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/ui/browser_instant_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 // "prefetch_results" flag is enabled via field trials. 793 // "prefetch_results" flag is enabled via field trials.
794 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 794 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
795 "EmbeddedSearch", 795 "EmbeddedSearch",
796 "Group1 espv:80 prefetch_results:1")); 796 "Group1 espv:80 prefetch_results:1"));
797 EXPECT_TRUE(ShouldPrefetchSearchResults()); 797 EXPECT_TRUE(ShouldPrefetchSearchResults());
798 798
799 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), 799 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"),
800 GetSearchResultPrefetchBaseURL(profile())); 800 GetSearchResultPrefetchBaseURL(profile()));
801 } 801 }
802 802
803 struct ExtractSearchTermsTestCase {
804 const char* url;
805 const char* expected_result;
806 const char* comment;
807 };
808
809 TEST_F(SearchTest, ExtractSearchTermsFromURL) {
810 const ExtractSearchTermsTestCase kTestCases[] = {
811 {chrome::kChromeSearchLocalNtpUrl, "", "NTP url"},
812 {"https://foo.com/instant?strk", "", "Invalid search url"},
813 {"https://foo.com/instant#strk", "", "Invalid search url"},
814 {"https://foo.com/alt#quux=foo", "foo", "Valid search url"},
815 {"https://foo.com/alt#quux=foo&strk", "foo", "Valid search url"}
816 };
817
818 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
819 const ExtractSearchTermsTestCase& test = kTestCases[i];
820 EXPECT_EQ(
821 test.expected_result,
822 UTF16ToASCII(chrome::ExtractSearchTermsFromURL(profile(),
823 GURL(test.url))))
824 << test.url << " " << test.comment;
825 }
826 }
827
828 struct QueryExtractionAllowedTestCase {
829 const char* url;
830 bool expected_result;
831 const char* comment;
832 };
833
834 TEST_F(SearchTest, IsQueryExtractionAllowedForURL) {
835 const QueryExtractionAllowedTestCase kTestCases[] = {
836 {"http://foo.com/instant?strk", false, "HTTP URL"},
837 {"https://foo.com/instant?strk", true, "Valid URL"},
838 {"https://foo.com/instant?", false,
839 "No search terms replacement key"},
840 {"https://foo.com/alt#quux=foo", false,
841 "No search terms replacement key"},
842 {"https://foo.com/alt#quux=foo&strk", true, "Valid search url"}
843 };
844
845 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
846 const QueryExtractionAllowedTestCase& test = kTestCases[i];
847 EXPECT_EQ(test.expected_result,
848 chrome::IsQueryExtractionAllowedForURL(profile(), GURL(test.url)))
849 << test.url << " " << test.comment;
850 }
851 }
852
803 class SearchURLTest : public SearchTest { 853 class SearchURLTest : public SearchTest {
804 protected: 854 protected:
805 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) 855 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url)
806 OVERRIDE { 856 OVERRIDE {
807 TemplateURLService* template_url_service = 857 TemplateURLService* template_url_service =
808 TemplateURLServiceFactory::GetForProfile(profile()); 858 TemplateURLServiceFactory::GetForProfile(profile());
809 TemplateURLData data; 859 TemplateURLData data;
810 data.SetURL("{google:baseURL}search?" 860 data.SetURL("{google:baseURL}search?"
811 "{google:instantExtendedEnabledParameter}q={searchTerms}"); 861 "{google:instantExtendedEnabledParameter}q={searchTerms}");
812 data.search_terms_replacement_key = "espv"; 862 data.search_terms_replacement_key = "espv";
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 } 1226 }
1177 1227
1178 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) { 1228 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) {
1179 CommandLine::ForCurrentProcess()->AppendSwitch( 1229 CommandLine::ForCurrentProcess()->AppendSwitch(
1180 switches::kEnableOriginChipV2HideOnUserInput); 1230 switches::kEnableOriginChipV2HideOnUserInput);
1181 EXPECT_TRUE(ShouldDisplayOriginChipV2()); 1231 EXPECT_TRUE(ShouldDisplayOriginChipV2());
1182 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger()); 1232 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger());
1183 } 1233 }
1184 1234
1185 } // namespace chrome 1235 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/ui/browser_instant_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698