| OLD | NEW |
| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 true); | 105 true); |
| 106 registry->RegisterIntegerPref(autofill::prefs::kAutofillLastVersionDeduped, | 106 registry->RegisterIntegerPref(autofill::prefs::kAutofillLastVersionDeduped, |
| 107 atoi(version_info::GetVersionNumber().c_str())); | 107 atoi(version_info::GetVersionNumber().c_str())); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void RunAndSignal(const base::Closure& cb, WaitableEvent* event) { | 110 void RunAndSignal(const base::Closure& cb, WaitableEvent* event) { |
| 111 cb.Run(); | 111 cb.Run(); |
| 112 event->Signal(); | 112 event->Signal(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 AutofillEntry MakeAutofillEntry(const char* name, | 115 AutofillEntry MakeAutofillEntry(const std::string& name, |
| 116 const char* value, | 116 const std::string& value, |
| 117 int time_shift0, | 117 int time_shift0, |
| 118 int time_shift1) { | 118 int time_shift1) { |
| 119 // Time deep in the past would cause Autocomplete sync to discard the | 119 // Time deep in the past would cause Autocomplete sync to discard the |
| 120 // entries. | 120 // entries. |
| 121 static Time base_time = Time::Now().LocalMidnight(); | 121 static Time base_time = Time::Now().LocalMidnight(); |
| 122 | 122 |
| 123 Time date_created = base_time + TimeDelta::FromSeconds(time_shift0); | 123 Time date_created = base_time + TimeDelta::FromSeconds(time_shift0); |
| 124 Time date_last_used = date_created; | 124 Time date_last_used = date_created; |
| 125 if (time_shift1 >= 0) | 125 if (time_shift1 >= 0) |
| 126 date_last_used = base_time + TimeDelta::FromSeconds(time_shift1); | 126 date_last_used = base_time + TimeDelta::FromSeconds(time_shift1); |
| 127 return AutofillEntry(AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), | 127 return AutofillEntry(AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), |
| 128 date_created, date_last_used); | 128 date_created, date_last_used); |
| 129 } | 129 } |
| 130 | 130 |
| 131 AutofillEntry MakeAutofillEntry(const char* name, | 131 AutofillEntry MakeAutofillEntry(const std::string& name, |
| 132 const char* value, | 132 const std::string& value, |
| 133 int time_shift) { | 133 int time_shift) { |
| 134 return MakeAutofillEntry(name, value, time_shift, -1); | 134 return MakeAutofillEntry(name, value, time_shift, -1); |
| 135 } | 135 } |
| 136 | 136 |
| 137 } // namespace | 137 } // namespace |
| 138 | 138 |
| 139 class AutofillTableMock : public AutofillTable { | 139 class AutofillTableMock : public AutofillTable { |
| 140 public: | 140 public: |
| 141 AutofillTableMock() {} | 141 AutofillTableMock() {} |
| 142 MOCK_METHOD2(RemoveFormElement, | 142 MOCK_METHOD2(RemoveFormElement, |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 std::vector<AutofillEntry> new_sync_entries; | 930 std::vector<AutofillEntry> new_sync_entries; |
| 931 std::vector<AutofillProfile> new_sync_profiles; | 931 std::vector<AutofillProfile> new_sync_profiles; |
| 932 ASSERT_TRUE( | 932 ASSERT_TRUE( |
| 933 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); | 933 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); |
| 934 std::set<AutofillEntry> new_sync_entries_set(new_sync_entries.begin(), | 934 std::set<AutofillEntry> new_sync_entries_set(new_sync_entries.begin(), |
| 935 new_sync_entries.end()); | 935 new_sync_entries.end()); |
| 936 | 936 |
| 937 EXPECT_EQ(expected_entries, new_sync_entries_set); | 937 EXPECT_EQ(expected_entries, new_sync_entries_set); |
| 938 } | 938 } |
| 939 | 939 |
| 940 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge_NullTerminated) { |
| 941 const char kEntry[] = "entry"; |
| 942 // A value which contains null terminating symbol. |
| 943 std::string entry(kEntry, arraysize(kEntry)); |
| 944 AutofillEntry native_entry0(MakeAutofillEntry("native", kEntry, 1)); |
| 945 AutofillEntry native_entry1(MakeAutofillEntry("native", entry, 1)); |
| 946 AutofillEntry sync_entry0(MakeAutofillEntry("sync", kEntry, 2)); |
| 947 AutofillEntry sync_entry1(MakeAutofillEntry("sync", entry, 2)); |
| 948 |
| 949 std::vector<AutofillEntry> native_entries; |
| 950 native_entries.push_back(native_entry0); |
| 951 native_entries.push_back(native_entry1); |
| 952 |
| 953 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 954 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
| 955 |
| 956 std::vector<AutofillEntry> sync_entries; |
| 957 sync_entries.push_back(sync_entry0); |
| 958 sync_entries.push_back(sync_entry1); |
| 959 |
| 960 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); |
| 961 |
| 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. |
| 964 EXPECT_CALL(autofill_table(), |
| 965 UpdateAutofillEntries(ElementsAre(sync_entry0, sync_entry1))) |
| 966 .WillOnce(Return(true)); |
| 967 |
| 968 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 969 StartSyncService(add_autofill.callback(), false, AUTOFILL); |
| 970 ASSERT_TRUE(add_autofill.success()); |
| 971 |
| 972 // Expecting that native_entry0 and native_entry1 won't merge into one entry. |
| 973 std::set<AutofillEntry> expected_entries; |
| 974 expected_entries.insert(native_entry0); |
| 975 expected_entries.insert(native_entry1); |
| 976 expected_entries.insert(sync_entry0); |
| 977 expected_entries.insert(sync_entry1); |
| 978 |
| 979 std::vector<AutofillEntry> new_sync_entries; |
| 980 std::vector<AutofillProfile> new_sync_profiles; |
| 981 ASSERT_TRUE( |
| 982 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); |
| 983 std::set<AutofillEntry> new_sync_entries_set(new_sync_entries.begin(), |
| 984 new_sync_entries.end()); |
| 985 |
| 986 EXPECT_EQ(expected_entries, new_sync_entries_set); |
| 987 } |
| 988 |
| 940 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { | 989 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { |
| 941 AutofillEntry native_entry(MakeAutofillEntry("merge", "entry", 1)); | 990 AutofillEntry native_entry(MakeAutofillEntry("merge", "entry", 1)); |
| 942 AutofillEntry sync_entry(MakeAutofillEntry("merge", "entry", 2)); | 991 AutofillEntry sync_entry(MakeAutofillEntry("merge", "entry", 2)); |
| 943 AutofillEntry merged_entry(MakeAutofillEntry("merge", "entry", 1, 2)); | 992 AutofillEntry merged_entry(MakeAutofillEntry("merge", "entry", 1, 2)); |
| 944 | 993 |
| 945 std::vector<AutofillEntry> native_entries; | 994 std::vector<AutofillEntry> native_entries; |
| 946 native_entries.push_back(native_entry); | 995 native_entries.push_back(native_entry); |
| 947 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) | 996 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 948 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); | 997 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
| 949 | 998 |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1552 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1504 EXPECT_EQ(3U, sync_entries.size()); | 1553 EXPECT_EQ(3U, sync_entries.size()); |
| 1505 EXPECT_EQ(0U, sync_profiles.size()); | 1554 EXPECT_EQ(0U, sync_profiles.size()); |
| 1506 for (size_t i = 0; i < sync_entries.size(); i++) { | 1555 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1507 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " | 1556 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " |
| 1508 << sync_entries[i].key().value(); | 1557 << sync_entries[i].key().value(); |
| 1509 } | 1558 } |
| 1510 } | 1559 } |
| 1511 | 1560 |
| 1512 } // namespace browser_sync | 1561 } // namespace browser_sync |
| OLD | NEW |