| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/password_manager/mock_password_store.h" | 10 #include "chrome/browser/password_manager/mock_password_store.h" |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 EXPECT_CALL(driver_, FillPasswordForm(_)); | 505 EXPECT_CALL(driver_, FillPasswordForm(_)); |
| 506 EXPECT_CALL(*store_.get(), | 506 EXPECT_CALL(*store_.get(), |
| 507 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) | 507 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
| 508 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 508 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 509 std::vector<PasswordForm> observed; | 509 std::vector<PasswordForm> observed; |
| 510 PasswordForm form(MakeSimpleForm()); | 510 PasswordForm form(MakeSimpleForm()); |
| 511 observed.push_back(form); | 511 observed.push_back(form); |
| 512 manager()->OnPasswordFormsParsed(observed); | 512 manager()->OnPasswordFormsParsed(observed); |
| 513 } | 513 } |
| 514 | 514 |
| 515 TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) { | 515 TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { |
| 516 // Test password form with non-generated password will not be saved if | 516 // Test password form with non-generated password will be saved even if |
| 517 // autocomplete=off. | 517 // autocomplete=off. |
| 518 std::vector<PasswordForm*> result; // Empty password store. | 518 std::vector<PasswordForm*> result; // Empty password store. |
| 519 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 519 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 520 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 520 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 521 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 521 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 522 std::vector<PasswordForm> observed; | 522 std::vector<PasswordForm> observed; |
| 523 PasswordForm form(MakeSimpleForm()); | 523 PasswordForm form(MakeSimpleForm()); |
| 524 form.password_autocomplete_set = false; | 524 form.password_autocomplete_set = false; |
| 525 observed.push_back(form); | 525 observed.push_back(form); |
| 526 manager()->OnPasswordFormsParsed(observed); // The initial load. | 526 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 527 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 527 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
| 528 | 528 |
| 529 // And the form submit contract is to call ProvisionallySavePassword. | 529 // And the form submit contract is to call ProvisionallySavePassword. |
| 530 manager()->ProvisionallySavePassword(form); | 530 manager()->ProvisionallySavePassword(form); |
| 531 | 531 |
| 532 // Password form should not be saved. | 532 // Password form should be saved. |
| 533 scoped_ptr<PasswordFormManager> form_to_save; |
| 533 EXPECT_CALL(delegate_, | 534 EXPECT_CALL(delegate_, |
| 534 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); | 535 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(1)) |
| 536 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
| 535 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 537 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
| 536 | 538 |
| 537 // Now the password manager waits for the navigation to complete. | 539 // Now the password manager waits for the navigation to complete. |
| 538 observed.clear(); | 540 observed.clear(); |
| 539 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 541 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 540 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 542 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
| 543 |
| 544 ASSERT_TRUE(form_to_save.get()); |
| 541 } | 545 } |
| 542 | 546 |
| 543 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { | 547 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
| 544 // Test password form with generated password will still be saved if | 548 // Test password form with generated password will still be saved if |
| 545 // autocomplete=off. | 549 // autocomplete=off. |
| 546 std::vector<PasswordForm*> result; // Empty password store. | 550 std::vector<PasswordForm*> result; // Empty password store. |
| 547 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 551 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 548 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 552 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 549 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 553 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 550 std::vector<PasswordForm> observed; | 554 std::vector<PasswordForm> observed; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 manager()->ProvisionallySavePassword(login_form); | 600 manager()->ProvisionallySavePassword(login_form); |
| 597 | 601 |
| 598 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); | 602 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); |
| 599 observed.clear(); | 603 observed.clear(); |
| 600 observed.push_back(failed_login_form); | 604 observed.push_back(failed_login_form); |
| 601 // A PasswordForm appears, and is visible in the layout: | 605 // A PasswordForm appears, and is visible in the layout: |
| 602 // No expected calls to the PasswordStore... | 606 // No expected calls to the PasswordStore... |
| 603 manager()->OnPasswordFormsParsed(observed); | 607 manager()->OnPasswordFormsParsed(observed); |
| 604 manager()->OnPasswordFormsRendered(observed); | 608 manager()->OnPasswordFormsRendered(observed); |
| 605 } | 609 } |
| OLD | NEW |