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

Side by Side Diff: chrome/browser/sync/profile_sync_service_autofill_unittest.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 23 matching lines...) Expand all
34 #include "chrome/browser/sync/profile_sync_test_util.h" 34 #include "chrome/browser/sync/profile_sync_test_util.h"
35 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" 35 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
36 #include "chrome/browser/sync/syncable/directory_manager.h" 36 #include "chrome/browser/sync/syncable/directory_manager.h"
37 #include "chrome/browser/sync/syncable/model_type.h" 37 #include "chrome/browser/sync/syncable/model_type.h"
38 #include "chrome/browser/sync/syncable/syncable.h" 38 #include "chrome/browser/sync/syncable/syncable.h"
39 #include "chrome/browser/sync/test_profile_sync_service.h" 39 #include "chrome/browser/sync/test_profile_sync_service.h"
40 #include "chrome/browser/webdata/autofill_change.h" 40 #include "chrome/browser/webdata/autofill_change.h"
41 #include "chrome/browser/webdata/autofill_entry.h" 41 #include "chrome/browser/webdata/autofill_entry.h"
42 #include "chrome/browser/webdata/autofill_table.h" 42 #include "chrome/browser/webdata/autofill_table.h"
43 #include "chrome/browser/webdata/web_database.h" 43 #include "chrome/browser/webdata/web_database.h"
44 #include "chrome/common/chrome_notification_types.h"
44 #include "chrome/common/net/gaia/gaia_constants.h" 45 #include "chrome/common/net/gaia/gaia_constants.h"
45 #include "chrome/test/sync/engine/test_id_factory.h" 46 #include "chrome/test/sync/engine/test_id_factory.h"
46 #include "content/browser/browser_thread.h" 47 #include "content/browser/browser_thread.h"
47 #include "content/common/notification_source.h" 48 #include "content/common/notification_source.h"
48 #include "content/common/notification_type.h"
49 #include "testing/gmock/include/gmock/gmock.h" 49 #include "testing/gmock/include/gmock/gmock.h"
50 50
51 using base::Time; 51 using base::Time;
52 using base::WaitableEvent; 52 using base::WaitableEvent;
53 using browser_sync::AutofillChangeProcessor; 53 using browser_sync::AutofillChangeProcessor;
54 using browser_sync::AutofillDataTypeController; 54 using browser_sync::AutofillDataTypeController;
55 using browser_sync::AutofillModelAssociator; 55 using browser_sync::AutofillModelAssociator;
56 using browser_sync::AutofillProfileChangeProcessor; 56 using browser_sync::AutofillProfileChangeProcessor;
57 using browser_sync::AutofillProfileDataTypeController; 57 using browser_sync::AutofillProfileDataTypeController;
58 using browser_sync::AutofillProfileModelAssociator; 58 using browser_sync::AutofillProfileModelAssociator;
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 864
865 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1)); 865 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1));
866 std::vector<base::Time> timestamps(added_entry.timestamps()); 866 std::vector<base::Time> timestamps(added_entry.timestamps());
867 867
868 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)). 868 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).
869 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true))); 869 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true)));
870 870
871 AutofillChangeList changes; 871 AutofillChangeList changes;
872 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); 872 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key()));
873 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); 873 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_));
874 notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, 874 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
875 Source<WebDataService>(web_data_service_.get()), 875 Source<WebDataService>(web_data_service_.get()),
876 Details<AutofillChangeList>(&changes)); 876 Details<AutofillChangeList>(&changes));
877 877
878 std::vector<AutofillEntry> new_sync_entries; 878 std::vector<AutofillEntry> new_sync_entries;
879 std::vector<AutofillProfile> new_sync_profiles; 879 std::vector<AutofillProfile> new_sync_profiles;
880 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 880 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
881 &new_sync_profiles)); 881 &new_sync_profiles));
882 ASSERT_EQ(1U, new_sync_entries.size()); 882 ASSERT_EQ(1U, new_sync_entries.size());
883 EXPECT_TRUE(added_entry == new_sync_entries[0]); 883 EXPECT_TRUE(added_entry == new_sync_entries[0]);
884 } 884 }
885 885
886 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { 886 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) {
887 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true)); 887 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true));
888 EXPECT_CALL(*personal_data_manager_, Refresh()); 888 EXPECT_CALL(*personal_data_manager_, Refresh());
889 SetIdleChangeProcessorExpectations(); 889 SetIdleChangeProcessorExpectations();
890 CreateRootTask task(this, syncable::AUTOFILL_PROFILE); 890 CreateRootTask task(this, syncable::AUTOFILL_PROFILE);
891 StartSyncService(&task, false, syncable::AUTOFILL_PROFILE); 891 StartSyncService(&task, false, syncable::AUTOFILL_PROFILE);
892 ASSERT_TRUE(task.success()); 892 ASSERT_TRUE(task.success());
893 893
894 AutofillProfile added_profile; 894 AutofillProfile added_profile;
895 autofill_test::SetProfileInfoWithGuid(&added_profile, 895 autofill_test::SetProfileInfoWithGuid(&added_profile,
896 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz", 896 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz",
897 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", 897 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
898 "32801", "US", "19482937549", "13502849239"); 898 "32801", "US", "19482937549", "13502849239");
899 899
900 AutofillProfileChange change(AutofillProfileChange::ADD, 900 AutofillProfileChange change(AutofillProfileChange::ADD,
901 added_profile.guid(), &added_profile); 901 added_profile.guid(), &added_profile);
902 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); 902 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_));
903 notifier->Notify(NotificationType::AUTOFILL_PROFILE_CHANGED, 903 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
904 Source<WebDataService>(web_data_service_.get()), 904 Source<WebDataService>(web_data_service_.get()),
905 Details<AutofillProfileChange>(&change)); 905 Details<AutofillProfileChange>(&change));
906 906
907 std::vector<AutofillProfile> new_sync_profiles; 907 std::vector<AutofillProfile> new_sync_profiles;
908 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 908 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
909 &new_sync_profiles)); 909 &new_sync_profiles));
910 ASSERT_EQ(1U, new_sync_profiles.size()); 910 ASSERT_EQ(1U, new_sync_profiles.size());
911 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0])); 911 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0]));
912 } 912 }
913 913
(...skipping 13 matching lines...) Expand all
927 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2)); 927 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2));
928 std::vector<base::Time> timestamps(updated_entry.timestamps()); 928 std::vector<base::Time> timestamps(updated_entry.timestamps());
929 929
930 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)). 930 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).
931 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true))); 931 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true)));
932 932
933 AutofillChangeList changes; 933 AutofillChangeList changes;
934 changes.push_back(AutofillChange(AutofillChange::UPDATE, 934 changes.push_back(AutofillChange(AutofillChange::UPDATE,
935 updated_entry.key())); 935 updated_entry.key()));
936 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); 936 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_));
937 notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, 937 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
938 Source<WebDataService>(web_data_service_.get()), 938 Source<WebDataService>(web_data_service_.get()),
939 Details<AutofillChangeList>(&changes)); 939 Details<AutofillChangeList>(&changes));
940 940
941 std::vector<AutofillEntry> new_sync_entries; 941 std::vector<AutofillEntry> new_sync_entries;
942 std::vector<AutofillProfile> new_sync_profiles; 942 std::vector<AutofillProfile> new_sync_profiles;
943 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 943 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
944 &new_sync_profiles)); 944 &new_sync_profiles));
945 ASSERT_EQ(1U, new_sync_entries.size()); 945 ASSERT_EQ(1U, new_sync_entries.size());
946 EXPECT_TRUE(updated_entry == new_sync_entries[0]); 946 EXPECT_TRUE(updated_entry == new_sync_entries[0]);
947 } 947 }
948 948
949 949
950 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { 950 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) {
951 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); 951 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1));
952 std::vector<AutofillEntry> original_entries; 952 std::vector<AutofillEntry> original_entries;
953 original_entries.push_back(original_entry); 953 original_entries.push_back(original_entry);
954 954
955 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 955 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
956 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); 956 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true)));
957 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true)); 957 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true));
958 EXPECT_CALL(*personal_data_manager_, Refresh()); 958 EXPECT_CALL(*personal_data_manager_, Refresh());
959 CreateRootTask task(this, syncable::AUTOFILL); 959 CreateRootTask task(this, syncable::AUTOFILL);
960 StartSyncService(&task, false, syncable::AUTOFILL); 960 StartSyncService(&task, false, syncable::AUTOFILL);
961 ASSERT_TRUE(task.success()); 961 ASSERT_TRUE(task.success());
962 962
963 AutofillChangeList changes; 963 AutofillChangeList changes;
964 changes.push_back(AutofillChange(AutofillChange::REMOVE, 964 changes.push_back(AutofillChange(AutofillChange::REMOVE,
965 original_entry.key())); 965 original_entry.key()));
966 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); 966 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_));
967 notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, 967 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
968 Source<WebDataService>(web_data_service_.get()), 968 Source<WebDataService>(web_data_service_.get()),
969 Details<AutofillChangeList>(&changes)); 969 Details<AutofillChangeList>(&changes));
970 970
971 std::vector<AutofillEntry> new_sync_entries; 971 std::vector<AutofillEntry> new_sync_entries;
972 std::vector<AutofillProfile> new_sync_profiles; 972 std::vector<AutofillProfile> new_sync_profiles;
973 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 973 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
974 &new_sync_profiles)); 974 &new_sync_profiles));
975 ASSERT_EQ(0U, new_sync_entries.size()); 975 ASSERT_EQ(0U, new_sync_entries.size());
976 } 976 }
977 977
(...skipping 17 matching lines...) Expand all
995 std::vector<AutofillProfile> sync_profiles; 995 std::vector<AutofillProfile> sync_profiles;
996 sync_profiles.push_back(sync_profile); 996 sync_profiles.push_back(sync_profile);
997 AddAutofillTask<AutofillProfile> task(this, sync_profiles); 997 AddAutofillTask<AutofillProfile> task(this, sync_profiles);
998 EXPECT_CALL(*personal_data_manager_, Refresh()); 998 EXPECT_CALL(*personal_data_manager_, Refresh());
999 StartSyncService(&task, false, syncable::AUTOFILL_PROFILE); 999 StartSyncService(&task, false, syncable::AUTOFILL_PROFILE);
1000 ASSERT_TRUE(task.success()); 1000 ASSERT_TRUE(task.success());
1001 1001
1002 AutofillProfileChange change(AutofillProfileChange::REMOVE, 1002 AutofillProfileChange change(AutofillProfileChange::REMOVE,
1003 sync_profile.guid(), NULL); 1003 sync_profile.guid(), NULL);
1004 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); 1004 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_));
1005 notifier->Notify(NotificationType::AUTOFILL_PROFILE_CHANGED, 1005 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
1006 Source<WebDataService>(web_data_service_.get()), 1006 Source<WebDataService>(web_data_service_.get()),
1007 Details<AutofillProfileChange>(&change)); 1007 Details<AutofillProfileChange>(&change));
1008 1008
1009 std::vector<AutofillProfile> new_sync_profiles; 1009 std::vector<AutofillProfile> new_sync_profiles;
1010 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 1010 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
1011 &new_sync_profiles)); 1011 &new_sync_profiles));
1012 ASSERT_EQ(0U, new_sync_profiles.size()); 1012 ASSERT_EQ(0U, new_sync_profiles.size());
1013 } 1013 }
1014 1014
1015 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeError) { 1015 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeError) {
1016 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true)); 1016 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true));
1017 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true)); 1017 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true));
1018 EXPECT_CALL(*personal_data_manager_, Refresh()); 1018 EXPECT_CALL(*personal_data_manager_, Refresh());
1019 CreateRootTask task(this, syncable::AUTOFILL); 1019 CreateRootTask task(this, syncable::AUTOFILL);
1020 StartSyncService(&task, false, syncable::AUTOFILL); 1020 StartSyncService(&task, false, syncable::AUTOFILL);
1021 ASSERT_TRUE(task.success()); 1021 ASSERT_TRUE(task.success());
1022 1022
1023 // Inject an evil entry into the sync db to conflict with the same 1023 // Inject an evil entry into the sync db to conflict with the same
1024 // entry added by the user. 1024 // entry added by the user.
1025 AutofillEntry evil_entry(MakeAutofillEntry("evil", "entry", 1)); 1025 AutofillEntry evil_entry(MakeAutofillEntry("evil", "entry", 1));
1026 ASSERT_TRUE(AddAutofillSyncNode(evil_entry)); 1026 ASSERT_TRUE(AddAutofillSyncNode(evil_entry));
1027 1027
1028 AutofillChangeList changes; 1028 AutofillChangeList changes;
1029 changes.push_back(AutofillChange(AutofillChange::ADD, 1029 changes.push_back(AutofillChange(AutofillChange::ADD,
1030 evil_entry.key())); 1030 evil_entry.key()));
1031 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); 1031 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_));
1032 notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, 1032 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1033 Source<WebDataService>(web_data_service_.get()), 1033 Source<WebDataService>(web_data_service_.get()),
1034 Details<AutofillChangeList>(&changes)); 1034 Details<AutofillChangeList>(&changes));
1035 1035
1036 // Wait for the PPS to shut everything down and signal us. 1036 // Wait for the PPS to shut everything down and signal us.
1037 ProfileSyncServiceObserverMock observer; 1037 ProfileSyncServiceObserverMock observer;
1038 service_->AddObserver(&observer); 1038 service_->AddObserver(&observer);
1039 EXPECT_CALL(observer, OnStateChanged()).WillOnce(QuitUIMessageLoop()); 1039 EXPECT_CALL(observer, OnStateChanged()).WillOnce(QuitUIMessageLoop());
1040 MessageLoop::current()->Run(); 1040 MessageLoop::current()->Run();
1041 EXPECT_TRUE(service_->unrecoverable_error_detected()); 1041 EXPECT_TRUE(service_->unrecoverable_error_detected());
1042 1042
1043 // Ensure future autofill notifications don't crash. 1043 // Ensure future autofill notifications don't crash.
1044 notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, 1044 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1045 Source<WebDataService>(web_data_service_.get()), 1045 Source<WebDataService>(web_data_service_.get()),
1046 Details<AutofillChangeList>(&changes)); 1046 Details<AutofillChangeList>(&changes));
1047 } 1047 }
1048 1048
1049 // Crashy, http://crbug.com/57884 1049 // Crashy, http://crbug.com/57884
1050 TEST_F(ProfileSyncServiceAutofillTest, DISABLED_ServerChangeRace) { 1050 TEST_F(ProfileSyncServiceAutofillTest, DISABLED_ServerChangeRace) {
1051 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true)); 1051 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true));
1052 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true)); 1052 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true));
1053 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(_)). 1053 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(_)).
1054 WillRepeatedly(Return(true)); 1054 WillRepeatedly(Return(true));
(...skipping 27 matching lines...) Expand all
1082 std::vector<AutofillEntry> sync_entries; 1082 std::vector<AutofillEntry> sync_entries;
1083 std::vector<AutofillProfile> sync_profiles; 1083 std::vector<AutofillProfile> sync_profiles;
1084 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1084 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1085 EXPECT_EQ(3U, sync_entries.size()); 1085 EXPECT_EQ(3U, sync_entries.size());
1086 EXPECT_EQ(0U, sync_profiles.size()); 1086 EXPECT_EQ(0U, sync_profiles.size());
1087 for (size_t i = 0; i < sync_entries.size(); i++) { 1087 for (size_t i = 0; i < sync_entries.size(); i++) {
1088 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1088 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1089 << ", " << sync_entries[i].key().value(); 1089 << ", " << sync_entries[i].key().value();
1090 } 1090 }
1091 } 1091 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.cc ('k') | chrome/browser/sync/profile_sync_service_password_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698