Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: components/password_manager/core/browser/affiliation_utils_unittest.cc

Issue 1668523002: [Password Manager] Switch password manager code to use the Feature framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes mac bot breakages. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/";
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 EXPECT_FALSE(AreEquivalenceClassesEqual(a, c)); 196 EXPECT_FALSE(AreEquivalenceClassesEqual(a, c));
197 EXPECT_FALSE(AreEquivalenceClassesEqual(b, a)); 197 EXPECT_FALSE(AreEquivalenceClassesEqual(b, a));
198 EXPECT_FALSE(AreEquivalenceClassesEqual(b, c)); 198 EXPECT_FALSE(AreEquivalenceClassesEqual(b, c));
199 EXPECT_FALSE(AreEquivalenceClassesEqual(c, a)); 199 EXPECT_FALSE(AreEquivalenceClassesEqual(c, a));
200 EXPECT_FALSE(AreEquivalenceClassesEqual(c, b)); 200 EXPECT_FALSE(AreEquivalenceClassesEqual(c, b));
201 } 201 }
202 202
203 TEST(AffiliationUtilsTest, IsAffiliationBasedMatchingEnabled) { 203 TEST(AffiliationUtilsTest, IsAffiliationBasedMatchingEnabled) {
204 struct { 204 struct {
205 const char* field_trial_group; 205 const char* field_trial_group;
206 const char* command_line_switch; 206 const char* command_line_feature;
207 bool expected_enabled; 207 bool expected_enabled;
208 } kTestCases[] = { 208 } kTestCases[] = {
209 {"", "", true}, 209 {"", "", true},
210 {"", switches::kEnableAffiliationBasedMatching, true}, 210 {"", features::kEnableAffiliationBasedMatching.name, true},
211 {"", switches::kDisableAffiliationBasedMatching, false}, 211 {"", features::kDisableAffiliationBasedMatching.name, false},
212 {"garbage value", "", true}, 212 {"garbage value", "", true},
213 {"disabled", "", false}, 213 {"disabled", "", false},
214 {"disabled2", "", false}, 214 {"disabled2", "", false},
215 {"Disabled", "", false}, 215 {"Disabled", "", false},
216 {"Disabled", switches::kDisableAffiliationBasedMatching, false}, 216 {"Disabled", features::kDisableAffiliationBasedMatching.name, false},
217 {"Disabled", switches::kEnableAffiliationBasedMatching, true}, 217 {"Disabled", features::kEnableAffiliationBasedMatching.name, true},
218 {"enabled", "", true}, 218 {"enabled", "", true},
219 {"enabled2", "", true}, 219 {"enabled2", "", true},
220 {"Enabled", "", true}, 220 {"Enabled", "", true},
221 {"Enabled", switches::kDisableAffiliationBasedMatching, false}, 221 {"Enabled", features::kDisableAffiliationBasedMatching.name, false},
222 {"Enabled", switches::kEnableAffiliationBasedMatching, true}}; 222 {"Enabled", features::kEnableAffiliationBasedMatching.name, true}};
223 223
224 for (const auto& test_case : kTestCases) { 224 for (const auto& test_case : kTestCases) {
225 SCOPED_TRACE(testing::Message("Command line = ") 225 SCOPED_TRACE(testing::Message("Command line = ")
226 << test_case.command_line_switch); 226 << test_case.command_line_feature);
227 SCOPED_TRACE(testing::Message("Group name = ") 227 SCOPED_TRACE(testing::Message("Group name = ")
228 << test_case.field_trial_group); 228 << test_case.field_trial_group);
229 229
230 base::FieldTrialList field_trials(nullptr); 230 base::FieldTrialList field_trials(nullptr);
231 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, 231 base::FieldTrialList::CreateFieldTrial(kFieldTrialName,
232 test_case.field_trial_group); 232 test_case.field_trial_group);
233 233
234 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 234 // Enable the command-line feature.
235 command_line.AppendSwitch(test_case.command_line_switch); 235 EnableFeature(test_case.command_line_feature);
236 EXPECT_EQ(test_case.expected_enabled, 236 EXPECT_EQ(test_case.expected_enabled, IsAffiliationBasedMatchingEnabled());
237 IsAffiliationBasedMatchingEnabled(command_line));
238 } 237 }
239 } 238 }
240 239
241 TEST(AffiliationUtilsTest, 240 TEST(AffiliationUtilsTest,
242 IsPropagatingPasswordChangesToWebCredentialsEnabled) { 241 IsPropagatingPasswordChangesToWebCredentialsEnabled) {
243 const char kExperimentName[] = "DoesNotMatter"; 242 const char kExperimentName[] = "DoesNotMatter";
244 243
245 struct { 244 struct {
246 const char* variation_param; 245 const char* variation_param;
247 const char* command_line_switch; 246 const char* command_line_feature;
248 bool expected_enabled; 247 bool expected_enabled;
249 } kTestCases[] = { 248 } kTestCases[] = {
250 {"", "", true}, 249 {"", "", true},
251 {"", switches::kEnableAffiliationBasedMatching, true}, 250 {"", features::kEnableAffiliationBasedMatching.name, true},
252 {"", switches::kDisableAffiliationBasedMatching, false}, 251 {"", features::kDisableAffiliationBasedMatching.name, false},
253 {"garbage value", "", true}, 252 {"garbage value", "", true},
254 {"disabled", "", false}, 253 {"disabled", "", false},
255 {"Disabled", "", false}, 254 {"Disabled", "", false},
256 {"Disabled", switches::kDisableAffiliationBasedMatching, false}, 255 {"Disabled", features::kDisableAffiliationBasedMatching.name, false},
257 {"Disabled", switches::kEnableAffiliationBasedMatching, true}, 256 {"Disabled", features::kEnableAffiliationBasedMatching.name, true},
258 {"enabled", "", true}, 257 {"enabled", "", true},
259 {"Enabled", "", true}, 258 {"Enabled", "", true},
260 {"Enabled", switches::kDisableAffiliationBasedMatching, false}, 259 {"Enabled", features::kDisableAffiliationBasedMatching.name, false},
261 {"Enabled", switches::kEnableAffiliationBasedMatching, true}}; 260 {"Enabled", features::kEnableAffiliationBasedMatching.name, true}};
262 261
263 for (const auto& test_case : kTestCases) { 262 for (const auto& test_case : kTestCases) {
264 SCOPED_TRACE(testing::Message("Command line = ") 263 SCOPED_TRACE(testing::Message("Command line = ")
265 << test_case.command_line_switch); 264 << test_case.command_line_feature);
266 SCOPED_TRACE(testing::Message("Variation param = ") 265 SCOPED_TRACE(testing::Message("Variation param = ")
267 << test_case.variation_param); 266 << test_case.variation_param);
268 267
269 variations::testing::ClearAllVariationParams(); 268 variations::testing::ClearAllVariationParams();
270 base::FieldTrialList field_trials(nullptr); 269 base::FieldTrialList field_trials(nullptr);
271 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, kExperimentName); 270 base::FieldTrialList::CreateFieldTrial(kFieldTrialName, kExperimentName);
272 std::map<std::string, std::string> variation_params; 271 std::map<std::string, std::string> variation_params;
273 variation_params["propagate_password_changes_to_web"] = 272 variation_params["propagate_password_changes_to_web"] =
274 test_case.variation_param; 273 test_case.variation_param;
275 ASSERT_TRUE(variations::AssociateVariationParams( 274 ASSERT_TRUE(variations::AssociateVariationParams(
276 kFieldTrialName, kExperimentName, variation_params)); 275 kFieldTrialName, kExperimentName, variation_params));
277 276
278 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 277 // Enable the command-line feature.
279 command_line.AppendSwitch(test_case.command_line_switch); 278 EnableFeature(test_case.command_line_feature);
280 EXPECT_EQ( 279 EXPECT_EQ(test_case.expected_enabled,
281 test_case.expected_enabled, 280 IsPropagatingPasswordChangesToWebCredentialsEnabled());
282 IsPropagatingPasswordChangesToWebCredentialsEnabled(command_line));
283 } 281 }
284 } 282 }
285 283
286 class GetHumanReadableOriginTest : public testing::Test { 284 class GetHumanReadableOriginTest : public testing::Test {
287 public: 285 public:
288 GetHumanReadableOriginTest() { 286 GetHumanReadableOriginTest() {
289 form_template_.origin = GURL(kSchemeHostExample); 287 form_template_.origin = GURL(kSchemeHostExample);
290 form_template_.action = GURL(kSchemeHostExample); 288 form_template_.action = GURL(kSchemeHostExample);
291 form_template_.username_element = base::ASCIIToUTF16("Email"); 289 form_template_.username_element = base::ASCIIToUTF16("Email");
292 form_template_.password_element = base::ASCIIToUTF16("Password"); 290 form_template_.password_element = base::ASCIIToUTF16("Password");
(...skipping 30 matching lines...) Expand all
323 android_form.signon_realm = 321 android_form.signon_realm =
324 "android://" 322 "android://"
325 "m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_" 323 "m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_"
326 "3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==" 324 "3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw=="
327 "@com.example.android"; 325 "@com.example.android";
328 EXPECT_EQ(GetHumanReadableOrigin(android_form, ""), 326 EXPECT_EQ(GetHumanReadableOrigin(android_form, ""),
329 "android://com.example.android"); 327 "android://com.example.android");
330 } 328 }
331 329
332 } // namespace password_manager 330 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698