| Index: components/password_manager/core/browser/affiliation_utils_unittest.cc
|
| diff --git a/components/password_manager/core/browser/affiliation_utils_unittest.cc b/components/password_manager/core/browser/affiliation_utils_unittest.cc
|
| index f8f32ec4f667c5fdb0974bbf5520962b7ea58cdd..eb2dbe8815deb2829275e0c7d3b86c0da48b46e8 100644
|
| --- a/components/password_manager/core/browser/affiliation_utils_unittest.cc
|
| +++ b/components/password_manager/core/browser/affiliation_utils_unittest.cc
|
| @@ -4,11 +4,14 @@
|
|
|
| #include "components/password_manager/core/browser/affiliation_utils.h"
|
|
|
| -#include "base/command_line.h"
|
| +#include <vector>
|
| +
|
| #include "base/metrics/field_trial.h"
|
| +#include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "components/autofill/core/common/password_form.h"
|
| -#include "components/password_manager/core/common/password_manager_switches.h"
|
| +#include "components/password_manager/core/browser/password_manager_test_utils.h"
|
| +#include "components/password_manager/core/common/password_manager_features.h"
|
| #include "components/variations/variations_associated_data.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/url_constants.h"
|
| @@ -21,6 +24,9 @@ const std::string kSchemeHostExample = "http://example.com";
|
| const char kTestFacetURI1[] = "https://alpha.example.com/";
|
| const char kTestFacetURI2[] = "https://beta.example.com/";
|
| const char kTestFacetURI3[] = "https://gamma.example.com/";
|
| +
|
| +const base::Feature kDummyFeature = {"FooBar",
|
| + base::FEATURE_DISABLED_BY_DEFAULT};
|
| } // namespace
|
|
|
| TEST(AffiliationUtilsTest, ValidWebFacetURIs) {
|
| @@ -203,83 +209,121 @@ TEST(AffiliationUtilsTest, NotEqualEquivalenceClasses) {
|
| TEST(AffiliationUtilsTest, IsAffiliationBasedMatchingEnabled) {
|
| struct {
|
| const char* field_trial_group;
|
| - const char* command_line_switch;
|
| + const base::Feature command_line_feature;
|
| + bool set_enabled;
|
| bool expected_enabled;
|
| } kTestCases[] = {
|
| - {"", "", true},
|
| - {"", switches::kEnableAffiliationBasedMatching, true},
|
| - {"", switches::kDisableAffiliationBasedMatching, false},
|
| - {"garbage value", "", true},
|
| - {"disabled", "", false},
|
| - {"disabled2", "", false},
|
| - {"Disabled", "", false},
|
| - {"Disabled", switches::kDisableAffiliationBasedMatching, false},
|
| - {"Disabled", switches::kEnableAffiliationBasedMatching, true},
|
| - {"enabled", "", true},
|
| - {"enabled2", "", true},
|
| - {"Enabled", "", true},
|
| - {"Enabled", switches::kDisableAffiliationBasedMatching, false},
|
| - {"Enabled", switches::kEnableAffiliationBasedMatching, true}};
|
| + {"", kDummyFeature, true, true},
|
| + {"", features::kAffiliationBasedMatching, true, true},
|
| + {"", features::kAffiliationBasedMatching, false, false},
|
| + {"garbage value", kDummyFeature, true, true},
|
| + {"disabled", kDummyFeature, true, false},
|
| + {"disabled2", kDummyFeature, true, false},
|
| + {"Disabled", kDummyFeature, true, false},
|
| + {"Disabled", features::kAffiliationBasedMatching, false, false},
|
| + {"Disabled", features::kAffiliationBasedMatching, true, false},
|
| + {"enabled", kDummyFeature, true, true},
|
| + {"enabled2", kDummyFeature, true, true},
|
| + {"Enabled", kDummyFeature, true, true},
|
| + {"Enabled", features::kAffiliationBasedMatching, false, false},
|
| + {"Enabled", features::kAffiliationBasedMatching, true, true}};
|
|
|
| for (const auto& test_case : kTestCases) {
|
| SCOPED_TRACE(testing::Message("Command line = ")
|
| - << test_case.command_line_switch);
|
| + << test_case.command_line_feature.name);
|
| + SCOPED_TRACE(testing::Message("Set enabled = ") << test_case.set_enabled);
|
| SCOPED_TRACE(testing::Message("Group name = ")
|
| << test_case.field_trial_group);
|
|
|
| base::FieldTrialList field_trials(nullptr);
|
| - base::FieldTrialList::CreateFieldTrial(kFieldTrialName,
|
| - test_case.field_trial_group);
|
| + scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
|
| + base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial(
|
| + kFieldTrialName, test_case.field_trial_group);
|
| +
|
| + // Set the command-line feature.
|
| + std::vector<const base::Feature*> enable_features;
|
| + std::vector<const base::Feature*> disable_features;
|
| + if (test_case.set_enabled) {
|
| + enable_features.push_back(&test_case.command_line_feature);
|
| + } else {
|
| + disable_features.push_back(&test_case.command_line_feature);
|
| + }
|
| +
|
| + if (base::StartsWith(test_case.field_trial_group, "disabled",
|
| + base::CompareCase::INSENSITIVE_ASCII)) {
|
| + feature_list->RegisterFieldTrialOverride(
|
| + test_case.command_line_feature.name,
|
| + base::FeatureList::OVERRIDE_DISABLE_FEATURE, field_trial);
|
| + }
|
|
|
| - base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
|
| - command_line.AppendSwitch(test_case.command_line_switch);
|
| + SetFeatures(enable_features, disable_features, std::move(feature_list));
|
| EXPECT_EQ(test_case.expected_enabled,
|
| - IsAffiliationBasedMatchingEnabled(command_line));
|
| + base::FeatureList::IsEnabled(test_case.command_line_feature));
|
| }
|
| }
|
|
|
| TEST(AffiliationUtilsTest,
|
| IsPropagatingPasswordChangesToWebCredentialsEnabled) {
|
| const char kExperimentName[] = "DoesNotMatter";
|
| + const char kVariationParam[] = "propagate_password_changes_to_web";
|
|
|
| struct {
|
| const char* variation_param;
|
| - const char* command_line_switch;
|
| + const base::Feature command_line_feature;
|
| + bool set_enabled;
|
| bool expected_enabled;
|
| } kTestCases[] = {
|
| - {"", "", true},
|
| - {"", switches::kEnableAffiliationBasedMatching, true},
|
| - {"", switches::kDisableAffiliationBasedMatching, false},
|
| - {"garbage value", "", true},
|
| - {"disabled", "", false},
|
| - {"Disabled", "", false},
|
| - {"Disabled", switches::kDisableAffiliationBasedMatching, false},
|
| - {"Disabled", switches::kEnableAffiliationBasedMatching, true},
|
| - {"enabled", "", true},
|
| - {"Enabled", "", true},
|
| - {"Enabled", switches::kDisableAffiliationBasedMatching, false},
|
| - {"Enabled", switches::kEnableAffiliationBasedMatching, true}};
|
| + {"", kDummyFeature, true, true},
|
| + {"", features::kAffiliationBasedMatching, true, true},
|
| + {"", features::kAffiliationBasedMatching, false, false},
|
| + {"garbage value", kDummyFeature, true, true},
|
| + {"disabled", kDummyFeature, true, false},
|
| + {"Disabled", kDummyFeature, true, false},
|
| + {"Disabled", features::kAffiliationBasedMatching, false, false},
|
| + {"Disabled", features::kAffiliationBasedMatching, true, false},
|
| + {"enabled", kDummyFeature, true, true},
|
| + {"Enabled", kDummyFeature, true, true},
|
| + {"Enabled", features::kAffiliationBasedMatching, false, false},
|
| + {"Enabled", features::kAffiliationBasedMatching, true, true}};
|
|
|
| for (const auto& test_case : kTestCases) {
|
| SCOPED_TRACE(testing::Message("Command line = ")
|
| - << test_case.command_line_switch);
|
| + << test_case.command_line_feature.name);
|
| + SCOPED_TRACE(testing::Message("Set enabled = ") << test_case.set_enabled);
|
| SCOPED_TRACE(testing::Message("Variation param = ")
|
| << test_case.variation_param);
|
|
|
| variations::testing::ClearAllVariationParams();
|
| base::FieldTrialList field_trials(nullptr);
|
| - base::FieldTrialList::CreateFieldTrial(kFieldTrialName, kExperimentName);
|
| + scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
|
| + base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial(
|
| + kFieldTrialName, kExperimentName);
|
| std::map<std::string, std::string> variation_params;
|
| - variation_params["propagate_password_changes_to_web"] =
|
| - test_case.variation_param;
|
| + variation_params[kVariationParam] = test_case.variation_param;
|
| ASSERT_TRUE(variations::AssociateVariationParams(
|
| kFieldTrialName, kExperimentName, variation_params));
|
|
|
| - base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
|
| - command_line.AppendSwitch(test_case.command_line_switch);
|
| - EXPECT_EQ(
|
| - test_case.expected_enabled,
|
| - IsPropagatingPasswordChangesToWebCredentialsEnabled(command_line));
|
| + // Set the command-line feature.
|
| + std::vector<const base::Feature*> enable_features;
|
| + std::vector<const base::Feature*> disable_features;
|
| + if (test_case.set_enabled) {
|
| + enable_features.push_back(&test_case.command_line_feature);
|
| + } else {
|
| + disable_features.push_back(&test_case.command_line_feature);
|
| + }
|
| +
|
| + const std::string update_enabled =
|
| + variations::GetVariationParamValue(kFieldTrialName, kVariationParam);
|
| + if (base::StartsWith(update_enabled, "disabled",
|
| + base::CompareCase::INSENSITIVE_ASCII)) {
|
| + feature_list->RegisterFieldTrialOverride(
|
| + test_case.command_line_feature.name,
|
| + base::FeatureList::OVERRIDE_DISABLE_FEATURE, field_trial);
|
| + }
|
| +
|
| + SetFeatures(enable_features, disable_features, std::move(feature_list));
|
| + EXPECT_EQ(test_case.expected_enabled,
|
| + base::FeatureList::IsEnabled(test_case.command_line_feature));
|
| }
|
| }
|
|
|
|
|