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..f9a77d6f600e943d82531c0f5530e5811472cdd8 100644 |
--- a/components/password_manager/core/browser/affiliation_utils_unittest.cc |
+++ b/components/password_manager/core/browser/affiliation_utils_unittest.cc |
@@ -4,11 +4,11 @@ |
#include "components/password_manager/core/browser/affiliation_utils.h" |
-#include "base/command_line.h" |
#include "base/metrics/field_trial.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 +21,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,38 +206,39 @@ TEST(AffiliationUtilsTest, NotEqualEquivalenceClasses) { |
TEST(AffiliationUtilsTest, IsAffiliationBasedMatchingEnabled) { |
Bernhard Bauer
2016/02/11 11:12:40
TBH, I think these tests now need much fewer test
|
struct { |
const char* field_trial_group; |
- const char* command_line_switch; |
+ 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, true}, |
+ {"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); |
- |
- base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
- command_line.AppendSwitch(test_case.command_line_switch); |
- EXPECT_EQ(test_case.expected_enabled, |
- IsAffiliationBasedMatchingEnabled(command_line)); |
+ // Enable the command-line feature. |
+ base::FeatureList::ClearInstanceForTesting(); |
+ EnableFeature(test_case.command_line_feature, test_case.set_enabled, false); |
+ EXPECT_EQ(test_case.expected_enabled, IsAffiliationBasedMatchingEnabled()); |
} |
} |
@@ -244,25 +248,27 @@ TEST(AffiliationUtilsTest, |
struct { |
const char* variation_param; |
- const char* command_line_switch; |
+ 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, true}, |
+ {"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); |
@@ -275,11 +281,10 @@ TEST(AffiliationUtilsTest, |
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)); |
+ // Enable the command-line feature. |
+ EnableFeature(test_case.command_line_feature, test_case.set_enabled, false); |
+ EXPECT_EQ(test_case.expected_enabled, |
+ IsPropagatingPasswordChangesToWebCredentialsEnabled()); |
} |
} |