OLD | NEW |
---|---|
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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 // "prefetch_results" flag is enabled via field trials. | 769 // "prefetch_results" flag is enabled via field trials. |
770 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 770 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
771 "EmbeddedSearch", | 771 "EmbeddedSearch", |
772 "Group1 espv:80 prefetch_results:1")); | 772 "Group1 espv:80 prefetch_results:1")); |
773 EXPECT_TRUE(ShouldPrefetchSearchResults()); | 773 EXPECT_TRUE(ShouldPrefetchSearchResults()); |
774 | 774 |
775 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), | 775 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), |
776 GetSearchResultPrefetchBaseURL(profile())); | 776 GetSearchResultPrefetchBaseURL(profile())); |
777 } | 777 } |
778 | 778 |
779 struct SearchURLTestCase { | |
780 const char* url; | |
781 const char* expected_result; | |
782 const char* comment; | |
783 }; | |
784 | |
785 TEST_F(SearchTest, ExtractSearchTermsFromURL) { | |
786 const SearchURLTestCase kTestCases[] = { | |
787 {chrome::kChromeSearchLocalNtpUrl, "", "NTP url"}, | |
788 {"https://foo.com/instant?strk", "", "Invalid search url"}, | |
789 {"https://foo.com/instant#strk", "", "Invalid search url"}, | |
790 {"https://foo.com/alt#quux=foo", "foo", "Valid search url"}, | |
791 {"https://foo.com/alt#quux=foo&strk", "foo", "Valid search url"} | |
792 }; | |
793 | |
794 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
795 const SearchURLTestCase& test = kTestCases[i]; | |
796 EXPECT_EQ( | |
797 test.expected_result, | |
798 UTF16ToASCII(chrome::ExtractSearchTermsFromURL(profile(), | |
799 GURL(test.url)))) | |
800 << test.url << " " << test.comment; | |
801 } | |
802 } | |
803 | |
804 struct InstantURLTestCase { | |
805 const char* url; | |
806 bool expected_result; | |
807 const char* comment; | |
808 }; | |
809 | |
810 TEST_F(SearchTest, IsSuitableForInstant) { | |
Jered
2014/02/11 23:33:28
Update this test case?
kmadhusu
2014/02/12 00:24:57
Oops. Fixed.
| |
811 const InstantURLTestCase kTestCases[] = { | |
812 {"http://foo.com/instant?strk", false, "HTTP URL"}, | |
813 {"https://foo.com/instant?strk", true, "Valid URL"}, | |
814 {"https://foo.com/instant?", false, | |
815 "No search terms replacement key"}, | |
816 {"https://foo.com/alt#quux=foo", false, | |
817 "No search terms replacement key"}, | |
818 {"https://foo.com/alt#quux=foo&strk", true, "Valid search url"} | |
819 }; | |
820 | |
821 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
822 const InstantURLTestCase& test = kTestCases[i]; | |
823 EXPECT_EQ(test.expected_result, | |
824 chrome::IsSuitableURLForInstant(profile(), GURL(test.url))) | |
825 << test.url << " " << test.comment; | |
826 } | |
827 } | |
828 | |
779 typedef SearchTest IsQueryExtractionEnabledTest; | 829 typedef SearchTest IsQueryExtractionEnabledTest; |
780 | 830 |
781 TEST_F(IsQueryExtractionEnabledTest, NotSet) { | 831 TEST_F(IsQueryExtractionEnabledTest, NotSet) { |
782 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 832 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
783 "EmbeddedSearch", "Group1 espv:2")); | 833 "EmbeddedSearch", "Group1 espv:2")); |
784 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 834 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
785 EXPECT_FALSE(IsQueryExtractionEnabled()); | 835 EXPECT_FALSE(IsQueryExtractionEnabled()); |
786 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | 836 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
787 } | 837 } |
788 | 838 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 } | 1121 } |
1072 | 1122 |
1073 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) { | 1123 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) { |
1074 CommandLine::ForCurrentProcess()->AppendSwitch( | 1124 CommandLine::ForCurrentProcess()->AppendSwitch( |
1075 switches::kEnableOriginChipV2HideOnUserInput); | 1125 switches::kEnableOriginChipV2HideOnUserInput); |
1076 EXPECT_TRUE(ShouldDisplayOriginChipV2()); | 1126 EXPECT_TRUE(ShouldDisplayOriginChipV2()); |
1077 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger()); | 1127 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger()); |
1078 } | 1128 } |
1079 | 1129 |
1080 } // namespace chrome | 1130 } // namespace chrome |
OLD | NEW |