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

Side by Side Diff: chrome/browser/omnibox/omnibox_field_trial_unittest.cc

Issue 18878007: Omnibox: Make the Controller Reorder Matches for Inlining (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 CreateTestTrial("AutocompleteDynamicTrial_2", "EnableZeroSuggest_Queries"); 152 CreateTestTrial("AutocompleteDynamicTrial_2", "EnableZeroSuggest_Queries");
153 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); 153 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial());
154 154
155 ResetFieldTrialList(); 155 ResetFieldTrialList();
156 CreateTestTrial("AutocompleteDynamicTrial_3", "EnableZeroSuggest_URLs"); 156 CreateTestTrial("AutocompleteDynamicTrial_3", "EnableZeroSuggest_URLs");
157 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); 157 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial());
158 } 158 }
159 } 159 }
160 160
161 TEST_F(OmniboxFieldTrialTest, GetDemotionsByTypeWithFallback) { 161 TEST_F(OmniboxFieldTrialTest, GetDemotionsByTypeWithFallback) {
162 // Must be the same as kBundledExperimentFieldTrialName
163 // defined in omnibox_field_trial.cc.
164 const std::string kTrialName = "OmniboxBundledExperimentV1";
165 // Must be the same as kDemoteByTypeRule defined in
166 // omnibox_field_trial.cc.
167 const std::string kRuleName = "DemoteByType";
168 { 162 {
169 std::map<std::string, std::string> params; 163 std::map<std::string, std::string> params;
170 params[kRuleName + ":1:*"] = "1:50,2:0"; 164 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":1:*"] =
171 params[kRuleName + ":3:*"] = "5:100"; 165 "1:50,2:0";
172 params[kRuleName + ":*:*"] = "1:25"; 166 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] =
167 "5:100";
168 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":*:*"] = "1:25";
173 ASSERT_TRUE(chrome_variations::AssociateVariationParams( 169 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
174 kTrialName, "A", params)); 170 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
175 } 171 }
176 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); 172 base::FieldTrialList::CreateFieldTrial(
173 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
177 OmniboxFieldTrial::DemotionMultipliers demotions_by_type; 174 OmniboxFieldTrial::DemotionMultipliers demotions_by_type;
178 OmniboxFieldTrial::GetDemotionsByType( 175 OmniboxFieldTrial::GetDemotionsByType(
179 AutocompleteInput::NEW_TAB_PAGE, &demotions_by_type); 176 AutocompleteInput::NEW_TAB_PAGE, &demotions_by_type);
180 ASSERT_EQ(2u, demotions_by_type.size()); 177 ASSERT_EQ(2u, demotions_by_type.size());
181 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.5); 178 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.5);
182 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_TITLE, 0.0); 179 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_TITLE, 0.0);
183 OmniboxFieldTrial::GetDemotionsByType( 180 OmniboxFieldTrial::GetDemotionsByType(
184 AutocompleteInput::HOMEPAGE, &demotions_by_type); 181 AutocompleteInput::HOMEPAGE, &demotions_by_type);
185 ASSERT_EQ(1u, demotions_by_type.size()); 182 ASSERT_EQ(1u, demotions_by_type.size());
186 VerifyDemotion(demotions_by_type, AutocompleteMatchType::NAVSUGGEST, 1.0); 183 VerifyDemotion(demotions_by_type, AutocompleteMatchType::NAVSUGGEST, 1.0);
187 OmniboxFieldTrial::GetDemotionsByType( 184 OmniboxFieldTrial::GetDemotionsByType(
188 AutocompleteInput::BLANK, &demotions_by_type); 185 AutocompleteInput::BLANK, &demotions_by_type);
189 ASSERT_EQ(1u, demotions_by_type.size()); 186 ASSERT_EQ(1u, demotions_by_type.size());
190 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.25); 187 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.25);
191 } 188 }
192 189
193 TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) { 190 TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) {
194 // This test starts with Instant Extended off (the default state), then 191 // This test starts with Instant Extended off (the default state), then
195 // enables Instant Extended and tests again on the same rules. 192 // enables Instant Extended and tests again on the same rules.
196 193
197 // Must be the same as kBundledExperimentFieldTrialName
198 // defined in omnibox_field_trial.cc.
199 const std::string kTrialName = "OmniboxBundledExperimentV1";
200 { 194 {
201 std::map<std::string, std::string> params; 195 std::map<std::string, std::string> params;
202 // Rule 1 has some exact matches and fallbacks at every level. 196 // Rule 1 has some exact matches and fallbacks at every level.
203 params["rule1:1:0"] = "rule1-1-0-value"; // NEW_TAB_PAGE 197 params["rule1:1:0"] = "rule1-1-0-value"; // NEW_TAB_PAGE
204 params["rule1:3:0"] = "rule1-3-0-value"; // HOMEPAGE 198 params["rule1:3:0"] = "rule1-3-0-value"; // HOMEPAGE
205 params["rule1:4:1"] = "rule1-4-1-value"; // OTHER 199 params["rule1:4:1"] = "rule1-4-1-value"; // OTHER
206 params["rule1:4:*"] = "rule1-4-*-value"; // OTHER 200 params["rule1:4:*"] = "rule1-4-*-value"; // OTHER
207 params["rule1:*:1"] = "rule1-*-1-value"; // global 201 params["rule1:*:1"] = "rule1-*-1-value"; // global
208 params["rule1:*:*"] = "rule1-*-*-value"; // global 202 params["rule1:*:*"] = "rule1-*-*-value"; // global
209 // Rule 2 has no exact matches but has fallbacks. 203 // Rule 2 has no exact matches but has fallbacks.
210 params["rule2:*:0"] = "rule2-*-0-value"; // global 204 params["rule2:*:0"] = "rule2-*-0-value"; // global
211 params["rule2:1:*"] = "rule2-1-*-value"; // NEW_TAB_PAGE 205 params["rule2:1:*"] = "rule2-1-*-value"; // NEW_TAB_PAGE
212 params["rule2:*:*"] = "rule2-*-*-value"; // global 206 params["rule2:*:*"] = "rule2-*-*-value"; // global
213 // Rule 3 has only a global fallback. 207 // Rule 3 has only a global fallback.
214 params["rule3:*:*"] = "rule3-*-*-value"; // global 208 params["rule3:*:*"] = "rule3-*-*-value"; // global
215 // Rule 4 has an exact match but no fallbacks. 209 // Rule 4 has an exact match but no fallbacks.
216 params["rule4:4:0"] = "rule4-4-0-value"; // OTHER 210 params["rule4:4:0"] = "rule4-4-0-value"; // OTHER
217 // Add a malformed rule to make sure it doesn't screw things up. 211 // Add a malformed rule to make sure it doesn't screw things up.
218 params["unrecognized"] = "unrecognized-value"; 212 params["unrecognized"] = "unrecognized-value";
219 ASSERT_TRUE(chrome_variations::AssociateVariationParams( 213 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
220 kTrialName, "A", params)); 214 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
221 } 215 }
222 216
223 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); 217 base::FieldTrialList::CreateFieldTrial(
218 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
224 219
225 // Tests with Instant Extended disabled. 220 // Tests with Instant Extended disabled.
226 // Tests for rule 1. 221 // Tests for rule 1.
227 ExpectRuleValue("rule1-1-0-value", 222 ExpectRuleValue("rule1-1-0-value",
228 "rule1", AutocompleteInput::NEW_TAB_PAGE); // exact match 223 "rule1", AutocompleteInput::NEW_TAB_PAGE); // exact match
229 ExpectRuleValue("rule1-1-0-value", 224 ExpectRuleValue("rule1-1-0-value",
230 "rule1", AutocompleteInput::NEW_TAB_PAGE); // exact match 225 "rule1", AutocompleteInput::NEW_TAB_PAGE); // exact match
231 ExpectRuleValue("rule1-*-*-value", 226 ExpectRuleValue("rule1-*-*-value",
232 "rule1", AutocompleteInput::BLANK); // fallback to global 227 "rule1", AutocompleteInput::BLANK); // fallback to global
233 ExpectRuleValue("rule1-3-0-value", 228 ExpectRuleValue("rule1-3-0-value",
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 ExpectRuleValue("", 291 ExpectRuleValue("",
297 "rule4", AutocompleteInput::BLANK); // no global fallback 292 "rule4", AutocompleteInput::BLANK); // no global fallback
298 ExpectRuleValue("", 293 ExpectRuleValue("",
299 "rule4", AutocompleteInput::HOMEPAGE); // no global fallback 294 "rule4", AutocompleteInput::HOMEPAGE); // no global fallback
300 295
301 // Tests for rule 5 (a missing rule). 296 // Tests for rule 5 (a missing rule).
302 ExpectRuleValue("", 297 ExpectRuleValue("",
303 "rule5", AutocompleteInput::OTHER); // no rule at all 298 "rule5", AutocompleteInput::OTHER); // no rule at all
304 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) 299 #endif // !defined(OS_IOS) && !defined(OS_ANDROID)
305 } 300 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698