Index: components/search/search_unittest.cc |
diff --git a/components/search/search_unittest.cc b/components/search/search_unittest.cc |
index 2fd5a23b45f4e4c0823b9df2d856a581b45e35fb..4a5db3860c0e94b435a142c6bfa828f11c18ef69 100644 |
--- a/components/search/search_unittest.cc |
+++ b/components/search/search_unittest.cc |
@@ -9,7 +9,7 @@ |
#include "components/variations/entropy_provider.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-namespace chrome { |
+namespace search { |
class EmbeddedSearchFieldTrialTest : public testing::Test { |
protected: |
@@ -130,4 +130,110 @@ TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) { |
EXPECT_EQ(3ul, flags.size()); |
} |
-} // namespace chrome |
+#if !defined(OS_IOS) && !defined(OS_ANDROID) |
+typedef EmbeddedSearchFieldTrialTest SearchTest; |
+ |
+TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
+ "Group1 espv:2")); |
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
+ EXPECT_TRUE(ShouldPrefetchSearchResults()); |
+} |
+ |
+TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) { |
+ EXPECT_TRUE(ShouldPrefetchSearchResults()); |
+} |
+ |
+TEST_F(SearchTest, ShouldReuseInstantSearchBasePage_Default) { |
+ EXPECT_TRUE(ShouldReuseInstantSearchBasePage()); |
+} |
+ |
+TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_DisabledViaFieldTrial) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
+ "EmbeddedSearch", "Group1 espv:89 allow_prefetch_non_default_match:0")); |
+ EXPECT_FALSE(ShouldAllowPrefetchNonDefaultMatch()); |
+ EXPECT_EQ(89ul, EmbeddedSearchPageVersion()); |
+} |
+ |
+TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_EnabledViaFieldTrial) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
+ "EmbeddedSearch", "Group1 espv:80 allow_prefetch_non_default_match:1")); |
+ EXPECT_TRUE(ShouldAllowPrefetchNonDefaultMatch()); |
+ EXPECT_EQ(80ul, EmbeddedSearchPageVersion()); |
+} |
+ |
+TEST_F(SearchTest, ForceInstantResultsParam) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
+ "Group1 espv:2")); |
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
+ EXPECT_EQ("ion=1&", ForceInstantResultsParam(true)); |
+ EXPECT_EQ(std::string(), ForceInstantResultsParam(false)); |
+} |
+ |
+typedef EmbeddedSearchFieldTrialTest InstantExtendedEnabledParamTest; |
+ |
+TEST_F(InstantExtendedEnabledParamTest, QueryExtractionDisabled) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
+ "Group1 espv:12")); |
+ // Make sure InstantExtendedEnabledParam() returns an empty string for search |
+ // requests. |
+ EXPECT_FALSE(IsQueryExtractionEnabled()); |
+ EXPECT_EQ("", InstantExtendedEnabledParam(true)); |
+ EXPECT_EQ("espv=12&", InstantExtendedEnabledParam(false)); |
+} |
+ |
+TEST_F(InstantExtendedEnabledParamTest, QueryExtractionEnabled) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
+ "EmbeddedSearch", "Group1 espv:10 query_extraction:1")); |
+ EXPECT_TRUE(IsQueryExtractionEnabled()); |
+ // Make sure InstantExtendedEnabledParam() returns a non-empty param string |
+ // for search requests. |
+ EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(true)); |
+ EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(false)); |
+} |
+ |
+TEST_F(InstantExtendedEnabledParamTest, UseDefaultEmbeddedSearchPageVersion) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
+ "EmbeddedSearch", "Group1 espv:-1 query_extraction:1")); |
+ EXPECT_TRUE(IsQueryExtractionEnabled()); |
+ EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(true)); |
+ EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false)); |
+} |
+ |
+typedef EmbeddedSearchFieldTrialTest IsQueryExtractionEnabledTest; |
+ |
+TEST_F(IsQueryExtractionEnabledTest, NotSet) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
+ "Group1 espv:2")); |
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
+ EXPECT_FALSE(IsQueryExtractionEnabled()); |
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
+} |
+ |
+TEST_F(IsQueryExtractionEnabledTest, EnabledViaFieldTrial) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
+ "EmbeddedSearch", "Group1 espv:2 query_extraction:1")); |
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
+ EXPECT_TRUE(IsQueryExtractionEnabled()); |
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
+} |
+ |
+TEST_F(IsQueryExtractionEnabledTest, DisabledViaFieldTrial) { |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
+ "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); |
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
+ EXPECT_FALSE(IsQueryExtractionEnabled()); |
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
+} |
+ |
+TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) { |
+ EnableQueryExtractionForTesting(); |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
+ "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); |
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
+ EXPECT_TRUE(IsQueryExtractionEnabled()); |
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
+} |
+#endif // !defined(OS_IOS) && !defined(OS_ANDROID) |
+ |
+} // namespace search |