OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/password_manager/core/browser/affiliation_utils.h" | 5 #include "components/password_manager/core/browser/affiliation_utils.h" |
6 | 6 |
7 #include "base/command_line.h" | |
8 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
9 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
11 #include "components/password_manager/core/common/password_manager_switches.h" | 10 #include "components/password_manager/core/browser/password_manager_test_utils.h " |
11 #include "components/password_manager/core/common/password_manager_features.h" | |
12 #include "components/variations/variations_associated_data.h" | 12 #include "components/variations/variations_associated_data.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "url/url_constants.h" | 14 #include "url/url_constants.h" |
15 | 15 |
16 namespace password_manager { | 16 namespace password_manager { |
17 | 17 |
18 namespace { | 18 namespace { |
19 const char kFieldTrialName[] = "AffiliationBasedMatching"; | 19 const char kFieldTrialName[] = "AffiliationBasedMatching"; |
20 const std::string kSchemeHostExample = "http://example.com"; | 20 const std::string kSchemeHostExample = "http://example.com"; |
21 const char kTestFacetURI1[] = "https://alpha.example.com/"; | 21 const char kTestFacetURI1[] = "https://alpha.example.com/"; |
22 const char kTestFacetURI2[] = "https://beta.example.com/"; | 22 const char kTestFacetURI2[] = "https://beta.example.com/"; |
23 const char kTestFacetURI3[] = "https://gamma.example.com/"; | 23 const char kTestFacetURI3[] = "https://gamma.example.com/"; |
24 | |
25 const base::Feature kDummyFeature = {"FooBar", | |
26 base::FEATURE_DISABLED_BY_DEFAULT}; | |
24 } // namespace | 27 } // namespace |
25 | 28 |
26 TEST(AffiliationUtilsTest, ValidWebFacetURIs) { | 29 TEST(AffiliationUtilsTest, ValidWebFacetURIs) { |
27 struct { | 30 struct { |
28 const char* valid_facet_uri; | 31 const char* valid_facet_uri; |
29 const char* expected_canonical_facet_uri; | 32 const char* expected_canonical_facet_uri; |
30 } kTestCases[] = { | 33 } kTestCases[] = { |
31 {"https://www.example.com", "https://www.example.com"}, | 34 {"https://www.example.com", "https://www.example.com"}, |
32 {"HTTPS://www.EXAMPLE.com", "https://www.example.com"}, | 35 {"HTTPS://www.EXAMPLE.com", "https://www.example.com"}, |
33 {"https://0321.0x86.161.0043", "https://209.134.161.35"}, | 36 {"https://0321.0x86.161.0043", "https://209.134.161.35"}, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 b.push_back(FacetURI::FromCanonicalSpec(kTestFacetURI3)); | 196 b.push_back(FacetURI::FromCanonicalSpec(kTestFacetURI3)); |
194 | 197 |
195 EXPECT_FALSE(AreEquivalenceClassesEqual(a, b)); | 198 EXPECT_FALSE(AreEquivalenceClassesEqual(a, b)); |
196 EXPECT_FALSE(AreEquivalenceClassesEqual(a, c)); | 199 EXPECT_FALSE(AreEquivalenceClassesEqual(a, c)); |
197 EXPECT_FALSE(AreEquivalenceClassesEqual(b, a)); | 200 EXPECT_FALSE(AreEquivalenceClassesEqual(b, a)); |
198 EXPECT_FALSE(AreEquivalenceClassesEqual(b, c)); | 201 EXPECT_FALSE(AreEquivalenceClassesEqual(b, c)); |
199 EXPECT_FALSE(AreEquivalenceClassesEqual(c, a)); | 202 EXPECT_FALSE(AreEquivalenceClassesEqual(c, a)); |
200 EXPECT_FALSE(AreEquivalenceClassesEqual(c, b)); | 203 EXPECT_FALSE(AreEquivalenceClassesEqual(c, b)); |
201 } | 204 } |
202 | 205 |
203 TEST(AffiliationUtilsTest, IsAffiliationBasedMatchingEnabled) { | 206 TEST(AffiliationUtilsTest, IsAffiliationBasedMatchingEnabled) { |
Bernhard Bauer
2016/02/11 11:12:40
TBH, I think these tests now need much fewer test
| |
204 struct { | 207 struct { |
205 const char* field_trial_group; | 208 const char* field_trial_group; |
206 const char* command_line_switch; | 209 base::Feature command_line_feature; |
210 bool set_enabled; | |
207 bool expected_enabled; | 211 bool expected_enabled; |
208 } kTestCases[] = { | 212 } kTestCases[] = { |
209 {"", "", true}, | 213 {"", kDummyFeature, true, true}, |
210 {"", switches::kEnableAffiliationBasedMatching, true}, | 214 {"", features::kAffiliationBasedMatching, true, true}, |
211 {"", switches::kDisableAffiliationBasedMatching, false}, | 215 {"", features::kAffiliationBasedMatching, false, false}, |
212 {"garbage value", "", true}, | 216 {"garbage value", kDummyFeature, true, true}, |
213 {"disabled", "", false}, | 217 {"disabled", kDummyFeature, true, false}, |
214 {"disabled2", "", false}, | 218 {"disabled2", kDummyFeature, true, false}, |
215 {"Disabled", "", false}, | 219 {"Disabled", kDummyFeature, true, false}, |
216 {"Disabled", switches::kDisableAffiliationBasedMatching, false}, | 220 {"Disabled", features::kAffiliationBasedMatching, false, false}, |
217 {"Disabled", switches::kEnableAffiliationBasedMatching, true}, | 221 {"Disabled", features::kAffiliationBasedMatching, true, true}, |
218 {"enabled", "", true}, | 222 {"enabled", kDummyFeature, true, true}, |
219 {"enabled2", "", true}, | 223 {"enabled2", kDummyFeature, true, true}, |
220 {"Enabled", "", true}, | 224 {"Enabled", kDummyFeature, true, true}, |
221 {"Enabled", switches::kDisableAffiliationBasedMatching, false}, | 225 {"Enabled", features::kAffiliationBasedMatching, false, false}, |
222 {"Enabled", switches::kEnableAffiliationBasedMatching, true}}; | 226 {"Enabled", features::kAffiliationBasedMatching, true, true}}; |
223 | 227 |
224 for (const auto& test_case : kTestCases) { | 228 for (const auto& test_case : kTestCases) { |
225 SCOPED_TRACE(testing::Message("Command line = ") | 229 SCOPED_TRACE(testing::Message("Command line = ") |
226 << test_case.command_line_switch); | 230 << test_case.command_line_feature.name); |
231 SCOPED_TRACE(testing::Message("Set enabled = ") << test_case.set_enabled); | |
227 SCOPED_TRACE(testing::Message("Group name = ") | 232 SCOPED_TRACE(testing::Message("Group name = ") |
228 << test_case.field_trial_group); | 233 << test_case.field_trial_group); |
229 | 234 |
230 base::FieldTrialList field_trials(nullptr); | 235 base::FieldTrialList field_trials(nullptr); |
231 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, | 236 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, |
232 test_case.field_trial_group); | 237 test_case.field_trial_group); |
233 | 238 // Enable the command-line feature. |
234 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 239 base::FeatureList::ClearInstanceForTesting(); |
235 command_line.AppendSwitch(test_case.command_line_switch); | 240 EnableFeature(test_case.command_line_feature, test_case.set_enabled, false); |
236 EXPECT_EQ(test_case.expected_enabled, | 241 EXPECT_EQ(test_case.expected_enabled, IsAffiliationBasedMatchingEnabled()); |
237 IsAffiliationBasedMatchingEnabled(command_line)); | |
238 } | 242 } |
239 } | 243 } |
240 | 244 |
241 TEST(AffiliationUtilsTest, | 245 TEST(AffiliationUtilsTest, |
242 IsPropagatingPasswordChangesToWebCredentialsEnabled) { | 246 IsPropagatingPasswordChangesToWebCredentialsEnabled) { |
243 const char kExperimentName[] = "DoesNotMatter"; | 247 const char kExperimentName[] = "DoesNotMatter"; |
244 | 248 |
245 struct { | 249 struct { |
246 const char* variation_param; | 250 const char* variation_param; |
247 const char* command_line_switch; | 251 base::Feature command_line_feature; |
252 bool set_enabled; | |
248 bool expected_enabled; | 253 bool expected_enabled; |
249 } kTestCases[] = { | 254 } kTestCases[] = { |
250 {"", "", true}, | 255 {"", kDummyFeature, true, true}, |
251 {"", switches::kEnableAffiliationBasedMatching, true}, | 256 {"", features::kAffiliationBasedMatching, true, true}, |
252 {"", switches::kDisableAffiliationBasedMatching, false}, | 257 {"", features::kAffiliationBasedMatching, false, false}, |
253 {"garbage value", "", true}, | 258 {"garbage value", kDummyFeature, true, true}, |
254 {"disabled", "", false}, | 259 {"disabled", kDummyFeature, true, false}, |
255 {"Disabled", "", false}, | 260 {"Disabled", kDummyFeature, true, false}, |
256 {"Disabled", switches::kDisableAffiliationBasedMatching, false}, | 261 {"Disabled", features::kAffiliationBasedMatching, false, false}, |
257 {"Disabled", switches::kEnableAffiliationBasedMatching, true}, | 262 {"Disabled", features::kAffiliationBasedMatching, true, true}, |
258 {"enabled", "", true}, | 263 {"enabled", kDummyFeature, true, true}, |
259 {"Enabled", "", true}, | 264 {"Enabled", kDummyFeature, true, true}, |
260 {"Enabled", switches::kDisableAffiliationBasedMatching, false}, | 265 {"Enabled", features::kAffiliationBasedMatching, false, false}, |
261 {"Enabled", switches::kEnableAffiliationBasedMatching, true}}; | 266 {"Enabled", features::kAffiliationBasedMatching, true, true}}; |
262 | 267 |
263 for (const auto& test_case : kTestCases) { | 268 for (const auto& test_case : kTestCases) { |
264 SCOPED_TRACE(testing::Message("Command line = ") | 269 SCOPED_TRACE(testing::Message("Command line = ") |
265 << test_case.command_line_switch); | 270 << test_case.command_line_feature.name); |
271 SCOPED_TRACE(testing::Message("Set enabled = ") << test_case.set_enabled); | |
266 SCOPED_TRACE(testing::Message("Variation param = ") | 272 SCOPED_TRACE(testing::Message("Variation param = ") |
267 << test_case.variation_param); | 273 << test_case.variation_param); |
268 | 274 |
269 variations::testing::ClearAllVariationParams(); | 275 variations::testing::ClearAllVariationParams(); |
270 base::FieldTrialList field_trials(nullptr); | 276 base::FieldTrialList field_trials(nullptr); |
271 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, kExperimentName); | 277 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, kExperimentName); |
272 std::map<std::string, std::string> variation_params; | 278 std::map<std::string, std::string> variation_params; |
273 variation_params["propagate_password_changes_to_web"] = | 279 variation_params["propagate_password_changes_to_web"] = |
274 test_case.variation_param; | 280 test_case.variation_param; |
275 ASSERT_TRUE(variations::AssociateVariationParams( | 281 ASSERT_TRUE(variations::AssociateVariationParams( |
276 kFieldTrialName, kExperimentName, variation_params)); | 282 kFieldTrialName, kExperimentName, variation_params)); |
277 | 283 |
278 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 284 // Enable the command-line feature. |
279 command_line.AppendSwitch(test_case.command_line_switch); | 285 EnableFeature(test_case.command_line_feature, test_case.set_enabled, false); |
280 EXPECT_EQ( | 286 EXPECT_EQ(test_case.expected_enabled, |
281 test_case.expected_enabled, | 287 IsPropagatingPasswordChangesToWebCredentialsEnabled()); |
282 IsPropagatingPasswordChangesToWebCredentialsEnabled(command_line)); | |
283 } | 288 } |
284 } | 289 } |
285 | 290 |
286 class GetHumanReadableOriginTest : public testing::Test { | 291 class GetHumanReadableOriginTest : public testing::Test { |
287 public: | 292 public: |
288 GetHumanReadableOriginTest() { | 293 GetHumanReadableOriginTest() { |
289 form_template_.origin = GURL(kSchemeHostExample); | 294 form_template_.origin = GURL(kSchemeHostExample); |
290 form_template_.action = GURL(kSchemeHostExample); | 295 form_template_.action = GURL(kSchemeHostExample); |
291 form_template_.username_element = base::ASCIIToUTF16("Email"); | 296 form_template_.username_element = base::ASCIIToUTF16("Email"); |
292 form_template_.password_element = base::ASCIIToUTF16("Password"); | 297 form_template_.password_element = base::ASCIIToUTF16("Password"); |
(...skipping 30 matching lines...) Expand all Loading... | |
323 android_form.signon_realm = | 328 android_form.signon_realm = |
324 "android://" | 329 "android://" |
325 "m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_" | 330 "m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_" |
326 "3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==" | 331 "3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==" |
327 "@com.example.android"; | 332 "@com.example.android"; |
328 EXPECT_EQ(GetHumanReadableOrigin(android_form, ""), | 333 EXPECT_EQ(GetHumanReadableOrigin(android_form, ""), |
329 "android://com.example.android"); | 334 "android://com.example.android"); |
330 } | 335 } |
331 | 336 |
332 } // namespace password_manager | 337 } // namespace password_manager |
OLD | NEW |