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..3bad6938ceacda6ba0114290d808ebaea8727367 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_METHOD3(ShowManualFallbackForSavingPtr, |
+ void(PasswordFormManager*, bool, bool)); |
+ MOCK_METHOD0(HideManualFallbackForSaving, void()); |
MOCK_METHOD1(NotifySuccessfulLoginWithExistingPassword, |
void(const autofill::PasswordForm&)); |
MOCK_METHOD0(AutomaticPasswordSaveIndicator, void()); |
@@ -80,6 +83,12 @@ class MockPasswordManagerClient : public StubPasswordManagerClient { |
PromptUserToSaveOrUpdatePasswordPtr(manager.release()); |
return false; |
} |
+ void ShowManualFallbackForSaving(std::unique_ptr<PasswordFormManager> manager, |
+ bool has_generated_password, |
+ bool is_update) override { |
+ ShowManualFallbackForSavingPtr(manager.release(), has_generated_password, |
+ is_update); |
+ } |
void AutomaticPasswordSave( |
std::unique_ptr<PasswordFormManager> manager) override { |
AutomaticPasswordSaveIndicator(); |
@@ -1809,4 +1818,70 @@ 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(_, _)) |
+ .WillOnce(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(_, false, true)) |
+ .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
+ manager()->ShowManualFallbackForSaving(&driver_, form); |
+ ASSERT_TRUE(form_manager_to_save); |
+ EXPECT_THAT(form_manager_to_save->pending_credentials(), FormMatches(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, false)) |
+ .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
+ manager()->ShowManualFallbackForSaving(&driver_, new_form); |
+ ASSERT_TRUE(form_manager_to_save); |
+ EXPECT_THAT(form_manager_to_save->pending_credentials(), |
+ FormMatches(new_form)); |
+ |
+ // 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); |
+ PasswordStoreConsumer* store_consumer = nullptr; |
+ EXPECT_CALL(*store_, GetLogins(_, _)).WillOnce(SaveArg<1>(&store_consumer)); |
+ 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. |
+ ASSERT_TRUE(store_consumer); |
+ store_consumer->OnGetPasswordStoreResults( |
+ std::vector<std::unique_ptr<PasswordForm>>()); |
+ std::unique_ptr<PasswordFormManager> form_manager_to_save; |
+ EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false, false)) |
+ .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
+ manager()->ShowManualFallbackForSaving(&driver_, form); |
+} |
+ |
vasilii
2017/08/03 10:46:37
How about a test for the generation scenario?
kolos1
2017/08/04 16:36:18
Done.
|
} // namespace password_manager |