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 f1b5e33ce24ba12a7385d04781543c7a553ca038..25724c04be4abea5c64ed8e65c473e3633e1c443 100644 |
--- a/components/password_manager/core/browser/password_manager_unittest.cc |
+++ b/components/password_manager/core/browser/password_manager_unittest.cc |
@@ -45,10 +45,21 @@ class MockPasswordManagerClient : public StubPasswordManagerClient { |
MOCK_CONST_METHOD0(IsPasswordManagerEnabledForCurrentPage, bool()); |
MOCK_CONST_METHOD2(IsSyncAccountCredential, |
bool(const std::string&, const std::string&)); |
- MOCK_METHOD1(PromptUserToSavePassword, void(PasswordFormManager*)); |
+ MOCK_METHOD1(PromptUserToSavePasswordPtr, void(PasswordFormManager*)); |
+ MOCK_METHOD1(AutomaticPasswordSavePtr, void(PasswordFormManager*)); |
MOCK_METHOD0(GetPasswordStore, PasswordStore*()); |
MOCK_METHOD0(GetPrefs, PrefService*()); |
MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); |
+ |
+ // Workaround for scoped_ptr<> lacking a copy constructor. |
+ virtual void PromptUserToSavePassword( |
+ scoped_ptr<PasswordFormManager> manager) OVERRIDE { |
+ PromptUserToSavePasswordPtr(manager.release()); |
+ } |
+ virtual void AutomaticPasswordSave( |
+ scoped_ptr<PasswordFormManager> manager) OVERRIDE { |
+ AutomaticPasswordSavePtr(manager.release()); |
+ } |
}; |
class MockPasswordManagerDriver : public StubPasswordManagerDriver { |
@@ -238,7 +249,7 @@ TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
manager()->ProvisionallySavePassword(form); |
scoped_ptr<PasswordFormManager> form_to_save; |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
.WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
// Now the password manager waits for the navigation to complete. |
@@ -272,7 +283,7 @@ TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) { |
manager()->ProvisionallySavePassword(form); |
scoped_ptr<PasswordFormManager> form_to_save; |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
.WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
// Now the password manager waits for the navigation to complete. |
@@ -318,9 +329,11 @@ TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
// The user should not be presented with an infobar as they have already given |
// consent by using the generated password. The form should be saved once |
- // navigation occurs. |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); |
+ // navigation occurs. The client will be informed that automatic saving has |
+ // occured. |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); |
EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
+ EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)).Times(Exactly(1)); |
// Now the password manager waits for the navigation to complete. |
observed.clear(); |
@@ -350,7 +363,7 @@ TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
// We still expect an add, since we didn't have a good match. |
scoped_ptr<PasswordFormManager> form_to_save; |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
.WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
// Now the password manager waits for the navigation to complete. |
@@ -379,7 +392,7 @@ TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
// No message from the renderer that a password was submitted. No |
// expected calls. |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(0); |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0); |
observed.clear(); |
manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
manager()->OnPasswordFormsRendered(observed, |
@@ -407,7 +420,7 @@ TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { |
// Now the password manager waits for the navigation to complete. |
scoped_ptr<PasswordFormManager> form_to_save; |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
.WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
observed.clear(); |
@@ -458,7 +471,7 @@ TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
// Navigation after form submit. |
scoped_ptr<PasswordFormManager> form_to_save; |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
.WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
observed.clear(); |
manager()->OnPasswordFormsParsed(observed); |
@@ -508,7 +521,7 @@ TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
// Expect info bar to appear: |
scoped_ptr<PasswordFormManager> form_to_save; |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
.WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
// The form reappears, but is not visible in the layout: |
@@ -591,8 +604,8 @@ TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { |
// Password form should be saved. |
scoped_ptr<PasswordFormManager> form_to_save; |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(1)).WillOnce( |
- WithArg<0>(SaveToScopedPtr(&form_to_save))); |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(1)) |
+ .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
// Now the password manager waits for the navigation to complete. |
@@ -624,9 +637,11 @@ TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
// The user should not be presented with an infobar as they have already given |
// consent by using the generated password. The form should be saved once |
- // navigation occurs. |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); |
+ // navigation occurs. The client will be informed that automatic saving has |
+ // occured. |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); |
EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
+ EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)).Times(Exactly(1)); |
// Now the password manager waits for the navigation to complete. |
observed.clear(); |
@@ -727,7 +742,7 @@ TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { |
manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
// User should not be prompted and password should not be saved. |
- EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); |
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); |
EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
// Submit form and finish navigation. |