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/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "chrome/common/metrics/entropy_provider.h" | 10 #include "chrome/common/metrics/entropy_provider.h" |
11 #include "chrome/common/metrics/variations/variations_util.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 class OmniboxFieldTrialTest : public testing::Test { | 14 class OmniboxFieldTrialTest : public testing::Test { |
14 public: | 15 public: |
15 OmniboxFieldTrialTest() {} | 16 OmniboxFieldTrialTest() {} |
16 | 17 |
17 static void SetUpTestCase() { | 18 static void SetUpTestCase() { |
18 ResetFieldTrialList(); | 19 ResetFieldTrialList(); |
19 } | 20 } |
20 | 21 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 123 |
123 ResetFieldTrialList(); | 124 ResetFieldTrialList(); |
124 CreateTestTrial("AutocompleteDynamicTrial_2", "EnableZeroSuggest_Queries"); | 125 CreateTestTrial("AutocompleteDynamicTrial_2", "EnableZeroSuggest_Queries"); |
125 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); | 126 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); |
126 | 127 |
127 ResetFieldTrialList(); | 128 ResetFieldTrialList(); |
128 CreateTestTrial("AutocompleteDynamicTrial_3", "EnableZeroSuggest_URLs"); | 129 CreateTestTrial("AutocompleteDynamicTrial_3", "EnableZeroSuggest_URLs"); |
129 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); | 130 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); |
130 } | 131 } |
131 } | 132 } |
133 | |
134 TEST_F(OmniboxFieldTrialTest, GetValueOfRuleInPageClassificationContext) { | |
135 // Must be the same as kBundledExperimentFieldTrialName | |
136 // defined in omnibox_field_trial.cc. | |
137 const std::string kTrialName = "OmniboxBundledExperimentV1"; | |
138 { | |
139 std::map<std::string, std::string> params; | |
140 params["rule1:1"] = "rule1-1-value"; | |
Peter Kasting
2013/08/01 22:44:48
Nit: Might want EOL comments like "// NEW_TAB_PAGE
Mark P
2013/08/02 00:44:36
Done.
| |
141 params["rule1:3"] = "rule1-3-value"; | |
142 params["rule1:*"] = "rule1-*-value"; | |
143 params["rule2:*"] = "rule2-*-value"; | |
144 params["rule3:4"] = "rule3-4-value"; | |
145 params["unrecognized"] = "unrecognized-value"; | |
146 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | |
147 kTrialName, "A", params)); | |
148 } | |
149 | |
150 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); | |
151 EXPECT_EQ("rule1-1-value", | |
Peter Kasting
2013/08/01 22:44:48
Tiny nit: All lines of args at the same nesting le
Mark P
2013/08/02 00:44:36
Done.
| |
152 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
153 "rule1", AutocompleteInput::NEW_TAB_PAGE)); // exact match | |
Peter Kasting
2013/08/01 22:44:48
Nit: Rather than these EOL comments, how about blo
Mark P
2013/08/02 00:44:36
I think this test is more easily understood by loo
Peter Kasting
2013/08/02 00:49:33
OK, then break the test into blocks that have to d
Mark P
2013/08/02 19:50:44
Done.
| |
154 EXPECT_EQ("rule1-*-value", | |
155 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
156 "rule1", AutocompleteInput::BLANK)); // fallback to global | |
157 EXPECT_EQ("rule1-3-value", | |
158 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
159 "rule1", AutocompleteInput::HOMEPAGE)); // exact match | |
160 EXPECT_EQ("rule1-*-value", | |
161 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
162 "rule1", AutocompleteInput::OTHER)); // fallback to global | |
163 EXPECT_EQ("rule2-*-value", | |
164 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
165 "rule2", AutocompleteInput::HOMEPAGE)); // fallback to global | |
166 EXPECT_EQ("rule2-*-value", | |
167 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
168 "rule2", AutocompleteInput::OTHER)); // fallback to global | |
169 EXPECT_EQ("", | |
170 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
171 "rule3", AutocompleteInput::BLANK)); // no global | |
172 EXPECT_EQ("", | |
173 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
174 "rule3", AutocompleteInput::HOMEPAGE)); // no global | |
175 EXPECT_EQ("rule3-4-value", | |
176 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
177 "rule3", AutocompleteInput::OTHER)); // exact match | |
178 EXPECT_EQ("", | |
179 OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext( | |
180 "rule4", AutocompleteInput::OTHER)); // no rule at all | |
181 } | |
OLD | NEW |