Index: components/browser_sync/profile_sync_service_autofill_unittest.cc |
diff --git a/components/browser_sync/profile_sync_service_autofill_unittest.cc b/components/browser_sync/profile_sync_service_autofill_unittest.cc |
index 24627d795191dc2af599896e8cf5870fcf2b3421..2fe640bbe6919a64698700e1ff1a0639b2a91ef1 100644 |
--- a/components/browser_sync/profile_sync_service_autofill_unittest.cc |
+++ b/components/browser_sync/profile_sync_service_autofill_unittest.cc |
@@ -152,7 +152,7 @@ class AutofillTableMock : public AutofillTable { |
MOCK_METHOD1(UpdateAutofillEntries, |
bool(const std::vector<AutofillEntry>&)); // NOLINT |
MOCK_METHOD1(GetAutofillProfiles, |
- bool(std::vector<AutofillProfile*>*)); // NOLINT |
+ bool(std::vector<std::unique_ptr<AutofillProfile>>*)); // NOLINT |
MOCK_METHOD1(UpdateAutofillProfile, bool(const AutofillProfile&)); // NOLINT |
MOCK_METHOD1(AddAutofillProfile, bool(const AutofillProfile&)); // NOLINT |
MOCK_METHOD1(RemoveAutofillProfile, bool(const std::string&)); // NOLINT |
@@ -162,6 +162,12 @@ MATCHER_P(MatchProfiles, profile, "") { |
return (profile.Compare(arg) == 0); |
} |
+ACTION_P(LoadAutofillProfiles, datafunc) { |
+ std::vector<std::unique_ptr<AutofillProfile>> profiles = |
+ std::move(datafunc()); |
+ arg0->swap(profiles); |
+} |
+ |
class WebDatabaseFake : public WebDatabase { |
public: |
explicit WebDatabaseFake(AutofillTable* autofill_table) { |
@@ -848,18 +854,19 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeEntriesEmptySync) { |
} |
TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) { |
- std::vector<AutofillProfile*> profiles; |
+ std::vector<std::unique_ptr<AutofillProfile>> profiles; |
std::vector<AutofillProfile> expected_profiles; |
- // Owned by GetAutofillProfiles caller. |
- AutofillProfile* profile0 = new AutofillProfile; |
+ std::unique_ptr<AutofillProfile> profile0 = |
+ base::MakeUnique<AutofillProfile>(); |
autofill::test::SetProfileInfoWithGuid( |
- profile0, "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing", "Mitchell", |
- "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
- "Hollywood", "CA", "91601", "US", "12345678910"); |
- profiles.push_back(profile0); |
+ profile0.get(), "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing", |
+ "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
+ "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
expected_profiles.push_back(*profile0); |
+ profiles.push_back(std::move(profile0)); |
+ auto profile_returner = [&profiles]() { return std::move(profiles); }; |
EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
- .WillOnce(DoAll(SetArgumentPointee<0>(profiles), Return(true))); |
+ .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
EXPECT_CALL(personal_data_manager(), Refresh()); |
SetIdleChangeProcessorExpectations(); |
CreateRootHelper create_root(this, AUTOFILL_PROFILE); |
@@ -963,16 +970,20 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { |
"Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
"unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
- AutofillProfile* native_profile = new AutofillProfile; |
+ std::unique_ptr<AutofillProfile> native_profile = |
+ base::MakeUnique<AutofillProfile>(); |
autofill::test::SetProfileInfoWithGuid( |
- native_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
+ native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
"Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", |
"Orlando", "FL", "32801", "US", "19482937549"); |
- std::vector<AutofillProfile*> native_profiles; |
- native_profiles.push_back(native_profile); |
+ std::vector<std::unique_ptr<AutofillProfile>> native_profiles; |
+ native_profiles.push_back(std::move(native_profile)); |
+ auto profile_returner = [&native_profiles]() { |
+ return std::move(native_profiles); |
+ }; |
EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
- .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
+ .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
std::vector<AutofillProfile> sync_profiles; |
sync_profiles.push_back(sync_profile); |
@@ -1007,9 +1018,10 @@ TEST_F( |
"unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
- AutofillProfile* native_profile = new AutofillProfile; |
+ std::unique_ptr<AutofillProfile> native_profile = |
+ base::MakeUnique<AutofillProfile>(); |
autofill::test::SetProfileInfoWithGuid( |
- native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
+ native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
"Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
"Hollywood", "CA", "91601", "US", "12345678910"); |
native_profile->set_use_date(base::Time::FromTimeT(1234)); |
@@ -1019,10 +1031,13 @@ TEST_F( |
ASCIIToUTF16("Billing Mitchell Morrison")); |
expected_profile.set_use_count(1); |
- std::vector<AutofillProfile*> native_profiles; |
- native_profiles.push_back(native_profile); |
+ std::vector<std::unique_ptr<AutofillProfile>> native_profiles; |
+ native_profiles.push_back(std::move(native_profile)); |
+ auto profile_returner = [&native_profiles]() { |
+ return std::move(native_profiles); |
+ }; |
EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
- .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
+ .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
EXPECT_CALL(autofill_table(), |
AddAutofillProfile(MatchProfiles(expected_profile))) |
.WillOnce(Return(true)); |
@@ -1067,9 +1082,10 @@ TEST_F(ProfileSyncServiceAutofillTest, |
"unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
sync_profile.set_use_date(base::Time::FromTimeT(1234)); |
- AutofillProfile* native_profile = new AutofillProfile; |
+ std::unique_ptr<AutofillProfile> native_profile = |
+ base::MakeUnique<AutofillProfile>(); |
autofill::test::SetProfileInfoWithGuid( |
- native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
+ native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
"Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
"Hollywood", "CA", "91601", "US", "12345678910"); |
native_profile->set_use_date(base::Time::FromTimeT(4321)); |
@@ -1080,10 +1096,13 @@ TEST_F(ProfileSyncServiceAutofillTest, |
expected_profile.set_use_count(1); |
expected_profile.set_use_date(native_profile->use_date()); |
- std::vector<AutofillProfile*> native_profiles; |
- native_profiles.push_back(native_profile); |
+ std::vector<std::unique_ptr<AutofillProfile>> native_profiles; |
+ native_profiles.push_back(std::move(native_profile)); |
+ auto profile_returner = [&native_profiles]() { |
+ return std::move(native_profiles); |
+ }; |
EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
- .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
+ .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
EXPECT_CALL(autofill_table(), |
AddAutofillProfile(MatchProfiles(expected_profile))) |
.WillOnce(Return(true)); |
@@ -1130,9 +1149,10 @@ TEST_F(ProfileSyncServiceAutofillTest, |
"Hollywood", "CA", "91601", "US", "12345678910"); |
sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
- AutofillProfile* native_profile = new AutofillProfile; |
+ std::unique_ptr<AutofillProfile> native_profile = |
+ base::MakeUnique<AutofillProfile>(); |
autofill::test::SetProfileInfoWithGuid( |
- native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
+ native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
"Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
"unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
native_profile->set_use_date(base::Time::FromTimeT(1234)); |
@@ -1143,10 +1163,13 @@ TEST_F(ProfileSyncServiceAutofillTest, |
expected_profile.set_use_date(sync_profile.use_date()); |
expected_profile.set_use_count(1); |
- std::vector<AutofillProfile*> native_profiles; |
- native_profiles.push_back(native_profile); |
+ std::vector<std::unique_ptr<AutofillProfile>> native_profiles; |
+ native_profiles.push_back(std::move(native_profile)); |
+ auto profile_returner = [&native_profiles]() { |
+ return std::move(native_profiles); |
+ }; |
EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
- .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
+ .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
EXPECT_CALL(autofill_table(), |
AddAutofillProfile(MatchProfiles(expected_profile))) |
.WillOnce(Return(true)); |
@@ -1168,7 +1191,7 @@ TEST_F(ProfileSyncServiceAutofillTest, |
ASSERT_EQ(1U, new_sync_profiles.size()); |
// Check that key fields are the same. |
EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US")); |
- // Make sure the addtional information of the native profile was saved into |
+ // Make sure the additional information of the native profile was saved into |
// the sync profile. |
EXPECT_EQ(ASCIIToUTF16("Fox"), |
new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
@@ -1188,17 +1211,21 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) { |
"unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
- AutofillProfile* native_profile = new AutofillProfile; |
+ std::unique_ptr<AutofillProfile> native_profile = |
+ base::MakeUnique<AutofillProfile>(); |
autofill::test::SetProfileInfoWithGuid( |
- native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "John", |
- "Smith", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", |
- "CA", "91601", "US", "12345678910"); |
+ native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
+ "John", "Smith", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
+ "Hollywood", "CA", "91601", "US", "12345678910"); |
native_profile->set_use_date(base::Time::FromTimeT(1234)); |
- std::vector<AutofillProfile*> native_profiles; |
- native_profiles.push_back(native_profile); |
+ std::vector<std::unique_ptr<AutofillProfile>> native_profiles; |
+ native_profiles.push_back(std::move(native_profile)); |
+ auto profile_returner = [&native_profiles]() { |
+ return std::move(native_profiles); |
+ }; |
EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
- .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
+ .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
EXPECT_CALL(autofill_table(), AddAutofillProfile(MatchProfiles(sync_profile))) |
.WillOnce(Return(true)); |
std::vector<AutofillProfile> sync_profiles; |
@@ -1231,18 +1258,22 @@ TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { |
sync_profile.set_use_date(base::Time::FromTimeT(1234)); |
std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; |
- AutofillProfile* native_profile = new AutofillProfile; |
+ std::unique_ptr<AutofillProfile> native_profile = |
+ base::MakeUnique<AutofillProfile>(); |
autofill::test::SetProfileInfoWithGuid( |
- native_profile, native_guid.c_str(), "Billing", "Mitchell", "Morrison", |
- "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
- "91601", "US", "12345678910"); |
+ native_profile.get(), native_guid.c_str(), "Billing", "Mitchell", |
+ "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
+ "Hollywood", "CA", "91601", "US", "12345678910"); |
native_profile->set_use_count(5); |
native_profile->set_use_date(base::Time::FromTimeT(4321)); |
- std::vector<AutofillProfile*> native_profiles; |
- native_profiles.push_back(native_profile); |
+ std::vector<std::unique_ptr<AutofillProfile>> native_profiles; |
+ native_profiles.push_back(std::move(native_profile)); |
+ auto profile_returner = [&native_profiles]() { |
+ return std::move(native_profiles); |
+ }; |
EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
- .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
+ .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
std::vector<AutofillProfile> sync_profiles; |
sync_profiles.push_back(sync_profile); |
@@ -1385,16 +1416,20 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { |
&sync_profile, "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", |
"Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", |
"Orlando", "FL", "32801", "US", "19482937549"); |
- AutofillProfile* native_profile = new AutofillProfile; |
+ std::unique_ptr<AutofillProfile> native_profile = |
+ base::MakeUnique<AutofillProfile>(); |
autofill::test::SetProfileInfoWithGuid( |
- native_profile, "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", |
+ native_profile.get(), "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", |
"Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", |
"Orlando", "FL", "32801", "US", "19482937549"); |
- std::vector<AutofillProfile*> native_profiles; |
- native_profiles.push_back(native_profile); |
+ std::vector<std::unique_ptr<AutofillProfile>> native_profiles; |
+ native_profiles.push_back(std::move(native_profile)); |
+ auto profile_returner = [&native_profiles]() { |
+ return std::move(native_profiles); |
+ }; |
EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
- .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
+ .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
std::vector<AutofillProfile> sync_profiles; |
sync_profiles.push_back(sync_profile); |