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

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 unit tests to OmniboxFieldTrialTest. 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
69 // |expected_from_last_keystroke| and |expected_delay_ms| for the given
70 // experiment params.
71 void VerifySuggestPollingStrategy(
72 const std::string& from_last_keystroke_rule_value,
73 const std::string& polling_delay_ms_rule_value,
74 bool expected_from_last_keystroke,
75 int expected_delay_ms);
76
68 private: 77 private:
69 scoped_ptr<base::FieldTrialList> field_trial_list_; 78 scoped_ptr<base::FieldTrialList> field_trial_list_;
70 79
71 DISALLOW_COPY_AND_ASSIGN(OmniboxFieldTrialTest); 80 DISALLOW_COPY_AND_ASSIGN(OmniboxFieldTrialTest);
72 }; 81 };
73 82
74 // static 83 // static
75 void OmniboxFieldTrialTest::VerifyDemotion( 84 void OmniboxFieldTrialTest::VerifyDemotion(
76 const OmniboxFieldTrial::DemotionMultipliers& demotions, 85 const OmniboxFieldTrial::DemotionMultipliers& demotions,
77 AutocompleteMatchType::Type match_type, 86 AutocompleteMatchType::Type match_type,
78 float expected_value) { 87 float expected_value) {
79 OmniboxFieldTrial::DemotionMultipliers::const_iterator demotion_it = 88 OmniboxFieldTrial::DemotionMultipliers::const_iterator demotion_it =
80 demotions.find(match_type); 89 demotions.find(match_type);
81 ASSERT_TRUE(demotion_it != demotions.end()); 90 ASSERT_TRUE(demotion_it != demotions.end());
82 EXPECT_FLOAT_EQ(expected_value, demotion_it->second); 91 EXPECT_FLOAT_EQ(expected_value, demotion_it->second);
83 } 92 }
84 93
85 // static 94 // static
86 void OmniboxFieldTrialTest::ExpectRuleValue( 95 void OmniboxFieldTrialTest::ExpectRuleValue(
87 const std::string& rule_value, 96 const std::string& rule_value,
88 const std::string& rule, 97 const std::string& rule,
89 OmniboxEventProto::PageClassification page_classification) { 98 OmniboxEventProto::PageClassification page_classification) {
90 EXPECT_EQ(rule_value, 99 EXPECT_EQ(rule_value,
91 OmniboxFieldTrial::GetValueForRuleInContext( 100 OmniboxFieldTrial::GetValueForRuleInContext(
92 rule, page_classification)); 101 rule, page_classification));
93 } 102 }
94 103
104 void OmniboxFieldTrialTest::VerifySuggestPollingStrategy(
105 const std::string& from_last_keystroke_rule_value,
106 const std::string& polling_delay_ms_rule_value,
107 bool expected_from_last_keystroke,
Mark P 2014/10/22 23:03:15 this and below might as well be const
Bart N. 2014/10/23 01:42:54 We don't typically put const for params passed by
108 int expected_delay_ms) {
109 ResetFieldTrialList();
110 std::map<std::string, std::string> params;
111 params[std::string(
112 OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule)] =
113 from_last_keystroke_rule_value;
114 params[std::string(
115 OmniboxFieldTrial::kSuggestPollingDelayMsRule)] =
116 polling_delay_ms_rule_value;
117 ASSERT_TRUE(variations::AssociateVariationParams(
118 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
119 base::FieldTrialList::CreateFieldTrial(
120 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
121
122 bool from_last_keystroke;
123 int delay_ms;
124 OmniboxFieldTrial::GetSuggestPollingStrategy(&from_last_keystroke, &delay_ms);
125 EXPECT_EQ(expected_from_last_keystroke, from_last_keystroke);
126 EXPECT_EQ(expected_delay_ms, delay_ms);
127 }
128
95 // Test if GetDisabledProviderTypes() properly parses various field trial 129 // Test if GetDisabledProviderTypes() properly parses various field trial
96 // group names. 130 // group names.
97 TEST_F(OmniboxFieldTrialTest, GetDisabledProviderTypes) { 131 TEST_F(OmniboxFieldTrialTest, GetDisabledProviderTypes) {
98 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes()); 132 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes());
99 133
100 { 134 {
101 SCOPED_TRACE("Invalid groups"); 135 SCOPED_TRACE("Invalid groups");
102 CreateTestTrial("AutocompleteDynamicTrial_0", "DisabledProviders_"); 136 CreateTestTrial("AutocompleteDynamicTrial_0", "DisabledProviders_");
103 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes()); 137 EXPECT_EQ(0, OmniboxFieldTrial::GetDisabledProviderTypes());
104 ResetFieldTrialList(); 138 ResetFieldTrialList();
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 405
372 // No decay by default. 406 // No decay by default.
373 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7))); 407 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7)));
374 408
375 buckets.set_half_life_days(7); 409 buckets.set_half_life_days(7);
376 EXPECT_EQ(0.5, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7))); 410 EXPECT_EQ(0.5, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(7)));
377 EXPECT_EQ(0.25, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(14))); 411 EXPECT_EQ(0.25, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(14)));
378 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(0))); 412 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(0)));
379 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(-1))); 413 EXPECT_EQ(1.0, buckets.HalfLifeTimeDecay(base::TimeDelta::FromDays(-1)));
380 } 414 }
415
416 TEST_F(OmniboxFieldTrialTest, DisableResultsCaching) {
417 EXPECT_FALSE(OmniboxFieldTrial::DisableResultsCaching());
418
419 {
420 std::map<std::string, std::string> params;
421 params[std::string(OmniboxFieldTrial::kDisableResultsCachingRule)] = "true";
422 ASSERT_TRUE(variations::AssociateVariationParams(
423 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
424 base::FieldTrialList::CreateFieldTrial(
425 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
426
427 EXPECT_TRUE(OmniboxFieldTrial::DisableResultsCaching());
428 }
429 }
430
431 TEST_F(OmniboxFieldTrialTest, GetSuggestPollingStrategy) {
Mark P 2014/10/22 23:03:15 The function this test uses VerifySuggestPollingSt
Bart N. 2014/10/23 01:42:53 Done.
432 // Invalid params.
433 VerifySuggestPollingStrategy(
434 "", "", false,
435 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs);
436 VerifySuggestPollingStrategy(
437 "foo", "-1", false,
438 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs);
439 VerifySuggestPollingStrategy(
440 "TRUE", "xyz", false,
441 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs);
442
443 // Valid params.
444 VerifySuggestPollingStrategy("true", "50", true, 50);
445 }
Mark P 2014/10/22 23:03:15 Please add a test for the default values of this p
Bart N. 2014/10/23 01:42:54 Done.
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