Index: components/password_manager/core/browser/form_saver_impl_unittest.cc |
diff --git a/components/password_manager/core/browser/form_saver_impl_unittest.cc b/components/password_manager/core/browser/form_saver_impl_unittest.cc |
index 6a143b3c4573f48c448a73ca4d52dab72464f251..d626697ddcd40c2af4c4381272c14a69f8589375 100644 |
--- a/components/password_manager/core/browser/form_saver_impl_unittest.cc |
+++ b/components/password_manager/core/browser/form_saver_impl_unittest.cc |
@@ -4,12 +4,14 @@ |
#include "components/password_manager/core/browser/form_saver_impl.h" |
+#include <map> |
+#include <memory> |
#include <set> |
#include <vector> |
-#include "base/memory/ptr_util.h" |
#include "base/memory/ref_counted.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/strings/string16.h" |
#include "base/strings/string_piece.h" |
#include "base/strings/utf_string_conversions.h" |
#include "components/autofill/core/common/password_form.h" |
@@ -19,10 +21,8 @@ |
#include "url/gurl.h" |
using autofill::PasswordForm; |
-using autofill::PasswordFormMap; |
using base::ASCIIToUTF16; |
using base::StringPiece; |
-using base::WrapUnique; |
using testing::_; |
using testing::DoAll; |
using testing::SaveArg; |
@@ -107,7 +107,8 @@ TEST_F(FormSaverImplTest, Save_AsNew) { |
EXPECT_CALL(*mock_store_, AddLogin(_)).WillOnce(SaveArg<0>(&saved)); |
EXPECT_CALL(*mock_store_, UpdateLogin(_)).Times(0); |
EXPECT_CALL(*mock_store_, UpdateLoginWithPrimaryKey(_, _)).Times(0); |
- form_saver_.Save(pending, PasswordFormMap(), nullptr); |
+ form_saver_.Save(pending, std::map<base::string16, const PasswordForm*>(), |
+ nullptr); |
EXPECT_EQ(ASCIIToUTF16("nameofuser"), saved.username_value); |
EXPECT_EQ(ASCIIToUTF16("wordToP4a55"), saved.password_value); |
} |
@@ -121,7 +122,8 @@ TEST_F(FormSaverImplTest, Save_Update) { |
EXPECT_CALL(*mock_store_, AddLogin(_)).Times(0); |
EXPECT_CALL(*mock_store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&saved)); |
EXPECT_CALL(*mock_store_, UpdateLoginWithPrimaryKey(_, _)).Times(0); |
- form_saver_.Update(pending, PasswordFormMap(), nullptr, nullptr); |
+ form_saver_.Update(pending, std::map<base::string16, const PasswordForm*>(), |
+ nullptr, nullptr); |
EXPECT_EQ(ASCIIToUTF16("nameofuser"), saved.username_value); |
EXPECT_EQ(ASCIIToUTF16("wordToP4a55"), saved.password_value); |
} |
@@ -148,8 +150,8 @@ TEST_F(FormSaverImplTest, Save_UpdateAlsoOtherCredentials) { |
.WillOnce(SaveArg<0>(&saved[1])) |
.WillOnce(SaveArg<0>(&saved[2])); |
EXPECT_CALL(*mock_store_, UpdateLoginWithPrimaryKey(_, _)).Times(0); |
- form_saver_.Update(pending, PasswordFormMap(), &credentials_to_update, |
- nullptr); |
+ form_saver_.Update(pending, std::map<base::string16, const PasswordForm*>(), |
+ &credentials_to_update, nullptr); |
std::set<GURL> different_origins; |
for (const PasswordForm& form : saved) { |
different_origins.insert(form.origin); |
@@ -172,7 +174,8 @@ TEST_F(FormSaverImplTest, Save_UpdateWithPrimaryKey) { |
EXPECT_CALL(*mock_store_, UpdateLogin(_)).Times(0); |
EXPECT_CALL(*mock_store_, UpdateLoginWithPrimaryKey(_, _)) |
.WillOnce(DoAll(SaveArg<0>(&saved_new), SaveArg<1>(&saved_old))); |
- form_saver_.Update(pending, PasswordFormMap(), nullptr, &old_key); |
+ form_saver_.Update(pending, std::map<base::string16, const PasswordForm*>(), |
+ nullptr, &old_key); |
EXPECT_EQ(ASCIIToUTF16("nameofuser"), saved_new.username_value); |
EXPECT_EQ(ASCIIToUTF16("wordToP4a55"), saved_new.password_value); |
EXPECT_EQ(ASCIIToUTF16("old username"), saved_old.username_value); |
@@ -189,14 +192,13 @@ TEST_F(FormSaverImplTest, Save_AndUpdatePreferredLoginState) { |
// as the pending one, both marked as "preferred". FormSaver should ignore |
// the pending and PSL-matched one, but should update the non-PSL matched |
// form (with different username) to no longer be preferred. |
- PasswordFormMap best_matches; |
+ std::map<base::string16, const PasswordForm*> best_matches; |
PasswordForm other = pending; |
other.username_value = ASCIIToUTF16("othername"); |
- best_matches[other.username_value] = WrapUnique(new PasswordForm(other)); |
+ best_matches[other.username_value] = &other; |
PasswordForm psl_match = pending; |
psl_match.is_public_suffix_match = true; |
- best_matches[psl_match.username_value] = |
- WrapUnique(new PasswordForm(psl_match)); |
+ best_matches[psl_match.username_value] = &psl_match; |
PasswordForm saved; |
PasswordForm updated; |
@@ -221,13 +223,12 @@ TEST_F(FormSaverImplTest, Save_AndUpdatePreferredLoginState) { |
TEST_F(FormSaverImplTest, Save_AndDeleteEmptyUsernameCredentials) { |
PasswordForm pending = CreatePending("nameofuser", "wordToP4a55"); |
- PasswordFormMap best_matches; |
- best_matches[pending.username_value] = WrapUnique(new PasswordForm(pending)); |
+ std::map<base::string16, const PasswordForm*> best_matches; |
+ best_matches[pending.username_value] = &pending; |
PasswordForm no_username = pending; |
no_username.username_value.clear(); |
no_username.preferred = false; |
- best_matches[no_username.username_value] = |
- WrapUnique(new PasswordForm(no_username)); |
+ best_matches[no_username.username_value] = &no_username; |
PasswordForm saved; |
PasswordForm removed; |
@@ -250,14 +251,13 @@ TEST_F(FormSaverImplTest, |
Save_AndDoNotDeleteEmptyUsernameCredentialsWithDifferentPassword) { |
PasswordForm pending = CreatePending("nameofuser", "wordToP4a55"); |
- PasswordFormMap best_matches; |
- best_matches[pending.username_value] = WrapUnique(new PasswordForm(pending)); |
+ std::map<base::string16, const PasswordForm*> best_matches; |
+ best_matches[pending.username_value] = &pending; |
PasswordForm no_username = pending; |
no_username.username_value.clear(); |
no_username.preferred = false; |
no_username.password_value = ASCIIToUTF16("abcd"); |
- best_matches[no_username.username_value] = |
- WrapUnique(new PasswordForm(no_username)); |
+ best_matches[no_username.username_value] = &no_username; |
PasswordForm saved; |
@@ -276,13 +276,12 @@ TEST_F(FormSaverImplTest, |
Save_DoNotDeleteUsernamelessOnUpdatingPasswordWithUsername) { |
PasswordForm pending = CreatePending("abc", "pwd"); |
- PasswordFormMap best_matches; |
- best_matches[pending.username_value] = WrapUnique(new PasswordForm(pending)); |
+ std::map<base::string16, const PasswordForm*> best_matches; |
+ best_matches[pending.username_value] = &pending; |
PasswordForm no_username = pending; |
no_username.username_value.clear(); |
no_username.preferred = false; |
- best_matches[no_username.username_value] = |
- WrapUnique(new PasswordForm(no_username)); |
+ best_matches[no_username.username_value] = &no_username; |
pending.password_value = ASCIIToUTF16("def"); |
@@ -303,12 +302,11 @@ TEST_F(FormSaverImplTest, |
TEST_F(FormSaverImplTest, Save_EmptyUsernameWillNotCauseDeletion) { |
PasswordForm pending = CreatePending("", "wordToP4a55"); |
- PasswordFormMap best_matches; |
+ std::map<base::string16, const PasswordForm*> best_matches; |
PasswordForm with_username = pending; |
with_username.username_value = ASCIIToUTF16("nameofuser"); |
with_username.preferred = false; |
- best_matches[with_username.username_value] = |
- WrapUnique(new PasswordForm(with_username)); |
+ best_matches[with_username.username_value] = &with_username; |
PasswordForm saved; |
@@ -327,13 +325,12 @@ TEST_F(FormSaverImplTest, Save_EmptyUsernameWillNotCauseDeletion) { |
TEST_F(FormSaverImplTest, Save_AndDoNotDeleteEmptyUsernamePSLCredentials) { |
PasswordForm pending = CreatePending("nameofuser", "wordToP4a55"); |
- PasswordFormMap best_matches; |
- best_matches[pending.username_value] = WrapUnique(new PasswordForm(pending)); |
+ std::map<base::string16, const PasswordForm*> best_matches; |
+ best_matches[pending.username_value] = &pending; |
PasswordForm no_username_psl = pending; |
no_username_psl.username_value.clear(); |
no_username_psl.is_public_suffix_match = true; |
- best_matches[no_username_psl.username_value] = |
- WrapUnique(new PasswordForm(no_username_psl)); |
+ best_matches[no_username_psl.username_value] = &no_username_psl; |
PasswordForm saved; |
@@ -351,13 +348,12 @@ TEST_F(FormSaverImplTest, Save_AndDoNotDeleteEmptyUsernamePSLCredentials) { |
TEST_F(FormSaverImplTest, Save_AndDoNotDeleteNonEmptyUsernameCredentials) { |
PasswordForm pending = CreatePending("nameofuser", "wordToP4a55"); |
- PasswordFormMap best_matches; |
- best_matches[pending.username_value] = WrapUnique(new PasswordForm(pending)); |
+ std::map<base::string16, const PasswordForm*> best_matches; |
+ best_matches[pending.username_value] = &pending; |
PasswordForm other_username = pending; |
other_username.username_value = ASCIIToUTF16("other username"); |
other_username.preferred = false; |
- best_matches[other_username.username_value] = |
- WrapUnique(new PasswordForm(other_username)); |
+ best_matches[other_username.username_value] = &other_username; |
PasswordForm saved; |
@@ -420,7 +416,8 @@ TEST_F(FormSaverImplTest, PresaveGeneratedPassword_ThenSaveAsNew) { |
EXPECT_CALL(*mock_store_, UpdateLogin(_)).Times(0); |
EXPECT_CALL(*mock_store_, UpdateLoginWithPrimaryKey(_, _)) |
.WillOnce(DoAll(SaveArg<0>(&saved_new), SaveArg<1>(&saved_old))); |
- form_saver_.Save(pending, PasswordFormMap(), nullptr); |
+ form_saver_.Save(pending, std::map<base::string16, const PasswordForm*>(), |
+ nullptr); |
EXPECT_EQ(ASCIIToUTF16("generatedU"), saved_old.username_value); |
EXPECT_EQ(ASCIIToUTF16("generatedP"), saved_old.password_value); |
EXPECT_EQ(ASCIIToUTF16("nameofuser"), saved_new.username_value); |
@@ -443,7 +440,8 @@ TEST_F(FormSaverImplTest, PresaveGeneratedPassword_ThenUpdate) { |
EXPECT_CALL(*mock_store_, UpdateLogin(_)).Times(0); |
EXPECT_CALL(*mock_store_, UpdateLoginWithPrimaryKey(_, _)) |
.WillOnce(DoAll(SaveArg<0>(&saved_new), SaveArg<1>(&saved_old))); |
- form_saver_.Update(pending, PasswordFormMap(), nullptr, nullptr); |
+ form_saver_.Update(pending, std::map<base::string16, const PasswordForm*>(), |
+ nullptr, nullptr); |
EXPECT_EQ(ASCIIToUTF16("generatedU"), saved_old.username_value); |
EXPECT_EQ(ASCIIToUTF16("generatedP"), saved_old.password_value); |
EXPECT_EQ(ASCIIToUTF16("nameofuser"), saved_new.username_value); |
@@ -519,12 +517,12 @@ TEST_F(FormSaverImplTest, RemovePresavedPassword_AndPresaveAgain) { |
TEST_F(FormSaverImplTest, WipeOutdatedCopies_Preferred) { |
PasswordForm pending = CreatePendingGAIA("nameofuser", "wordToP4a55"); |
- PasswordFormMap best_matches; |
+ std::map<base::string16, const PasswordForm*> best_matches; |
PasswordForm other = pending; |
other.password_value = ASCIIToUTF16("oldpwd"); |
- best_matches[other.username_value] = WrapUnique(new PasswordForm(other)); |
+ best_matches[other.username_value] = &other; |
- const PasswordForm* preferred = best_matches[other.username_value].get(); |
+ const PasswordForm* preferred = best_matches[other.username_value]; |
EXPECT_CALL(*mock_store_, RemoveLogin(other)); |
form_saver_.WipeOutdatedCopies(pending, &best_matches, &preferred); |
@@ -535,10 +533,10 @@ TEST_F(FormSaverImplTest, WipeOutdatedCopies_Preferred) { |
TEST_F(FormSaverImplTest, WipeOutdatedCopies_NullPreferred) { |
PasswordForm pending = CreatePendingGAIA("nameofuser", "wordToP4a55"); |
- PasswordFormMap best_matches; |
+ std::map<base::string16, const PasswordForm*> best_matches; |
PasswordForm other = pending; |
other.password_value = ASCIIToUTF16("oldpwd"); |
- best_matches[other.username_value] = WrapUnique(new PasswordForm(other)); |
+ best_matches[other.username_value] = &other; |
const PasswordForm* preferred = nullptr; |
@@ -550,21 +548,21 @@ TEST_F(FormSaverImplTest, WipeOutdatedCopies_NullPreferred) { |
TEST_F(FormSaverImplTest, WipeOutdatedCopies_EquivalentNames) { |
PasswordForm pending = CreatePendingGAIA("nameofuser", "wordToP4a55"); |
- PasswordFormMap best_matches; |
+ std::map<base::string16, const PasswordForm*> best_matches; |
PasswordForm old = pending; |
old.password_value = ASCIIToUTF16("oldpwd"); |
- best_matches[old.username_value] = WrapUnique(new PasswordForm(old)); |
+ best_matches[old.username_value] = &old; |
// For GAIA authentication, the first two other usernames are equivalent to |
// |pending| but the third is not. |
PasswordForm eq1 = old; |
eq1.username_value = ASCIIToUTF16("nameofuser@gmail.com"); |
- best_matches[eq1.username_value] = WrapUnique(new PasswordForm(eq1)); |
+ best_matches[eq1.username_value] = &eq1; |
PasswordForm eq2 = old; |
eq2.username_value = ASCIIToUTF16("name.of.user"); |
- best_matches[eq2.username_value] = WrapUnique(new PasswordForm(eq2)); |
+ best_matches[eq2.username_value] = &eq2; |
PasswordForm non_eq = old; |
non_eq.username_value = ASCIIToUTF16("other.user"); |
- best_matches[non_eq.username_value] = WrapUnique(new PasswordForm(non_eq)); |
+ best_matches[non_eq.username_value] = &non_eq; |
const PasswordForm* preferred = nullptr; |
@@ -578,14 +576,14 @@ TEST_F(FormSaverImplTest, WipeOutdatedCopies_EquivalentNames) { |
TEST_F(FormSaverImplTest, WipeOutdatedCopies_NotOutdated) { |
PasswordForm pending = CreatePendingGAIA("nameofuser", "wordToP4a55"); |
- PasswordFormMap best_matches; |
- best_matches[pending.username_value] = WrapUnique(new PasswordForm(pending)); |
+ std::map<base::string16, const PasswordForm*> best_matches; |
+ best_matches[pending.username_value] = &pending; |
PasswordForm eq1 = pending; |
eq1.username_value = ASCIIToUTF16("nameofuser@gmail.com"); |
- best_matches[eq1.username_value] = WrapUnique(new PasswordForm(eq1)); |
+ best_matches[eq1.username_value] = &eq1; |
PasswordForm eq2 = pending; |
eq2.username_value = ASCIIToUTF16("name.of.user"); |
- best_matches[eq2.username_value] = WrapUnique(new PasswordForm(eq2)); |
+ best_matches[eq2.username_value] = &eq2; |
const PasswordForm* preferred = nullptr; |