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

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
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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 // "prefetch_results" flag is enabled via field trials. 792 // "prefetch_results" flag is enabled via field trials.
793 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 793 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
794 "EmbeddedSearch", 794 "EmbeddedSearch",
795 "Group1 espv:80 prefetch_results:1")); 795 "Group1 espv:80 prefetch_results:1"));
796 EXPECT_TRUE(ShouldPrefetchSearchResults()); 796 EXPECT_TRUE(ShouldPrefetchSearchResults());
797 797
798 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), 798 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"),
799 GetSearchResultPrefetchBaseURL(profile())); 799 GetSearchResultPrefetchBaseURL(profile()));
800 } 800 }
801 801
802 struct SearchURLTestCase {
samarth 2014/02/12 18:02:39 s/SearchURLTestCase/ExtractSearchTermsTestCase/
kmadhusu 2014/02/12 19:58:09 Done.
803 const char* url;
804 const char* expected_result;
805 const char* comment;
806 };
807
808 TEST_F(SearchTest, ExtractSearchTermsFromURL) {
809 const SearchURLTestCase kTestCases[] = {
810 {chrome::kChromeSearchLocalNtpUrl, "", "NTP url"},
811 {"https://foo.com/instant?strk", "", "Invalid search url"},
812 {"https://foo.com/instant#strk", "", "Invalid search url"},
813 {"https://foo.com/alt#quux=foo", "foo", "Valid search url"},
814 {"https://foo.com/alt#quux=foo&strk", "foo", "Valid search url"}
815 };
816
817 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
818 const SearchURLTestCase& test = kTestCases[i];
819 EXPECT_EQ(
820 test.expected_result,
821 UTF16ToASCII(chrome::ExtractSearchTermsFromURL(profile(),
822 GURL(test.url))))
823 << test.url << " " << test.comment;
824 }
825 }
826
827 struct InstantURLTestCase {
samarth 2014/02/12 18:02:39 QueryExtractionAllowedTestCase
kmadhusu 2014/02/12 19:58:09 Done.
828 const char* url;
829 bool expected_result;
830 const char* comment;
831 };
832
833 TEST_F(SearchTest, IsQueryExtractionAllowedForURL) {
834 const InstantURLTestCase kTestCases[] = {
835 {"http://foo.com/instant?strk", false, "HTTP URL"},
836 {"https://foo.com/instant?strk", true, "Valid URL"},
837 {"https://foo.com/instant?", false,
838 "No search terms replacement key"},
839 {"https://foo.com/alt#quux=foo", false,
840 "No search terms replacement key"},
841 {"https://foo.com/alt#quux=foo&strk", true, "Valid search url"}
842 };
843
844 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
845 const InstantURLTestCase& test = kTestCases[i];
846 EXPECT_EQ(test.expected_result,
847 chrome::IsQueryExtractionAllowedForURL(profile(), GURL(test.url)))
848 << test.url << " " << test.comment;
849 }
850 }
851
802 typedef SearchTest IsQueryExtractionEnabledTest; 852 typedef SearchTest IsQueryExtractionEnabledTest;
803 853
804 TEST_F(IsQueryExtractionEnabledTest, NotSet) { 854 TEST_F(IsQueryExtractionEnabledTest, NotSet) {
805 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 855 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
806 "EmbeddedSearch", "Group1 espv:2")); 856 "EmbeddedSearch", "Group1 espv:2"));
807 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); 857 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
808 EXPECT_FALSE(IsQueryExtractionEnabled()); 858 EXPECT_FALSE(IsQueryExtractionEnabled());
809 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); 859 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
810 } 860 }
811 861
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 } 1144 }
1095 1145
1096 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) { 1146 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) {
1097 CommandLine::ForCurrentProcess()->AppendSwitch( 1147 CommandLine::ForCurrentProcess()->AppendSwitch(
1098 switches::kEnableOriginChipV2HideOnUserInput); 1148 switches::kEnableOriginChipV2HideOnUserInput);
1099 EXPECT_TRUE(ShouldDisplayOriginChipV2()); 1149 EXPECT_TRUE(ShouldDisplayOriginChipV2());
1100 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger()); 1150 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger());
1101 } 1151 }
1102 1152
1103 } // namespace chrome 1153 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698