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

Side by Side Diff: components/browser_sync/profile_sync_service_autofill_unittest.cc

Issue 1302233003: Replace gmock's deprecated SetArgumentPointee with SetArgPointee. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2017 Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 using syncer::syncable::CREATE; 83 using syncer::syncable::CREATE;
84 using syncer::syncable::GET_TYPE_ROOT; 84 using syncer::syncable::GET_TYPE_ROOT;
85 using syncer::syncable::MutableEntry; 85 using syncer::syncable::MutableEntry;
86 using syncer::syncable::UNITTEST; 86 using syncer::syncable::UNITTEST;
87 using syncer::syncable::WriterTag; 87 using syncer::syncable::WriterTag;
88 using syncer::syncable::WriteTransaction; 88 using syncer::syncable::WriteTransaction;
89 using testing::_; 89 using testing::_;
90 using testing::DoAll; 90 using testing::DoAll;
91 using testing::ElementsAre; 91 using testing::ElementsAre;
92 using testing::Not; 92 using testing::Not;
93 using testing::SetArgumentPointee; 93 using testing::SetArgPointee;
94 using testing::Return; 94 using testing::Return;
95 95
96 namespace browser_sync { 96 namespace browser_sync {
97 97
98 namespace { 98 namespace {
99 99
100 void RegisterAutofillPrefs(user_prefs::PrefRegistrySyncable* registry) { 100 void RegisterAutofillPrefs(user_prefs::PrefRegistrySyncable* registry) {
101 registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, true); 101 registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, true);
102 registry->RegisterBooleanPref(autofill::prefs::kAutofillWalletImportEnabled, 102 registry->RegisterBooleanPref(autofill::prefs::kAutofillWalletImportEnabled,
103 true); 103 true);
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 std::vector<AutofillProfile> sync_profiles; 835 std::vector<AutofillProfile> sync_profiles;
836 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 836 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
837 EXPECT_EQ(0U, sync_entries.size()); 837 EXPECT_EQ(0U, sync_entries.size());
838 EXPECT_EQ(0U, sync_profiles.size()); 838 EXPECT_EQ(0U, sync_profiles.size());
839 } 839 }
840 840
841 TEST_F(ProfileSyncServiceAutofillTest, HasNativeEntriesEmptySync) { 841 TEST_F(ProfileSyncServiceAutofillTest, HasNativeEntriesEmptySync) {
842 std::vector<AutofillEntry> entries; 842 std::vector<AutofillEntry> entries;
843 entries.push_back(MakeAutofillEntry("foo", "bar", 1)); 843 entries.push_back(MakeAutofillEntry("foo", "bar", 1));
844 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) 844 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_))
845 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); 845 .WillOnce(DoAll(SetArgPointee<0>(entries), Return(true)));
846 SetIdleChangeProcessorExpectations(); 846 SetIdleChangeProcessorExpectations();
847 CreateRootHelper create_root(this, AUTOFILL); 847 CreateRootHelper create_root(this, AUTOFILL);
848 EXPECT_CALL(personal_data_manager(), Refresh()); 848 EXPECT_CALL(personal_data_manager(), Refresh());
849 StartSyncService(create_root.callback(), false, AUTOFILL); 849 StartSyncService(create_root.callback(), false, AUTOFILL);
850 ASSERT_TRUE(create_root.success()); 850 ASSERT_TRUE(create_root.success());
851 std::vector<AutofillEntry> sync_entries; 851 std::vector<AutofillEntry> sync_entries;
852 std::vector<AutofillProfile> sync_profiles; 852 std::vector<AutofillProfile> sync_profiles;
853 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 853 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
854 ASSERT_EQ(1U, sync_entries.size()); 854 ASSERT_EQ(1U, sync_entries.size());
855 EXPECT_EQ(entries[0], sync_entries[0]); 855 EXPECT_EQ(entries[0], sync_entries[0]);
(...skipping 26 matching lines...) Expand all
882 } 882 }
883 883
884 TEST_F(ProfileSyncServiceAutofillTest, HasNativeWithDuplicatesEmptySync) { 884 TEST_F(ProfileSyncServiceAutofillTest, HasNativeWithDuplicatesEmptySync) {
885 // There is buggy autofill code that allows duplicate name/value 885 // There is buggy autofill code that allows duplicate name/value
886 // pairs to exist in the database with separate pair_ids. 886 // pairs to exist in the database with separate pair_ids.
887 std::vector<AutofillEntry> entries; 887 std::vector<AutofillEntry> entries;
888 entries.push_back(MakeAutofillEntry("foo", "bar", 1)); 888 entries.push_back(MakeAutofillEntry("foo", "bar", 1));
889 entries.push_back(MakeAutofillEntry("dup", "", 2)); 889 entries.push_back(MakeAutofillEntry("dup", "", 2));
890 entries.push_back(MakeAutofillEntry("dup", "", 3)); 890 entries.push_back(MakeAutofillEntry("dup", "", 3));
891 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) 891 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_))
892 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); 892 .WillOnce(DoAll(SetArgPointee<0>(entries), Return(true)));
893 SetIdleChangeProcessorExpectations(); 893 SetIdleChangeProcessorExpectations();
894 CreateRootHelper create_root(this, AUTOFILL); 894 CreateRootHelper create_root(this, AUTOFILL);
895 EXPECT_CALL(personal_data_manager(), Refresh()); 895 EXPECT_CALL(personal_data_manager(), Refresh());
896 StartSyncService(create_root.callback(), false, AUTOFILL); 896 StartSyncService(create_root.callback(), false, AUTOFILL);
897 ASSERT_TRUE(create_root.success()); 897 ASSERT_TRUE(create_root.success());
898 std::vector<AutofillEntry> sync_entries; 898 std::vector<AutofillEntry> sync_entries;
899 std::vector<AutofillProfile> sync_profiles; 899 std::vector<AutofillProfile> sync_profiles;
900 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 900 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
901 EXPECT_EQ(2U, sync_entries.size()); 901 EXPECT_EQ(2U, sync_entries.size());
902 } 902 }
903 903
904 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) { 904 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) {
905 AutofillEntry native_entry(MakeAutofillEntry("native", "entry", 1)); 905 AutofillEntry native_entry(MakeAutofillEntry("native", "entry", 1));
906 AutofillEntry sync_entry(MakeAutofillEntry("sync", "entry", 2)); 906 AutofillEntry sync_entry(MakeAutofillEntry("sync", "entry", 2));
907 907
908 std::vector<AutofillEntry> native_entries; 908 std::vector<AutofillEntry> native_entries;
909 native_entries.push_back(native_entry); 909 native_entries.push_back(native_entry);
910 910
911 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) 911 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_))
912 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); 912 .WillOnce(DoAll(SetArgPointee<0>(native_entries), Return(true)));
913 913
914 std::vector<AutofillEntry> sync_entries; 914 std::vector<AutofillEntry> sync_entries;
915 sync_entries.push_back(sync_entry); 915 sync_entries.push_back(sync_entry);
916 916
917 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); 917 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries);
918 918
919 EXPECT_CALL(autofill_table(), UpdateAutofillEntries(ElementsAre(sync_entry))) 919 EXPECT_CALL(autofill_table(), UpdateAutofillEntries(ElementsAre(sync_entry)))
920 .WillOnce(Return(true)); 920 .WillOnce(Return(true));
921 921
922 EXPECT_CALL(personal_data_manager(), Refresh()); 922 EXPECT_CALL(personal_data_manager(), Refresh());
(...skipping 21 matching lines...) Expand all
944 AutofillEntry native_entry0(MakeAutofillEntry("native", kEntry, 1)); 944 AutofillEntry native_entry0(MakeAutofillEntry("native", kEntry, 1));
945 AutofillEntry native_entry1(MakeAutofillEntry("native", entry, 1)); 945 AutofillEntry native_entry1(MakeAutofillEntry("native", entry, 1));
946 AutofillEntry sync_entry0(MakeAutofillEntry("sync", kEntry, 2)); 946 AutofillEntry sync_entry0(MakeAutofillEntry("sync", kEntry, 2));
947 AutofillEntry sync_entry1(MakeAutofillEntry("sync", entry, 2)); 947 AutofillEntry sync_entry1(MakeAutofillEntry("sync", entry, 2));
948 948
949 std::vector<AutofillEntry> native_entries; 949 std::vector<AutofillEntry> native_entries;
950 native_entries.push_back(native_entry0); 950 native_entries.push_back(native_entry0);
951 native_entries.push_back(native_entry1); 951 native_entries.push_back(native_entry1);
952 952
953 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) 953 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_))
954 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); 954 .WillOnce(DoAll(SetArgPointee<0>(native_entries), Return(true)));
955 955
956 std::vector<AutofillEntry> sync_entries; 956 std::vector<AutofillEntry> sync_entries;
957 sync_entries.push_back(sync_entry0); 957 sync_entries.push_back(sync_entry0);
958 sync_entries.push_back(sync_entry1); 958 sync_entries.push_back(sync_entry1);
959 959
960 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); 960 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries);
961 961
962 // Expecting that sync_entry0 and sync_entry1 will be written in an autofill 962 // Expecting that sync_entry0 and sync_entry1 will be written in an autofill
963 // table and a value in sync_entry1 won't lose null terminating symbol. 963 // table and a value in sync_entry1 won't lose null terminating symbol.
964 EXPECT_CALL(autofill_table(), 964 EXPECT_CALL(autofill_table(),
(...skipping 22 matching lines...) Expand all
987 } 987 }
988 988
989 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { 989 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) {
990 AutofillEntry native_entry(MakeAutofillEntry("merge", "entry", 1)); 990 AutofillEntry native_entry(MakeAutofillEntry("merge", "entry", 1));
991 AutofillEntry sync_entry(MakeAutofillEntry("merge", "entry", 2)); 991 AutofillEntry sync_entry(MakeAutofillEntry("merge", "entry", 2));
992 AutofillEntry merged_entry(MakeAutofillEntry("merge", "entry", 1, 2)); 992 AutofillEntry merged_entry(MakeAutofillEntry("merge", "entry", 1, 2));
993 993
994 std::vector<AutofillEntry> native_entries; 994 std::vector<AutofillEntry> native_entries;
995 native_entries.push_back(native_entry); 995 native_entries.push_back(native_entry);
996 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) 996 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_))
997 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); 997 .WillOnce(DoAll(SetArgPointee<0>(native_entries), Return(true)));
998 998
999 std::vector<AutofillEntry> sync_entries; 999 std::vector<AutofillEntry> sync_entries;
1000 sync_entries.push_back(sync_entry); 1000 sync_entries.push_back(sync_entry);
1001 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); 1001 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries);
1002 1002
1003 EXPECT_CALL(autofill_table(), 1003 EXPECT_CALL(autofill_table(),
1004 UpdateAutofillEntries(ElementsAre(merged_entry))) 1004 UpdateAutofillEntries(ElementsAre(merged_entry)))
1005 .WillOnce(Return(true)); 1005 .WillOnce(Return(true));
1006 EXPECT_CALL(personal_data_manager(), Refresh()); 1006 EXPECT_CALL(personal_data_manager(), Refresh());
1007 StartSyncService(add_autofill.callback(), false, AUTOFILL); 1007 StartSyncService(add_autofill.callback(), false, AUTOFILL);
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 .WillOnce(Return(true)); 1357 .WillOnce(Return(true));
1358 EXPECT_CALL(personal_data_manager(), Refresh()); 1358 EXPECT_CALL(personal_data_manager(), Refresh());
1359 SetIdleChangeProcessorExpectations(); 1359 SetIdleChangeProcessorExpectations();
1360 CreateRootHelper create_root(this, AUTOFILL); 1360 CreateRootHelper create_root(this, AUTOFILL);
1361 StartSyncService(create_root.callback(), false, AUTOFILL); 1361 StartSyncService(create_root.callback(), false, AUTOFILL);
1362 ASSERT_TRUE(create_root.success()); 1362 ASSERT_TRUE(create_root.success());
1363 1363
1364 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1)); 1364 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1));
1365 1365
1366 EXPECT_CALL(autofill_table(), GetAutofillTimestamps(_, _, _, _)) 1366 EXPECT_CALL(autofill_table(), GetAutofillTimestamps(_, _, _, _))
1367 .WillOnce(DoAll(SetArgumentPointee<2>(added_entry.date_created()), 1367 .WillOnce(DoAll(SetArgPointee<2>(added_entry.date_created()),
1368 SetArgumentPointee<3>(added_entry.date_last_used()), 1368 SetArgPointee<3>(added_entry.date_last_used()),
1369 Return(true))); 1369 Return(true)));
1370 1370
1371 AutofillChangeList changes; 1371 AutofillChangeList changes;
1372 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); 1372 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key()));
1373 1373
1374 web_data_service()->OnAutofillEntriesChanged(changes); 1374 web_data_service()->OnAutofillEntriesChanged(changes);
1375 1375
1376 std::vector<AutofillEntry> new_sync_entries; 1376 std::vector<AutofillEntry> new_sync_entries;
1377 std::vector<AutofillProfile> new_sync_profiles; 1377 std::vector<AutofillProfile> new_sync_profiles;
1378 ASSERT_TRUE( 1378 ASSERT_TRUE(
(...skipping 26 matching lines...) Expand all
1405 ASSERT_EQ(1U, new_sync_profiles.size()); 1405 ASSERT_EQ(1U, new_sync_profiles.size());
1406 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0])); 1406 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0]));
1407 } 1407 }
1408 1408
1409 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { 1409 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) {
1410 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); 1410 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1));
1411 std::vector<AutofillEntry> original_entries; 1411 std::vector<AutofillEntry> original_entries;
1412 original_entries.push_back(original_entry); 1412 original_entries.push_back(original_entry);
1413 1413
1414 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) 1414 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_))
1415 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); 1415 .WillOnce(DoAll(SetArgPointee<0>(original_entries), Return(true)));
1416 EXPECT_CALL(personal_data_manager(), Refresh()); 1416 EXPECT_CALL(personal_data_manager(), Refresh());
1417 CreateRootHelper create_root(this, AUTOFILL); 1417 CreateRootHelper create_root(this, AUTOFILL);
1418 StartSyncService(create_root.callback(), false, AUTOFILL); 1418 StartSyncService(create_root.callback(), false, AUTOFILL);
1419 ASSERT_TRUE(create_root.success()); 1419 ASSERT_TRUE(create_root.success());
1420 1420
1421 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2)); 1421 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2));
1422 1422
1423 EXPECT_CALL(autofill_table(), GetAutofillTimestamps(_, _, _, _)) 1423 EXPECT_CALL(autofill_table(), GetAutofillTimestamps(_, _, _, _))
1424 .WillOnce(DoAll(SetArgumentPointee<2>(updated_entry.date_created()), 1424 .WillOnce(DoAll(SetArgPointee<2>(updated_entry.date_created()),
1425 SetArgumentPointee<3>(updated_entry.date_last_used()), 1425 SetArgPointee<3>(updated_entry.date_last_used()),
1426 Return(true))); 1426 Return(true)));
1427 1427
1428 AutofillChangeList changes; 1428 AutofillChangeList changes;
1429 changes.push_back( 1429 changes.push_back(
1430 AutofillChange(AutofillChange::UPDATE, updated_entry.key())); 1430 AutofillChange(AutofillChange::UPDATE, updated_entry.key()));
1431 web_data_service()->OnAutofillEntriesChanged(changes); 1431 web_data_service()->OnAutofillEntriesChanged(changes);
1432 1432
1433 std::vector<AutofillEntry> new_sync_entries; 1433 std::vector<AutofillEntry> new_sync_entries;
1434 std::vector<AutofillProfile> new_sync_profiles; 1434 std::vector<AutofillProfile> new_sync_profiles;
1435 ASSERT_TRUE( 1435 ASSERT_TRUE(
1436 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); 1436 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles));
1437 ASSERT_EQ(1U, new_sync_entries.size()); 1437 ASSERT_EQ(1U, new_sync_entries.size());
1438 EXPECT_EQ(updated_entry, new_sync_entries[0]); 1438 EXPECT_EQ(updated_entry, new_sync_entries[0]);
1439 } 1439 }
1440 1440
1441 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { 1441 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) {
1442 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); 1442 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1));
1443 std::vector<AutofillEntry> original_entries; 1443 std::vector<AutofillEntry> original_entries;
1444 original_entries.push_back(original_entry); 1444 original_entries.push_back(original_entry);
1445 1445
1446 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) 1446 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_))
1447 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); 1447 .WillOnce(DoAll(SetArgPointee<0>(original_entries), Return(true)));
1448 EXPECT_CALL(personal_data_manager(), Refresh()); 1448 EXPECT_CALL(personal_data_manager(), Refresh());
1449 CreateRootHelper create_root(this, AUTOFILL); 1449 CreateRootHelper create_root(this, AUTOFILL);
1450 StartSyncService(create_root.callback(), false, AUTOFILL); 1450 StartSyncService(create_root.callback(), false, AUTOFILL);
1451 ASSERT_TRUE(create_root.success()); 1451 ASSERT_TRUE(create_root.success());
1452 1452
1453 AutofillChangeList changes; 1453 AutofillChangeList changes;
1454 changes.push_back( 1454 changes.push_back(
1455 AutofillChange(AutofillChange::REMOVE, original_entry.key())); 1455 AutofillChange(AutofillChange::REMOVE, original_entry.key()));
1456 web_data_service()->OnAutofillEntriesChanged(changes); 1456 web_data_service()->OnAutofillEntriesChanged(changes);
1457 1457
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1552 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1553 EXPECT_EQ(3U, sync_entries.size()); 1553 EXPECT_EQ(3U, sync_entries.size());
1554 EXPECT_EQ(0U, sync_profiles.size()); 1554 EXPECT_EQ(0U, sync_profiles.size());
1555 for (size_t i = 0; i < sync_entries.size(); i++) { 1555 for (size_t i = 0; i < sync_entries.size(); i++) {
1556 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " 1556 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", "
1557 << sync_entries[i].key().value(); 1557 << sync_entries[i].key().value();
1558 } 1558 }
1559 } 1559 }
1560 1560
1561 } // namespace browser_sync 1561 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698