OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search/search.h" | 5 #include "components/search/search.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/metrics/statistics_recorder.h" | 8 #include "base/metrics/statistics_recorder.h" |
9 #include "components/variations/entropy_provider.h" | 9 #include "components/variations/entropy_provider.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace chrome { | 12 namespace search { |
13 | 13 |
14 class EmbeddedSearchFieldTrialTest : public testing::Test { | 14 class EmbeddedSearchFieldTrialTest : public testing::Test { |
15 protected: | 15 protected: |
16 void SetUp() override { | 16 void SetUp() override { |
17 field_trial_list_.reset(new base::FieldTrialList( | 17 field_trial_list_.reset(new base::FieldTrialList( |
18 new metrics::SHA1EntropyProvider("42"))); | 18 new metrics::SHA1EntropyProvider("42"))); |
19 base::StatisticsRecorder::Initialize(); | 19 base::StatisticsRecorder::Initialize(); |
20 } | 20 } |
21 | 21 |
22 private: | 22 private: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) { | 124 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) { |
125 FieldTrialFlags flags; | 125 FieldTrialFlags flags; |
126 | 126 |
127 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 127 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
128 "EmbeddedSearch", "Control77 bar:1 baz:7 cat:dogs")); | 128 "EmbeddedSearch", "Control77 bar:1 baz:7 cat:dogs")); |
129 EXPECT_TRUE(GetFieldTrialInfo(&flags)); | 129 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
130 EXPECT_EQ(3ul, flags.size()); | 130 EXPECT_EQ(3ul, flags.size()); |
131 } | 131 } |
132 | 132 |
133 } // namespace chrome | 133 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 134 typedef EmbeddedSearchFieldTrialTest SearchTest; |
| 135 |
| 136 TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) { |
| 137 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 138 "Group1 espv:2")); |
| 139 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 140 EXPECT_TRUE(ShouldPrefetchSearchResults()); |
| 141 } |
| 142 |
| 143 TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) { |
| 144 EXPECT_TRUE(ShouldPrefetchSearchResults()); |
| 145 } |
| 146 |
| 147 TEST_F(SearchTest, ShouldReuseInstantSearchBasePage_Default) { |
| 148 EXPECT_TRUE(ShouldReuseInstantSearchBasePage()); |
| 149 } |
| 150 |
| 151 TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_DisabledViaFieldTrial) { |
| 152 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 153 "EmbeddedSearch", "Group1 espv:89 allow_prefetch_non_default_match:0")); |
| 154 EXPECT_FALSE(ShouldAllowPrefetchNonDefaultMatch()); |
| 155 EXPECT_EQ(89ul, EmbeddedSearchPageVersion()); |
| 156 } |
| 157 |
| 158 TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_EnabledViaFieldTrial) { |
| 159 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 160 "EmbeddedSearch", "Group1 espv:80 allow_prefetch_non_default_match:1")); |
| 161 EXPECT_TRUE(ShouldAllowPrefetchNonDefaultMatch()); |
| 162 EXPECT_EQ(80ul, EmbeddedSearchPageVersion()); |
| 163 } |
| 164 |
| 165 TEST_F(SearchTest, ForceInstantResultsParam) { |
| 166 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 167 "Group1 espv:2")); |
| 168 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 169 EXPECT_EQ("ion=1&", ForceInstantResultsParam(true)); |
| 170 EXPECT_EQ(std::string(), ForceInstantResultsParam(false)); |
| 171 } |
| 172 |
| 173 typedef EmbeddedSearchFieldTrialTest InstantExtendedEnabledParamTest; |
| 174 |
| 175 TEST_F(InstantExtendedEnabledParamTest, QueryExtractionDisabled) { |
| 176 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 177 "Group1 espv:12")); |
| 178 // Make sure InstantExtendedEnabledParam() returns an empty string for search |
| 179 // requests. |
| 180 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 181 EXPECT_EQ("", InstantExtendedEnabledParam(true)); |
| 182 EXPECT_EQ("espv=12&", InstantExtendedEnabledParam(false)); |
| 183 } |
| 184 |
| 185 TEST_F(InstantExtendedEnabledParamTest, QueryExtractionEnabled) { |
| 186 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 187 "EmbeddedSearch", "Group1 espv:10 query_extraction:1")); |
| 188 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 189 // Make sure InstantExtendedEnabledParam() returns a non-empty param string |
| 190 // for search requests. |
| 191 EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(true)); |
| 192 EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(false)); |
| 193 } |
| 194 |
| 195 TEST_F(InstantExtendedEnabledParamTest, UseDefaultEmbeddedSearchPageVersion) { |
| 196 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 197 "EmbeddedSearch", "Group1 espv:-1 query_extraction:1")); |
| 198 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 199 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(true)); |
| 200 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false)); |
| 201 } |
| 202 |
| 203 typedef EmbeddedSearchFieldTrialTest IsQueryExtractionEnabledTest; |
| 204 |
| 205 TEST_F(IsQueryExtractionEnabledTest, NotSet) { |
| 206 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 207 "Group1 espv:2")); |
| 208 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 209 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 210 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 211 } |
| 212 |
| 213 TEST_F(IsQueryExtractionEnabledTest, EnabledViaFieldTrial) { |
| 214 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 215 "EmbeddedSearch", "Group1 espv:2 query_extraction:1")); |
| 216 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 217 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 218 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 219 } |
| 220 |
| 221 TEST_F(IsQueryExtractionEnabledTest, DisabledViaFieldTrial) { |
| 222 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 223 "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); |
| 224 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 225 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 226 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 227 } |
| 228 |
| 229 TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) { |
| 230 EnableQueryExtractionForTesting(); |
| 231 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 232 "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); |
| 233 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 234 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 235 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 236 } |
| 237 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) |
| 238 |
| 239 } // namespace search |
OLD | NEW |