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" | 7 #include <vector> |
8 | |
8 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_util.h" | |
9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/common/password_form.h" | 12 #include "components/autofill/core/common/password_form.h" |
11 #include "components/password_manager/core/common/password_manager_switches.h" | 13 #include "components/password_manager/core/browser/password_manager_test_utils.h " |
14 #include "components/password_manager/core/common/password_manager_features.h" | |
12 #include "components/variations/variations_associated_data.h" | 15 #include "components/variations/variations_associated_data.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "url/url_constants.h" | 17 #include "url/url_constants.h" |
15 | 18 |
16 namespace password_manager { | 19 namespace password_manager { |
17 | 20 |
18 namespace { | 21 namespace { |
19 const char kFieldTrialName[] = "AffiliationBasedMatching"; | 22 const char kFieldTrialName[] = "AffiliationBasedMatching"; |
20 const std::string kSchemeHostExample = "http://example.com"; | 23 const std::string kSchemeHostExample = "http://example.com"; |
21 const char kTestFacetURI1[] = "https://alpha.example.com/"; | 24 const char kTestFacetURI1[] = "https://alpha.example.com/"; |
22 const char kTestFacetURI2[] = "https://beta.example.com/"; | 25 const char kTestFacetURI2[] = "https://beta.example.com/"; |
23 const char kTestFacetURI3[] = "https://gamma.example.com/"; | 26 const char kTestFacetURI3[] = "https://gamma.example.com/"; |
27 | |
28 const base::Feature kDummyFeature = {"FooBar", | |
29 base::FEATURE_DISABLED_BY_DEFAULT}; | |
24 } // namespace | 30 } // namespace |
25 | 31 |
26 TEST(AffiliationUtilsTest, ValidWebFacetURIs) { | 32 TEST(AffiliationUtilsTest, ValidWebFacetURIs) { |
27 struct { | 33 struct { |
28 const char* valid_facet_uri; | 34 const char* valid_facet_uri; |
29 const char* expected_canonical_facet_uri; | 35 const char* expected_canonical_facet_uri; |
30 } kTestCases[] = { | 36 } kTestCases[] = { |
31 {"https://www.example.com", "https://www.example.com"}, | 37 {"https://www.example.com", "https://www.example.com"}, |
32 {"HTTPS://www.EXAMPLE.com", "https://www.example.com"}, | 38 {"HTTPS://www.EXAMPLE.com", "https://www.example.com"}, |
33 {"https://0321.0x86.161.0043", "https://209.134.161.35"}, | 39 {"https://0321.0x86.161.0043", "https://209.134.161.35"}, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 EXPECT_FALSE(AreEquivalenceClassesEqual(a, c)); | 202 EXPECT_FALSE(AreEquivalenceClassesEqual(a, c)); |
197 EXPECT_FALSE(AreEquivalenceClassesEqual(b, a)); | 203 EXPECT_FALSE(AreEquivalenceClassesEqual(b, a)); |
198 EXPECT_FALSE(AreEquivalenceClassesEqual(b, c)); | 204 EXPECT_FALSE(AreEquivalenceClassesEqual(b, c)); |
199 EXPECT_FALSE(AreEquivalenceClassesEqual(c, a)); | 205 EXPECT_FALSE(AreEquivalenceClassesEqual(c, a)); |
200 EXPECT_FALSE(AreEquivalenceClassesEqual(c, b)); | 206 EXPECT_FALSE(AreEquivalenceClassesEqual(c, b)); |
201 } | 207 } |
202 | 208 |
203 TEST(AffiliationUtilsTest, IsAffiliationBasedMatchingEnabled) { | 209 TEST(AffiliationUtilsTest, IsAffiliationBasedMatchingEnabled) { |
204 struct { | 210 struct { |
205 const char* field_trial_group; | 211 const char* field_trial_group; |
206 const char* command_line_switch; | 212 const base::Feature command_line_feature; |
213 bool set_enabled; | |
207 bool expected_enabled; | 214 bool expected_enabled; |
208 } kTestCases[] = { | 215 } kTestCases[] = { |
209 {"", "", true}, | 216 {"", kDummyFeature, true, true}, |
210 {"", switches::kEnableAffiliationBasedMatching, true}, | 217 {"", features::kAffiliationBasedMatching, true, true}, |
211 {"", switches::kDisableAffiliationBasedMatching, false}, | 218 {"", features::kAffiliationBasedMatching, false, false}, |
212 {"garbage value", "", true}, | 219 {"garbage value", kDummyFeature, true, true}, |
213 {"disabled", "", false}, | 220 {"disabled", kDummyFeature, true, false}, |
214 {"disabled2", "", false}, | 221 {"disabled2", kDummyFeature, true, false}, |
215 {"Disabled", "", false}, | 222 {"Disabled", kDummyFeature, true, false}, |
216 {"Disabled", switches::kDisableAffiliationBasedMatching, false}, | 223 {"Disabled", features::kAffiliationBasedMatching, false, false}, |
217 {"Disabled", switches::kEnableAffiliationBasedMatching, true}, | 224 {"Disabled", features::kAffiliationBasedMatching, true, false}, |
218 {"enabled", "", true}, | 225 {"enabled", kDummyFeature, true, true}, |
219 {"enabled2", "", true}, | 226 {"enabled2", kDummyFeature, true, true}, |
220 {"Enabled", "", true}, | 227 {"Enabled", kDummyFeature, true, true}, |
221 {"Enabled", switches::kDisableAffiliationBasedMatching, false}, | 228 {"Enabled", features::kAffiliationBasedMatching, false, false}, |
222 {"Enabled", switches::kEnableAffiliationBasedMatching, true}}; | 229 {"Enabled", features::kAffiliationBasedMatching, true, true}}; |
223 | 230 |
224 for (const auto& test_case : kTestCases) { | 231 for (const auto& test_case : kTestCases) { |
225 SCOPED_TRACE(testing::Message("Command line = ") | 232 SCOPED_TRACE(testing::Message("Command line = ") |
226 << test_case.command_line_switch); | 233 << test_case.command_line_feature.name); |
234 SCOPED_TRACE(testing::Message("Set enabled = ") << test_case.set_enabled); | |
227 SCOPED_TRACE(testing::Message("Group name = ") | 235 SCOPED_TRACE(testing::Message("Group name = ") |
228 << test_case.field_trial_group); | 236 << test_case.field_trial_group); |
229 | 237 |
230 base::FieldTrialList field_trials(nullptr); | 238 base::FieldTrialList field_trials(nullptr); |
231 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, | 239 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
232 test_case.field_trial_group); | 240 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( |
241 kFieldTrialName, test_case.field_trial_group); | |
233 | 242 |
234 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 243 // Set the command-line feature. |
235 command_line.AppendSwitch(test_case.command_line_switch); | 244 std::vector<const base::Feature*> enable_features; |
245 std::vector<const base::Feature*> disable_features; | |
246 if (test_case.set_enabled) { | |
247 enable_features.push_back(&test_case.command_line_feature); | |
248 } else { | |
249 disable_features.push_back(&test_case.command_line_feature); | |
250 } | |
251 | |
252 if (base::StartsWith(test_case.field_trial_group, "disabled", | |
253 base::CompareCase::INSENSITIVE_ASCII)) { | |
254 feature_list->RegisterFieldTrialOverride( | |
255 test_case.command_line_feature.name, | |
256 base::FeatureList::OVERRIDE_DISABLE_FEATURE, field_trial); | |
257 } | |
258 | |
259 SetFeatures(enable_features, disable_features, std::move(feature_list)); | |
236 EXPECT_EQ(test_case.expected_enabled, | 260 EXPECT_EQ(test_case.expected_enabled, |
237 IsAffiliationBasedMatchingEnabled(command_line)); | 261 base::FeatureList::IsEnabled(test_case.command_line_feature)); |
238 } | 262 } |
239 } | 263 } |
240 | 264 |
241 TEST(AffiliationUtilsTest, | 265 TEST(AffiliationUtilsTest, |
242 IsPropagatingPasswordChangesToWebCredentialsEnabled) { | 266 IsPropagatingPasswordChangesToWebCredentialsEnabled) { |
243 const char kExperimentName[] = "DoesNotMatter"; | 267 const char kExperimentName[] = "DoesNotMatter"; |
268 const char kVaraiationParam[] = "propagate_password_changes_to_web"; | |
vabr (Chromium)
2016/02/26 09:43:41
typo: Varaiaition -> Variation
Pritam Nikam
2016/02/26 12:42:23
Done.
| |
244 | 269 |
245 struct { | 270 struct { |
246 const char* variation_param; | 271 const char* variation_param; |
247 const char* command_line_switch; | 272 const base::Feature command_line_feature; |
273 bool set_enabled; | |
248 bool expected_enabled; | 274 bool expected_enabled; |
249 } kTestCases[] = { | 275 } kTestCases[] = { |
250 {"", "", true}, | 276 {"", kDummyFeature, true, true}, |
251 {"", switches::kEnableAffiliationBasedMatching, true}, | 277 {"", features::kAffiliationBasedMatching, true, true}, |
252 {"", switches::kDisableAffiliationBasedMatching, false}, | 278 {"", features::kAffiliationBasedMatching, false, false}, |
253 {"garbage value", "", true}, | 279 {"garbage value", kDummyFeature, true, true}, |
254 {"disabled", "", false}, | 280 {"disabled", kDummyFeature, true, false}, |
255 {"Disabled", "", false}, | 281 {"Disabled", kDummyFeature, true, false}, |
256 {"Disabled", switches::kDisableAffiliationBasedMatching, false}, | 282 {"Disabled", features::kAffiliationBasedMatching, false, false}, |
257 {"Disabled", switches::kEnableAffiliationBasedMatching, true}, | 283 {"Disabled", features::kAffiliationBasedMatching, true, false}, |
258 {"enabled", "", true}, | 284 {"enabled", kDummyFeature, true, true}, |
259 {"Enabled", "", true}, | 285 {"Enabled", kDummyFeature, true, true}, |
260 {"Enabled", switches::kDisableAffiliationBasedMatching, false}, | 286 {"Enabled", features::kAffiliationBasedMatching, false, false}, |
261 {"Enabled", switches::kEnableAffiliationBasedMatching, true}}; | 287 {"Enabled", features::kAffiliationBasedMatching, true, true}}; |
262 | 288 |
263 for (const auto& test_case : kTestCases) { | 289 for (const auto& test_case : kTestCases) { |
264 SCOPED_TRACE(testing::Message("Command line = ") | 290 SCOPED_TRACE(testing::Message("Command line = ") |
265 << test_case.command_line_switch); | 291 << test_case.command_line_feature.name); |
292 SCOPED_TRACE(testing::Message("Set enabled = ") << test_case.set_enabled); | |
266 SCOPED_TRACE(testing::Message("Variation param = ") | 293 SCOPED_TRACE(testing::Message("Variation param = ") |
267 << test_case.variation_param); | 294 << test_case.variation_param); |
268 | 295 |
269 variations::testing::ClearAllVariationParams(); | 296 variations::testing::ClearAllVariationParams(); |
270 base::FieldTrialList field_trials(nullptr); | 297 base::FieldTrialList field_trials(nullptr); |
271 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, kExperimentName); | 298 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
299 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( | |
300 kFieldTrialName, kExperimentName); | |
272 std::map<std::string, std::string> variation_params; | 301 std::map<std::string, std::string> variation_params; |
273 variation_params["propagate_password_changes_to_web"] = | 302 variation_params[kVaraiationParam] = test_case.variation_param; |
274 test_case.variation_param; | |
275 ASSERT_TRUE(variations::AssociateVariationParams( | 303 ASSERT_TRUE(variations::AssociateVariationParams( |
276 kFieldTrialName, kExperimentName, variation_params)); | 304 kFieldTrialName, kExperimentName, variation_params)); |
277 | 305 |
278 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 306 // Set the command-line feature. |
279 command_line.AppendSwitch(test_case.command_line_switch); | 307 std::vector<const base::Feature*> enable_features; |
280 EXPECT_EQ( | 308 std::vector<const base::Feature*> disable_features; |
281 test_case.expected_enabled, | 309 if (test_case.set_enabled) { |
282 IsPropagatingPasswordChangesToWebCredentialsEnabled(command_line)); | 310 enable_features.push_back(&test_case.command_line_feature); |
311 } else { | |
312 disable_features.push_back(&test_case.command_line_feature); | |
313 } | |
314 | |
315 const std::string update_enabled = | |
316 variations::GetVariationParamValue(kFieldTrialName, kVaraiationParam); | |
317 if (base::StartsWith(update_enabled, "disabled", | |
318 base::CompareCase::INSENSITIVE_ASCII)) { | |
319 feature_list->RegisterFieldTrialOverride( | |
320 test_case.command_line_feature.name, | |
321 base::FeatureList::OVERRIDE_DISABLE_FEATURE, field_trial); | |
322 } | |
323 | |
324 SetFeatures(enable_features, disable_features, std::move(feature_list)); | |
325 EXPECT_EQ(test_case.expected_enabled, | |
326 base::FeatureList::IsEnabled(test_case.command_line_feature)); | |
283 } | 327 } |
284 } | 328 } |
285 | 329 |
286 class GetHumanReadableOriginTest : public testing::Test { | 330 class GetHumanReadableOriginTest : public testing::Test { |
287 public: | 331 public: |
288 GetHumanReadableOriginTest() { | 332 GetHumanReadableOriginTest() { |
289 form_template_.origin = GURL(kSchemeHostExample); | 333 form_template_.origin = GURL(kSchemeHostExample); |
290 form_template_.action = GURL(kSchemeHostExample); | 334 form_template_.action = GURL(kSchemeHostExample); |
291 form_template_.username_element = base::ASCIIToUTF16("Email"); | 335 form_template_.username_element = base::ASCIIToUTF16("Email"); |
292 form_template_.password_element = base::ASCIIToUTF16("Password"); | 336 form_template_.password_element = base::ASCIIToUTF16("Password"); |
(...skipping 30 matching lines...) Expand all Loading... | |
323 android_form.signon_realm = | 367 android_form.signon_realm = |
324 "android://" | 368 "android://" |
325 "m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_" | 369 "m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_" |
326 "3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==" | 370 "3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==" |
327 "@com.example.android"; | 371 "@com.example.android"; |
328 EXPECT_EQ(GetHumanReadableOrigin(android_form, ""), | 372 EXPECT_EQ(GetHumanReadableOrigin(android_form, ""), |
329 "android://com.example.android"); | 373 "android://com.example.android"); |
330 } | 374 } |
331 | 375 |
332 } // namespace password_manager | 376 } // namespace password_manager |
OLD | NEW |