Chromium Code Reviews| Index: components/password_manager/core/browser/password_manager_unittest.cc |
| diff --git a/components/password_manager/core/browser/password_manager_unittest.cc b/components/password_manager/core/browser/password_manager_unittest.cc |
| index 485458a8e53627ea0d14efd9b350420429ff5f05..156312a2c59ec5952818f8283a55680d35011cc1 100644 |
| --- a/components/password_manager/core/browser/password_manager_unittest.cc |
| +++ b/components/password_manager/core/browser/password_manager_unittest.cc |
| @@ -62,9 +62,12 @@ class MockPasswordManagerClient : public StubPasswordManagerClient { |
| MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); |
| MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
| MOCK_CONST_METHOD0(GetPasswordStore, PasswordStore*()); |
| - // The code inside EXPECT_CALL for PromptUserToSaveOrUpdatePasswordPtr owns |
| - // the PasswordFormManager* argument. |
| + // The code inside EXPECT_CALL for PromptUserToSaveOrUpdatePasswordPtr and |
| + // ShowManualFallbackForSavingPtr owns the PasswordFormManager* argument. |
| MOCK_METHOD1(PromptUserToSaveOrUpdatePasswordPtr, void(PasswordFormManager*)); |
| + MOCK_METHOD2(ShowManualFallbackForSavingPtr, |
| + void(PasswordFormManager*, bool)); |
| + MOCK_METHOD0(HideManualFallbackForSaving, void()); |
| MOCK_METHOD1(NotifySuccessfulLoginWithExistingPassword, |
| void(const autofill::PasswordForm&)); |
| MOCK_METHOD0(AutomaticPasswordSaveIndicator, void()); |
| @@ -80,6 +83,10 @@ class MockPasswordManagerClient : public StubPasswordManagerClient { |
| PromptUserToSaveOrUpdatePasswordPtr(manager.release()); |
| return false; |
| } |
| + void ShowManualFallbackForSaving(std::unique_ptr<PasswordFormManager> manager, |
| + bool is_update) override { |
| + ShowManualFallbackForSavingPtr(manager.release(), is_update); |
| + } |
| void AutomaticPasswordSave( |
| std::unique_ptr<PasswordFormManager> manager) override { |
| AutomaticPasswordSaveIndicator(); |
| @@ -113,6 +120,10 @@ ACTION(InvokeEmptyConsumerWithForms) { |
| ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } |
| +ACTION_P(SaveConsumerToList, list) { |
| + list->push_back(arg0); |
| +} |
| + |
| } // namespace |
| class PasswordManagerTest : public testing::Test { |
| @@ -1809,4 +1820,72 @@ TEST_F(PasswordManagerTest, NotSavingSyncPasswordHash_NotSyncCredentials) { |
| } |
| #endif |
| +TEST_F(PasswordManagerTest, ManualFallbackForSaving) { |
| + EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
| + .WillRepeatedly(Return(true)); |
| + |
| + std::vector<PasswordForm> observed; |
| + PasswordForm form(MakeSimpleForm()); |
| + observed.push_back(form); |
| + PasswordForm stored_form = form; |
| + stored_form.password_value = ASCIIToUTF16("old_password"); |
| + EXPECT_CALL(*store_, GetLogins(_, _)) |
| + .WillRepeatedly(WithArg<1>(InvokeConsumer(stored_form))); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); |
| + manager()->OnPasswordFormsParsed(&driver_, observed); |
| + manager()->OnPasswordFormsRendered(&driver_, observed, true); |
| + |
| + // The username of the stored form is the same, there should be update bubble. |
| + std::unique_ptr<PasswordFormManager> form_manager_to_save; |
| + EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, true)) |
| + .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
| + manager()->ShowManualFallbackForSaving(&driver_, form); |
| + ASSERT_TRUE(form_manager_to_save); |
| + EXPECT_THAT(form, FormMatches(*form_manager_to_save->submitted_form())); |
| + |
| + // The username of the stored form is different, there should be save bubble. |
| + PasswordForm new_form = form; |
| + new_form.username_value = ASCIIToUTF16("another_username"); |
| + EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false)) |
| + .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
| + manager()->ShowManualFallbackForSaving(&driver_, new_form); |
| + ASSERT_TRUE(form_manager_to_save); |
| + EXPECT_THAT(new_form, FormMatches(*form_manager_to_save->submitted_form())); |
|
vasilii
2017/07/25 11:17:47
Check pending_credentials(). The UI is entirely ba
kolos1
2017/07/26 13:40:57
Done.
|
| + |
| + // Hide the manual fallback. |
| + EXPECT_CALL(client_, HideManualFallbackForSaving()); |
| + manager()->HideManualFallbackForSaving(); |
| +} |
| + |
| +// Tests that the manual fallback for saving isn't shown if there is no response |
| +// from the password storage. When crbug.com/741537 is fixed, change this test. |
| +TEST_F(PasswordManagerTest, ManualFallbackForSaving_SlowBackend) { |
| + EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
| + .WillRepeatedly(Return(true)); |
| + |
| + std::vector<PasswordForm> observed; |
| + PasswordForm form(MakeSimpleForm()); |
| + observed.push_back(form); |
| + std::vector<PasswordStoreConsumer*> consumers; |
| + EXPECT_CALL(*store_, GetLogins(_, _)) |
| + .WillRepeatedly(WithArg<1>(SaveConsumerToList(&consumers))); |
| + manager()->OnPasswordFormsParsed(&driver_, observed); |
| + manager()->OnPasswordFormsRendered(&driver_, observed, true); |
| + |
| + // There is no response from the store. Don't show the fallback. |
| + EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, _)).Times(0); |
| + manager()->ShowManualFallbackForSaving(&driver_, form); |
| + |
| + // The storage responded. The fallback can be shown. |
| + for (PasswordStoreConsumer* consumer : consumers) { |
| + ASSERT_TRUE(consumer); |
| + consumer->OnGetPasswordStoreResults( |
| + std::vector<std::unique_ptr<PasswordForm>>()); |
| + } |
| + std::unique_ptr<PasswordFormManager> form_manager_to_save; |
| + EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false)) |
| + .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
| + manager()->ShowManualFallbackForSaving(&driver_, form); |
| +} |
| + |
| } // namespace password_manager |