Chromium Code Reviews| 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/command_line.h" | |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "chrome/browser/search/search.h" | |
| 13 #include "chrome/common/chrome_switches.h" | |
| 11 #include "chrome/common/metrics/entropy_provider.h" | 14 #include "chrome/common/metrics/entropy_provider.h" |
| 12 #include "chrome/common/metrics/variations/variations_util.h" | 15 #include "chrome/common/metrics/variations/variations_util.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 17 |
| 15 class OmniboxFieldTrialTest : public testing::Test { | 18 class OmniboxFieldTrialTest : public testing::Test { |
| 16 public: | 19 public: |
| 17 OmniboxFieldTrialTest() { | 20 OmniboxFieldTrialTest() { |
| 18 ResetFieldTrialList(); | 21 ResetFieldTrialList(); |
| 19 } | 22 } |
| 20 | 23 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 | 143 |
| 141 TEST_F(OmniboxFieldTrialTest, GetDemotionsByTypeWithFallback) { | 144 TEST_F(OmniboxFieldTrialTest, GetDemotionsByTypeWithFallback) { |
| 142 // Must be the same as kBundledExperimentFieldTrialName | 145 // Must be the same as kBundledExperimentFieldTrialName |
| 143 // defined in omnibox_field_trial.cc. | 146 // defined in omnibox_field_trial.cc. |
| 144 const std::string kTrialName = "OmniboxBundledExperimentV1"; | 147 const std::string kTrialName = "OmniboxBundledExperimentV1"; |
| 145 // Must be the same as kDemoteByTypeRule defined in | 148 // Must be the same as kDemoteByTypeRule defined in |
| 146 // omnibox_field_trial.cc. | 149 // omnibox_field_trial.cc. |
| 147 const std::string kRuleName = "DemoteByType"; | 150 const std::string kRuleName = "DemoteByType"; |
| 148 { | 151 { |
| 149 std::map<std::string, std::string> params; | 152 std::map<std::string, std::string> params; |
| 150 params[kRuleName + ":1"] = "1:50,2:0"; | 153 params[kRuleName + ":1:*"] = "1:50,2:0"; |
| 151 params[kRuleName + ":3"] = "5:100"; | 154 params[kRuleName + ":3:*"] = "5:100"; |
| 152 params[kRuleName + ":*"] = "1:25"; | 155 params[kRuleName + ":*:*"] = "1:25"; |
| 153 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 156 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 154 kTrialName, "A", params)); | 157 kTrialName, "A", params)); |
| 155 } | 158 } |
| 156 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); | 159 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); |
| 157 OmniboxFieldTrial::DemotionMultipliers demotions_by_type; | 160 OmniboxFieldTrial::DemotionMultipliers demotions_by_type; |
| 158 OmniboxFieldTrial::GetDemotionsByType( | 161 OmniboxFieldTrial::GetDemotionsByType( |
| 159 AutocompleteInput::NEW_TAB_PAGE, &demotions_by_type); | 162 AutocompleteInput::NEW_TAB_PAGE, &demotions_by_type); |
| 160 ASSERT_EQ(2u, demotions_by_type.size()); | 163 ASSERT_EQ(2u, demotions_by_type.size()); |
| 161 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.5); | 164 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.5); |
| 162 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_TITLE, 0.0); | 165 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_TITLE, 0.0); |
| 163 OmniboxFieldTrial::GetDemotionsByType( | 166 OmniboxFieldTrial::GetDemotionsByType( |
| 164 AutocompleteInput::HOMEPAGE, &demotions_by_type); | 167 AutocompleteInput::HOMEPAGE, &demotions_by_type); |
| 165 ASSERT_EQ(1u, demotions_by_type.size()); | 168 ASSERT_EQ(1u, demotions_by_type.size()); |
| 166 VerifyDemotion(demotions_by_type, AutocompleteMatchType::NAVSUGGEST, 1.0); | 169 VerifyDemotion(demotions_by_type, AutocompleteMatchType::NAVSUGGEST, 1.0); |
| 167 OmniboxFieldTrial::GetDemotionsByType( | 170 OmniboxFieldTrial::GetDemotionsByType( |
| 168 AutocompleteInput::BLANK, &demotions_by_type); | 171 AutocompleteInput::BLANK, &demotions_by_type); |
| 169 ASSERT_EQ(1u, demotions_by_type.size()); | 172 ASSERT_EQ(1u, demotions_by_type.size()); |
| 170 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.25); | 173 VerifyDemotion(demotions_by_type, AutocompleteMatchType::HISTORY_URL, 0.25); |
| 171 } | 174 } |
| 172 | 175 |
| 173 TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) { | 176 TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) { |
| 177 // This test starts with Instant Extended off (the default state), then | |
| 178 // enables Instant Extended and tests again on the same rules. | |
| 179 | |
| 174 // Must be the same as kBundledExperimentFieldTrialName | 180 // Must be the same as kBundledExperimentFieldTrialName |
| 175 // defined in omnibox_field_trial.cc. | 181 // defined in omnibox_field_trial.cc. |
| 176 const std::string kTrialName = "OmniboxBundledExperimentV1"; | 182 const std::string kTrialName = "OmniboxBundledExperimentV1"; |
| 177 { | 183 { |
| 178 std::map<std::string, std::string> params; | 184 std::map<std::string, std::string> params; |
| 179 // Rule 1 has some exact matches and a global fallback. | 185 // Rule 1 has some exact matches and fallbacks at every level. |
| 180 params["rule1:1"] = "rule1-1-value"; // NEW_TAB_PAGE | 186 params["rule1:1:0"] = "rule1-1-0-value"; // NEW_TAB_PAGE |
| 181 params["rule1:3"] = "rule1-3-value"; // HOMEPAGE | 187 params["rule1:3:0"] = "rule1-3-0-value"; // HOMEPAGE |
| 182 params["rule1:*"] = "rule1-*-value"; // global | 188 params["rule1:4:1"] = "rule1-4-1-value"; // OTHER |
| 183 // Rule 2 has no exact matches but has a global fallback. | 189 params["rule1:4:*"] = "rule1-4-*-value"; // OTHER |
| 184 params["rule2:*"] = "rule2-*-value"; // global | 190 params["rule1:*:1"] = "rule1-*-1-value"; // global |
| 185 // Rule 3 has an exact match but no global fallback. | 191 params["rule1:*:*"] = "rule1-*-*-value"; // global |
| 186 params["rule3:4"] = "rule3-4-value"; // OTHER | 192 // Rule 2 has no exact matches but has fallbacks. |
| 193 params["rule2:*:0"] = "rule2-*-0-value"; // global | |
| 194 params["rule2:1:*"] = "rule2-1-*-value"; // NEW_TAB_PAGE | |
| 195 params["rule2:*:*"] = "rule2-*-*-value"; // global | |
| 196 // Rule 3 has only a global fallback. | |
| 197 params["rule3:*:*"] = "rule3-*-*-value"; // global | |
| 198 // Rule 4 has an exact match but no fallbacks. | |
| 199 params["rule4:4:0"] = "rule4-4-0-value"; // OTHER | |
| 187 // Add a malformed rule to make sure it doesn't screw things up. | 200 // Add a malformed rule to make sure it doesn't screw things up. |
| 188 params["unrecognized"] = "unrecognized-value"; | 201 params["unrecognized"] = "unrecognized-value"; |
| 189 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 202 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 190 kTrialName, "A", params)); | 203 kTrialName, "A", params)); |
| 191 } | 204 } |
| 192 | 205 |
| 193 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); | 206 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); |
| 194 | 207 |
| 208 // Tests for Instant Extended is off. | |
|
Peter Kasting
2013/08/09 20:45:45
Nit: "Tests with Instant Extended disabled."?
Mark P
2013/08/09 21:55:01
Done.
| |
| 195 // Tests for rule 1. | 209 // Tests for rule 1. |
| 196 EXPECT_EQ( | 210 EXPECT_EQ( |
| 197 "rule1-1-value", | 211 "rule1-1-0-value", |
| 198 OmniboxFieldTrial::GetValueForRuleInContext( | 212 OmniboxFieldTrial::GetValueForRuleInContext( |
|
Peter Kasting
2013/08/09 20:45:45
Nit: It might be possible to condense this test ca
Mark P
2013/08/09 21:55:01
I wasn't sure either, but I went and tried it and
| |
| 199 "rule1", AutocompleteInput::NEW_TAB_PAGE)); // exact match | 213 "rule1", AutocompleteInput::NEW_TAB_PAGE)); // exact match |
|
Peter Kasting
2013/08/09 20:45:45
Nit: In principle, it would be nice if all these E
Mark P
2013/08/09 21:55:01
Done.
| |
| 200 EXPECT_EQ( | 214 EXPECT_EQ( |
| 201 "rule1-*-value", | 215 "rule1-*-*-value", |
| 202 OmniboxFieldTrial::GetValueForRuleInContext( | 216 OmniboxFieldTrial::GetValueForRuleInContext( |
| 203 "rule1", AutocompleteInput::BLANK)); // fallback to global | 217 "rule1", AutocompleteInput::BLANK)); // fallback to global |
| 204 EXPECT_EQ( | 218 EXPECT_EQ( |
| 205 "rule1-3-value", | 219 "rule1-3-0-value", |
| 206 OmniboxFieldTrial::GetValueForRuleInContext( | 220 OmniboxFieldTrial::GetValueForRuleInContext( |
| 207 "rule1", AutocompleteInput::HOMEPAGE)); // exact match | 221 "rule1", AutocompleteInput::HOMEPAGE)); // exact match |
| 208 EXPECT_EQ( | 222 EXPECT_EQ( |
| 209 "rule1-*-value", | 223 "rule1-4-*-value", |
| 210 OmniboxFieldTrial::GetValueForRuleInContext( | 224 OmniboxFieldTrial::GetValueForRuleInContext( |
| 211 "rule1", AutocompleteInput::OTHER)); // fallback to global | 225 "rule1", AutocompleteInput::OTHER)); // partial fallback |
| 226 EXPECT_EQ( | |
| 227 "rule1-*-*-value", | |
| 228 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 229 "rule1", // fallback to global | |
| 230 AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT)); | |
| 212 | 231 |
| 213 // Tests for rule 2. | 232 // Tests for rule 2. |
| 214 EXPECT_EQ( | 233 EXPECT_EQ( |
| 215 "rule2-*-value", | 234 "rule2-*-0-value", |
| 216 OmniboxFieldTrial::GetValueForRuleInContext( | 235 OmniboxFieldTrial::GetValueForRuleInContext( |
| 217 "rule2", AutocompleteInput::HOMEPAGE)); // fallback to global | 236 "rule2", AutocompleteInput::HOMEPAGE)); // partial fallback |
| 218 EXPECT_EQ( | 237 EXPECT_EQ( |
| 219 "rule2-*-value", | 238 "rule2-*-0-value", |
| 220 OmniboxFieldTrial::GetValueForRuleInContext( | 239 OmniboxFieldTrial::GetValueForRuleInContext( |
| 221 "rule2", AutocompleteInput::OTHER)); // fallback to global | 240 "rule2", AutocompleteInput::OTHER)); // partial fallback |
| 222 | 241 |
| 223 // Tests for rule 3. | 242 // Tests for rule 3. |
| 224 EXPECT_EQ( | 243 EXPECT_EQ( |
| 225 "", | 244 "rule3-*-*-value", |
| 226 OmniboxFieldTrial::GetValueForRuleInContext( | 245 OmniboxFieldTrial::GetValueForRuleInContext( |
| 227 "rule3", AutocompleteInput::BLANK)); // no global fallback | 246 "rule3", AutocompleteInput::HOMEPAGE)); // fallback to global |
| 247 EXPECT_EQ( | |
| 248 "rule3-*-*-value", | |
| 249 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 250 "rule3", AutocompleteInput::OTHER)); // fallback to global | |
| 251 | |
| 252 // Tests for rule 4. | |
| 228 EXPECT_EQ( | 253 EXPECT_EQ( |
| 229 "", | 254 "", |
| 230 OmniboxFieldTrial::GetValueForRuleInContext( | 255 OmniboxFieldTrial::GetValueForRuleInContext( |
| 231 "rule3", AutocompleteInput::HOMEPAGE)); // no global fallback | 256 "rule4", AutocompleteInput::BLANK)); // no global fallback |
| 232 EXPECT_EQ( | |
| 233 "rule3-4-value", | |
| 234 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 235 "rule3", AutocompleteInput::OTHER)); // exact match | |
| 236 | |
| 237 // Tests for rule 4 (a missing rule). | |
| 238 EXPECT_EQ( | 257 EXPECT_EQ( |
| 239 "", | 258 "", |
| 240 OmniboxFieldTrial::GetValueForRuleInContext( | 259 OmniboxFieldTrial::GetValueForRuleInContext( |
| 241 "rule4", AutocompleteInput::OTHER)); // no rule at all | 260 "rule4", AutocompleteInput::HOMEPAGE)); // no global fallback |
| 261 EXPECT_EQ( | |
| 262 "rule4-4-0-value", | |
| 263 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 264 "rule4", AutocompleteInput::OTHER)); // exact match | |
| 265 | |
| 266 // Tests for rule 5 (a missing rule). | |
| 267 EXPECT_EQ( | |
| 268 "", | |
| 269 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 270 "rule5", AutocompleteInput::OTHER)); // no rule at all | |
| 271 | |
| 272 // Now change the Instant Extended state and run analogous tests. | |
| 273 chrome::ResetInstantExtendedOptInStateGateForTest(); | |
| 274 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 275 switches::kEnableInstantExtendedAPI); | |
| 276 | |
| 277 // Tests for rule 1. | |
| 278 EXPECT_EQ( | |
| 279 "rule1-4-1-value", | |
| 280 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 281 "rule1", AutocompleteInput::OTHER)); // exact match | |
| 282 EXPECT_EQ( | |
| 283 "rule1-*-1-value", | |
| 284 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 285 "rule1", AutocompleteInput::BLANK)); // partial fallback | |
| 286 EXPECT_EQ( | |
| 287 "rule1-*-1-value", | |
| 288 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 289 "rule1", AutocompleteInput::NEW_TAB_PAGE)); // partial fallback | |
| 290 | |
| 291 // Tests for rule 2. | |
| 292 EXPECT_EQ( | |
| 293 "rule2-1-*-value", | |
| 294 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 295 "rule2", AutocompleteInput::NEW_TAB_PAGE)); // partial fallback | |
| 296 EXPECT_EQ( | |
| 297 "rule2-*-*-value", | |
| 298 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 299 "rule2", AutocompleteInput::OTHER)); // global fallback | |
| 300 | |
| 301 // Tests for rule 3. | |
| 302 EXPECT_EQ( | |
| 303 "rule3-*-*-value", | |
| 304 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 305 "rule3", AutocompleteInput::HOMEPAGE)); // global fallback | |
| 306 EXPECT_EQ( | |
| 307 "rule3-*-*-value", | |
| 308 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 309 "rule3", AutocompleteInput::OTHER)); // global fallback | |
| 310 | |
| 311 // Tests for rule 4. | |
| 312 EXPECT_EQ( | |
| 313 "", | |
| 314 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 315 "rule4", AutocompleteInput::BLANK)); // no global fallback | |
| 316 EXPECT_EQ( | |
| 317 "", | |
| 318 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 319 "rule4", AutocompleteInput::HOMEPAGE)); // no global fallback | |
| 320 | |
| 321 // Tests for rule 5 (a missing rule). | |
| 322 EXPECT_EQ( | |
| 323 "", | |
| 324 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 325 "rule5", AutocompleteInput::OTHER)); // no rule at all | |
| 242 } | 326 } |
| OLD | NEW |