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" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 CreateTestTrial("AutocompleteDynamicTrial_2", "EnableZeroSuggest_Queries"); | 125 CreateTestTrial("AutocompleteDynamicTrial_2", "EnableZeroSuggest_Queries"); |
126 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); | 126 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); |
127 | 127 |
128 ResetFieldTrialList(); | 128 ResetFieldTrialList(); |
129 CreateTestTrial("AutocompleteDynamicTrial_3", "EnableZeroSuggest_URLs"); | 129 CreateTestTrial("AutocompleteDynamicTrial_3", "EnableZeroSuggest_URLs"); |
130 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); | 130 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) { | 134 TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) { |
135 // Must be the same as kBundledExperimentFieldTrialName | |
136 // defined in omnibox_field_trial.cc. | |
137 const std::string kTrialName = "OmniboxBundledExperimentV1"; | |
138 { | 135 { |
139 std::map<std::string, std::string> params; | 136 std::map<std::string, std::string> params; |
140 // Rule 1 has some exact matches and a global fallback. | 137 // Rule 1 has some exact matches and a global fallback. |
141 params["rule1:1"] = "rule1-1-value"; // NEW_TAB_PAGE | 138 params["rule1:1"] = "rule1-1-value"; // NEW_TAB_PAGE |
142 params["rule1:3"] = "rule1-3-value"; // HOMEPAGE | 139 params["rule1:3"] = "rule1-3-value"; // HOMEPAGE |
143 params["rule1:*"] = "rule1-*-value"; // global | 140 params["rule1:*"] = "rule1-*-value"; // global |
144 // Rule 2 has no exact matches but has a global fallback. | 141 // Rule 2 has no exact matches but has a global fallback. |
145 params["rule2:*"] = "rule2-*-value"; // global | 142 params["rule2:*"] = "rule2-*-value"; // global |
146 // Rule 3 has an exact match but no global fallback. | 143 // Rule 3 has an exact match but no global fallback. |
147 params["rule3:4"] = "rule3-4-value"; // OTHER | 144 params["rule3:4"] = "rule3-4-value"; // OTHER |
148 // Add a malformed rule to make sure it doesn't screw things up. | 145 // Add a malformed rule to make sure it doesn't screw things up. |
149 params["unrecognized"] = "unrecognized-value"; | 146 params["unrecognized"] = "unrecognized-value"; |
150 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 147 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
151 kTrialName, "A", params)); | 148 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
152 } | 149 } |
153 | 150 |
154 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); | 151 base::FieldTrialList::CreateFieldTrial( |
| 152 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
155 | 153 |
156 // Tests for rule 1. | 154 // Tests for rule 1. |
157 EXPECT_EQ( | 155 EXPECT_EQ( |
158 "rule1-1-value", | 156 "rule1-1-value", |
159 OmniboxFieldTrial::GetValueForRuleInContext( | 157 OmniboxFieldTrial::GetValueForRuleInContext( |
160 "rule1", AutocompleteInput::NEW_TAB_PAGE)); // exact match | 158 "rule1", AutocompleteInput::NEW_TAB_PAGE)); // exact match |
161 EXPECT_EQ( | 159 EXPECT_EQ( |
162 "rule1-*-value", | 160 "rule1-*-value", |
163 OmniboxFieldTrial::GetValueForRuleInContext( | 161 OmniboxFieldTrial::GetValueForRuleInContext( |
164 "rule1", AutocompleteInput::BLANK)); // fallback to global | 162 "rule1", AutocompleteInput::BLANK)); // fallback to global |
(...skipping 29 matching lines...) Expand all Loading... |
194 "rule3-4-value", | 192 "rule3-4-value", |
195 OmniboxFieldTrial::GetValueForRuleInContext( | 193 OmniboxFieldTrial::GetValueForRuleInContext( |
196 "rule3", AutocompleteInput::OTHER)); // exact match | 194 "rule3", AutocompleteInput::OTHER)); // exact match |
197 | 195 |
198 // Tests for rule 4 (a missing rule). | 196 // Tests for rule 4 (a missing rule). |
199 EXPECT_EQ( | 197 EXPECT_EQ( |
200 "", | 198 "", |
201 OmniboxFieldTrial::GetValueForRuleInContext( | 199 OmniboxFieldTrial::GetValueForRuleInContext( |
202 "rule4", AutocompleteInput::OTHER)); // no rule at all | 200 "rule4", AutocompleteInput::OTHER)); // no rule at all |
203 } | 201 } |
OLD | NEW |