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

Side by Side Diff: components/omnibox/omnibox_field_trial_unittest.cc

Issue 645303003: Parametrize Suggest polling strategy and delay. Also add a parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added more tests. Created 6 years, 1 month 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
« no previous file with comments | « components/omnibox/omnibox_field_trial.cc ('k') | components/omnibox/search_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/omnibox/omnibox_field_trial.h" 5 #include "components/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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 AutocompleteMatchType::Type match_type, 58 AutocompleteMatchType::Type match_type,
59 float expected_value); 59 float expected_value);
60 60
61 // EXPECT()s that OmniboxFieldTrial::GetValueForRuleInContext(|rule|, 61 // EXPECT()s that OmniboxFieldTrial::GetValueForRuleInContext(|rule|,
62 // |page_classification|) returns |rule_value|. 62 // |page_classification|) returns |rule_value|.
63 static void ExpectRuleValue( 63 static void ExpectRuleValue(
64 const std::string& rule_value, 64 const std::string& rule_value,
65 const std::string& rule, 65 const std::string& rule,
66 OmniboxEventProto::PageClassification page_classification); 66 OmniboxEventProto::PageClassification page_classification);
67 67
68 // EXPECTS that OmniboxFieldTrial::GetSuggestPollingStrategy returns
H Fung 2014/10/23 17:58:56 EXPECT()s instead of EXPECTS similar to above?
Bart N. 2014/10/23 19:19:58 It was a copy from VerifyDemotion above, which I a
69 // |expected_from_last_keystroke| and |expected_delay_ms| for the given
70 // experiment params. If one the rule values is NULL, the corresponding
71 // variation parameter won't be set thus allowing to test the default
72 // behavior.
73 void VerifySuggestPollingStrategy(
74 const char* from_last_keystroke_rule_value,
75 const char* polling_delay_ms_rule_value,
76 bool expected_from_last_keystroke,
77 int expected_delay_ms);
78
68 private: 79 private:
69 scoped_ptr<base::FieldTrialList> field_trial_list_; 80 scoped_ptr<base::FieldTrialList> field_trial_list_;
70 81
71 DISALLOW_COPY_AND_ASSIGN(OmniboxFieldTrialTest); 82 DISALLOW_COPY_AND_ASSIGN(OmniboxFieldTrialTest);
72 }; 83 };
73 84
74 // static 85 // static
75 void OmniboxFieldTrialTest::VerifyDemotion( 86 void OmniboxFieldTrialTest::VerifyDemotion(
76 const OmniboxFieldTrial::DemotionMultipliers& demotions, 87 const OmniboxFieldTrial::DemotionMultipliers& demotions,
77 AutocompleteMatchType::Type match_type, 88 AutocompleteMatchType::Type match_type,
78 float expected_value) { 89 float expected_value) {
79 OmniboxFieldTrial::DemotionMultipliers::const_iterator demotion_it = 90 OmniboxFieldTrial::DemotionMultipliers::const_iterator demotion_it =
80 demotions.find(match_type); 91 demotions.find(match_type);
81 ASSERT_TRUE(demotion_it != demotions.end()); 92 ASSERT_TRUE(demotion_it != demotions.end());
82 EXPECT_FLOAT_EQ(expected_value, demotion_it->second); 93 EXPECT_FLOAT_EQ(expected_value, demotion_it->second);
83 } 94 }
84 95
85 // static 96 // static
86 void OmniboxFieldTrialTest::ExpectRuleValue( 97 void OmniboxFieldTrialTest::ExpectRuleValue(
87 const std::string& rule_value, 98 const std::string& rule_value,
88 const std::string& rule, 99 const std::string& rule,
89 OmniboxEventProto::PageClassification page_classification) { 100 OmniboxEventProto::PageClassification page_classification) {
90 EXPECT_EQ(rule_value, 101 EXPECT_EQ(rule_value,
91 OmniboxFieldTrial::GetValueForRuleInContext( 102 OmniboxFieldTrial::GetValueForRuleInContext(
92 rule, page_classification)); 103 rule, page_classification));
93 } 104 }
94 105
106 void OmniboxFieldTrialTest::VerifySuggestPollingStrategy(
107 const char* from_last_keystroke_rule_value,
108 const char* polling_delay_ms_rule_value,
109 bool expected_from_last_keystroke,
110 int expected_delay_ms) {
111 ResetFieldTrialList();
112 std::map<std::string, std::string> params;
113 if (from_last_keystroke_rule_value != NULL) {
114 params[std::string(
115 OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule)] =
116 from_last_keystroke_rule_value;
117 }
118 if (polling_delay_ms_rule_value != NULL) {
119 params[std::string(
120 OmniboxFieldTrial::kSuggestPollingDelayMsRule)] =
121 polling_delay_ms_rule_value;
122 }
123 ASSERT_TRUE(variations::AssociateVariationParams(
124 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
125 base::FieldTrialList::CreateFieldTrial(
126 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
127
128 bool from_last_keystroke;
129 int delay_ms;
130 OmniboxFieldTrial::GetSuggestPollingStrategy(&from_last_keystroke, &delay_ms);
131 EXPECT_EQ(expected_from_last_keystroke, from_last_keystroke);
132 EXPECT_EQ(expected_delay_ms, delay_ms);
133 }
134
95 // Test if GetDisabledProviderTypes() properly parses various field trial 135 // Test if GetDisabledProviderTypes() properly parses various field trial
96 // group names. 136 // group names.
97 TEST_F(OmniboxFieldTrialTest, GetDisabledProviderTypes) { 137 TEST_F(OmniboxFieldTrialTest, GetDisabledProviderTypes) {
98 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes()); 138 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes());
99 139
100 { 140 {
101 SCOPED_TRACE("Invalid groups"); 141 SCOPED_TRACE("Invalid groups");
102 CreateTestTrial("AutocompleteDynamicTrial_0", "DisabledProviders_"); 142 CreateTestTrial("AutocompleteDynamicTrial_0", "DisabledProviders_");
103 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes()); 143 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes());
104 ResetFieldTrialList(); 144 ResetFieldTrialList();
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 411
372 // No decay by default. 412 // No decay by default.
373 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7))); 413 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7)));
374 414
375 buckets.set_half_life_days(7); 415 buckets.set_half_life_days(7);
376 EXPECT_EQ(0.5, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7))); 416 EXPECT_EQ(0.5, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7)));
377 EXPECT_EQ(0.25, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(14))); 417 EXPECT_EQ(0.25, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(14)));
378 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(0))); 418 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(0)));
379 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(-1))); 419 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(-1)));
380 } 420 }
421
422 TEST_F(OmniboxFieldTrialTest, DisableResultsCaching) {
423 EXPECT_FALSE(OmniboxFieldTrial::DisableResultsCaching());
424
425 {
426 std::map<std::string, std::string> params;
427 params[std::string(OmniboxFieldTrial::kDisableResultsCachingRule)] = "true";
428 ASSERT_TRUE(variations::AssociateVariationParams(
429 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
430 base::FieldTrialList::CreateFieldTrial(
431 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
432
433 EXPECT_TRUE(OmniboxFieldTrial::DisableResultsCaching());
434 }
435 }
436
437 TEST_F(OmniboxFieldTrialTest, GetSuggestPollingStrategy) {
438 // Invalid params.
439 VerifySuggestPollingStrategy(
440 "", "", false,
441 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs);
442 VerifySuggestPollingStrategy(
443 "foo", "-1", false,
444 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs);
445 VerifySuggestPollingStrategy(
446 "TRUE", "xyz", false,
447 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs);
448
449 // Default values.
450 VerifySuggestPollingStrategy(
451 NULL, NULL, false,
452 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs);
453
454 // Valid params.
455 VerifySuggestPollingStrategy("true", "50", true, 50);
456 VerifySuggestPollingStrategy(NULL, "35", false, 35);
457 VerifySuggestPollingStrategy(
458 "true", NULL, true,
459 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs);
460 }
OLDNEW
« no previous file with comments | « components/omnibox/omnibox_field_trial.cc ('k') | components/omnibox/search_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698