Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Unified Diff: components/password_manager/core/browser/password_manager_unittest.cc

Issue 2915763003: [Password Manager] Show omnibox icon and anchored prompt once user start typing password (Closed)
Patch Set: Changes addressed to vasilii@ comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698