OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/variations/variations_associated_data.h" | 5 #include "components/variations/variations_associated_data.h" |
6 | 6 |
7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/test/scoped_feature_list.h" | 10 #include "base/test/scoped_feature_list.h" |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 scoped_refptr<base::FieldTrial> trial( | 396 scoped_refptr<base::FieldTrial> trial( |
397 CreateFieldTrial(kTrialName, 100, "A", NULL)); | 397 CreateFieldTrial(kTrialName, 100, "A", NULL)); |
398 | 398 |
399 CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_DISABLE_FEATURE, | 399 CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_DISABLE_FEATURE, |
400 trial.get()); | 400 trial.get()); |
401 | 401 |
402 std::map<std::string, std::string> actualParams; | 402 std::map<std::string, std::string> actualParams; |
403 EXPECT_EQ(std::string(), GetVariationParamValueByFeature(kFeature, "x")); | 403 EXPECT_EQ(std::string(), GetVariationParamValueByFeature(kFeature, "x")); |
404 } | 404 } |
405 | 405 |
| 406 TEST_F(VariationsAssociatedDataTest, GetVariationParamByFeatureAsInt) { |
| 407 const std::string kTrialName = "GetVariationParamsByFeature"; |
| 408 const base::Feature kFeature{"TestFeature", |
| 409 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 410 |
| 411 std::map<std::string, std::string> params; |
| 412 params["a"] = "1"; |
| 413 params["b"] = "1.5"; |
| 414 params["c"] = "foo"; |
| 415 params["d"] = ""; |
| 416 // "e" is not registered |
| 417 variations::AssociateVariationParams(kTrialName, "A", params); |
| 418 scoped_refptr<base::FieldTrial> trial( |
| 419 CreateFieldTrial(kTrialName, 100, "A", NULL)); |
| 420 |
| 421 CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 422 trial.get()); |
| 423 |
| 424 std::map<std::string, std::string> actualParams; |
| 425 EXPECT_EQ(1, GetVariationParamByFeatureAsInt(kFeature, "a", 0)); |
| 426 EXPECT_EQ(0, GetVariationParamByFeatureAsInt(kFeature, "b", 0)); // invalid |
| 427 EXPECT_EQ(0, GetVariationParamByFeatureAsInt(kFeature, "c", 0)); // invalid |
| 428 EXPECT_EQ(0, GetVariationParamByFeatureAsInt(kFeature, "d", 0)); // empty |
| 429 EXPECT_EQ(0, GetVariationParamByFeatureAsInt(kFeature, "e", 0)); // empty |
| 430 } |
| 431 |
| 432 TEST_F(VariationsAssociatedDataTest, GetVariationParamByFeatureAsDouble) { |
| 433 const std::string kTrialName = "GetVariationParamsByFeature"; |
| 434 const base::Feature kFeature{"TestFeature", |
| 435 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 436 |
| 437 std::map<std::string, std::string> params; |
| 438 params["a"] = "1"; |
| 439 params["b"] = "1.5"; |
| 440 params["c"] = "1.0e-10"; |
| 441 params["d"] = "foo"; |
| 442 params["e"] = ""; |
| 443 // "f" is not registered |
| 444 variations::AssociateVariationParams(kTrialName, "A", params); |
| 445 scoped_refptr<base::FieldTrial> trial( |
| 446 CreateFieldTrial(kTrialName, 100, "A", NULL)); |
| 447 |
| 448 CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 449 trial.get()); |
| 450 |
| 451 std::map<std::string, std::string> actualParams; |
| 452 EXPECT_EQ(1, GetVariationParamByFeatureAsDouble(kFeature, "a", 0)); |
| 453 EXPECT_EQ(1.5, GetVariationParamByFeatureAsDouble(kFeature, "b", 0)); |
| 454 EXPECT_EQ(1.0e-10, GetVariationParamByFeatureAsDouble(kFeature, "c", 0)); |
| 455 EXPECT_EQ(0, |
| 456 GetVariationParamByFeatureAsDouble(kFeature, "d", 0)); // invalid |
| 457 EXPECT_EQ(0, GetVariationParamByFeatureAsDouble(kFeature, "e", 0)); // empty |
| 458 EXPECT_EQ(0, GetVariationParamByFeatureAsDouble(kFeature, "f", 0)); // empty |
| 459 } |
| 460 |
| 461 TEST_F(VariationsAssociatedDataTest, GetVariationParamByFeatureAsBool) { |
| 462 const std::string kTrialName = "GetVariationParamsByFeature"; |
| 463 const base::Feature kFeature{"TestFeature", |
| 464 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 465 |
| 466 std::map<std::string, std::string> params; |
| 467 params["a"] = "true"; |
| 468 params["b"] = "false"; |
| 469 params["c"] = "1"; |
| 470 params["d"] = "False"; |
| 471 params["e"] = ""; |
| 472 // "f" is not registered |
| 473 variations::AssociateVariationParams(kTrialName, "A", params); |
| 474 scoped_refptr<base::FieldTrial> trial( |
| 475 CreateFieldTrial(kTrialName, 100, "A", NULL)); |
| 476 |
| 477 CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 478 trial.get()); |
| 479 |
| 480 std::map<std::string, std::string> actualParams; |
| 481 EXPECT_TRUE(GetVariationParamByFeatureAsBool(kFeature, "a", false)); |
| 482 EXPECT_FALSE(GetVariationParamByFeatureAsBool(kFeature, "b", true)); |
| 483 EXPECT_FALSE( |
| 484 GetVariationParamByFeatureAsBool(kFeature, "c", false)); // invalid |
| 485 EXPECT_TRUE( |
| 486 GetVariationParamByFeatureAsBool(kFeature, "d", true)); // invalid |
| 487 EXPECT_TRUE(GetVariationParamByFeatureAsBool(kFeature, "e", true)); // empty |
| 488 EXPECT_TRUE(GetVariationParamByFeatureAsBool(kFeature, "f", true)); // empty |
| 489 } |
| 490 |
406 } // namespace variations | 491 } // namespace variations |
OLD | NEW |