OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/sync/browser/sync_credentials_filter.h" | 5 #include "components/password_manager/sync/browser/sync_credentials_filter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 enum { FORM_FILTERED, FORM_NOT_FILTERED } is_form_filtered; | 89 enum { FORM_FILTERED, FORM_NOT_FILTERED } is_form_filtered; |
90 enum { NO_HISTOGRAM, HISTOGRAM_REPORTED } histogram_reported; | 90 enum { NO_HISTOGRAM, HISTOGRAM_REPORTED } histogram_reported; |
91 }; | 91 }; |
92 | 92 |
93 // Flag for creating a PasswordFormManager, deciding its IsNewLogin() value. | 93 // Flag for creating a PasswordFormManager, deciding its IsNewLogin() value. |
94 enum class LoginState { NEW, EXISTING }; | 94 enum class LoginState { NEW, EXISTING }; |
95 | 95 |
96 CredentialsFilterTest() | 96 CredentialsFilterTest() |
97 : password_manager_(&client_), | 97 : password_manager_(&client_), |
98 pending_(SimpleGaiaForm("user@gmail.com")), | 98 pending_(SimpleGaiaForm("user@gmail.com")), |
99 form_manager_(&password_manager_, | 99 form_manager_(base::MakeRefCounted<PasswordFormManager>( |
100 &client_, | 100 &password_manager_, |
101 driver_.AsWeakPtr(), | 101 &client_, |
102 pending_, | 102 driver_.AsWeakPtr(), |
103 base::MakeUnique<StubFormSaver>(), | 103 pending_, |
104 &fetcher_), | 104 base::MakeUnique<StubFormSaver>(), |
| 105 &fetcher_)), |
105 filter_(&client_, | 106 filter_(&client_, |
106 base::Bind(&SyncUsernameTestBase::sync_service, | 107 base::Bind(&SyncUsernameTestBase::sync_service, |
107 base::Unretained(this)), | 108 base::Unretained(this)), |
108 base::Bind(&SyncUsernameTestBase::signin_manager, | 109 base::Bind(&SyncUsernameTestBase::signin_manager, |
109 base::Unretained(this))) { | 110 base::Unretained(this))) { |
110 fetcher_.Fetch(); | 111 fetcher_.Fetch(); |
111 } | 112 } |
112 | 113 |
113 void CheckFilterResultsTestCase(const TestCase& test_case) { | 114 void CheckFilterResultsTestCase(const TestCase& test_case) { |
114 SetSyncingPasswords(test_case.password_sync == TestCase::SYNCING_PASSWORDS); | 115 SetSyncingPasswords(test_case.password_sync == TestCase::SYNCING_PASSWORDS); |
(...skipping 16 matching lines...) Expand all Loading... |
131 // Makes |form_manager_| provisionally save |pending_|. Depending on | 132 // Makes |form_manager_| provisionally save |pending_|. Depending on |
132 // |login_state| being NEW or EXISTING, prepares |form_manager_| in a state in | 133 // |login_state| being NEW or EXISTING, prepares |form_manager_| in a state in |
133 // which |pending_| looks like a new or existing credential, respectively. | 134 // which |pending_| looks like a new or existing credential, respectively. |
134 void SavePending(LoginState login_state) { | 135 void SavePending(LoginState login_state) { |
135 std::vector<const PasswordForm*> matches; | 136 std::vector<const PasswordForm*> matches; |
136 if (login_state == LoginState::EXISTING) { | 137 if (login_state == LoginState::EXISTING) { |
137 matches.push_back(&pending_); | 138 matches.push_back(&pending_); |
138 } | 139 } |
139 fetcher_.SetNonFederated(matches, 0u); | 140 fetcher_.SetNonFederated(matches, 0u); |
140 | 141 |
141 form_manager_.ProvisionallySave( | 142 form_manager_->ProvisionallySave( |
142 pending_, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 143 pending_, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
143 } | 144 } |
144 | 145 |
145 protected: | 146 protected: |
146 FakePasswordManagerClient client_; | 147 FakePasswordManagerClient client_; |
147 PasswordManager password_manager_; | 148 PasswordManager password_manager_; |
148 StubPasswordManagerDriver driver_; | 149 StubPasswordManagerDriver driver_; |
149 PasswordForm pending_; | 150 PasswordForm pending_; |
150 FakeFormFetcher fetcher_; | 151 FakeFormFetcher fetcher_; |
151 PasswordFormManager form_manager_; | 152 scoped_refptr<PasswordFormManager> form_manager_; |
152 | 153 |
153 SyncCredentialsFilter filter_; | 154 SyncCredentialsFilter filter_; |
154 }; | 155 }; |
155 | 156 |
156 TEST_F(CredentialsFilterTest, FilterResults_AllowAll) { | 157 TEST_F(CredentialsFilterTest, FilterResults_AllowAll) { |
157 // By default, sync username is not filtered at all. | 158 // By default, sync username is not filtered at all. |
158 const TestCase kTestCases[] = { | 159 const TestCase kTestCases[] = { |
159 // Reauth URL, not sync username. | 160 // Reauth URL, not sync username. |
160 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), | 161 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), |
161 "another_user@example.org", | 162 "another_user@example.org", |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 CheckFilterResultsTestCase(kTestCases[i]); | 280 CheckFilterResultsTestCase(kTestCases[i]); |
280 } | 281 } |
281 } | 282 } |
282 | 283 |
283 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_ExistingSyncCredentials) { | 284 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_ExistingSyncCredentials) { |
284 FakeSigninAs("user@gmail.com"); | 285 FakeSigninAs("user@gmail.com"); |
285 SetSyncingPasswords(true); | 286 SetSyncingPasswords(true); |
286 | 287 |
287 base::UserActionTester tester; | 288 base::UserActionTester tester; |
288 SavePending(LoginState::EXISTING); | 289 SavePending(LoginState::EXISTING); |
289 filter_.ReportFormLoginSuccess(form_manager_); | 290 filter_.ReportFormLoginSuccess(*form_manager_); |
290 EXPECT_EQ(1, tester.GetActionCount(kFilledAndLoginActionName)); | 291 EXPECT_EQ(1, tester.GetActionCount(kFilledAndLoginActionName)); |
291 } | 292 } |
292 | 293 |
293 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_NewSyncCredentials) { | 294 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_NewSyncCredentials) { |
294 FakeSigninAs("user@gmail.com"); | 295 FakeSigninAs("user@gmail.com"); |
295 SetSyncingPasswords(true); | 296 SetSyncingPasswords(true); |
296 | 297 |
297 base::UserActionTester tester; | 298 base::UserActionTester tester; |
298 SavePending(LoginState::NEW); | 299 SavePending(LoginState::NEW); |
299 filter_.ReportFormLoginSuccess(form_manager_); | 300 filter_.ReportFormLoginSuccess(*form_manager_); |
300 EXPECT_EQ(0, tester.GetActionCount(kFilledAndLoginActionName)); | 301 EXPECT_EQ(0, tester.GetActionCount(kFilledAndLoginActionName)); |
301 } | 302 } |
302 | 303 |
303 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_GAIANotSyncCredentials) { | 304 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_GAIANotSyncCredentials) { |
304 const char kOtherUsername[] = "other_user@gmail.com"; | 305 const char kOtherUsername[] = "other_user@gmail.com"; |
305 FakeSigninAs(kOtherUsername); | 306 FakeSigninAs(kOtherUsername); |
306 ASSERT_NE(pending_.username_value, base::ASCIIToUTF16(kOtherUsername)); | 307 ASSERT_NE(pending_.username_value, base::ASCIIToUTF16(kOtherUsername)); |
307 SetSyncingPasswords(true); | 308 SetSyncingPasswords(true); |
308 | 309 |
309 base::UserActionTester tester; | 310 base::UserActionTester tester; |
310 SavePending(LoginState::EXISTING); | 311 SavePending(LoginState::EXISTING); |
311 filter_.ReportFormLoginSuccess(form_manager_); | 312 filter_.ReportFormLoginSuccess(*form_manager_); |
312 EXPECT_EQ(0, tester.GetActionCount(kFilledAndLoginActionName)); | 313 EXPECT_EQ(0, tester.GetActionCount(kFilledAndLoginActionName)); |
313 } | 314 } |
314 | 315 |
315 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_NotGAIACredentials) { | 316 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_NotGAIACredentials) { |
316 pending_ = SimpleNonGaiaForm("user@gmail.com"); | 317 pending_ = SimpleNonGaiaForm("user@gmail.com"); |
317 FakeSigninAs("user@gmail.com"); | 318 FakeSigninAs("user@gmail.com"); |
318 SetSyncingPasswords(true); | 319 SetSyncingPasswords(true); |
319 | 320 |
320 base::UserActionTester tester; | 321 base::UserActionTester tester; |
321 SavePending(LoginState::EXISTING); | 322 SavePending(LoginState::EXISTING); |
322 filter_.ReportFormLoginSuccess(form_manager_); | 323 filter_.ReportFormLoginSuccess(*form_manager_); |
323 EXPECT_EQ(0, tester.GetActionCount(kFilledAndLoginActionName)); | 324 EXPECT_EQ(0, tester.GetActionCount(kFilledAndLoginActionName)); |
324 } | 325 } |
325 | 326 |
326 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_NotSyncing) { | 327 TEST_F(CredentialsFilterTest, ReportFormLoginSuccess_NotSyncing) { |
327 FakeSigninAs("user@gmail.com"); | 328 FakeSigninAs("user@gmail.com"); |
328 SetSyncingPasswords(false); | 329 SetSyncingPasswords(false); |
329 | 330 |
330 base::UserActionTester tester; | 331 base::UserActionTester tester; |
331 SavePending(LoginState::EXISTING); | 332 SavePending(LoginState::EXISTING); |
332 filter_.ReportFormLoginSuccess(form_manager_); | 333 filter_.ReportFormLoginSuccess(*form_manager_); |
333 EXPECT_EQ(0, tester.GetActionCount(kFilledAndLoginActionName)); | 334 EXPECT_EQ(0, tester.GetActionCount(kFilledAndLoginActionName)); |
334 } | 335 } |
335 | 336 |
336 TEST_F(CredentialsFilterTest, ShouldSave_NotSyncCredential) { | 337 TEST_F(CredentialsFilterTest, ShouldSave_NotSyncCredential) { |
337 PasswordForm form = SimpleGaiaForm("user@example.org"); | 338 PasswordForm form = SimpleGaiaForm("user@example.org"); |
338 | 339 |
339 ASSERT_NE("user@example.org", | 340 ASSERT_NE("user@example.org", |
340 signin_manager()->GetAuthenticatedAccountInfo().email); | 341 signin_manager()->GetAuthenticatedAccountInfo().email); |
341 SetSyncingPasswords(true); | 342 SetSyncingPasswords(true); |
342 EXPECT_TRUE(filter_.ShouldSave(form)); | 343 EXPECT_TRUE(filter_.ShouldSave(form)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 376 |
376 FakeSigninAs("test1@gmail.com"); | 377 FakeSigninAs("test1@gmail.com"); |
377 | 378 |
378 results = filter_.FilterResults(std::move(results)); | 379 results = filter_.FilterResults(std::move(results)); |
379 | 380 |
380 ASSERT_EQ(1u, results.size()); | 381 ASSERT_EQ(1u, results.size()); |
381 EXPECT_EQ(SimpleGaiaForm("test2@gmail.com"), *results[0]); | 382 EXPECT_EQ(SimpleGaiaForm("test2@gmail.com"), *results[0]); |
382 } | 383 } |
383 | 384 |
384 } // namespace password_manager | 385 } // namespace password_manager |
OLD | NEW |