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 "chrome/browser/omnibox/omnibox_field_trial.h" | 5 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "chrome/browser/autocomplete/autocomplete_input.h" | |
13 #include "chrome/browser/search/search.h" | 12 #include "chrome/browser/search/search.h" |
14 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "components/metrics/proto/omnibox_event.pb.h" |
15 #include "components/variations/entropy_provider.h" | 15 #include "components/variations/entropy_provider.h" |
16 #include "components/variations/variations_associated_data.h" | 16 #include "components/variations/variations_associated_data.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
| 19 using metrics::OmniboxEventProto; |
| 20 |
19 class OmniboxFieldTrialTest : public testing::Test { | 21 class OmniboxFieldTrialTest : public testing::Test { |
20 public: | 22 public: |
21 OmniboxFieldTrialTest() { | 23 OmniboxFieldTrialTest() { |
22 ResetFieldTrialList(); | 24 ResetFieldTrialList(); |
23 } | 25 } |
24 | 26 |
25 void ResetFieldTrialList() { | 27 void ResetFieldTrialList() { |
26 // Destroy the existing FieldTrialList before creating a new one to avoid | 28 // Destroy the existing FieldTrialList before creating a new one to avoid |
27 // a DCHECK. | 29 // a DCHECK. |
28 field_trial_list_.reset(); | 30 field_trial_list_.reset(); |
(...skipping 16 matching lines...) Expand all Loading... |
45 static void VerifyDemotion( | 47 static void VerifyDemotion( |
46 const OmniboxFieldTrial::DemotionMultipliers& demotions, | 48 const OmniboxFieldTrial::DemotionMultipliers& demotions, |
47 AutocompleteMatchType::Type match_type, | 49 AutocompleteMatchType::Type match_type, |
48 float expected_value); | 50 float expected_value); |
49 | 51 |
50 // EXPECT()s that OmniboxFieldTrial::GetValueForRuleInContext(|rule|, | 52 // EXPECT()s that OmniboxFieldTrial::GetValueForRuleInContext(|rule|, |
51 // |page_classification|) returns |rule_value|. | 53 // |page_classification|) returns |rule_value|. |
52 static void ExpectRuleValue( | 54 static void ExpectRuleValue( |
53 const std::string& rule_value, | 55 const std::string& rule_value, |
54 const std::string& rule, | 56 const std::string& rule, |
55 AutocompleteInput::PageClassification page_classification); | 57 OmniboxEventProto::PageClassification page_classification); |
56 | 58 |
57 private: | 59 private: |
58 scoped_ptr<base::FieldTrialList> field_trial_list_; | 60 scoped_ptr<base::FieldTrialList> field_trial_list_; |
59 | 61 |
60 DISALLOW_COPY_AND_ASSIGN(OmniboxFieldTrialTest); | 62 DISALLOW_COPY_AND_ASSIGN(OmniboxFieldTrialTest); |
61 }; | 63 }; |
62 | 64 |
63 // static | 65 // static |
64 void OmniboxFieldTrialTest::VerifyDemotion( | 66 void OmniboxFieldTrialTest::VerifyDemotion( |
65 const OmniboxFieldTrial::DemotionMultipliers& demotions, | 67 const OmniboxFieldTrial::DemotionMultipliers& demotions, |
66 AutocompleteMatchType::Type match_type, | 68 AutocompleteMatchType::Type match_type, |
67 float expected_value) { | 69 float expected_value) { |
68 OmniboxFieldTrial::DemotionMultipliers::const_iterator demotion_it = | 70 OmniboxFieldTrial::DemotionMultipliers::const_iterator demotion_it = |
69 demotions.find(match_type); | 71 demotions.find(match_type); |
70 ASSERT_TRUE(demotion_it != demotions.end()); | 72 ASSERT_TRUE(demotion_it != demotions.end()); |
71 EXPECT_FLOAT_EQ(expected_value, demotion_it->second); | 73 EXPECT_FLOAT_EQ(expected_value, demotion_it->second); |
72 } | 74 } |
73 | 75 |
74 // static | 76 // static |
75 void OmniboxFieldTrialTest::ExpectRuleValue( | 77 void OmniboxFieldTrialTest::ExpectRuleValue( |
76 const std::string& rule_value, | 78 const std::string& rule_value, |
77 const std::string& rule, | 79 const std::string& rule, |
78 AutocompleteInput::PageClassification page_classification) { | 80 OmniboxEventProto::PageClassification page_classification) { |
79 EXPECT_EQ(rule_value, | 81 EXPECT_EQ(rule_value, |
80 OmniboxFieldTrial::GetValueForRuleInContext( | 82 OmniboxFieldTrial::GetValueForRuleInContext( |
81 rule, page_classification)); | 83 rule, page_classification)); |
82 } | 84 } |
83 | 85 |
84 // Test if GetDisabledProviderTypes() properly parses various field trial | 86 // Test if GetDisabledProviderTypes() properly parses various field trial |
85 // group names. | 87 // group names. |
86 TEST_F(OmniboxFieldTrialTest, GetDisabledProviderTypes) { | 88 TEST_F(OmniboxFieldTrialTest, GetDisabledProviderTypes) { |
87 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes()); | 89 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes()); |
88 | 90 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = | 205 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = |
204 "5:100"; | 206 "5:100"; |
205 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":*:*"] = "1:25"; | 207 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":*:*"] = "1:25"; |
206 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 208 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
207 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 209 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
208 } | 210 } |
209 base::FieldTrialList::CreateFieldTrial( | 211 base::FieldTrialList::CreateFieldTrial( |
210 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 212 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
211 OmniboxFieldTrial::DemotionMultipliers demotions_by_type; | 213 OmniboxFieldTrial::DemotionMultipliers demotions_by_type; |
212 OmniboxFieldTrial::GetDemotionsByType( | 214 OmniboxFieldTrial::GetDemotionsByType( |
213 AutocompleteInput::NTP, &demotions_by_type); | 215 OmniboxEventProto::NTP, &demotions_by_type); |
214 ASSERT_EQ(2u, demotions_by_type.size()); | 216 ASSERT_EQ(2u, demotions_by_type.size()); |
215 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.5); | 217 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.5); |
216 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_TITLE, 0.0); | 218 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_TITLE, 0.0); |
217 OmniboxFieldTrial::GetDemotionsByType( | 219 OmniboxFieldTrial::GetDemotionsByType( |
218 AutocompleteInput::HOME_PAGE, &demotions_by_type); | 220 OmniboxEventProto::HOME_PAGE, &demotions_by_type); |
219 ASSERT_EQ(1u, demotions_by_type.size()); | 221 ASSERT_EQ(1u, demotions_by_type.size()); |
220 VerifyDemotion(demotions_by_type, AutocompleteMatchType::NAVSUGGEST, 1.0); | 222 VerifyDemotion(demotions_by_type, AutocompleteMatchType::NAVSUGGEST, 1.0); |
221 OmniboxFieldTrial::GetDemotionsByType( | 223 OmniboxFieldTrial::GetDemotionsByType( |
222 AutocompleteInput::BLANK, &demotions_by_type); | 224 OmniboxEventProto::BLANK, &demotions_by_type); |
223 ASSERT_EQ(1u, demotions_by_type.size()); | 225 ASSERT_EQ(1u, demotions_by_type.size()); |
224 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.25); | 226 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.25); |
225 } | 227 } |
226 | 228 |
227 TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) { | 229 TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) { |
228 { | 230 { |
229 std::map<std::string, std::string> params; | 231 std::map<std::string, std::string> params; |
230 // Rule 1 has some exact matches and fallbacks at every level. | 232 // Rule 1 has some exact matches and fallbacks at every level. |
231 params["rule1:1:0"] = "rule1-1-0-value"; // NTP | 233 params["rule1:1:0"] = "rule1-1-0-value"; // NTP |
232 params["rule1:3:0"] = "rule1-3-0-value"; // HOME_PAGE | 234 params["rule1:3:0"] = "rule1-3-0-value"; // HOME_PAGE |
(...skipping 15 matching lines...) Expand all Loading... |
248 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 250 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
249 } | 251 } |
250 | 252 |
251 base::FieldTrialList::CreateFieldTrial( | 253 base::FieldTrialList::CreateFieldTrial( |
252 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 254 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
253 | 255 |
254 if (chrome::IsInstantExtendedAPIEnabled()) { | 256 if (chrome::IsInstantExtendedAPIEnabled()) { |
255 // Tests with Instant Extended enabled. | 257 // Tests with Instant Extended enabled. |
256 // Tests for rule 1. | 258 // Tests for rule 1. |
257 ExpectRuleValue("rule1-4-1-value", | 259 ExpectRuleValue("rule1-4-1-value", |
258 "rule1", AutocompleteInput::OTHER); // exact match | 260 "rule1", OmniboxEventProto::OTHER); // exact match |
259 ExpectRuleValue("rule1-*-1-value", | 261 ExpectRuleValue("rule1-*-1-value", |
260 "rule1", AutocompleteInput::BLANK); // partial fallback | 262 "rule1", OmniboxEventProto::BLANK); // partial fallback |
261 ExpectRuleValue("rule1-*-1-value", | 263 ExpectRuleValue("rule1-*-1-value", |
262 "rule1", | 264 "rule1", |
263 AutocompleteInput::NTP); // partial fallback | 265 OmniboxEventProto::NTP); // partial fallback |
264 | 266 |
265 // Tests for rule 2. | 267 // Tests for rule 2. |
266 ExpectRuleValue("rule2-1-*-value", | 268 ExpectRuleValue("rule2-1-*-value", |
267 "rule2", | 269 "rule2", |
268 AutocompleteInput::NTP); // partial fallback | 270 OmniboxEventProto::NTP); // partial fallback |
269 ExpectRuleValue("rule2-*-*-value", | 271 ExpectRuleValue("rule2-*-*-value", |
270 "rule2", AutocompleteInput::OTHER); // global fallback | 272 "rule2", OmniboxEventProto::OTHER); // global fallback |
271 | 273 |
272 // Tests for rule 3. | 274 // Tests for rule 3. |
273 ExpectRuleValue("rule3-*-*-value", | 275 ExpectRuleValue("rule3-*-*-value", |
274 "rule3", | 276 "rule3", |
275 AutocompleteInput::HOME_PAGE); // global fallback | 277 OmniboxEventProto::HOME_PAGE); // global fallback |
276 ExpectRuleValue("rule3-*-*-value", | 278 ExpectRuleValue("rule3-*-*-value", |
277 "rule3", | 279 "rule3", |
278 AutocompleteInput::OTHER); // global fallback | 280 OmniboxEventProto::OTHER); // global fallback |
279 | 281 |
280 // Tests for rule 4. | 282 // Tests for rule 4. |
281 ExpectRuleValue("", | 283 ExpectRuleValue("", |
282 "rule4", | 284 "rule4", |
283 AutocompleteInput::BLANK); // no global fallback | 285 OmniboxEventProto::BLANK); // no global fallback |
284 ExpectRuleValue("", | 286 ExpectRuleValue("", |
285 "rule4", | 287 "rule4", |
286 AutocompleteInput::HOME_PAGE); // no global fallback | 288 OmniboxEventProto::HOME_PAGE); // no global fallback |
287 | 289 |
288 // Tests for rule 5 (a missing rule). | 290 // Tests for rule 5 (a missing rule). |
289 ExpectRuleValue("", | 291 ExpectRuleValue("", |
290 "rule5", AutocompleteInput::OTHER); // no rule at all | 292 "rule5", OmniboxEventProto::OTHER); // no rule at all |
291 } else { | 293 } else { |
292 // Tests for rule 1. | 294 // Tests for rule 1. |
293 ExpectRuleValue("rule1-1-0-value", | 295 ExpectRuleValue("rule1-1-0-value", |
294 "rule1", AutocompleteInput::NTP); // exact match | 296 "rule1", OmniboxEventProto::NTP); // exact match |
295 ExpectRuleValue("rule1-1-0-value", | 297 ExpectRuleValue("rule1-1-0-value", |
296 "rule1", AutocompleteInput::NTP); // exact match | 298 "rule1", OmniboxEventProto::NTP); // exact match |
297 ExpectRuleValue("rule1-*-*-value", | 299 ExpectRuleValue("rule1-*-*-value", |
298 "rule1", AutocompleteInput::BLANK); // fallback to global | 300 "rule1", OmniboxEventProto::BLANK); // fallback to global |
299 ExpectRuleValue("rule1-3-0-value", | 301 ExpectRuleValue("rule1-3-0-value", |
300 "rule1", | 302 "rule1", |
301 AutocompleteInput::HOME_PAGE); // exact match | 303 OmniboxEventProto::HOME_PAGE); // exact match |
302 ExpectRuleValue("rule1-4-*-value", | 304 ExpectRuleValue("rule1-4-*-value", |
303 "rule1", AutocompleteInput::OTHER); // partial fallback | 305 "rule1", OmniboxEventProto::OTHER); // partial fallback |
304 ExpectRuleValue("rule1-*-*-value", | 306 ExpectRuleValue("rule1-*-*-value", |
305 "rule1", | 307 "rule1", |
306 AutocompleteInput:: // fallback to global | 308 OmniboxEventProto:: // fallback to global |
307 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT); | 309 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT); |
308 // Tests for rule 2. | 310 // Tests for rule 2. |
309 ExpectRuleValue("rule2-*-0-value", | 311 ExpectRuleValue("rule2-*-0-value", |
310 "rule2", | 312 "rule2", |
311 AutocompleteInput::HOME_PAGE); // partial fallback | 313 OmniboxEventProto::HOME_PAGE); // partial fallback |
312 ExpectRuleValue("rule2-*-0-value", | 314 ExpectRuleValue("rule2-*-0-value", |
313 "rule2", AutocompleteInput::OTHER); // partial fallback | 315 "rule2", OmniboxEventProto::OTHER); // partial fallback |
314 | 316 |
315 // Tests for rule 3. | 317 // Tests for rule 3. |
316 ExpectRuleValue("rule3-*-*-value", | 318 ExpectRuleValue("rule3-*-*-value", |
317 "rule3", | 319 "rule3", |
318 AutocompleteInput::HOME_PAGE); // fallback to global | 320 OmniboxEventProto::HOME_PAGE); // fallback to global |
319 ExpectRuleValue("rule3-*-*-value", | 321 ExpectRuleValue("rule3-*-*-value", |
320 "rule3", AutocompleteInput::OTHER); // fallback to global | 322 "rule3", OmniboxEventProto::OTHER); // fallback to global |
321 | 323 |
322 // Tests for rule 4. | 324 // Tests for rule 4. |
323 ExpectRuleValue("", | 325 ExpectRuleValue("", |
324 "rule4", AutocompleteInput::BLANK); // no global fallback | 326 "rule4", OmniboxEventProto::BLANK); // no global fallback |
325 ExpectRuleValue("", | 327 ExpectRuleValue("", |
326 "rule4", | 328 "rule4", |
327 AutocompleteInput::HOME_PAGE); // no global fallback | 329 OmniboxEventProto::HOME_PAGE); // no global fallback |
328 ExpectRuleValue("rule4-4-0-value", | 330 ExpectRuleValue("rule4-4-0-value", |
329 "rule4", AutocompleteInput::OTHER); // exact match | 331 "rule4", OmniboxEventProto::OTHER); // exact match |
330 | 332 |
331 // Tests for rule 5 (a missing rule). | 333 // Tests for rule 5 (a missing rule). |
332 ExpectRuleValue("", | 334 ExpectRuleValue("", |
333 "rule5", AutocompleteInput::OTHER); // no rule at all | 335 "rule5", OmniboxEventProto::OTHER); // no rule at all |
334 } | 336 } |
335 } | 337 } |
336 | 338 |
337 TEST_F(OmniboxFieldTrialTest, HUPNewScoringFieldTrial) { | 339 TEST_F(OmniboxFieldTrialTest, HUPNewScoringFieldTrial) { |
338 { | 340 { |
339 std::map<std::string, std::string> params; | 341 std::map<std::string, std::string> params; |
340 params[std::string(OmniboxFieldTrial::kHUPNewScoringEnabledParam)] = "1"; | 342 params[std::string(OmniboxFieldTrial::kHUPNewScoringEnabledParam)] = "1"; |
341 params[std::string( | 343 params[std::string( |
342 OmniboxFieldTrial::kHUPNewScoringTypedCountRelevanceCapParam)] = "56"; | 344 OmniboxFieldTrial::kHUPNewScoringTypedCountRelevanceCapParam)] = "56"; |
343 params[std::string( | 345 params[std::string( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 386 |
385 // No decay by default. | 387 // No decay by default. |
386 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7))); | 388 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7))); |
387 | 389 |
388 buckets.set_half_life_days(7); | 390 buckets.set_half_life_days(7); |
389 EXPECT_EQ(0.5, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7))); | 391 EXPECT_EQ(0.5, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7))); |
390 EXPECT_EQ(0.25, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(14))); | 392 EXPECT_EQ(0.25, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(14))); |
391 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(0))); | 393 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(0))); |
392 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(-1))); | 394 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(-1))); |
393 } | 395 } |
OLD | NEW |