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 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 TEST_F(PasswordFormManagerTest, TestAlternateUsername) { | 373 TEST_F(PasswordFormManagerTest, TestAlternateUsername) { |
374 // Need a MessageLoop for callbacks. | 374 // Need a MessageLoop for callbacks. |
375 base::MessageLoop message_loop; | 375 base::MessageLoop message_loop; |
376 scoped_refptr<TestPasswordStore> password_store = new TestPasswordStore; | 376 scoped_refptr<TestPasswordStore> password_store = new TestPasswordStore; |
377 CHECK(password_store->Init(syncer::SyncableService::StartSyncFlare())); | 377 CHECK(password_store->Init(syncer::SyncableService::StartSyncFlare())); |
378 | 378 |
379 TestPasswordManagerClient client(password_store.get()); | 379 TestPasswordManagerClient client(password_store.get()); |
380 TestPasswordManager password_manager(&client); | 380 TestPasswordManager password_manager(&client); |
381 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( | 381 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( |
382 &password_manager, &client, client.GetDriver(), *observed_form(), false)); | 382 &password_manager, &client, client.GetDriver(), *observed_form(), false)); |
| 383 EXPECT_CALL(*client.GetMockDriver(), AllowPasswordGenerationForForm(_)) |
| 384 .Times(1); |
| 385 EXPECT_CALL(*client.GetMockDriver(), IsOffTheRecord()) |
| 386 .WillRepeatedly(Return(false)); |
383 | 387 |
384 password_store->AddLogin(*saved_match()); | 388 password_store->AddLogin(*saved_match()); |
385 manager->FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); | 389 manager->FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); |
386 RunAllPendingTasks(); | 390 RunAllPendingTasks(); |
387 | 391 |
388 // The saved match has the right username already. | 392 // The saved match has the right username already. |
389 PasswordForm login(*observed_form()); | 393 PasswordForm login(*observed_form()); |
390 login.username_value = saved_match()->username_value; | 394 login.username_value = saved_match()->username_value; |
391 login.password_value = saved_match()->password_value; | 395 login.password_value = saved_match()->password_value; |
392 login.preferred = true; | 396 login.preferred = true; |
(...skipping 11 matching lines...) Expand all Loading... |
404 ASSERT_EQ(1U, passwords[saved_match()->signon_realm].size()); | 408 ASSERT_EQ(1U, passwords[saved_match()->signon_realm].size()); |
405 EXPECT_EQ(saved_match()->username_value, | 409 EXPECT_EQ(saved_match()->username_value, |
406 passwords[saved_match()->signon_realm][0].username_value); | 410 passwords[saved_match()->signon_realm][0].username_value); |
407 EXPECT_EQ(0U, | 411 EXPECT_EQ(0U, |
408 passwords[saved_match()->signon_realm][0] | 412 passwords[saved_match()->signon_realm][0] |
409 .other_possible_usernames.size()); | 413 .other_possible_usernames.size()); |
410 | 414 |
411 // This time use an alternate username | 415 // This time use an alternate username |
412 manager.reset(new PasswordFormManager( | 416 manager.reset(new PasswordFormManager( |
413 &password_manager, &client, client.GetDriver(), *observed_form(), false)); | 417 &password_manager, &client, client.GetDriver(), *observed_form(), false)); |
| 418 EXPECT_CALL(*client.GetMockDriver(), AllowPasswordGenerationForForm(_)) |
| 419 .Times(1); |
414 password_store->Clear(); | 420 password_store->Clear(); |
415 password_store->AddLogin(*saved_match()); | 421 password_store->AddLogin(*saved_match()); |
416 manager->FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); | 422 manager->FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); |
417 RunAllPendingTasks(); | 423 RunAllPendingTasks(); |
418 | 424 |
419 base::string16 new_username = saved_match()->other_possible_usernames[0]; | 425 base::string16 new_username = saved_match()->other_possible_usernames[0]; |
420 login.username_value = new_username; | 426 login.username_value = new_username; |
421 manager->ProvisionallySave( | 427 manager->ProvisionallySave( |
422 login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES); | 428 login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES); |
423 | 429 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 SimulateResponseFromPasswordStore(manager.get(), result); | 528 SimulateResponseFromPasswordStore(manager.get(), result); |
523 Mock::VerifyAndClearExpectations(client.GetMockDriver()); | 529 Mock::VerifyAndClearExpectations(client.GetMockDriver()); |
524 | 530 |
525 // Sign up attempt to previously visited sites; Login result is found from | 531 // Sign up attempt to previously visited sites; Login result is found from |
526 // password store, and is not blacklisted; We should send the not blacklisted | 532 // password store, and is not blacklisted; We should send the not blacklisted |
527 // message. | 533 // message. |
528 manager.reset(new PasswordFormManager( | 534 manager.reset(new PasswordFormManager( |
529 &password_manager, &client, client.GetDriver(), *observed_form(), false)); | 535 &password_manager, &client, client.GetDriver(), *observed_form(), false)); |
530 EXPECT_CALL(*client.GetMockDriver(), AllowPasswordGenerationForForm(_)) | 536 EXPECT_CALL(*client.GetMockDriver(), AllowPasswordGenerationForForm(_)) |
531 .Times(1); | 537 .Times(1); |
| 538 EXPECT_CALL(*client.GetMockDriver(), IsOffTheRecord()) |
| 539 .WillRepeatedly(Return(false)); |
532 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); | 540 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); |
533 // We need add heap allocated objects to result. | 541 // We need add heap allocated objects to result. |
534 result.push_back(CreateSavedMatch(false)); | 542 result.push_back(CreateSavedMatch(false)); |
535 SimulateResponseFromPasswordStore(manager.get(), result); | 543 SimulateResponseFromPasswordStore(manager.get(), result); |
536 Mock::VerifyAndClearExpectations(client.GetMockDriver()); | 544 Mock::VerifyAndClearExpectations(client.GetMockDriver()); |
537 | 545 |
538 // Sign up attempt to previously visited sites; Login result is found from | 546 // Sign up attempt to previously visited sites; Login result is found from |
539 // password store, but is blacklisted; We should not send the not blacklisted | 547 // password store, but is blacklisted; We should not send the not blacklisted |
540 // message. | 548 // message. |
541 manager.reset(new PasswordFormManager( | 549 manager.reset(new PasswordFormManager( |
542 &password_manager, &client, client.GetDriver(), *observed_form(), false)); | 550 &password_manager, &client, client.GetDriver(), *observed_form(), false)); |
543 EXPECT_CALL(*client.GetMockDriver(), AllowPasswordGenerationForForm(_)) | 551 EXPECT_CALL(*client.GetMockDriver(), AllowPasswordGenerationForForm(_)) |
544 .Times(0); | 552 .Times(0); |
545 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); | 553 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); |
546 result.clear(); | 554 result.clear(); |
547 result.push_back(CreateSavedMatch(true)); | 555 result.push_back(CreateSavedMatch(true)); |
548 SimulateResponseFromPasswordStore(manager.get(), result); | 556 SimulateResponseFromPasswordStore(manager.get(), result); |
549 Mock::VerifyAndClearExpectations(client.GetMockDriver()); | 557 Mock::VerifyAndClearExpectations(client.GetMockDriver()); |
550 } | 558 } |
551 | 559 |
552 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) { | 560 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) { |
553 base::MessageLoop message_loop; | 561 base::MessageLoop message_loop; |
554 | 562 |
555 TestPasswordManagerClient client(NULL); | 563 TestPasswordManagerClient client(NULL); |
556 TestPasswordManager password_manager(&client); | 564 TestPasswordManager password_manager(&client); |
557 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( | 565 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( |
558 &password_manager, &client, client.GetDriver(), *observed_form(), false)); | 566 &password_manager, &client, client.GetDriver(), *observed_form(), false)); |
| 567 EXPECT_CALL(*client.GetMockDriver(), AllowPasswordGenerationForForm(_)) |
| 568 .Times(1); |
| 569 EXPECT_CALL(*client.GetMockDriver(), IsOffTheRecord()) |
| 570 .WillRepeatedly(Return(false)); |
559 | 571 |
560 // Simulate having two matches for this origin, one of which was from a form | 572 // Simulate having two matches for this origin, one of which was from a form |
561 // with different HTML tags for elements. Because of scoring differences, | 573 // with different HTML tags for elements. Because of scoring differences, |
562 // only the first form will be sent to Autofill(). | 574 // only the first form will be sent to Autofill(). |
563 std::vector<PasswordForm*> results; | 575 std::vector<PasswordForm*> results; |
564 results.push_back(CreateSavedMatch(false)); | 576 results.push_back(CreateSavedMatch(false)); |
565 results.push_back(CreateSavedMatch(false)); | 577 results.push_back(CreateSavedMatch(false)); |
566 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); | 578 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); |
567 results[1]->password_element = ASCIIToUTF16("signup_password"); | 579 results[1]->password_element = ASCIIToUTF16("signup_password"); |
568 results[1]->username_element = ASCIIToUTF16("signup_username"); | 580 results[1]->username_element = ASCIIToUTF16("signup_username"); |
569 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); | 581 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); |
570 SimulateResponseFromPasswordStore(manager.get(), results); | 582 SimulateResponseFromPasswordStore(manager.get(), results); |
571 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); | 583 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); |
572 results.clear(); | 584 results.clear(); |
573 | 585 |
574 // Same thing, except this time the credentials that don't match quite as | 586 // Same thing, except this time the credentials that don't match quite as |
575 // well are generated. They should now be sent to Autofill(). | 587 // well are generated. They should now be sent to Autofill(). |
576 manager.reset(new PasswordFormManager( | 588 manager.reset(new PasswordFormManager( |
577 &password_manager, &client, client.GetDriver(), *observed_form(), false)); | 589 &password_manager, &client, client.GetDriver(), *observed_form(), false)); |
| 590 EXPECT_CALL(*client.GetMockDriver(), AllowPasswordGenerationForForm(_)) |
| 591 .Times(1); |
| 592 |
578 results.push_back(CreateSavedMatch(false)); | 593 results.push_back(CreateSavedMatch(false)); |
579 results.push_back(CreateSavedMatch(false)); | 594 results.push_back(CreateSavedMatch(false)); |
580 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); | 595 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); |
581 results[1]->password_element = ASCIIToUTF16("signup_password"); | 596 results[1]->password_element = ASCIIToUTF16("signup_password"); |
582 results[1]->username_element = ASCIIToUTF16("signup_username"); | 597 results[1]->username_element = ASCIIToUTF16("signup_username"); |
583 results[1]->type = PasswordForm::TYPE_GENERATED; | 598 results[1]->type = PasswordForm::TYPE_GENERATED; |
584 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); | 599 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); |
585 SimulateResponseFromPasswordStore(manager.get(), results); | 600 SimulateResponseFromPasswordStore(manager.get(), results); |
586 EXPECT_EQ(2u, password_manager.GetLatestBestMatches().size()); | 601 EXPECT_EQ(2u, password_manager.GetLatestBestMatches().size()); |
587 } | 602 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 results[1]->origin = GURL("http://accounts.google.com/a/ServiceLoginAuth2"); | 726 results[1]->origin = GURL("http://accounts.google.com/a/ServiceLoginAuth2"); |
712 results[1]->action = GURL("http://accounts.google.com/a/ServiceLogin2"); | 727 results[1]->action = GURL("http://accounts.google.com/a/ServiceLogin2"); |
713 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); | 728 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); |
714 SimulateResponseFromPasswordStore(manager.get(), results); | 729 SimulateResponseFromPasswordStore(manager.get(), results); |
715 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); | 730 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); |
716 EXPECT_EQ("", password_manager.GetLatestBestMatches().begin() | 731 EXPECT_EQ("", password_manager.GetLatestBestMatches().begin() |
717 ->second->original_signon_realm); | 732 ->second->original_signon_realm); |
718 } | 733 } |
719 | 734 |
720 } // namespace password_manager | 735 } // namespace password_manager |
OLD | NEW |