OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The passwords in the tests below are all empty because PasswordStoreDefault | 5 // The passwords in the tests below are all empty because PasswordStoreDefault |
6 // does not store the actual passwords on OS X (they are stored in the Keychain | 6 // does not store the actual passwords on OS X (they are stored in the Keychain |
7 // instead). We could special-case it, but it is easier to just have empty | 7 // instead). We could special-case it, but it is easier to just have empty |
8 // passwords. This will not be needed anymore if crbug.com/466638 is fixed. | 8 // passwords. This will not be needed anymore if crbug.com/466638 is fixed. |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/run_loop.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
25 #include "components/password_manager/core/browser/affiliated_match_helper.h" | 26 #include "components/password_manager/core/browser/affiliated_match_helper.h" |
26 #include "components/password_manager/core/browser/affiliation_service.h" | 27 #include "components/password_manager/core/browser/affiliation_service.h" |
27 #include "components/password_manager/core/browser/mock_affiliated_match_helper.
h" | 28 #include "components/password_manager/core/browser/mock_affiliated_match_helper.
h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 L"", | 169 L"", |
169 true, false, cutoff - 1 }, | 170 true, false, cutoff - 1 }, |
170 }; | 171 }; |
171 | 172 |
172 // Build the forms vector and add the forms to the store. | 173 // Build the forms vector and add the forms to the store. |
173 ScopedVector<PasswordForm> all_forms; | 174 ScopedVector<PasswordForm> all_forms; |
174 for (size_t i = 0; i < arraysize(form_data); ++i) { | 175 for (size_t i = 0; i < arraysize(form_data); ++i) { |
175 all_forms.push_back(CreatePasswordFormFromDataForTesting(form_data[i])); | 176 all_forms.push_back(CreatePasswordFormFromDataForTesting(form_data[i])); |
176 store->AddLogin(*all_forms.back()); | 177 store->AddLogin(*all_forms.back()); |
177 } | 178 } |
178 base::MessageLoop::current()->RunUntilIdle(); | 179 base::RunLoop().RunUntilIdle(); |
179 | 180 |
180 // We expect to get back only the "recent" www.google.com login. | 181 // We expect to get back only the "recent" www.google.com login. |
181 // Theoretically these should never actually exist since there are no longer | 182 // Theoretically these should never actually exist since there are no longer |
182 // any login forms on www.google.com to save, but we technically allow them. | 183 // any login forms on www.google.com to save, but we technically allow them. |
183 // We should not get back the older saved password though. | 184 // We should not get back the older saved password though. |
184 PasswordForm www_google; | 185 PasswordForm www_google; |
185 www_google.scheme = PasswordForm::SCHEME_HTML; | 186 www_google.scheme = PasswordForm::SCHEME_HTML; |
186 www_google.signon_realm = "https://www.google.com"; | 187 www_google.signon_realm = "https://www.google.com"; |
187 std::vector<PasswordForm*> www_google_expected; | 188 std::vector<PasswordForm*> www_google_expected; |
188 www_google_expected.push_back(all_forms[2]); | 189 www_google_expected.push_back(all_forms[2]); |
(...skipping 25 matching lines...) Expand all Loading... |
214 .RetiresOnSaturation(); | 215 .RetiresOnSaturation(); |
215 EXPECT_CALL(consumer, | 216 EXPECT_CALL(consumer, |
216 OnGetPasswordStoreResultsConstRef( | 217 OnGetPasswordStoreResultsConstRef( |
217 UnorderedPasswordFormElementsAre(bar_example_expected))) | 218 UnorderedPasswordFormElementsAre(bar_example_expected))) |
218 .RetiresOnSaturation(); | 219 .RetiresOnSaturation(); |
219 | 220 |
220 store->GetLogins(www_google, &consumer); | 221 store->GetLogins(www_google, &consumer); |
221 store->GetLogins(accounts_google, &consumer); | 222 store->GetLogins(accounts_google, &consumer); |
222 store->GetLogins(bar_example, &consumer); | 223 store->GetLogins(bar_example, &consumer); |
223 | 224 |
224 base::MessageLoop::current()->RunUntilIdle(); | 225 base::RunLoop().RunUntilIdle(); |
225 | 226 |
226 store->ShutdownOnUIThread(); | 227 store->ShutdownOnUIThread(); |
227 base::MessageLoop::current()->RunUntilIdle(); | 228 base::RunLoop().RunUntilIdle(); |
228 } | 229 } |
229 | 230 |
230 TEST_F(PasswordStoreTest, StartSyncFlare) { | 231 TEST_F(PasswordStoreTest, StartSyncFlare) { |
231 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( | 232 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( |
232 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), | 233 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), |
233 base::WrapUnique(new LoginDatabase(test_login_db_file_path())))); | 234 base::WrapUnique(new LoginDatabase(test_login_db_file_path())))); |
234 StartSyncFlareMock mock; | 235 StartSyncFlareMock mock; |
235 store->Init( | 236 store->Init( |
236 base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock))); | 237 base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock))); |
237 { | 238 { |
238 PasswordForm form; | 239 PasswordForm form; |
239 form.origin = GURL("http://accounts.google.com/LoginAuth"); | 240 form.origin = GURL("http://accounts.google.com/LoginAuth"); |
240 form.signon_realm = "http://accounts.google.com/"; | 241 form.signon_realm = "http://accounts.google.com/"; |
241 EXPECT_CALL(mock, StartSyncFlare(syncer::PASSWORDS)); | 242 EXPECT_CALL(mock, StartSyncFlare(syncer::PASSWORDS)); |
242 store->AddLogin(form); | 243 store->AddLogin(form); |
243 base::MessageLoop::current()->RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
244 } | 245 } |
245 store->ShutdownOnUIThread(); | 246 store->ShutdownOnUIThread(); |
246 base::MessageLoop::current()->RunUntilIdle(); | 247 base::RunLoop().RunUntilIdle(); |
247 } | 248 } |
248 | 249 |
249 TEST_F(PasswordStoreTest, GetLoginImpl) { | 250 TEST_F(PasswordStoreTest, GetLoginImpl) { |
250 /* clang-format off */ | 251 /* clang-format off */ |
251 static const PasswordFormData kTestCredential = { | 252 static const PasswordFormData kTestCredential = { |
252 PasswordForm::SCHEME_HTML, | 253 PasswordForm::SCHEME_HTML, |
253 kTestWebRealm1, | 254 kTestWebRealm1, |
254 kTestWebOrigin1, | 255 kTestWebOrigin1, |
255 "", L"", L"username_element", L"password_element", | 256 "", L"", L"username_element", L"password_element", |
256 L"username_value", | 257 L"username_value", |
(...skipping 24 matching lines...) Expand all Loading... |
281 std::unique_ptr<PasswordForm> mismatching_form_5( | 282 std::unique_ptr<PasswordForm> mismatching_form_5( |
282 new PasswordForm(*test_form)); | 283 new PasswordForm(*test_form)); |
283 mismatching_form_5->username_value = | 284 mismatching_form_5->username_value = |
284 base::ASCIIToUTF16("other_username_value"); | 285 base::ASCIIToUTF16("other_username_value"); |
285 | 286 |
286 store->AddLogin(*mismatching_form_1); | 287 store->AddLogin(*mismatching_form_1); |
287 store->AddLogin(*mismatching_form_2); | 288 store->AddLogin(*mismatching_form_2); |
288 store->AddLogin(*mismatching_form_3); | 289 store->AddLogin(*mismatching_form_3); |
289 store->AddLogin(*mismatching_form_4); | 290 store->AddLogin(*mismatching_form_4); |
290 store->AddLogin(*mismatching_form_5); | 291 store->AddLogin(*mismatching_form_5); |
291 base::MessageLoop::current()->RunUntilIdle(); | 292 base::RunLoop().RunUntilIdle(); |
292 EXPECT_FALSE(store->GetLoginImpl(*test_form)); | 293 EXPECT_FALSE(store->GetLoginImpl(*test_form)); |
293 | 294 |
294 store->AddLogin(*test_form); | 295 store->AddLogin(*test_form); |
295 base::MessageLoop::current()->RunUntilIdle(); | 296 base::RunLoop().RunUntilIdle(); |
296 std::unique_ptr<PasswordForm> returned_form = store->GetLoginImpl(*test_form); | 297 std::unique_ptr<PasswordForm> returned_form = store->GetLoginImpl(*test_form); |
297 ASSERT_TRUE(returned_form); | 298 ASSERT_TRUE(returned_form); |
298 EXPECT_EQ(*test_form, *returned_form); | 299 EXPECT_EQ(*test_form, *returned_form); |
299 | 300 |
300 store->ShutdownOnUIThread(); | 301 store->ShutdownOnUIThread(); |
301 base::MessageLoop::current()->RunUntilIdle(); | 302 base::RunLoop().RunUntilIdle(); |
302 } | 303 } |
303 | 304 |
304 TEST_F(PasswordStoreTest, UpdateLoginPrimaryKeyFields) { | 305 TEST_F(PasswordStoreTest, UpdateLoginPrimaryKeyFields) { |
305 /* clang-format off */ | 306 /* clang-format off */ |
306 static const PasswordFormData kTestCredentials[] = { | 307 static const PasswordFormData kTestCredentials[] = { |
307 // The old credential. | 308 // The old credential. |
308 {PasswordForm::SCHEME_HTML, | 309 {PasswordForm::SCHEME_HTML, |
309 kTestWebRealm1, | 310 kTestWebRealm1, |
310 kTestWebOrigin1, | 311 kTestWebOrigin1, |
311 "", L"", L"username_element_1", L"password_element_1", | 312 "", L"", L"username_element_1", L"password_element_1", |
312 L"username_value_1", | 313 L"username_value_1", |
313 L"", true, true, 1}, | 314 L"", true, true, 1}, |
314 // The new credential with different values for all primary key fields. | 315 // The new credential with different values for all primary key fields. |
315 {PasswordForm::SCHEME_HTML, | 316 {PasswordForm::SCHEME_HTML, |
316 kTestWebRealm2, | 317 kTestWebRealm2, |
317 kTestWebOrigin2, | 318 kTestWebOrigin2, |
318 "", L"", L"username_element_2", L"password_element_2", | 319 "", L"", L"username_element_2", L"password_element_2", |
319 L"username_value_2", | 320 L"username_value_2", |
320 L"", true, true, 1}}; | 321 L"", true, true, 1}}; |
321 /* clang-format on */ | 322 /* clang-format on */ |
322 | 323 |
323 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( | 324 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( |
324 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), | 325 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), |
325 base::WrapUnique(new LoginDatabase(test_login_db_file_path())))); | 326 base::WrapUnique(new LoginDatabase(test_login_db_file_path())))); |
326 store->Init(syncer::SyncableService::StartSyncFlare()); | 327 store->Init(syncer::SyncableService::StartSyncFlare()); |
327 | 328 |
328 std::unique_ptr<PasswordForm> old_form( | 329 std::unique_ptr<PasswordForm> old_form( |
329 CreatePasswordFormFromDataForTesting(kTestCredentials[0])); | 330 CreatePasswordFormFromDataForTesting(kTestCredentials[0])); |
330 store->AddLogin(*old_form); | 331 store->AddLogin(*old_form); |
331 base::MessageLoop::current()->RunUntilIdle(); | 332 base::RunLoop().RunUntilIdle(); |
332 | 333 |
333 MockPasswordStoreObserver mock_observer; | 334 MockPasswordStoreObserver mock_observer; |
334 store->AddObserver(&mock_observer); | 335 store->AddObserver(&mock_observer); |
335 | 336 |
336 std::unique_ptr<PasswordForm> new_form( | 337 std::unique_ptr<PasswordForm> new_form( |
337 CreatePasswordFormFromDataForTesting(kTestCredentials[1])); | 338 CreatePasswordFormFromDataForTesting(kTestCredentials[1])); |
338 EXPECT_CALL(mock_observer, OnLoginsChanged(testing::SizeIs(2u))); | 339 EXPECT_CALL(mock_observer, OnLoginsChanged(testing::SizeIs(2u))); |
339 PasswordForm old_primary_key; | 340 PasswordForm old_primary_key; |
340 old_primary_key.signon_realm = old_form->signon_realm; | 341 old_primary_key.signon_realm = old_form->signon_realm; |
341 old_primary_key.origin = old_form->origin; | 342 old_primary_key.origin = old_form->origin; |
342 old_primary_key.username_element = old_form->username_element; | 343 old_primary_key.username_element = old_form->username_element; |
343 old_primary_key.username_value = old_form->username_value; | 344 old_primary_key.username_value = old_form->username_value; |
344 old_primary_key.password_element = old_form->password_element; | 345 old_primary_key.password_element = old_form->password_element; |
345 store->UpdateLoginWithPrimaryKey(*new_form, old_primary_key); | 346 store->UpdateLoginWithPrimaryKey(*new_form, old_primary_key); |
346 base::MessageLoop::current()->RunUntilIdle(); | 347 base::RunLoop().RunUntilIdle(); |
347 | 348 |
348 MockPasswordStoreConsumer mock_consumer; | 349 MockPasswordStoreConsumer mock_consumer; |
349 ScopedVector<autofill::PasswordForm> expected_forms; | 350 ScopedVector<autofill::PasswordForm> expected_forms; |
350 expected_forms.push_back(std::move(new_form)); | 351 expected_forms.push_back(std::move(new_form)); |
351 EXPECT_CALL(mock_consumer, | 352 EXPECT_CALL(mock_consumer, |
352 OnGetPasswordStoreResultsConstRef( | 353 OnGetPasswordStoreResultsConstRef( |
353 UnorderedPasswordFormElementsAre(expected_forms.get()))); | 354 UnorderedPasswordFormElementsAre(expected_forms.get()))); |
354 store->GetAutofillableLogins(&mock_consumer); | 355 store->GetAutofillableLogins(&mock_consumer); |
355 base::MessageLoop::current()->RunUntilIdle(); | 356 base::RunLoop().RunUntilIdle(); |
356 | 357 |
357 store->RemoveObserver(&mock_observer); | 358 store->RemoveObserver(&mock_observer); |
358 store->ShutdownOnUIThread(); | 359 store->ShutdownOnUIThread(); |
359 base::MessageLoop::current()->RunUntilIdle(); | 360 base::RunLoop().RunUntilIdle(); |
360 } | 361 } |
361 | 362 |
362 // Verify that RemoveLoginsCreatedBetween() fires the completion callback after | 363 // Verify that RemoveLoginsCreatedBetween() fires the completion callback after |
363 // deletions have been performed and notifications have been sent out. Whether | 364 // deletions have been performed and notifications have been sent out. Whether |
364 // the correct logins are removed or not is verified in detail in other tests. | 365 // the correct logins are removed or not is verified in detail in other tests. |
365 TEST_F(PasswordStoreTest, RemoveLoginsCreatedBetweenCallbackIsCalled) { | 366 TEST_F(PasswordStoreTest, RemoveLoginsCreatedBetweenCallbackIsCalled) { |
366 /* clang-format off */ | 367 /* clang-format off */ |
367 static const PasswordFormData kTestCredential = | 368 static const PasswordFormData kTestCredential = |
368 {PasswordForm::SCHEME_HTML, | 369 {PasswordForm::SCHEME_HTML, |
369 kTestWebRealm1, | 370 kTestWebRealm1, |
370 kTestWebOrigin1, | 371 kTestWebOrigin1, |
371 "", L"", L"username_element_1", L"password_element_1", | 372 "", L"", L"username_element_1", L"password_element_1", |
372 L"username_value_1", | 373 L"username_value_1", |
373 L"", true, true, 1}; | 374 L"", true, true, 1}; |
374 /* clang-format on */ | 375 /* clang-format on */ |
375 | 376 |
376 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( | 377 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( |
377 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), | 378 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), |
378 base::WrapUnique(new LoginDatabase(test_login_db_file_path())))); | 379 base::WrapUnique(new LoginDatabase(test_login_db_file_path())))); |
379 store->Init(syncer::SyncableService::StartSyncFlare()); | 380 store->Init(syncer::SyncableService::StartSyncFlare()); |
380 | 381 |
381 std::unique_ptr<PasswordForm> test_form( | 382 std::unique_ptr<PasswordForm> test_form( |
382 CreatePasswordFormFromDataForTesting(kTestCredential)); | 383 CreatePasswordFormFromDataForTesting(kTestCredential)); |
383 store->AddLogin(*test_form); | 384 store->AddLogin(*test_form); |
384 base::MessageLoop::current()->RunUntilIdle(); | 385 base::RunLoop().RunUntilIdle(); |
385 | 386 |
386 MockPasswordStoreObserver mock_observer; | 387 MockPasswordStoreObserver mock_observer; |
387 store->AddObserver(&mock_observer); | 388 store->AddObserver(&mock_observer); |
388 | 389 |
389 EXPECT_CALL(mock_observer, OnLoginsChanged(testing::SizeIs(1u))); | 390 EXPECT_CALL(mock_observer, OnLoginsChanged(testing::SizeIs(1u))); |
390 store->RemoveLoginsCreatedBetween( | 391 store->RemoveLoginsCreatedBetween( |
391 base::Time::FromDoubleT(0), base::Time::FromDoubleT(2), | 392 base::Time::FromDoubleT(0), base::Time::FromDoubleT(2), |
392 base::MessageLoop::current()->QuitWhenIdleClosure()); | 393 base::MessageLoop::current()->QuitWhenIdleClosure()); |
393 base::MessageLoop::current()->Run(); | 394 base::MessageLoop::current()->Run(); |
394 testing::Mock::VerifyAndClearExpectations(&mock_observer); | 395 testing::Mock::VerifyAndClearExpectations(&mock_observer); |
395 | 396 |
396 store->RemoveObserver(&mock_observer); | 397 store->RemoveObserver(&mock_observer); |
397 store->ShutdownOnUIThread(); | 398 store->ShutdownOnUIThread(); |
398 base::MessageLoop::current()->RunUntilIdle(); | 399 base::RunLoop().RunUntilIdle(); |
399 } | 400 } |
400 | 401 |
401 // When no Android applications are actually affiliated with the realm of the | 402 // When no Android applications are actually affiliated with the realm of the |
402 // observed form, GetLoginsWithAffiliations() should still return the exact and | 403 // observed form, GetLoginsWithAffiliations() should still return the exact and |
403 // PSL matching results, but not any stored Android credentials. | 404 // PSL matching results, but not any stored Android credentials. |
404 TEST_F(PasswordStoreTest, GetLoginsWithoutAffiliations) { | 405 TEST_F(PasswordStoreTest, GetLoginsWithoutAffiliations) { |
405 /* clang-format off */ | 406 /* clang-format off */ |
406 static const PasswordFormData kTestCredentials[] = { | 407 static const PasswordFormData kTestCredentials[] = { |
407 // Credential that is an exact match of the observed form. | 408 // Credential that is an exact match of the observed form. |
408 {PasswordForm::SCHEME_HTML, | 409 {PasswordForm::SCHEME_HTML, |
(...skipping 23 matching lines...) Expand all Loading... |
432 store->Init(syncer::SyncableService::StartSyncFlare()); | 433 store->Init(syncer::SyncableService::StartSyncFlare()); |
433 | 434 |
434 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 435 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; |
435 store->SetAffiliatedMatchHelper(base::WrapUnique(mock_helper)); | 436 store->SetAffiliatedMatchHelper(base::WrapUnique(mock_helper)); |
436 | 437 |
437 ScopedVector<PasswordForm> all_credentials; | 438 ScopedVector<PasswordForm> all_credentials; |
438 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) { | 439 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) { |
439 all_credentials.push_back( | 440 all_credentials.push_back( |
440 CreatePasswordFormFromDataForTesting(kTestCredentials[i])); | 441 CreatePasswordFormFromDataForTesting(kTestCredentials[i])); |
441 store->AddLogin(*all_credentials.back()); | 442 store->AddLogin(*all_credentials.back()); |
442 base::MessageLoop::current()->RunUntilIdle(); | 443 base::RunLoop().RunUntilIdle(); |
443 } | 444 } |
444 | 445 |
445 PasswordForm observed_form; | 446 PasswordForm observed_form; |
446 observed_form.scheme = PasswordForm::SCHEME_HTML; | 447 observed_form.scheme = PasswordForm::SCHEME_HTML; |
447 observed_form.origin = GURL(kTestWebOrigin1); | 448 observed_form.origin = GURL(kTestWebOrigin1); |
448 observed_form.ssl_valid = true; | 449 observed_form.ssl_valid = true; |
449 observed_form.signon_realm = kTestWebRealm1; | 450 observed_form.signon_realm = kTestWebRealm1; |
450 | 451 |
451 MockPasswordStoreConsumer mock_consumer; | 452 MockPasswordStoreConsumer mock_consumer; |
452 ScopedVector<PasswordForm> expected_results; | 453 ScopedVector<PasswordForm> expected_results; |
453 expected_results.push_back(new PasswordForm(*all_credentials[0])); | 454 expected_results.push_back(new PasswordForm(*all_credentials[0])); |
454 expected_results.push_back(new PasswordForm(*all_credentials[1])); | 455 expected_results.push_back(new PasswordForm(*all_credentials[1])); |
455 for (PasswordForm* result : expected_results) { | 456 for (PasswordForm* result : expected_results) { |
456 if (result->signon_realm != observed_form.signon_realm) | 457 if (result->signon_realm != observed_form.signon_realm) |
457 result->is_public_suffix_match = true; | 458 result->is_public_suffix_match = true; |
458 } | 459 } |
459 | 460 |
460 std::vector<std::string> no_affiliated_android_realms; | 461 std::vector<std::string> no_affiliated_android_realms; |
461 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( | 462 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( |
462 observed_form, no_affiliated_android_realms); | 463 observed_form, no_affiliated_android_realms); |
463 | 464 |
464 EXPECT_CALL(mock_consumer, | 465 EXPECT_CALL(mock_consumer, |
465 OnGetPasswordStoreResultsConstRef( | 466 OnGetPasswordStoreResultsConstRef( |
466 UnorderedPasswordFormElementsAre(expected_results.get()))); | 467 UnorderedPasswordFormElementsAre(expected_results.get()))); |
467 store->GetLogins(observed_form, &mock_consumer); | 468 store->GetLogins(observed_form, &mock_consumer); |
468 store->ShutdownOnUIThread(); | 469 store->ShutdownOnUIThread(); |
469 base::MessageLoop::current()->RunUntilIdle(); | 470 base::RunLoop().RunUntilIdle(); |
470 } | 471 } |
471 | 472 |
472 // There are 3 Android applications affiliated with the realm of the observed | 473 // There are 3 Android applications affiliated with the realm of the observed |
473 // form, with the PasswordStore having credentials for two of these (even two | 474 // form, with the PasswordStore having credentials for two of these (even two |
474 // credentials for one). GetLoginsWithAffiliations() should return the exact, | 475 // credentials for one). GetLoginsWithAffiliations() should return the exact, |
475 // and PSL matching credentials, and the credentials for these two Android | 476 // and PSL matching credentials, and the credentials for these two Android |
476 // applications, but not for the unaffiliated Android application. | 477 // applications, but not for the unaffiliated Android application. |
477 TEST_F(PasswordStoreTest, GetLoginsWithAffiliations) { | 478 TEST_F(PasswordStoreTest, GetLoginsWithAffiliations) { |
478 /* clang-format off */ | 479 /* clang-format off */ |
479 static const PasswordFormData kTestCredentials[] = { | 480 static const PasswordFormData kTestCredentials[] = { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 store->Init(syncer::SyncableService::StartSyncFlare()); | 540 store->Init(syncer::SyncableService::StartSyncFlare()); |
540 | 541 |
541 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 542 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; |
542 store->SetAffiliatedMatchHelper(base::WrapUnique(mock_helper)); | 543 store->SetAffiliatedMatchHelper(base::WrapUnique(mock_helper)); |
543 | 544 |
544 ScopedVector<PasswordForm> all_credentials; | 545 ScopedVector<PasswordForm> all_credentials; |
545 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) { | 546 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) { |
546 all_credentials.push_back( | 547 all_credentials.push_back( |
547 CreatePasswordFormFromDataForTesting(kTestCredentials[i])); | 548 CreatePasswordFormFromDataForTesting(kTestCredentials[i])); |
548 store->AddLogin(*all_credentials.back()); | 549 store->AddLogin(*all_credentials.back()); |
549 base::MessageLoop::current()->RunUntilIdle(); | 550 base::RunLoop().RunUntilIdle(); |
550 } | 551 } |
551 | 552 |
552 PasswordForm observed_form; | 553 PasswordForm observed_form; |
553 observed_form.scheme = PasswordForm::SCHEME_HTML; | 554 observed_form.scheme = PasswordForm::SCHEME_HTML; |
554 observed_form.origin = GURL(kTestWebOrigin1); | 555 observed_form.origin = GURL(kTestWebOrigin1); |
555 observed_form.ssl_valid = true; | 556 observed_form.ssl_valid = true; |
556 observed_form.signon_realm = kTestWebRealm1; | 557 observed_form.signon_realm = kTestWebRealm1; |
557 | 558 |
558 MockPasswordStoreConsumer mock_consumer; | 559 MockPasswordStoreConsumer mock_consumer; |
559 ScopedVector<PasswordForm> expected_results; | 560 ScopedVector<PasswordForm> expected_results; |
(...skipping 17 matching lines...) Expand all Loading... |
577 affiliated_android_realms.push_back(kTestAndroidRealm3); | 578 affiliated_android_realms.push_back(kTestAndroidRealm3); |
578 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( | 579 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( |
579 observed_form, affiliated_android_realms); | 580 observed_form, affiliated_android_realms); |
580 | 581 |
581 EXPECT_CALL(mock_consumer, | 582 EXPECT_CALL(mock_consumer, |
582 OnGetPasswordStoreResultsConstRef( | 583 OnGetPasswordStoreResultsConstRef( |
583 UnorderedPasswordFormElementsAre(expected_results.get()))); | 584 UnorderedPasswordFormElementsAre(expected_results.get()))); |
584 | 585 |
585 store->GetLogins(observed_form, &mock_consumer); | 586 store->GetLogins(observed_form, &mock_consumer); |
586 store->ShutdownOnUIThread(); | 587 store->ShutdownOnUIThread(); |
587 base::MessageLoop::current()->RunUntilIdle(); | 588 base::RunLoop().RunUntilIdle(); |
588 } | 589 } |
589 | 590 |
590 // This test must use passwords, which are not stored on Mac, therefore the test | 591 // This test must use passwords, which are not stored on Mac, therefore the test |
591 // is disabled on Mac. This should not be a huge issue as functionality in the | 592 // is disabled on Mac. This should not be a huge issue as functionality in the |
592 // platform-independent base class is tested. See also the file-level comment. | 593 // platform-independent base class is tested. See also the file-level comment. |
593 #if defined(OS_MACOSX) | 594 #if defined(OS_MACOSX) |
594 #define MAYBE_UpdatePasswordsStoredForAffiliatedWebsites \ | 595 #define MAYBE_UpdatePasswordsStoredForAffiliatedWebsites \ |
595 DISABLED_UpdatePasswordsStoredForAffiliatedWebsites | 596 DISABLED_UpdatePasswordsStoredForAffiliatedWebsites |
596 #else | 597 #else |
597 #define MAYBE_UpdatePasswordsStoredForAffiliatedWebsites \ | 598 #define MAYBE_UpdatePasswordsStoredForAffiliatedWebsites \ |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 base::Closure()); | 730 base::Closure()); |
730 | 731 |
731 // Set up the initial test data set. | 732 // Set up the initial test data set. |
732 ScopedVector<PasswordForm> all_credentials; | 733 ScopedVector<PasswordForm> all_credentials; |
733 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) { | 734 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) { |
734 all_credentials.push_back( | 735 all_credentials.push_back( |
735 CreatePasswordFormFromDataForTesting(kTestCredentials[i])); | 736 CreatePasswordFormFromDataForTesting(kTestCredentials[i])); |
736 all_credentials.back()->date_synced = | 737 all_credentials.back()->date_synced = |
737 all_credentials.back()->date_created; | 738 all_credentials.back()->date_created; |
738 store->AddLogin(*all_credentials.back()); | 739 store->AddLogin(*all_credentials.back()); |
739 base::MessageLoop::current()->RunUntilIdle(); | 740 base::RunLoop().RunUntilIdle(); |
740 } | 741 } |
741 | 742 |
742 // The helper must be injected after the initial test data is set up, | 743 // The helper must be injected after the initial test data is set up, |
743 // otherwise it will already start propagating updates as new Android | 744 // otherwise it will already start propagating updates as new Android |
744 // credentials are added. | 745 // credentials are added. |
745 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 746 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; |
746 store->SetAffiliatedMatchHelper(base::WrapUnique(mock_helper)); | 747 store->SetAffiliatedMatchHelper(base::WrapUnique(mock_helper)); |
747 store->enable_propagating_password_changes_to_web_credentials( | 748 store->enable_propagating_password_changes_to_web_credentials( |
748 propagation_enabled); | 749 propagation_enabled); |
749 | 750 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 if (propagation_enabled) { | 785 if (propagation_enabled) { |
785 EXPECT_CALL(mock_observer, OnLoginsChanged(testing::SizeIs( | 786 EXPECT_CALL(mock_observer, OnLoginsChanged(testing::SizeIs( |
786 expected_number_of_propageted_updates))); | 787 expected_number_of_propageted_updates))); |
787 } | 788 } |
788 if (test_remove_and_add_login) { | 789 if (test_remove_and_add_login) { |
789 store->RemoveLoginSync(*all_credentials[0]); | 790 store->RemoveLoginSync(*all_credentials[0]); |
790 store->AddLoginSync(*expected_credentials_after_update[0]); | 791 store->AddLoginSync(*expected_credentials_after_update[0]); |
791 } else { | 792 } else { |
792 store->UpdateLoginSync(*expected_credentials_after_update[0]); | 793 store->UpdateLoginSync(*expected_credentials_after_update[0]); |
793 } | 794 } |
794 base::MessageLoop::current()->RunUntilIdle(); | 795 base::RunLoop().RunUntilIdle(); |
795 store->RemoveObserver(&mock_observer); | 796 store->RemoveObserver(&mock_observer); |
796 | 797 |
797 MockPasswordStoreConsumer mock_consumer; | 798 MockPasswordStoreConsumer mock_consumer; |
798 EXPECT_CALL( | 799 EXPECT_CALL( |
799 mock_consumer, | 800 mock_consumer, |
800 OnGetPasswordStoreResultsConstRef(UnorderedPasswordFormElementsAre( | 801 OnGetPasswordStoreResultsConstRef(UnorderedPasswordFormElementsAre( |
801 expected_credentials_after_update.get()))); | 802 expected_credentials_after_update.get()))); |
802 store->GetAutofillableLogins(&mock_consumer); | 803 store->GetAutofillableLogins(&mock_consumer); |
803 store->ShutdownOnUIThread(); | 804 store->ShutdownOnUIThread(); |
804 base::MessageLoop::current()->RunUntilIdle(); | 805 base::RunLoop().RunUntilIdle(); |
805 } | 806 } |
806 } | 807 } |
807 } | 808 } |
808 | 809 |
809 TEST_F(PasswordStoreTest, GetLoginsWithAffiliatedRealms) { | 810 TEST_F(PasswordStoreTest, GetLoginsWithAffiliatedRealms) { |
810 /* clang-format off */ | 811 /* clang-format off */ |
811 static const PasswordFormData kTestCredentials[] = { | 812 static const PasswordFormData kTestCredentials[] = { |
812 {PasswordForm::SCHEME_HTML, | 813 {PasswordForm::SCHEME_HTML, |
813 kTestAndroidRealm1, | 814 kTestAndroidRealm1, |
814 "", "", L"", L"", L"", | 815 "", "", L"", L"", L"", |
(...skipping 22 matching lines...) Expand all Loading... |
837 store->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max(), | 838 store->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max(), |
838 base::Closure()); | 839 base::Closure()); |
839 | 840 |
840 ScopedVector<PasswordForm> all_credentials; | 841 ScopedVector<PasswordForm> all_credentials; |
841 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) { | 842 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) { |
842 all_credentials.push_back( | 843 all_credentials.push_back( |
843 CreatePasswordFormFromDataForTesting(kTestCredentials[i])); | 844 CreatePasswordFormFromDataForTesting(kTestCredentials[i])); |
844 if (blacklisted) | 845 if (blacklisted) |
845 all_credentials.back()->blacklisted_by_user = true; | 846 all_credentials.back()->blacklisted_by_user = true; |
846 store->AddLogin(*all_credentials.back()); | 847 store->AddLogin(*all_credentials.back()); |
847 base::MessageLoop::current()->RunUntilIdle(); | 848 base::RunLoop().RunUntilIdle(); |
848 } | 849 } |
849 | 850 |
850 MockPasswordStoreConsumer mock_consumer; | 851 MockPasswordStoreConsumer mock_consumer; |
851 ScopedVector<PasswordForm> expected_results; | 852 ScopedVector<PasswordForm> expected_results; |
852 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) | 853 for (size_t i = 0; i < arraysize(kTestCredentials); ++i) |
853 expected_results.push_back(new PasswordForm(*all_credentials[i])); | 854 expected_results.push_back(new PasswordForm(*all_credentials[i])); |
854 | 855 |
855 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 856 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; |
856 store->SetAffiliatedMatchHelper(base::WrapUnique(mock_helper)); | 857 store->SetAffiliatedMatchHelper(base::WrapUnique(mock_helper)); |
857 | 858 |
858 std::vector<std::string> affiliated_web_realms; | 859 std::vector<std::string> affiliated_web_realms; |
859 affiliated_web_realms.push_back(kTestWebRealm1); | 860 affiliated_web_realms.push_back(kTestWebRealm1); |
860 affiliated_web_realms.push_back(kTestWebRealm2); | 861 affiliated_web_realms.push_back(kTestWebRealm2); |
861 affiliated_web_realms.push_back(std::string()); | 862 affiliated_web_realms.push_back(std::string()); |
862 mock_helper->ExpectCallToInjectAffiliatedWebRealms(affiliated_web_realms); | 863 mock_helper->ExpectCallToInjectAffiliatedWebRealms(affiliated_web_realms); |
863 for (size_t i = 0; i < expected_results.size(); ++i) | 864 for (size_t i = 0; i < expected_results.size(); ++i) |
864 expected_results[i]->affiliated_web_realm = affiliated_web_realms[i]; | 865 expected_results[i]->affiliated_web_realm = affiliated_web_realms[i]; |
865 | 866 |
866 EXPECT_CALL(mock_consumer, | 867 EXPECT_CALL(mock_consumer, |
867 OnGetPasswordStoreResultsConstRef( | 868 OnGetPasswordStoreResultsConstRef( |
868 UnorderedPasswordFormElementsAre(expected_results.get()))); | 869 UnorderedPasswordFormElementsAre(expected_results.get()))); |
869 if (blacklisted) | 870 if (blacklisted) |
870 store->GetBlacklistLoginsWithAffiliatedRealms(&mock_consumer); | 871 store->GetBlacklistLoginsWithAffiliatedRealms(&mock_consumer); |
871 else | 872 else |
872 store->GetAutofillableLoginsWithAffiliatedRealms(&mock_consumer); | 873 store->GetAutofillableLoginsWithAffiliatedRealms(&mock_consumer); |
873 | 874 |
874 // Since GetAutofillableLoginsWithAffiliatedRealms schedules a request for | 875 // Since GetAutofillableLoginsWithAffiliatedRealms schedules a request for |
875 // affiliated realms to UI thread, don't shutdown UI thread until there are | 876 // affiliated realms to UI thread, don't shutdown UI thread until there are |
876 // no tasks in the UI queue. | 877 // no tasks in the UI queue. |
877 base::MessageLoop::current()->RunUntilIdle(); | 878 base::RunLoop().RunUntilIdle(); |
878 store->ShutdownOnUIThread(); | 879 store->ShutdownOnUIThread(); |
879 base::MessageLoop::current()->RunUntilIdle(); | 880 base::RunLoop().RunUntilIdle(); |
880 } | 881 } |
881 } | 882 } |
882 | 883 |
883 } // namespace password_manager | 884 } // namespace password_manager |
OLD | NEW |