OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet; | 92 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet; |
93 typedef std::set<AutofillEntry, bool (*)(const AutofillEntry&, | 93 typedef std::set<AutofillEntry, bool (*)(const AutofillEntry&, |
94 const AutofillEntry&)>::iterator AutofillEntrySetIterator; | 94 const AutofillEntry&)>::iterator AutofillEntrySetIterator; |
95 | 95 |
96 virtual void SetUp() { | 96 virtual void SetUp() { |
97 #if defined(OS_MACOSX) | 97 #if defined(OS_MACOSX) |
98 Encryptor::UseMockKeychain(true); | 98 Encryptor::UseMockKeychain(true); |
99 #endif | 99 #endif |
100 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 100 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
101 file_ = temp_dir_.path().AppendASCII("TestWebDatabase"); | 101 file_ = temp_dir_.path().AppendASCII("TestWebDatabase"); |
| 102 |
| 103 table_.reset(new AutofillTable); |
| 104 db_.reset(new WebDatabase); |
| 105 db_->AddTable(table_.get()); |
| 106 ASSERT_EQ(sql::INIT_OK, db_->Init(file_, std::string())); |
102 } | 107 } |
103 | 108 |
104 static AutofillEntry MakeAutofillEntry(const char* name, | 109 static AutofillEntry MakeAutofillEntry(const char* name, |
105 const char* value, | 110 const char* value, |
106 time_t timestamp0, | 111 time_t timestamp0, |
107 time_t timestamp1) { | 112 time_t timestamp1) { |
108 std::vector<Time> timestamps; | 113 std::vector<Time> timestamps; |
109 if (timestamp0 >= 0) | 114 if (timestamp0 >= 0) |
110 timestamps.push_back(Time::FromTimeT(timestamp0)); | 115 timestamps.push_back(Time::FromTimeT(timestamp0)); |
111 if (timestamp1 >= 0) | 116 if (timestamp1 >= 0) |
112 timestamps.push_back(Time::FromTimeT(timestamp1)); | 117 timestamps.push_back(Time::FromTimeT(timestamp1)); |
113 return AutofillEntry( | 118 return AutofillEntry( |
114 AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), timestamps); | 119 AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), timestamps); |
115 } | 120 } |
116 | 121 |
117 base::FilePath file_; | 122 base::FilePath file_; |
118 base::ScopedTempDir temp_dir_; | 123 base::ScopedTempDir temp_dir_; |
| 124 scoped_ptr<AutofillTable> table_; |
| 125 scoped_ptr<WebDatabase> db_; |
119 | 126 |
120 private: | 127 private: |
121 DISALLOW_COPY_AND_ASSIGN(AutofillTableTest); | 128 DISALLOW_COPY_AND_ASSIGN(AutofillTableTest); |
122 }; | 129 }; |
123 | 130 |
124 TEST_F(AutofillTableTest, Autofill) { | 131 TEST_F(AutofillTableTest, Autofill) { |
125 WebDatabase db; | |
126 | |
127 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
128 | |
129 Time t1 = Time::Now(); | 132 Time t1 = Time::Now(); |
130 | 133 |
131 // Simulate the submission of a handful of entries in a field called "Name", | 134 // Simulate the submission of a handful of entries in a field called "Name", |
132 // some more often than others. | 135 // some more often than others. |
133 AutofillChangeList changes; | 136 AutofillChangeList changes; |
134 FormFieldData field; | 137 FormFieldData field; |
135 field.name = ASCIIToUTF16("Name"); | 138 field.name = ASCIIToUTF16("Name"); |
136 field.value = ASCIIToUTF16("Superman"); | 139 field.value = ASCIIToUTF16("Superman"); |
137 base::Time now = base::Time::Now(); | 140 base::Time now = base::Time::Now(); |
138 base::TimeDelta two_seconds = base::TimeDelta::FromSeconds(2); | 141 base::TimeDelta two_seconds = base::TimeDelta::FromSeconds(2); |
139 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes)); | 142 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); |
140 std::vector<string16> v; | 143 std::vector<string16> v; |
141 for (int i = 0; i < 5; i++) { | 144 for (int i = 0; i < 5; i++) { |
142 field.value = ASCIIToUTF16("Clark Kent"); | 145 field.value = ASCIIToUTF16("Clark Kent"); |
143 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, | 146 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, |
144 now + i * two_seconds)); | 147 now + i * two_seconds)); |
145 } | 148 } |
146 for (int i = 0; i < 3; i++) { | 149 for (int i = 0; i < 3; i++) { |
147 field.value = ASCIIToUTF16("Clark Sutter"); | 150 field.value = ASCIIToUTF16("Clark Sutter"); |
148 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, | 151 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, |
149 now + i * two_seconds)); | 152 now + i * two_seconds)); |
150 } | 153 } |
151 for (int i = 0; i < 2; i++) { | 154 for (int i = 0; i < 2; i++) { |
152 field.name = ASCIIToUTF16("Favorite Color"); | 155 field.name = ASCIIToUTF16("Favorite Color"); |
153 field.value = ASCIIToUTF16("Green"); | 156 field.value = ASCIIToUTF16("Green"); |
154 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, | 157 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, |
155 now + i * two_seconds)); | 158 now + i * two_seconds)); |
156 } | 159 } |
157 | 160 |
158 int count = 0; | 161 int count = 0; |
159 int64 pair_id = 0; | 162 int64 pair_id = 0; |
160 | 163 |
161 // We have added the name Clark Kent 5 times, so count should be 5 and pair_id | 164 // We have added the name Clark Kent 5 times, so count should be 5 and pair_id |
162 // should be somthing non-zero. | 165 // should be somthing non-zero. |
163 field.name = ASCIIToUTF16("Name"); | 166 field.name = ASCIIToUTF16("Name"); |
164 field.value = ASCIIToUTF16("Clark Kent"); | 167 field.value = ASCIIToUTF16("Clark Kent"); |
165 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id, | 168 EXPECT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count)); |
166 &count)); | |
167 EXPECT_EQ(5, count); | 169 EXPECT_EQ(5, count); |
168 EXPECT_NE(0, pair_id); | 170 EXPECT_NE(0, pair_id); |
169 | 171 |
170 // Storing in the data base should be case sensitive, so there should be no | 172 // Storing in the data base should be case sensitive, so there should be no |
171 // database entry for clark kent lowercase. | 173 // database entry for clark kent lowercase. |
172 field.value = ASCIIToUTF16("clark kent"); | 174 field.value = ASCIIToUTF16("clark kent"); |
173 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id, | 175 EXPECT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count)); |
174 &count)); | |
175 EXPECT_EQ(0, count); | 176 EXPECT_EQ(0, count); |
176 | 177 |
177 field.name = ASCIIToUTF16("Favorite Color"); | 178 field.name = ASCIIToUTF16("Favorite Color"); |
178 field.value = ASCIIToUTF16("Green"); | 179 field.value = ASCIIToUTF16("Green"); |
179 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id, | 180 EXPECT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count)); |
180 &count)); | |
181 EXPECT_EQ(2, count); | 181 EXPECT_EQ(2, count); |
182 | 182 |
183 // This is meant to get a list of suggestions for Name. The empty prefix | 183 // This is meant to get a list of suggestions for Name. The empty prefix |
184 // in the second argument means it should return all suggestions for a name | 184 // in the second argument means it should return all suggestions for a name |
185 // no matter what they start with. The order that the names occur in the list | 185 // no matter what they start with. The order that the names occur in the list |
186 // should be decreasing order by count. | 186 // should be decreasing order by count. |
187 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( | 187 EXPECT_TRUE(table_->GetFormValuesForElementName( |
188 ASCIIToUTF16("Name"), string16(), &v, 6)); | 188 ASCIIToUTF16("Name"), string16(), &v, 6)); |
189 EXPECT_EQ(3U, v.size()); | 189 EXPECT_EQ(3U, v.size()); |
190 if (v.size() == 3) { | 190 if (v.size() == 3) { |
191 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]); | 191 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]); |
192 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]); | 192 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]); |
193 EXPECT_EQ(ASCIIToUTF16("Superman"), v[2]); | 193 EXPECT_EQ(ASCIIToUTF16("Superman"), v[2]); |
194 } | 194 } |
195 | 195 |
196 // If we query again limiting the list size to 1, we should only get the most | 196 // If we query again limiting the list size to 1, we should only get the most |
197 // frequent entry. | 197 // frequent entry. |
198 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( | 198 EXPECT_TRUE(table_->GetFormValuesForElementName( |
199 ASCIIToUTF16("Name"), string16(), &v, 1)); | 199 ASCIIToUTF16("Name"), string16(), &v, 1)); |
200 EXPECT_EQ(1U, v.size()); | 200 EXPECT_EQ(1U, v.size()); |
201 if (v.size() == 1) { | 201 if (v.size() == 1) { |
202 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]); | 202 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]); |
203 } | 203 } |
204 | 204 |
205 // Querying for suggestions given a prefix is case-insensitive, so the prefix | 205 // Querying for suggestions given a prefix is case-insensitive, so the prefix |
206 // "cLa" shoud get suggestions for both Clarks. | 206 // "cLa" shoud get suggestions for both Clarks. |
207 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( | 207 EXPECT_TRUE(table_->GetFormValuesForElementName( |
208 ASCIIToUTF16("Name"), ASCIIToUTF16("cLa"), &v, 6)); | 208 ASCIIToUTF16("Name"), ASCIIToUTF16("cLa"), &v, 6)); |
209 EXPECT_EQ(2U, v.size()); | 209 EXPECT_EQ(2U, v.size()); |
210 if (v.size() == 2) { | 210 if (v.size() == 2) { |
211 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]); | 211 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]); |
212 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]); | 212 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]); |
213 } | 213 } |
214 | 214 |
215 // Removing all elements since the beginning of this function should remove | 215 // Removing all elements since the beginning of this function should remove |
216 // everything from the database. | 216 // everything from the database. |
217 changes.clear(); | 217 changes.clear(); |
218 EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween( | 218 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(t1, Time(), &changes)); |
219 t1, Time(), &changes)); | |
220 | 219 |
221 const AutofillChange expected_changes[] = { | 220 const AutofillChange expected_changes[] = { |
222 AutofillChange(AutofillChange::REMOVE, | 221 AutofillChange(AutofillChange::REMOVE, |
223 AutofillKey(ASCIIToUTF16("Name"), | 222 AutofillKey(ASCIIToUTF16("Name"), |
224 ASCIIToUTF16("Superman"))), | 223 ASCIIToUTF16("Superman"))), |
225 AutofillChange(AutofillChange::REMOVE, | 224 AutofillChange(AutofillChange::REMOVE, |
226 AutofillKey(ASCIIToUTF16("Name"), | 225 AutofillKey(ASCIIToUTF16("Name"), |
227 ASCIIToUTF16("Clark Kent"))), | 226 ASCIIToUTF16("Clark Kent"))), |
228 AutofillChange(AutofillChange::REMOVE, | 227 AutofillChange(AutofillChange::REMOVE, |
229 AutofillKey(ASCIIToUTF16("Name"), | 228 AutofillKey(ASCIIToUTF16("Name"), |
230 ASCIIToUTF16("Clark Sutter"))), | 229 ASCIIToUTF16("Clark Sutter"))), |
231 AutofillChange(AutofillChange::REMOVE, | 230 AutofillChange(AutofillChange::REMOVE, |
232 AutofillKey(ASCIIToUTF16("Favorite Color"), | 231 AutofillKey(ASCIIToUTF16("Favorite Color"), |
233 ASCIIToUTF16("Green"))), | 232 ASCIIToUTF16("Green"))), |
234 }; | 233 }; |
235 EXPECT_EQ(arraysize(expected_changes), changes.size()); | 234 EXPECT_EQ(arraysize(expected_changes), changes.size()); |
236 for (size_t i = 0; i < arraysize(expected_changes); i++) { | 235 for (size_t i = 0; i < arraysize(expected_changes); i++) { |
237 EXPECT_EQ(expected_changes[i], changes[i]); | 236 EXPECT_EQ(expected_changes[i], changes[i]); |
238 } | 237 } |
239 | 238 |
240 field.name = ASCIIToUTF16("Name"); | 239 field.name = ASCIIToUTF16("Name"); |
241 field.value = ASCIIToUTF16("Clark Kent"); | 240 field.value = ASCIIToUTF16("Clark Kent"); |
242 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id, | 241 EXPECT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count)); |
243 &count)); | |
244 EXPECT_EQ(0, count); | 242 EXPECT_EQ(0, count); |
245 | 243 |
246 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( | 244 EXPECT_TRUE(table_->GetFormValuesForElementName( |
247 ASCIIToUTF16("Name"), string16(), &v, 6)); | 245 ASCIIToUTF16("Name"), string16(), &v, 6)); |
248 EXPECT_EQ(0U, v.size()); | 246 EXPECT_EQ(0U, v.size()); |
249 | 247 |
250 // Now add some values with empty strings. | 248 // Now add some values with empty strings. |
251 const string16 kValue = ASCIIToUTF16(" toto "); | 249 const string16 kValue = ASCIIToUTF16(" toto "); |
252 field.name = ASCIIToUTF16("blank"); | 250 field.name = ASCIIToUTF16("blank"); |
253 field.value = string16(); | 251 field.value = string16(); |
254 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes)); | 252 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); |
255 field.name = ASCIIToUTF16("blank"); | 253 field.name = ASCIIToUTF16("blank"); |
256 field.value = ASCIIToUTF16(" "); | 254 field.value = ASCIIToUTF16(" "); |
257 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes)); | 255 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); |
258 field.name = ASCIIToUTF16("blank"); | 256 field.name = ASCIIToUTF16("blank"); |
259 field.value = ASCIIToUTF16(" "); | 257 field.value = ASCIIToUTF16(" "); |
260 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes)); | 258 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); |
261 field.name = ASCIIToUTF16("blank"); | 259 field.name = ASCIIToUTF16("blank"); |
262 field.value = kValue; | 260 field.value = kValue; |
263 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes)); | 261 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); |
264 | 262 |
265 // They should be stored normally as the DB layer does not check for empty | 263 // They should be stored normally as the DB layer does not check for empty |
266 // values. | 264 // values. |
267 v.clear(); | 265 v.clear(); |
268 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( | 266 EXPECT_TRUE(table_->GetFormValuesForElementName( |
269 ASCIIToUTF16("blank"), string16(), &v, 10)); | 267 ASCIIToUTF16("blank"), string16(), &v, 10)); |
270 EXPECT_EQ(4U, v.size()); | 268 EXPECT_EQ(4U, v.size()); |
271 | 269 |
272 // Now we'll check that ClearAutofillEmptyValueElements() works as expected. | 270 // Now we'll check that ClearAutofillEmptyValueElements() works as expected. |
273 db.GetAutofillTable()->ClearAutofillEmptyValueElements(); | 271 table_->ClearAutofillEmptyValueElements(); |
274 | 272 |
275 v.clear(); | 273 v.clear(); |
276 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( | 274 EXPECT_TRUE(table_->GetFormValuesForElementName( |
277 ASCIIToUTF16("blank"), string16(), &v, 10)); | 275 ASCIIToUTF16("blank"), string16(), &v, 10)); |
278 ASSERT_EQ(1U, v.size()); | 276 ASSERT_EQ(1U, v.size()); |
279 | 277 |
280 EXPECT_EQ(kValue, v[0]); | 278 EXPECT_EQ(kValue, v[0]); |
281 } | 279 } |
282 | 280 |
283 TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) { | 281 TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) { |
284 WebDatabase db; | |
285 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
286 | |
287 TimeDelta one_day(TimeDelta::FromDays(1)); | 282 TimeDelta one_day(TimeDelta::FromDays(1)); |
288 Time t1 = Time::Now(); | 283 Time t1 = Time::Now(); |
289 Time t2 = t1 + one_day; | 284 Time t2 = t1 + one_day; |
290 | 285 |
291 AutofillChangeList changes; | 286 AutofillChangeList changes; |
292 FormFieldData field; | 287 FormFieldData field; |
293 field.name = ASCIIToUTF16("Name"); | 288 field.name = ASCIIToUTF16("Name"); |
294 field.value = ASCIIToUTF16("Superman"); | 289 field.value = ASCIIToUTF16("Superman"); |
295 EXPECT_TRUE( | 290 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t1)); |
296 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t1)); | 291 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t2)); |
297 EXPECT_TRUE( | |
298 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t2)); | |
299 | 292 |
300 changes.clear(); | 293 changes.clear(); |
301 EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween( | 294 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(t1, t2, &changes)); |
302 t1, t2, &changes)); | |
303 ASSERT_EQ(1U, changes.size()); | 295 ASSERT_EQ(1U, changes.size()); |
304 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE, | 296 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE, |
305 AutofillKey(ASCIIToUTF16("Name"), | 297 AutofillKey(ASCIIToUTF16("Name"), |
306 ASCIIToUTF16("Superman"))), | 298 ASCIIToUTF16("Superman"))), |
307 changes[0]); | 299 changes[0]); |
308 changes.clear(); | 300 changes.clear(); |
309 | 301 |
310 EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween( | 302 EXPECT_TRUE( |
311 t2, t2 + one_day, &changes)); | 303 table_->RemoveFormElementsAddedBetween(t2, t2 + one_day, &changes)); |
312 ASSERT_EQ(1U, changes.size()); | 304 ASSERT_EQ(1U, changes.size()); |
313 EXPECT_EQ(AutofillChange(AutofillChange::REMOVE, | 305 EXPECT_EQ(AutofillChange(AutofillChange::REMOVE, |
314 AutofillKey(ASCIIToUTF16("Name"), | 306 AutofillKey(ASCIIToUTF16("Name"), |
315 ASCIIToUTF16("Superman"))), | 307 ASCIIToUTF16("Superman"))), |
316 changes[0]); | 308 changes[0]); |
317 } | 309 } |
318 | 310 |
319 TEST_F(AutofillTableTest, Autofill_AddChanges) { | 311 TEST_F(AutofillTableTest, Autofill_AddChanges) { |
320 WebDatabase db; | |
321 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
322 | |
323 TimeDelta one_day(TimeDelta::FromDays(1)); | 312 TimeDelta one_day(TimeDelta::FromDays(1)); |
324 Time t1 = Time::Now(); | 313 Time t1 = Time::Now(); |
325 Time t2 = t1 + one_day; | 314 Time t2 = t1 + one_day; |
326 | 315 |
327 AutofillChangeList changes; | 316 AutofillChangeList changes; |
328 FormFieldData field; | 317 FormFieldData field; |
329 field.name = ASCIIToUTF16("Name"); | 318 field.name = ASCIIToUTF16("Name"); |
330 field.value = ASCIIToUTF16("Superman"); | 319 field.value = ASCIIToUTF16("Superman"); |
331 EXPECT_TRUE( | 320 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t1)); |
332 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t1)); | |
333 ASSERT_EQ(1U, changes.size()); | 321 ASSERT_EQ(1U, changes.size()); |
334 EXPECT_EQ(AutofillChange(AutofillChange::ADD, | 322 EXPECT_EQ(AutofillChange(AutofillChange::ADD, |
335 AutofillKey(ASCIIToUTF16("Name"), | 323 AutofillKey(ASCIIToUTF16("Name"), |
336 ASCIIToUTF16("Superman"))), | 324 ASCIIToUTF16("Superman"))), |
337 changes[0]); | 325 changes[0]); |
338 | 326 |
339 changes.clear(); | 327 changes.clear(); |
340 EXPECT_TRUE( | 328 EXPECT_TRUE( |
341 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t2)); | 329 table_->AddFormFieldValueTime(field, &changes, t2)); |
342 ASSERT_EQ(1U, changes.size()); | 330 ASSERT_EQ(1U, changes.size()); |
343 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE, | 331 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE, |
344 AutofillKey(ASCIIToUTF16("Name"), | 332 AutofillKey(ASCIIToUTF16("Name"), |
345 ASCIIToUTF16("Superman"))), | 333 ASCIIToUTF16("Superman"))), |
346 changes[0]); | 334 changes[0]); |
347 } | 335 } |
348 | 336 |
349 TEST_F(AutofillTableTest, Autofill_UpdateOneWithOneTimestamp) { | 337 TEST_F(AutofillTableTest, Autofill_UpdateOneWithOneTimestamp) { |
350 WebDatabase db; | |
351 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
352 | |
353 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, -1)); | 338 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, -1)); |
354 std::vector<AutofillEntry> entries; | 339 std::vector<AutofillEntry> entries; |
355 entries.push_back(entry); | 340 entries.push_back(entry); |
356 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); | 341 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); |
357 | 342 |
358 FormFieldData field; | 343 FormFieldData field; |
359 field.name = ASCIIToUTF16("foo"); | 344 field.name = ASCIIToUTF16("foo"); |
360 field.value = ASCIIToUTF16("bar"); | 345 field.value = ASCIIToUTF16("bar"); |
361 int64 pair_id; | 346 int64 pair_id; |
362 int count; | 347 int count; |
363 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( | 348 ASSERT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count)); |
364 field, &pair_id, &count)); | |
365 EXPECT_LE(0, pair_id); | 349 EXPECT_LE(0, pair_id); |
366 EXPECT_EQ(1, count); | 350 EXPECT_EQ(1, count); |
367 | 351 |
368 std::vector<AutofillEntry> all_entries; | 352 std::vector<AutofillEntry> all_entries; |
369 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); | 353 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries)); |
370 ASSERT_EQ(1U, all_entries.size()); | 354 ASSERT_EQ(1U, all_entries.size()); |
371 EXPECT_TRUE(entry == all_entries[0]); | 355 EXPECT_TRUE(entry == all_entries[0]); |
372 } | 356 } |
373 | 357 |
374 TEST_F(AutofillTableTest, Autofill_UpdateOneWithTwoTimestamps) { | 358 TEST_F(AutofillTableTest, Autofill_UpdateOneWithTwoTimestamps) { |
375 WebDatabase db; | |
376 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
377 | |
378 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2)); | 359 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2)); |
379 std::vector<AutofillEntry> entries; | 360 std::vector<AutofillEntry> entries; |
380 entries.push_back(entry); | 361 entries.push_back(entry); |
381 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); | 362 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); |
382 | 363 |
383 FormFieldData field; | 364 FormFieldData field; |
384 field.name = ASCIIToUTF16("foo"); | 365 field.name = ASCIIToUTF16("foo"); |
385 field.value = ASCIIToUTF16("bar"); | 366 field.value = ASCIIToUTF16("bar"); |
386 int64 pair_id; | 367 int64 pair_id; |
387 int count; | 368 int count; |
388 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( | 369 ASSERT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count)); |
389 field, &pair_id, &count)); | |
390 EXPECT_LE(0, pair_id); | 370 EXPECT_LE(0, pair_id); |
391 EXPECT_EQ(2, count); | 371 EXPECT_EQ(2, count); |
392 | 372 |
393 std::vector<AutofillEntry> all_entries; | 373 std::vector<AutofillEntry> all_entries; |
394 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); | 374 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries)); |
395 ASSERT_EQ(1U, all_entries.size()); | 375 ASSERT_EQ(1U, all_entries.size()); |
396 EXPECT_TRUE(entry == all_entries[0]); | 376 EXPECT_TRUE(entry == all_entries[0]); |
397 } | 377 } |
398 | 378 |
399 TEST_F(AutofillTableTest, Autofill_GetAutofillTimestamps) { | 379 TEST_F(AutofillTableTest, Autofill_GetAutofillTimestamps) { |
400 WebDatabase db; | |
401 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
402 | |
403 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2)); | 380 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2)); |
404 std::vector<AutofillEntry> entries; | 381 std::vector<AutofillEntry> entries; |
405 entries.push_back(entry); | 382 entries.push_back(entry); |
406 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); | 383 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); |
407 | 384 |
408 std::vector<Time> timestamps; | 385 std::vector<Time> timestamps; |
409 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillTimestamps(ASCIIToUTF16("foo"), | 386 ASSERT_TRUE(table_->GetAutofillTimestamps(ASCIIToUTF16("foo"), |
410 ASCIIToUTF16("bar"), | 387 ASCIIToUTF16("bar"), |
411 ×tamps)); | 388 ×tamps)); |
412 ASSERT_EQ(2U, timestamps.size()); | 389 ASSERT_EQ(2U, timestamps.size()); |
413 EXPECT_TRUE(Time::FromTimeT(1) == timestamps[0]); | 390 EXPECT_TRUE(Time::FromTimeT(1) == timestamps[0]); |
414 EXPECT_TRUE(Time::FromTimeT(2) == timestamps[1]); | 391 EXPECT_TRUE(Time::FromTimeT(2) == timestamps[1]); |
415 } | 392 } |
416 | 393 |
417 TEST_F(AutofillTableTest, Autofill_UpdateTwo) { | 394 TEST_F(AutofillTableTest, Autofill_UpdateTwo) { |
418 WebDatabase db; | |
419 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
420 | |
421 AutofillEntry entry0(MakeAutofillEntry("foo", "bar0", 1, -1)); | 395 AutofillEntry entry0(MakeAutofillEntry("foo", "bar0", 1, -1)); |
422 AutofillEntry entry1(MakeAutofillEntry("foo", "bar1", 2, 3)); | 396 AutofillEntry entry1(MakeAutofillEntry("foo", "bar1", 2, 3)); |
423 std::vector<AutofillEntry> entries; | 397 std::vector<AutofillEntry> entries; |
424 entries.push_back(entry0); | 398 entries.push_back(entry0); |
425 entries.push_back(entry1); | 399 entries.push_back(entry1); |
426 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); | 400 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); |
427 | 401 |
428 FormFieldData field0; | 402 FormFieldData field0; |
429 field0.name = ASCIIToUTF16("foo"); | 403 field0.name = ASCIIToUTF16("foo"); |
430 field0.value = ASCIIToUTF16("bar0"); | 404 field0.value = ASCIIToUTF16("bar0"); |
431 int64 pair_id; | 405 int64 pair_id; |
432 int count; | 406 int count; |
433 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( | 407 ASSERT_TRUE(table_->GetIDAndCountOfFormElement(field0, &pair_id, &count)); |
434 field0, &pair_id, &count)); | |
435 EXPECT_LE(0, pair_id); | 408 EXPECT_LE(0, pair_id); |
436 EXPECT_EQ(1, count); | 409 EXPECT_EQ(1, count); |
437 | 410 |
438 FormFieldData field1; | 411 FormFieldData field1; |
439 field1.name = ASCIIToUTF16("foo"); | 412 field1.name = ASCIIToUTF16("foo"); |
440 field1.value = ASCIIToUTF16("bar1"); | 413 field1.value = ASCIIToUTF16("bar1"); |
441 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( | 414 ASSERT_TRUE(table_->GetIDAndCountOfFormElement(field1, &pair_id, &count)); |
442 field1, &pair_id, &count)); | |
443 EXPECT_LE(0, pair_id); | 415 EXPECT_LE(0, pair_id); |
444 EXPECT_EQ(2, count); | 416 EXPECT_EQ(2, count); |
445 } | 417 } |
446 | 418 |
447 TEST_F(AutofillTableTest, Autofill_UpdateReplace) { | 419 TEST_F(AutofillTableTest, Autofill_UpdateReplace) { |
448 WebDatabase db; | |
449 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
450 | |
451 AutofillChangeList changes; | 420 AutofillChangeList changes; |
452 // Add a form field. This will be replaced. | 421 // Add a form field. This will be replaced. |
453 FormFieldData field; | 422 FormFieldData field; |
454 field.name = ASCIIToUTF16("Name"); | 423 field.name = ASCIIToUTF16("Name"); |
455 field.value = ASCIIToUTF16("Superman"); | 424 field.value = ASCIIToUTF16("Superman"); |
456 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes)); | 425 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); |
457 | 426 |
458 AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2)); | 427 AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2)); |
459 std::vector<AutofillEntry> entries; | 428 std::vector<AutofillEntry> entries; |
460 entries.push_back(entry); | 429 entries.push_back(entry); |
461 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); | 430 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); |
462 | 431 |
463 std::vector<AutofillEntry> all_entries; | 432 std::vector<AutofillEntry> all_entries; |
464 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); | 433 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries)); |
465 ASSERT_EQ(1U, all_entries.size()); | 434 ASSERT_EQ(1U, all_entries.size()); |
466 EXPECT_TRUE(entry == all_entries[0]); | 435 EXPECT_TRUE(entry == all_entries[0]); |
467 } | 436 } |
468 | 437 |
469 TEST_F(AutofillTableTest, Autofill_UpdateDontReplace) { | 438 TEST_F(AutofillTableTest, Autofill_UpdateDontReplace) { |
470 WebDatabase db; | |
471 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
472 | |
473 Time t = Time::Now(); | 439 Time t = Time::Now(); |
474 AutofillEntry existing( | 440 AutofillEntry existing( |
475 MakeAutofillEntry("Name", "Superman", t.ToTimeT(), -1)); | 441 MakeAutofillEntry("Name", "Superman", t.ToTimeT(), -1)); |
476 | 442 |
477 AutofillChangeList changes; | 443 AutofillChangeList changes; |
478 // Add a form field. This will NOT be replaced. | 444 // Add a form field. This will NOT be replaced. |
479 FormFieldData field; | 445 FormFieldData field; |
480 field.name = existing.key().name(); | 446 field.name = existing.key().name(); |
481 field.value = existing.key().value(); | 447 field.value = existing.key().value(); |
482 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t)); | 448 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t)); |
483 AutofillEntry entry(MakeAutofillEntry("Name", "Clark Kent", 1, 2)); | 449 AutofillEntry entry(MakeAutofillEntry("Name", "Clark Kent", 1, 2)); |
484 std::vector<AutofillEntry> entries; | 450 std::vector<AutofillEntry> entries; |
485 entries.push_back(entry); | 451 entries.push_back(entry); |
486 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); | 452 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); |
487 | 453 |
488 std::vector<AutofillEntry> all_entries; | 454 std::vector<AutofillEntry> all_entries; |
489 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); | 455 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries)); |
490 ASSERT_EQ(2U, all_entries.size()); | 456 ASSERT_EQ(2U, all_entries.size()); |
491 AutofillEntrySet expected_entries(all_entries.begin(), | 457 AutofillEntrySet expected_entries(all_entries.begin(), |
492 all_entries.end(), | 458 all_entries.end(), |
493 CompareAutofillEntries); | 459 CompareAutofillEntries); |
494 EXPECT_EQ(1U, expected_entries.count(existing)); | 460 EXPECT_EQ(1U, expected_entries.count(existing)); |
495 EXPECT_EQ(1U, expected_entries.count(entry)); | 461 EXPECT_EQ(1U, expected_entries.count(entry)); |
496 } | 462 } |
497 | 463 |
498 TEST_F(AutofillTableTest, Autofill_AddFormFieldValues) { | 464 TEST_F(AutofillTableTest, Autofill_AddFormFieldValues) { |
499 WebDatabase db; | |
500 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
501 | |
502 Time t = Time::Now(); | 465 Time t = Time::Now(); |
503 | 466 |
504 // Add multiple values for "firstname" and "lastname" names. Test that only | 467 // Add multiple values for "firstname" and "lastname" names. Test that only |
505 // first value of each gets added. Related to security issue: | 468 // first value of each gets added. Related to security issue: |
506 // http://crbug.com/51727. | 469 // http://crbug.com/51727. |
507 std::vector<FormFieldData> elements; | 470 std::vector<FormFieldData> elements; |
508 FormFieldData field; | 471 FormFieldData field; |
509 field.name = ASCIIToUTF16("firstname"); | 472 field.name = ASCIIToUTF16("firstname"); |
510 field.value = ASCIIToUTF16("Joe"); | 473 field.value = ASCIIToUTF16("Joe"); |
511 elements.push_back(field); | 474 elements.push_back(field); |
512 | 475 |
513 field.name = ASCIIToUTF16("firstname"); | 476 field.name = ASCIIToUTF16("firstname"); |
514 field.value = ASCIIToUTF16("Jane"); | 477 field.value = ASCIIToUTF16("Jane"); |
515 elements.push_back(field); | 478 elements.push_back(field); |
516 | 479 |
517 field.name = ASCIIToUTF16("lastname"); | 480 field.name = ASCIIToUTF16("lastname"); |
518 field.value = ASCIIToUTF16("Smith"); | 481 field.value = ASCIIToUTF16("Smith"); |
519 elements.push_back(field); | 482 elements.push_back(field); |
520 | 483 |
521 field.name = ASCIIToUTF16("lastname"); | 484 field.name = ASCIIToUTF16("lastname"); |
522 field.value = ASCIIToUTF16("Jones"); | 485 field.value = ASCIIToUTF16("Jones"); |
523 elements.push_back(field); | 486 elements.push_back(field); |
524 | 487 |
525 std::vector<AutofillChange> changes; | 488 std::vector<AutofillChange> changes; |
526 db.GetAutofillTable()->AddFormFieldValuesTime(elements, &changes, t); | 489 table_->AddFormFieldValuesTime(elements, &changes, t); |
527 | 490 |
528 ASSERT_EQ(2U, changes.size()); | 491 ASSERT_EQ(2U, changes.size()); |
529 EXPECT_EQ(changes[0], AutofillChange(AutofillChange::ADD, | 492 EXPECT_EQ(changes[0], AutofillChange(AutofillChange::ADD, |
530 AutofillKey(ASCIIToUTF16("firstname"), | 493 AutofillKey(ASCIIToUTF16("firstname"), |
531 ASCIIToUTF16("Joe")))); | 494 ASCIIToUTF16("Joe")))); |
532 EXPECT_EQ(changes[1], AutofillChange(AutofillChange::ADD, | 495 EXPECT_EQ(changes[1], AutofillChange(AutofillChange::ADD, |
533 AutofillKey(ASCIIToUTF16("lastname"), | 496 AutofillKey(ASCIIToUTF16("lastname"), |
534 ASCIIToUTF16("Smith")))); | 497 ASCIIToUTF16("Smith")))); |
535 | 498 |
536 std::vector<AutofillEntry> all_entries; | 499 std::vector<AutofillEntry> all_entries; |
537 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); | 500 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries)); |
538 ASSERT_EQ(2U, all_entries.size()); | 501 ASSERT_EQ(2U, all_entries.size()); |
539 } | 502 } |
540 | 503 |
541 TEST_F(AutofillTableTest, AutofillProfile) { | 504 TEST_F(AutofillTableTest, AutofillProfile) { |
542 WebDatabase db; | |
543 | |
544 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
545 | |
546 // Add a 'Home' profile. | 505 // Add a 'Home' profile. |
547 AutofillProfile home_profile; | 506 AutofillProfile home_profile; |
548 home_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); | 507 home_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); |
549 home_profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); | 508 home_profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); |
550 home_profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith")); | 509 home_profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith")); |
551 home_profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz")); | 510 home_profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz")); |
552 home_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google")); | 511 home_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google")); |
553 home_profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way")); | 512 home_profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way")); |
554 home_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5")); | 513 home_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5")); |
555 home_profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); | 514 home_profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); |
556 home_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | 515 home_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
557 home_profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); | 516 home_profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); |
558 home_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | 517 home_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
559 home_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567")); | 518 home_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567")); |
560 | 519 |
561 Time pre_creation_time = Time::Now(); | 520 Time pre_creation_time = Time::Now(); |
562 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(home_profile)); | 521 EXPECT_TRUE(table_->AddAutofillProfile(home_profile)); |
563 Time post_creation_time = Time::Now(); | 522 Time post_creation_time = Time::Now(); |
564 | 523 |
565 // Get the 'Home' profile. | 524 // Get the 'Home' profile. |
566 AutofillProfile* db_profile; | 525 AutofillProfile* db_profile; |
567 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile( | 526 ASSERT_TRUE(table_->GetAutofillProfile(home_profile.guid(), &db_profile)); |
568 home_profile.guid(), &db_profile)); | |
569 EXPECT_EQ(home_profile, *db_profile); | 527 EXPECT_EQ(home_profile, *db_profile); |
570 sql::Statement s_home(db.GetSQLConnection()->GetUniqueStatement( | 528 sql::Statement s_home(db_->GetSQLConnection()->GetUniqueStatement( |
571 "SELECT date_modified " | 529 "SELECT date_modified " |
572 "FROM autofill_profiles WHERE guid=?")); | 530 "FROM autofill_profiles WHERE guid=?")); |
573 s_home.BindString(0, home_profile.guid()); | 531 s_home.BindString(0, home_profile.guid()); |
574 ASSERT_TRUE(s_home.is_valid()); | 532 ASSERT_TRUE(s_home.is_valid()); |
575 ASSERT_TRUE(s_home.Step()); | 533 ASSERT_TRUE(s_home.Step()); |
576 EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT()); | 534 EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT()); |
577 EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT()); | 535 EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT()); |
578 EXPECT_FALSE(s_home.Step()); | 536 EXPECT_FALSE(s_home.Step()); |
579 delete db_profile; | 537 delete db_profile; |
580 | 538 |
581 // Add a 'Billing' profile. | 539 // Add a 'Billing' profile. |
582 AutofillProfile billing_profile = home_profile; | 540 AutofillProfile billing_profile = home_profile; |
583 billing_profile.set_guid(base::GenerateGUID()); | 541 billing_profile.set_guid(base::GenerateGUID()); |
584 billing_profile.SetRawInfo(ADDRESS_HOME_LINE1, | 542 billing_profile.SetRawInfo(ADDRESS_HOME_LINE1, |
585 ASCIIToUTF16("5678 Bottom Street")); | 543 ASCIIToUTF16("5678 Bottom Street")); |
586 billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("suite 3")); | 544 billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("suite 3")); |
587 | 545 |
588 pre_creation_time = Time::Now(); | 546 pre_creation_time = Time::Now(); |
589 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(billing_profile)); | 547 EXPECT_TRUE(table_->AddAutofillProfile(billing_profile)); |
590 post_creation_time = Time::Now(); | 548 post_creation_time = Time::Now(); |
591 | 549 |
592 // Get the 'Billing' profile. | 550 // Get the 'Billing' profile. |
593 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile( | 551 ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile)); |
594 billing_profile.guid(), &db_profile)); | |
595 EXPECT_EQ(billing_profile, *db_profile); | 552 EXPECT_EQ(billing_profile, *db_profile); |
596 sql::Statement s_billing(db.GetSQLConnection()->GetUniqueStatement( | 553 sql::Statement s_billing(db_->GetSQLConnection()->GetUniqueStatement( |
597 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); | 554 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); |
598 s_billing.BindString(0, billing_profile.guid()); | 555 s_billing.BindString(0, billing_profile.guid()); |
599 ASSERT_TRUE(s_billing.is_valid()); | 556 ASSERT_TRUE(s_billing.is_valid()); |
600 ASSERT_TRUE(s_billing.Step()); | 557 ASSERT_TRUE(s_billing.Step()); |
601 EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT()); | 558 EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT()); |
602 EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT()); | 559 EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT()); |
603 EXPECT_FALSE(s_billing.Step()); | 560 EXPECT_FALSE(s_billing.Step()); |
604 delete db_profile; | 561 delete db_profile; |
605 | 562 |
606 // Update the 'Billing' profile, name only. | 563 // Update the 'Billing' profile, name only. |
607 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); | 564 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); |
608 Time pre_modification_time = Time::Now(); | 565 Time pre_modification_time = Time::Now(); |
609 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti( | 566 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(billing_profile)); |
610 billing_profile)); | |
611 Time post_modification_time = Time::Now(); | 567 Time post_modification_time = Time::Now(); |
612 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile( | 568 ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile)); |
613 billing_profile.guid(), &db_profile)); | |
614 EXPECT_EQ(billing_profile, *db_profile); | 569 EXPECT_EQ(billing_profile, *db_profile); |
615 sql::Statement s_billing_updated(db.GetSQLConnection()->GetUniqueStatement( | 570 sql::Statement s_billing_updated(db_->GetSQLConnection()->GetUniqueStatement( |
616 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); | 571 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); |
617 s_billing_updated.BindString(0, billing_profile.guid()); | 572 s_billing_updated.BindString(0, billing_profile.guid()); |
618 ASSERT_TRUE(s_billing_updated.is_valid()); | 573 ASSERT_TRUE(s_billing_updated.is_valid()); |
619 ASSERT_TRUE(s_billing_updated.Step()); | 574 ASSERT_TRUE(s_billing_updated.Step()); |
620 EXPECT_GE(s_billing_updated.ColumnInt64(0), | 575 EXPECT_GE(s_billing_updated.ColumnInt64(0), |
621 pre_modification_time.ToTimeT()); | 576 pre_modification_time.ToTimeT()); |
622 EXPECT_LE(s_billing_updated.ColumnInt64(0), | 577 EXPECT_LE(s_billing_updated.ColumnInt64(0), |
623 post_modification_time.ToTimeT()); | 578 post_modification_time.ToTimeT()); |
624 EXPECT_FALSE(s_billing_updated.Step()); | 579 EXPECT_FALSE(s_billing_updated.Step()); |
625 delete db_profile; | 580 delete db_profile; |
626 | 581 |
627 // Update the 'Billing' profile. | 582 // Update the 'Billing' profile. |
628 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Janice")); | 583 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Janice")); |
629 billing_profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("C.")); | 584 billing_profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("C.")); |
630 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Joplin")); | 585 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Joplin")); |
631 billing_profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("jane@singer.com")); | 586 billing_profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("jane@singer.com")); |
632 billing_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Indy")); | 587 billing_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Indy")); |
633 billing_profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("Open Road")); | 588 billing_profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("Open Road")); |
634 billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Route 66")); | 589 billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Route 66")); |
635 billing_profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("NFA")); | 590 billing_profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("NFA")); |
636 billing_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("NY")); | 591 billing_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("NY")); |
637 billing_profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("10011")); | 592 billing_profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("10011")); |
638 billing_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | 593 billing_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
639 billing_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 594 billing_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
640 ASCIIToUTF16("18181230000")); | 595 ASCIIToUTF16("18181230000")); |
641 Time pre_modification_time_2 = Time::Now(); | 596 Time pre_modification_time_2 = Time::Now(); |
642 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti( | 597 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(billing_profile)); |
643 billing_profile)); | |
644 Time post_modification_time_2 = Time::Now(); | 598 Time post_modification_time_2 = Time::Now(); |
645 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile( | 599 ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile)); |
646 billing_profile.guid(), &db_profile)); | |
647 EXPECT_EQ(billing_profile, *db_profile); | 600 EXPECT_EQ(billing_profile, *db_profile); |
648 sql::Statement s_billing_updated_2(db.GetSQLConnection()->GetUniqueStatement( | 601 sql::Statement s_billing_updated_2( |
649 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); | 602 db_->GetSQLConnection()->GetUniqueStatement( |
| 603 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); |
650 s_billing_updated_2.BindString(0, billing_profile.guid()); | 604 s_billing_updated_2.BindString(0, billing_profile.guid()); |
651 ASSERT_TRUE(s_billing_updated_2.is_valid()); | 605 ASSERT_TRUE(s_billing_updated_2.is_valid()); |
652 ASSERT_TRUE(s_billing_updated_2.Step()); | 606 ASSERT_TRUE(s_billing_updated_2.Step()); |
653 EXPECT_GE(s_billing_updated_2.ColumnInt64(0), | 607 EXPECT_GE(s_billing_updated_2.ColumnInt64(0), |
654 pre_modification_time_2.ToTimeT()); | 608 pre_modification_time_2.ToTimeT()); |
655 EXPECT_LE(s_billing_updated_2.ColumnInt64(0), | 609 EXPECT_LE(s_billing_updated_2.ColumnInt64(0), |
656 post_modification_time_2.ToTimeT()); | 610 post_modification_time_2.ToTimeT()); |
657 EXPECT_FALSE(s_billing_updated_2.Step()); | 611 EXPECT_FALSE(s_billing_updated_2.Step()); |
658 delete db_profile; | 612 delete db_profile; |
659 | 613 |
660 // Remove the 'Billing' profile. | 614 // Remove the 'Billing' profile. |
661 EXPECT_TRUE(db.GetAutofillTable()->RemoveAutofillProfile( | 615 EXPECT_TRUE(table_->RemoveAutofillProfile(billing_profile.guid())); |
662 billing_profile.guid())); | 616 EXPECT_FALSE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile)); |
663 EXPECT_FALSE(db.GetAutofillTable()->GetAutofillProfile( | |
664 billing_profile.guid(), &db_profile)); | |
665 } | 617 } |
666 | 618 |
667 TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) { | 619 TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) { |
668 WebDatabase db; | |
669 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
670 | |
671 AutofillProfile p; | 620 AutofillProfile p; |
672 const string16 kJohnDoe(ASCIIToUTF16("John Doe")); | 621 const string16 kJohnDoe(ASCIIToUTF16("John Doe")); |
673 const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe")); | 622 const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe")); |
674 std::vector<string16> set_values; | 623 std::vector<string16> set_values; |
675 set_values.push_back(kJohnDoe); | 624 set_values.push_back(kJohnDoe); |
676 set_values.push_back(kJohnPDoe); | 625 set_values.push_back(kJohnPDoe); |
677 p.SetRawMultiInfo(NAME_FULL, set_values); | 626 p.SetRawMultiInfo(NAME_FULL, set_values); |
678 | 627 |
679 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(p)); | 628 EXPECT_TRUE(table_->AddAutofillProfile(p)); |
680 | 629 |
681 AutofillProfile* db_profile; | 630 AutofillProfile* db_profile; |
682 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 631 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
683 EXPECT_EQ(p, *db_profile); | 632 EXPECT_EQ(p, *db_profile); |
684 EXPECT_EQ(0, p.Compare(*db_profile)); | 633 EXPECT_EQ(0, p.Compare(*db_profile)); |
685 delete db_profile; | 634 delete db_profile; |
686 | 635 |
687 // Update the values. | 636 // Update the values. |
688 const string16 kNoOne(ASCIIToUTF16("No One")); | 637 const string16 kNoOne(ASCIIToUTF16("No One")); |
689 set_values[1] = kNoOne; | 638 set_values[1] = kNoOne; |
690 p.SetRawMultiInfo(NAME_FULL, set_values); | 639 p.SetRawMultiInfo(NAME_FULL, set_values); |
691 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); | 640 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p)); |
692 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 641 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
693 EXPECT_EQ(p, *db_profile); | 642 EXPECT_EQ(p, *db_profile); |
694 EXPECT_EQ(0, p.Compare(*db_profile)); | 643 EXPECT_EQ(0, p.Compare(*db_profile)); |
695 delete db_profile; | 644 delete db_profile; |
696 | 645 |
697 // Delete values. | 646 // Delete values. |
698 set_values.clear(); | 647 set_values.clear(); |
699 p.SetRawMultiInfo(NAME_FULL, set_values); | 648 p.SetRawMultiInfo(NAME_FULL, set_values); |
700 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); | 649 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p)); |
701 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 650 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
702 EXPECT_EQ(p, *db_profile); | 651 EXPECT_EQ(p, *db_profile); |
703 EXPECT_EQ(0, p.Compare(*db_profile)); | 652 EXPECT_EQ(0, p.Compare(*db_profile)); |
704 EXPECT_EQ(string16(), db_profile->GetRawInfo(NAME_FULL)); | 653 EXPECT_EQ(string16(), db_profile->GetRawInfo(NAME_FULL)); |
705 delete db_profile; | 654 delete db_profile; |
706 } | 655 } |
707 | 656 |
708 TEST_F(AutofillTableTest, AutofillProfileSingleValue) { | 657 TEST_F(AutofillTableTest, AutofillProfileSingleValue) { |
709 WebDatabase db; | |
710 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
711 | |
712 AutofillProfile p; | 658 AutofillProfile p; |
713 const string16 kJohnDoe(ASCIIToUTF16("John Doe")); | 659 const string16 kJohnDoe(ASCIIToUTF16("John Doe")); |
714 const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe")); | 660 const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe")); |
715 std::vector<string16> set_values; | 661 std::vector<string16> set_values; |
716 set_values.push_back(kJohnDoe); | 662 set_values.push_back(kJohnDoe); |
717 set_values.push_back(kJohnPDoe); | 663 set_values.push_back(kJohnPDoe); |
718 p.SetRawMultiInfo(NAME_FULL, set_values); | 664 p.SetRawMultiInfo(NAME_FULL, set_values); |
719 | 665 |
720 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(p)); | 666 EXPECT_TRUE(table_->AddAutofillProfile(p)); |
721 | 667 |
722 AutofillProfile* db_profile; | 668 AutofillProfile* db_profile; |
723 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 669 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
724 EXPECT_EQ(p, *db_profile); | 670 EXPECT_EQ(p, *db_profile); |
725 EXPECT_EQ(0, p.Compare(*db_profile)); | 671 EXPECT_EQ(0, p.Compare(*db_profile)); |
726 delete db_profile; | 672 delete db_profile; |
727 | 673 |
728 const string16 kNoOne(ASCIIToUTF16("No One")); | 674 const string16 kNoOne(ASCIIToUTF16("No One")); |
729 set_values.resize(1); | 675 set_values.resize(1); |
730 set_values[0] = kNoOne; | 676 set_values[0] = kNoOne; |
731 p.SetRawMultiInfo(NAME_FULL, set_values); | 677 p.SetRawMultiInfo(NAME_FULL, set_values); |
732 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfile(p)); | 678 EXPECT_TRUE(table_->UpdateAutofillProfile(p)); |
733 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 679 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
734 EXPECT_EQ(p.PrimaryValue(), db_profile->PrimaryValue()); | 680 EXPECT_EQ(p.PrimaryValue(), db_profile->PrimaryValue()); |
735 EXPECT_EQ(p.guid(), db_profile->guid()); | 681 EXPECT_EQ(p.guid(), db_profile->guid()); |
736 EXPECT_NE(0, p.Compare(*db_profile)); | 682 EXPECT_NE(0, p.Compare(*db_profile)); |
737 db_profile->GetRawMultiInfo(NAME_FULL, &set_values); | 683 db_profile->GetRawMultiInfo(NAME_FULL, &set_values); |
738 ASSERT_EQ(2UL, set_values.size()); | 684 ASSERT_EQ(2UL, set_values.size()); |
739 EXPECT_EQ(kNoOne, set_values[0]); | 685 EXPECT_EQ(kNoOne, set_values[0]); |
740 EXPECT_EQ(kJohnPDoe, set_values[1]); | 686 EXPECT_EQ(kJohnPDoe, set_values[1]); |
741 delete db_profile; | 687 delete db_profile; |
742 } | 688 } |
743 | 689 |
744 TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) { | 690 TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) { |
745 WebDatabase db; | |
746 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
747 | |
748 AutofillProfile p; | 691 AutofillProfile p; |
749 const string16 kJohnDoe(ASCIIToUTF16("john@doe.com")); | 692 const string16 kJohnDoe(ASCIIToUTF16("john@doe.com")); |
750 const string16 kJohnPDoe(ASCIIToUTF16("john_p@doe.com")); | 693 const string16 kJohnPDoe(ASCIIToUTF16("john_p@doe.com")); |
751 std::vector<string16> set_values; | 694 std::vector<string16> set_values; |
752 set_values.push_back(kJohnDoe); | 695 set_values.push_back(kJohnDoe); |
753 set_values.push_back(kJohnPDoe); | 696 set_values.push_back(kJohnPDoe); |
754 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); | 697 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); |
755 | 698 |
756 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(p)); | 699 EXPECT_TRUE(table_->AddAutofillProfile(p)); |
757 | 700 |
758 AutofillProfile* db_profile; | 701 AutofillProfile* db_profile; |
759 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 702 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
760 EXPECT_EQ(p, *db_profile); | 703 EXPECT_EQ(p, *db_profile); |
761 EXPECT_EQ(0, p.Compare(*db_profile)); | 704 EXPECT_EQ(0, p.Compare(*db_profile)); |
762 delete db_profile; | 705 delete db_profile; |
763 | 706 |
764 // Update the values. | 707 // Update the values. |
765 const string16 kNoOne(ASCIIToUTF16("no@one.com")); | 708 const string16 kNoOne(ASCIIToUTF16("no@one.com")); |
766 set_values[1] = kNoOne; | 709 set_values[1] = kNoOne; |
767 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); | 710 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); |
768 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); | 711 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p)); |
769 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 712 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
770 EXPECT_EQ(p, *db_profile); | 713 EXPECT_EQ(p, *db_profile); |
771 EXPECT_EQ(0, p.Compare(*db_profile)); | 714 EXPECT_EQ(0, p.Compare(*db_profile)); |
772 delete db_profile; | 715 delete db_profile; |
773 | 716 |
774 // Delete values. | 717 // Delete values. |
775 set_values.clear(); | 718 set_values.clear(); |
776 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); | 719 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); |
777 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); | 720 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p)); |
778 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 721 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
779 EXPECT_EQ(p, *db_profile); | 722 EXPECT_EQ(p, *db_profile); |
780 EXPECT_EQ(0, p.Compare(*db_profile)); | 723 EXPECT_EQ(0, p.Compare(*db_profile)); |
781 EXPECT_EQ(string16(), db_profile->GetRawInfo(EMAIL_ADDRESS)); | 724 EXPECT_EQ(string16(), db_profile->GetRawInfo(EMAIL_ADDRESS)); |
782 delete db_profile; | 725 delete db_profile; |
783 } | 726 } |
784 | 727 |
785 TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) { | 728 TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) { |
786 WebDatabase db; | |
787 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
788 | |
789 AutofillProfile p; | 729 AutofillProfile p; |
790 const string16 kJohnDoe(ASCIIToUTF16("4151112222")); | 730 const string16 kJohnDoe(ASCIIToUTF16("4151112222")); |
791 const string16 kJohnPDoe(ASCIIToUTF16("4151113333")); | 731 const string16 kJohnPDoe(ASCIIToUTF16("4151113333")); |
792 std::vector<string16> set_values; | 732 std::vector<string16> set_values; |
793 set_values.push_back(kJohnDoe); | 733 set_values.push_back(kJohnDoe); |
794 set_values.push_back(kJohnPDoe); | 734 set_values.push_back(kJohnPDoe); |
795 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); | 735 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); |
796 | 736 |
797 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(p)); | 737 EXPECT_TRUE(table_->AddAutofillProfile(p)); |
798 | 738 |
799 AutofillProfile* db_profile; | 739 AutofillProfile* db_profile; |
800 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 740 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
801 EXPECT_EQ(p, *db_profile); | 741 EXPECT_EQ(p, *db_profile); |
802 EXPECT_EQ(0, p.Compare(*db_profile)); | 742 EXPECT_EQ(0, p.Compare(*db_profile)); |
803 delete db_profile; | 743 delete db_profile; |
804 | 744 |
805 // Update the values. | 745 // Update the values. |
806 const string16 kNoOne(ASCIIToUTF16("4151110000")); | 746 const string16 kNoOne(ASCIIToUTF16("4151110000")); |
807 set_values[1] = kNoOne; | 747 set_values[1] = kNoOne; |
808 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); | 748 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); |
809 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); | 749 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p)); |
810 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 750 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
811 EXPECT_EQ(p, *db_profile); | 751 EXPECT_EQ(p, *db_profile); |
812 EXPECT_EQ(0, p.Compare(*db_profile)); | 752 EXPECT_EQ(0, p.Compare(*db_profile)); |
813 delete db_profile; | 753 delete db_profile; |
814 | 754 |
815 // Delete values. | 755 // Delete values. |
816 set_values.clear(); | 756 set_values.clear(); |
817 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); | 757 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); |
818 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); | 758 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p)); |
819 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); | 759 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); |
820 EXPECT_EQ(p, *db_profile); | 760 EXPECT_EQ(p, *db_profile); |
821 EXPECT_EQ(0, p.Compare(*db_profile)); | 761 EXPECT_EQ(0, p.Compare(*db_profile)); |
822 EXPECT_EQ(string16(), db_profile->GetRawInfo(EMAIL_ADDRESS)); | 762 EXPECT_EQ(string16(), db_profile->GetRawInfo(EMAIL_ADDRESS)); |
823 delete db_profile; | 763 delete db_profile; |
824 } | 764 } |
825 | 765 |
826 TEST_F(AutofillTableTest, AutofillProfileTrash) { | 766 TEST_F(AutofillTableTest, AutofillProfileTrash) { |
827 WebDatabase db; | |
828 | |
829 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
830 | |
831 std::vector<std::string> guids; | 767 std::vector<std::string> guids; |
832 db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids); | 768 table_->GetAutofillProfilesInTrash(&guids); |
833 EXPECT_TRUE(guids.empty()); | 769 EXPECT_TRUE(guids.empty()); |
834 | 770 |
835 ASSERT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash( | 771 ASSERT_TRUE(table_->AddAutofillGUIDToTrash( |
836 "00000000-0000-0000-0000-000000000000")); | 772 "00000000-0000-0000-0000-000000000000")); |
837 ASSERT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash( | 773 ASSERT_TRUE(table_->AddAutofillGUIDToTrash( |
838 "00000000-0000-0000-0000-000000000001")); | 774 "00000000-0000-0000-0000-000000000001")); |
839 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids)); | 775 ASSERT_TRUE(table_->GetAutofillProfilesInTrash(&guids)); |
840 EXPECT_EQ(2UL, guids.size()); | 776 EXPECT_EQ(2UL, guids.size()); |
841 EXPECT_EQ("00000000-0000-0000-0000-000000000000", guids[0]); | 777 EXPECT_EQ("00000000-0000-0000-0000-000000000000", guids[0]); |
842 EXPECT_EQ("00000000-0000-0000-0000-000000000001", guids[1]); | 778 EXPECT_EQ("00000000-0000-0000-0000-000000000001", guids[1]); |
843 | 779 |
844 ASSERT_TRUE(db.GetAutofillTable()->EmptyAutofillProfilesTrash()); | 780 ASSERT_TRUE(table_->EmptyAutofillProfilesTrash()); |
845 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids)); | 781 ASSERT_TRUE(table_->GetAutofillProfilesInTrash(&guids)); |
846 EXPECT_TRUE(guids.empty()); | 782 EXPECT_TRUE(guids.empty()); |
847 } | 783 } |
848 | 784 |
849 TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) { | 785 TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) { |
850 WebDatabase db; | |
851 | |
852 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
853 | |
854 std::vector<std::string> guids; | 786 std::vector<std::string> guids; |
855 db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids); | 787 table_->GetAutofillProfilesInTrash(&guids); |
856 EXPECT_TRUE(guids.empty()); | 788 EXPECT_TRUE(guids.empty()); |
857 | 789 |
858 AutofillProfile profile; | 790 AutofillProfile profile; |
859 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); | 791 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); |
860 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); | 792 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); |
861 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith")); | 793 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith")); |
862 profile.SetRawInfo(EMAIL_ADDRESS,ASCIIToUTF16("js@smith.xyz")); | 794 profile.SetRawInfo(EMAIL_ADDRESS,ASCIIToUTF16("js@smith.xyz")); |
863 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 Main St")); | 795 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 Main St")); |
864 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); | 796 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); |
865 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | 797 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
866 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); | 798 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); |
867 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | 799 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
868 | 800 |
869 // Mark this profile as in the trash. This stops |AddAutofillProfile| from | 801 // Mark this profile as in the trash. This stops |AddAutofillProfile| from |
870 // adding it. | 802 // adding it. |
871 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(profile.guid())); | 803 EXPECT_TRUE(table_->AddAutofillGUIDToTrash(profile.guid())); |
872 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(profile)); | 804 EXPECT_TRUE(table_->AddAutofillProfile(profile)); |
873 AutofillProfile* added_profile = NULL; | 805 AutofillProfile* added_profile = NULL; |
874 EXPECT_FALSE(db.GetAutofillTable()->GetAutofillProfile( | 806 EXPECT_FALSE(table_->GetAutofillProfile(profile.guid(), &added_profile)); |
875 profile.guid(), &added_profile)); | |
876 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), added_profile); | 807 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), added_profile); |
877 | 808 |
878 // Add the profile for real this time. | 809 // Add the profile for real this time. |
879 EXPECT_TRUE(db.GetAutofillTable()->EmptyAutofillProfilesTrash()); | 810 EXPECT_TRUE(table_->EmptyAutofillProfilesTrash()); |
880 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids)); | 811 EXPECT_TRUE(table_->GetAutofillProfilesInTrash(&guids)); |
881 EXPECT_TRUE(guids.empty()); | 812 EXPECT_TRUE(guids.empty()); |
882 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(profile)); | 813 EXPECT_TRUE(table_->AddAutofillProfile(profile)); |
883 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), | 814 EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(), |
884 &added_profile)); | 815 &added_profile)); |
885 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile); | 816 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile); |
886 delete added_profile; | 817 delete added_profile; |
887 | 818 |
888 // Mark this profile as in the trash. This stops |UpdateAutofillProfileMulti| | 819 // Mark this profile as in the trash. This stops |UpdateAutofillProfileMulti| |
889 // from updating it. In normal operation a profile should not be both in the | 820 // from updating it. In normal operation a profile should not be both in the |
890 // trash and in the profiles table simultaneously. | 821 // trash and in the profiles table simultaneously. |
891 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(profile.guid())); | 822 EXPECT_TRUE(table_->AddAutofillGUIDToTrash(profile.guid())); |
892 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); | 823 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); |
893 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(profile)); | 824 EXPECT_TRUE(table_->UpdateAutofillProfileMulti(profile)); |
894 AutofillProfile* updated_profile = NULL; | 825 AutofillProfile* updated_profile = NULL; |
895 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile( | 826 EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(), &updated_profile)); |
896 profile.guid(), &updated_profile)); | |
897 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile); | 827 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile); |
898 EXPECT_EQ(ASCIIToUTF16("John"), updated_profile->GetRawInfo(NAME_FIRST)); | 828 EXPECT_EQ(ASCIIToUTF16("John"), updated_profile->GetRawInfo(NAME_FIRST)); |
899 delete updated_profile; | 829 delete updated_profile; |
900 | 830 |
901 // Try to delete the trashed profile. This stops |RemoveAutofillProfile| from | 831 // Try to delete the trashed profile. This stops |RemoveAutofillProfile| from |
902 // deleting it. In normal operation deletion is done by migration step, and | 832 // deleting it. In normal operation deletion is done by migration step, and |
903 // removal from trash is done by |WebDataService|. |RemoveAutofillProfile| | 833 // removal from trash is done by |WebDataService|. |RemoveAutofillProfile| |
904 // does remove the item from the trash if it is found however, so that if | 834 // does remove the item from the trash if it is found however, so that if |
905 // other clients remove it (via Sync say) then it is gone and doesn't need to | 835 // other clients remove it (via Sync say) then it is gone and doesn't need to |
906 // be processed further by |WebDataService|. | 836 // be processed further by |WebDataService|. |
907 EXPECT_TRUE(db.GetAutofillTable()->RemoveAutofillProfile(profile.guid())); | 837 EXPECT_TRUE(table_->RemoveAutofillProfile(profile.guid())); |
908 AutofillProfile* removed_profile = NULL; | 838 AutofillProfile* removed_profile = NULL; |
909 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), | 839 EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(), &removed_profile)); |
910 &removed_profile)); | 840 EXPECT_FALSE(table_->IsAutofillGUIDInTrash(profile.guid())); |
911 EXPECT_FALSE(db.GetAutofillTable()->IsAutofillGUIDInTrash(profile.guid())); | |
912 ASSERT_NE(static_cast<AutofillProfile*>(NULL), removed_profile); | 841 ASSERT_NE(static_cast<AutofillProfile*>(NULL), removed_profile); |
913 delete removed_profile; | 842 delete removed_profile; |
914 | 843 |
915 // Check that emptying the trash now allows removal to occur. | 844 // Check that emptying the trash now allows removal to occur. |
916 EXPECT_TRUE(db.GetAutofillTable()->EmptyAutofillProfilesTrash()); | 845 EXPECT_TRUE(table_->EmptyAutofillProfilesTrash()); |
917 EXPECT_TRUE(db.GetAutofillTable()->RemoveAutofillProfile(profile.guid())); | 846 EXPECT_TRUE(table_->RemoveAutofillProfile(profile.guid())); |
918 removed_profile = NULL; | 847 removed_profile = NULL; |
919 EXPECT_FALSE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), | 848 EXPECT_FALSE(table_->GetAutofillProfile(profile.guid(), &removed_profile)); |
920 &removed_profile)); | |
921 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), removed_profile); | 849 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), removed_profile); |
922 } | 850 } |
923 | 851 |
924 TEST_F(AutofillTableTest, CreditCard) { | 852 TEST_F(AutofillTableTest, CreditCard) { |
925 WebDatabase db; | |
926 | |
927 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
928 | |
929 // Add a 'Work' credit card. | 853 // Add a 'Work' credit card. |
930 CreditCard work_creditcard; | 854 CreditCard work_creditcard; |
931 work_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); | 855 work_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); |
932 work_creditcard.SetRawInfo(CREDIT_CARD_NUMBER, | 856 work_creditcard.SetRawInfo(CREDIT_CARD_NUMBER, |
933 ASCIIToUTF16("1234567890123456")); | 857 ASCIIToUTF16("1234567890123456")); |
934 work_creditcard.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04")); | 858 work_creditcard.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04")); |
935 work_creditcard.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 859 work_creditcard.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
936 ASCIIToUTF16("2013")); | 860 ASCIIToUTF16("2013")); |
937 | 861 |
938 Time pre_creation_time = Time::Now(); | 862 Time pre_creation_time = Time::Now(); |
939 EXPECT_TRUE(db.GetAutofillTable()->AddCreditCard(work_creditcard)); | 863 EXPECT_TRUE(table_->AddCreditCard(work_creditcard)); |
940 Time post_creation_time = Time::Now(); | 864 Time post_creation_time = Time::Now(); |
941 | 865 |
942 // Get the 'Work' credit card. | 866 // Get the 'Work' credit card. |
943 CreditCard* db_creditcard; | 867 CreditCard* db_creditcard; |
944 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(work_creditcard.guid(), | 868 ASSERT_TRUE(table_->GetCreditCard(work_creditcard.guid(), &db_creditcard)); |
945 &db_creditcard)); | |
946 EXPECT_EQ(work_creditcard, *db_creditcard); | 869 EXPECT_EQ(work_creditcard, *db_creditcard); |
947 sql::Statement s_work(db.GetSQLConnection()->GetUniqueStatement( | 870 sql::Statement s_work(db_->GetSQLConnection()->GetUniqueStatement( |
948 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 871 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
949 "card_number_encrypted, date_modified " | 872 "card_number_encrypted, date_modified " |
950 "FROM credit_cards WHERE guid=?")); | 873 "FROM credit_cards WHERE guid=?")); |
951 s_work.BindString(0, work_creditcard.guid()); | 874 s_work.BindString(0, work_creditcard.guid()); |
952 ASSERT_TRUE(s_work.is_valid()); | 875 ASSERT_TRUE(s_work.is_valid()); |
953 ASSERT_TRUE(s_work.Step()); | 876 ASSERT_TRUE(s_work.Step()); |
954 EXPECT_GE(s_work.ColumnInt64(5), pre_creation_time.ToTimeT()); | 877 EXPECT_GE(s_work.ColumnInt64(5), pre_creation_time.ToTimeT()); |
955 EXPECT_LE(s_work.ColumnInt64(5), post_creation_time.ToTimeT()); | 878 EXPECT_LE(s_work.ColumnInt64(5), post_creation_time.ToTimeT()); |
956 EXPECT_FALSE(s_work.Step()); | 879 EXPECT_FALSE(s_work.Step()); |
957 delete db_creditcard; | 880 delete db_creditcard; |
958 | 881 |
959 // Add a 'Target' credit card. | 882 // Add a 'Target' credit card. |
960 CreditCard target_creditcard; | 883 CreditCard target_creditcard; |
961 target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); | 884 target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); |
962 target_creditcard.SetRawInfo(CREDIT_CARD_NUMBER, | 885 target_creditcard.SetRawInfo(CREDIT_CARD_NUMBER, |
963 ASCIIToUTF16("1111222233334444")); | 886 ASCIIToUTF16("1111222233334444")); |
964 target_creditcard.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06")); | 887 target_creditcard.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06")); |
965 target_creditcard.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 888 target_creditcard.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
966 ASCIIToUTF16("2012")); | 889 ASCIIToUTF16("2012")); |
967 | 890 |
968 pre_creation_time = Time::Now(); | 891 pre_creation_time = Time::Now(); |
969 EXPECT_TRUE(db.GetAutofillTable()->AddCreditCard(target_creditcard)); | 892 EXPECT_TRUE(table_->AddCreditCard(target_creditcard)); |
970 post_creation_time = Time::Now(); | 893 post_creation_time = Time::Now(); |
971 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(), | 894 ASSERT_TRUE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard)); |
972 &db_creditcard)); | |
973 EXPECT_EQ(target_creditcard, *db_creditcard); | 895 EXPECT_EQ(target_creditcard, *db_creditcard); |
974 sql::Statement s_target(db.GetSQLConnection()->GetUniqueStatement( | 896 sql::Statement s_target(db_->GetSQLConnection()->GetUniqueStatement( |
975 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 897 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
976 "card_number_encrypted, date_modified " | 898 "card_number_encrypted, date_modified " |
977 "FROM credit_cards WHERE guid=?")); | 899 "FROM credit_cards WHERE guid=?")); |
978 s_target.BindString(0, target_creditcard.guid()); | 900 s_target.BindString(0, target_creditcard.guid()); |
979 ASSERT_TRUE(s_target.is_valid()); | 901 ASSERT_TRUE(s_target.is_valid()); |
980 ASSERT_TRUE(s_target.Step()); | 902 ASSERT_TRUE(s_target.Step()); |
981 EXPECT_GE(s_target.ColumnInt64(5), pre_creation_time.ToTimeT()); | 903 EXPECT_GE(s_target.ColumnInt64(5), pre_creation_time.ToTimeT()); |
982 EXPECT_LE(s_target.ColumnInt64(5), post_creation_time.ToTimeT()); | 904 EXPECT_LE(s_target.ColumnInt64(5), post_creation_time.ToTimeT()); |
983 EXPECT_FALSE(s_target.Step()); | 905 EXPECT_FALSE(s_target.Step()); |
984 delete db_creditcard; | 906 delete db_creditcard; |
985 | 907 |
986 // Update the 'Target' credit card. | 908 // Update the 'Target' credit card. |
987 target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Charles Grady")); | 909 target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Charles Grady")); |
988 Time pre_modification_time = Time::Now(); | 910 Time pre_modification_time = Time::Now(); |
989 EXPECT_TRUE(db.GetAutofillTable()->UpdateCreditCard(target_creditcard)); | 911 EXPECT_TRUE(table_->UpdateCreditCard(target_creditcard)); |
990 Time post_modification_time = Time::Now(); | 912 Time post_modification_time = Time::Now(); |
991 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(), | 913 ASSERT_TRUE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard)); |
992 &db_creditcard)); | |
993 EXPECT_EQ(target_creditcard, *db_creditcard); | 914 EXPECT_EQ(target_creditcard, *db_creditcard); |
994 sql::Statement s_target_updated(db.GetSQLConnection()->GetUniqueStatement( | 915 sql::Statement s_target_updated(db_->GetSQLConnection()->GetUniqueStatement( |
995 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 916 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
996 "card_number_encrypted, date_modified " | 917 "card_number_encrypted, date_modified " |
997 "FROM credit_cards WHERE guid=?")); | 918 "FROM credit_cards WHERE guid=?")); |
998 s_target_updated.BindString(0, target_creditcard.guid()); | 919 s_target_updated.BindString(0, target_creditcard.guid()); |
999 ASSERT_TRUE(s_target_updated.is_valid()); | 920 ASSERT_TRUE(s_target_updated.is_valid()); |
1000 ASSERT_TRUE(s_target_updated.Step()); | 921 ASSERT_TRUE(s_target_updated.Step()); |
1001 EXPECT_GE(s_target_updated.ColumnInt64(5), pre_modification_time.ToTimeT()); | 922 EXPECT_GE(s_target_updated.ColumnInt64(5), pre_modification_time.ToTimeT()); |
1002 EXPECT_LE(s_target_updated.ColumnInt64(5), post_modification_time.ToTimeT()); | 923 EXPECT_LE(s_target_updated.ColumnInt64(5), post_modification_time.ToTimeT()); |
1003 EXPECT_FALSE(s_target_updated.Step()); | 924 EXPECT_FALSE(s_target_updated.Step()); |
1004 delete db_creditcard; | 925 delete db_creditcard; |
1005 | 926 |
1006 // Remove the 'Target' credit card. | 927 // Remove the 'Target' credit card. |
1007 EXPECT_TRUE(db.GetAutofillTable()->RemoveCreditCard( | 928 EXPECT_TRUE(table_->RemoveCreditCard(target_creditcard.guid())); |
1008 target_creditcard.guid())); | 929 EXPECT_FALSE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard)); |
1009 EXPECT_FALSE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(), | |
1010 &db_creditcard)); | |
1011 } | 930 } |
1012 | 931 |
1013 TEST_F(AutofillTableTest, UpdateAutofillProfile) { | 932 TEST_F(AutofillTableTest, UpdateAutofillProfile) { |
1014 WebDatabase db; | |
1015 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
1016 | |
1017 // Add a profile to the db. | 933 // Add a profile to the db. |
1018 AutofillProfile profile; | 934 AutofillProfile profile; |
1019 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); | 935 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); |
1020 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); | 936 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); |
1021 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith")); | 937 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith")); |
1022 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@example.com")); | 938 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@example.com")); |
1023 profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google")); | 939 profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google")); |
1024 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way")); | 940 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way")); |
1025 profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5")); | 941 profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5")); |
1026 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); | 942 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); |
1027 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | 943 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
1028 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); | 944 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); |
1029 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | 945 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
1030 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567")); | 946 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567")); |
1031 db.GetAutofillTable()->AddAutofillProfile(profile); | 947 table_->AddAutofillProfile(profile); |
1032 | 948 |
1033 // Set a mocked value for the profile's creation time. | 949 // Set a mocked value for the profile's creation time. |
1034 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; | 950 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; |
1035 sql::Statement s_mock_creation_date(db.GetSQLConnection()->GetUniqueStatement( | 951 sql::Statement s_mock_creation_date( |
1036 "UPDATE autofill_profiles SET date_modified = ?")); | 952 db_->GetSQLConnection()->GetUniqueStatement( |
| 953 "UPDATE autofill_profiles SET date_modified = ?")); |
1037 ASSERT_TRUE(s_mock_creation_date.is_valid()); | 954 ASSERT_TRUE(s_mock_creation_date.is_valid()); |
1038 s_mock_creation_date.BindInt64(0, mock_creation_date); | 955 s_mock_creation_date.BindInt64(0, mock_creation_date); |
1039 ASSERT_TRUE(s_mock_creation_date.Run()); | 956 ASSERT_TRUE(s_mock_creation_date.Run()); |
1040 | 957 |
1041 // Get the profile. | 958 // Get the profile. |
1042 AutofillProfile* tmp_profile; | 959 AutofillProfile* tmp_profile; |
1043 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), | 960 ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile)); |
1044 &tmp_profile)); | |
1045 scoped_ptr<AutofillProfile> db_profile(tmp_profile); | 961 scoped_ptr<AutofillProfile> db_profile(tmp_profile); |
1046 EXPECT_EQ(profile, *db_profile); | 962 EXPECT_EQ(profile, *db_profile); |
1047 sql::Statement s_original(db.GetSQLConnection()->GetUniqueStatement( | 963 sql::Statement s_original(db_->GetSQLConnection()->GetUniqueStatement( |
1048 "SELECT date_modified FROM autofill_profiles")); | 964 "SELECT date_modified FROM autofill_profiles")); |
1049 ASSERT_TRUE(s_original.is_valid()); | 965 ASSERT_TRUE(s_original.is_valid()); |
1050 ASSERT_TRUE(s_original.Step()); | 966 ASSERT_TRUE(s_original.Step()); |
1051 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); | 967 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); |
1052 EXPECT_FALSE(s_original.Step()); | 968 EXPECT_FALSE(s_original.Step()); |
1053 | 969 |
1054 // Now, update the profile and save the update to the database. | 970 // Now, update the profile and save the update to the database. |
1055 // The modification date should change to reflect the update. | 971 // The modification date should change to reflect the update. |
1056 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz")); | 972 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz")); |
1057 db.GetAutofillTable()->UpdateAutofillProfileMulti(profile); | 973 table_->UpdateAutofillProfileMulti(profile); |
1058 | 974 |
1059 // Get the profile. | 975 // Get the profile. |
1060 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), | 976 ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile)); |
1061 &tmp_profile)); | |
1062 db_profile.reset(tmp_profile); | 977 db_profile.reset(tmp_profile); |
1063 EXPECT_EQ(profile, *db_profile); | 978 EXPECT_EQ(profile, *db_profile); |
1064 sql::Statement s_updated(db.GetSQLConnection()->GetUniqueStatement( | 979 sql::Statement s_updated(db_->GetSQLConnection()->GetUniqueStatement( |
1065 "SELECT date_modified FROM autofill_profiles")); | 980 "SELECT date_modified FROM autofill_profiles")); |
1066 ASSERT_TRUE(s_updated.is_valid()); | 981 ASSERT_TRUE(s_updated.is_valid()); |
1067 ASSERT_TRUE(s_updated.Step()); | 982 ASSERT_TRUE(s_updated.Step()); |
1068 EXPECT_LT(mock_creation_date, s_updated.ColumnInt64(0)); | 983 EXPECT_LT(mock_creation_date, s_updated.ColumnInt64(0)); |
1069 EXPECT_FALSE(s_updated.Step()); | 984 EXPECT_FALSE(s_updated.Step()); |
1070 | 985 |
1071 // Set a mocked value for the profile's modification time. | 986 // Set a mocked value for the profile's modification time. |
1072 const time_t mock_modification_date = Time::Now().ToTimeT() - 7; | 987 const time_t mock_modification_date = Time::Now().ToTimeT() - 7; |
1073 sql::Statement s_mock_modification_date( | 988 sql::Statement s_mock_modification_date( |
1074 db.GetSQLConnection()->GetUniqueStatement( | 989 db_->GetSQLConnection()->GetUniqueStatement( |
1075 "UPDATE autofill_profiles SET date_modified = ?")); | 990 "UPDATE autofill_profiles SET date_modified = ?")); |
1076 ASSERT_TRUE(s_mock_modification_date.is_valid()); | 991 ASSERT_TRUE(s_mock_modification_date.is_valid()); |
1077 s_mock_modification_date.BindInt64(0, mock_modification_date); | 992 s_mock_modification_date.BindInt64(0, mock_modification_date); |
1078 ASSERT_TRUE(s_mock_modification_date.Run()); | 993 ASSERT_TRUE(s_mock_modification_date.Run()); |
1079 | 994 |
1080 // Finally, call into |UpdateAutofillProfileMulti()| without changing the | 995 // Finally, call into |UpdateAutofillProfileMulti()| without changing the |
1081 // profile. The modification date should not change. | 996 // profile. The modification date should not change. |
1082 db.GetAutofillTable()->UpdateAutofillProfileMulti(profile); | 997 table_->UpdateAutofillProfileMulti(profile); |
1083 | 998 |
1084 // Get the profile. | 999 // Get the profile. |
1085 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), | 1000 ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile)); |
1086 &tmp_profile)); | |
1087 db_profile.reset(tmp_profile); | 1001 db_profile.reset(tmp_profile); |
1088 EXPECT_EQ(profile, *db_profile); | 1002 EXPECT_EQ(profile, *db_profile); |
1089 sql::Statement s_unchanged(db.GetSQLConnection()->GetUniqueStatement( | 1003 sql::Statement s_unchanged(db_->GetSQLConnection()->GetUniqueStatement( |
1090 "SELECT date_modified FROM autofill_profiles")); | 1004 "SELECT date_modified FROM autofill_profiles")); |
1091 ASSERT_TRUE(s_unchanged.is_valid()); | 1005 ASSERT_TRUE(s_unchanged.is_valid()); |
1092 ASSERT_TRUE(s_unchanged.Step()); | 1006 ASSERT_TRUE(s_unchanged.Step()); |
1093 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); | 1007 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); |
1094 EXPECT_FALSE(s_unchanged.Step()); | 1008 EXPECT_FALSE(s_unchanged.Step()); |
1095 } | 1009 } |
1096 | 1010 |
1097 TEST_F(AutofillTableTest, UpdateCreditCard) { | 1011 TEST_F(AutofillTableTest, UpdateCreditCard) { |
1098 WebDatabase db; | |
1099 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
1100 | |
1101 // Add a credit card to the db. | 1012 // Add a credit card to the db. |
1102 CreditCard credit_card; | 1013 CreditCard credit_card; |
1103 credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); | 1014 credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); |
1104 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234567890123456")); | 1015 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234567890123456")); |
1105 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04")); | 1016 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04")); |
1106 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2013")); | 1017 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2013")); |
1107 db.GetAutofillTable()->AddCreditCard(credit_card); | 1018 table_->AddCreditCard(credit_card); |
1108 | 1019 |
1109 // Set a mocked value for the credit card's creation time. | 1020 // Set a mocked value for the credit card's creation time. |
1110 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; | 1021 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; |
1111 sql::Statement s_mock_creation_date(db.GetSQLConnection()->GetUniqueStatement( | 1022 sql::Statement s_mock_creation_date( |
1112 "UPDATE credit_cards SET date_modified = ?")); | 1023 db_->GetSQLConnection()->GetUniqueStatement( |
| 1024 "UPDATE credit_cards SET date_modified = ?")); |
1113 ASSERT_TRUE(s_mock_creation_date.is_valid()); | 1025 ASSERT_TRUE(s_mock_creation_date.is_valid()); |
1114 s_mock_creation_date.BindInt64(0, mock_creation_date); | 1026 s_mock_creation_date.BindInt64(0, mock_creation_date); |
1115 ASSERT_TRUE(s_mock_creation_date.Run()); | 1027 ASSERT_TRUE(s_mock_creation_date.Run()); |
1116 | 1028 |
1117 // Get the credit card. | 1029 // Get the credit card. |
1118 CreditCard* tmp_credit_card; | 1030 CreditCard* tmp_credit_card; |
1119 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(), | 1031 ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card)); |
1120 &tmp_credit_card)); | |
1121 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card); | 1032 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card); |
1122 EXPECT_EQ(credit_card, *db_credit_card); | 1033 EXPECT_EQ(credit_card, *db_credit_card); |
1123 sql::Statement s_original(db.GetSQLConnection()->GetUniqueStatement( | 1034 sql::Statement s_original(db_->GetSQLConnection()->GetUniqueStatement( |
1124 "SELECT date_modified FROM credit_cards")); | 1035 "SELECT date_modified FROM credit_cards")); |
1125 ASSERT_TRUE(s_original.is_valid()); | 1036 ASSERT_TRUE(s_original.is_valid()); |
1126 ASSERT_TRUE(s_original.Step()); | 1037 ASSERT_TRUE(s_original.Step()); |
1127 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); | 1038 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); |
1128 EXPECT_FALSE(s_original.Step()); | 1039 EXPECT_FALSE(s_original.Step()); |
1129 | 1040 |
1130 // Now, update the credit card and save the update to the database. | 1041 // Now, update the credit card and save the update to the database. |
1131 // The modification date should change to reflect the update. | 1042 // The modification date should change to reflect the update. |
1132 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 1043 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
1133 db.GetAutofillTable()->UpdateCreditCard(credit_card); | 1044 table_->UpdateCreditCard(credit_card); |
1134 | 1045 |
1135 // Get the credit card. | 1046 // Get the credit card. |
1136 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(), | 1047 ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card)); |
1137 &tmp_credit_card)); | |
1138 db_credit_card.reset(tmp_credit_card); | 1048 db_credit_card.reset(tmp_credit_card); |
1139 EXPECT_EQ(credit_card, *db_credit_card); | 1049 EXPECT_EQ(credit_card, *db_credit_card); |
1140 sql::Statement s_updated(db.GetSQLConnection()->GetUniqueStatement( | 1050 sql::Statement s_updated(db_->GetSQLConnection()->GetUniqueStatement( |
1141 "SELECT date_modified FROM credit_cards")); | 1051 "SELECT date_modified FROM credit_cards")); |
1142 ASSERT_TRUE(s_updated.is_valid()); | 1052 ASSERT_TRUE(s_updated.is_valid()); |
1143 ASSERT_TRUE(s_updated.Step()); | 1053 ASSERT_TRUE(s_updated.Step()); |
1144 EXPECT_LT(mock_creation_date, s_updated.ColumnInt64(0)); | 1054 EXPECT_LT(mock_creation_date, s_updated.ColumnInt64(0)); |
1145 EXPECT_FALSE(s_updated.Step()); | 1055 EXPECT_FALSE(s_updated.Step()); |
1146 | 1056 |
1147 // Set a mocked value for the credit card's modification time. | 1057 // Set a mocked value for the credit card's modification time. |
1148 const time_t mock_modification_date = Time::Now().ToTimeT() - 7; | 1058 const time_t mock_modification_date = Time::Now().ToTimeT() - 7; |
1149 sql::Statement s_mock_modification_date( | 1059 sql::Statement s_mock_modification_date( |
1150 db.GetSQLConnection()->GetUniqueStatement( | 1060 db_->GetSQLConnection()->GetUniqueStatement( |
1151 "UPDATE credit_cards SET date_modified = ?")); | 1061 "UPDATE credit_cards SET date_modified = ?")); |
1152 ASSERT_TRUE(s_mock_modification_date.is_valid()); | 1062 ASSERT_TRUE(s_mock_modification_date.is_valid()); |
1153 s_mock_modification_date.BindInt64(0, mock_modification_date); | 1063 s_mock_modification_date.BindInt64(0, mock_modification_date); |
1154 ASSERT_TRUE(s_mock_modification_date.Run()); | 1064 ASSERT_TRUE(s_mock_modification_date.Run()); |
1155 | 1065 |
1156 // Finally, call into |UpdateCreditCard()| without changing the credit card. | 1066 // Finally, call into |UpdateCreditCard()| without changing the credit card. |
1157 // The modification date should not change. | 1067 // The modification date should not change. |
1158 db.GetAutofillTable()->UpdateCreditCard(credit_card); | 1068 table_->UpdateCreditCard(credit_card); |
1159 | 1069 |
1160 // Get the profile. | 1070 // Get the profile. |
1161 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(), | 1071 ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card)); |
1162 &tmp_credit_card)); | |
1163 db_credit_card.reset(tmp_credit_card); | 1072 db_credit_card.reset(tmp_credit_card); |
1164 EXPECT_EQ(credit_card, *db_credit_card); | 1073 EXPECT_EQ(credit_card, *db_credit_card); |
1165 sql::Statement s_unchanged(db.GetSQLConnection()->GetUniqueStatement( | 1074 sql::Statement s_unchanged(db_->GetSQLConnection()->GetUniqueStatement( |
1166 "SELECT date_modified FROM credit_cards")); | 1075 "SELECT date_modified FROM credit_cards")); |
1167 ASSERT_TRUE(s_unchanged.is_valid()); | 1076 ASSERT_TRUE(s_unchanged.is_valid()); |
1168 ASSERT_TRUE(s_unchanged.Step()); | 1077 ASSERT_TRUE(s_unchanged.Step()); |
1169 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); | 1078 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); |
1170 EXPECT_FALSE(s_unchanged.Step()); | 1079 EXPECT_FALSE(s_unchanged.Step()); |
1171 } | 1080 } |
1172 | 1081 |
1173 TEST_F(AutofillTableTest, RemoveAutofillProfilesAndCreditCardsModifiedBetween) { | 1082 TEST_F(AutofillTableTest, RemoveAutofillProfilesAndCreditCardsModifiedBetween) { |
1174 WebDatabase db; | |
1175 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
1176 | |
1177 // Populate the autofill_profiles and credit_cards tables. | 1083 // Populate the autofill_profiles and credit_cards tables. |
1178 ASSERT_TRUE(db.GetSQLConnection()->Execute( | 1084 ASSERT_TRUE(db_->GetSQLConnection()->Execute( |
1179 "INSERT INTO autofill_profiles (guid, date_modified) " | 1085 "INSERT INTO autofill_profiles (guid, date_modified) " |
1180 "VALUES('00000000-0000-0000-0000-000000000000', 11);" | 1086 "VALUES('00000000-0000-0000-0000-000000000000', 11);" |
1181 "INSERT INTO autofill_profiles (guid, date_modified) " | 1087 "INSERT INTO autofill_profiles (guid, date_modified) " |
1182 "VALUES('00000000-0000-0000-0000-000000000001', 21);" | 1088 "VALUES('00000000-0000-0000-0000-000000000001', 21);" |
1183 "INSERT INTO autofill_profiles (guid, date_modified) " | 1089 "INSERT INTO autofill_profiles (guid, date_modified) " |
1184 "VALUES('00000000-0000-0000-0000-000000000002', 31);" | 1090 "VALUES('00000000-0000-0000-0000-000000000002', 31);" |
1185 "INSERT INTO autofill_profiles (guid, date_modified) " | 1091 "INSERT INTO autofill_profiles (guid, date_modified) " |
1186 "VALUES('00000000-0000-0000-0000-000000000003', 41);" | 1092 "VALUES('00000000-0000-0000-0000-000000000003', 41);" |
1187 "INSERT INTO autofill_profiles (guid, date_modified) " | 1093 "INSERT INTO autofill_profiles (guid, date_modified) " |
1188 "VALUES('00000000-0000-0000-0000-000000000004', 51);" | 1094 "VALUES('00000000-0000-0000-0000-000000000004', 51);" |
1189 "INSERT INTO autofill_profiles (guid, date_modified) " | 1095 "INSERT INTO autofill_profiles (guid, date_modified) " |
1190 "VALUES('00000000-0000-0000-0000-000000000005', 61);" | 1096 "VALUES('00000000-0000-0000-0000-000000000005', 61);" |
1191 "INSERT INTO credit_cards (guid, date_modified) " | 1097 "INSERT INTO credit_cards (guid, date_modified) " |
1192 "VALUES('00000000-0000-0000-0000-000000000006', 17);" | 1098 "VALUES('00000000-0000-0000-0000-000000000006', 17);" |
1193 "INSERT INTO credit_cards (guid, date_modified) " | 1099 "INSERT INTO credit_cards (guid, date_modified) " |
1194 "VALUES('00000000-0000-0000-0000-000000000007', 27);" | 1100 "VALUES('00000000-0000-0000-0000-000000000007', 27);" |
1195 "INSERT INTO credit_cards (guid, date_modified) " | 1101 "INSERT INTO credit_cards (guid, date_modified) " |
1196 "VALUES('00000000-0000-0000-0000-000000000008', 37);" | 1102 "VALUES('00000000-0000-0000-0000-000000000008', 37);" |
1197 "INSERT INTO credit_cards (guid, date_modified) " | 1103 "INSERT INTO credit_cards (guid, date_modified) " |
1198 "VALUES('00000000-0000-0000-0000-000000000009', 47);" | 1104 "VALUES('00000000-0000-0000-0000-000000000009', 47);" |
1199 "INSERT INTO credit_cards (guid, date_modified) " | 1105 "INSERT INTO credit_cards (guid, date_modified) " |
1200 "VALUES('00000000-0000-0000-0000-000000000010', 57);" | 1106 "VALUES('00000000-0000-0000-0000-000000000010', 57);" |
1201 "INSERT INTO credit_cards (guid, date_modified) " | 1107 "INSERT INTO credit_cards (guid, date_modified) " |
1202 "VALUES('00000000-0000-0000-0000-000000000011', 67);")); | 1108 "VALUES('00000000-0000-0000-0000-000000000011', 67);")); |
1203 | 1109 |
1204 // Remove all entries modified in the bounded time range [17,41). | 1110 // Remove all entries modified in the bounded time range [17,41). |
1205 std::vector<std::string> profile_guids; | 1111 std::vector<std::string> profile_guids; |
1206 std::vector<std::string> credit_card_guids; | 1112 std::vector<std::string> credit_card_guids; |
1207 db.GetAutofillTable()->RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 1113 table_->RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
1208 Time::FromTimeT(17), Time::FromTimeT(41), | 1114 Time::FromTimeT(17), Time::FromTimeT(41), |
1209 &profile_guids, &credit_card_guids); | 1115 &profile_guids, &credit_card_guids); |
1210 ASSERT_EQ(2UL, profile_guids.size()); | 1116 ASSERT_EQ(2UL, profile_guids.size()); |
1211 EXPECT_EQ("00000000-0000-0000-0000-000000000001", profile_guids[0]); | 1117 EXPECT_EQ("00000000-0000-0000-0000-000000000001", profile_guids[0]); |
1212 EXPECT_EQ("00000000-0000-0000-0000-000000000002", profile_guids[1]); | 1118 EXPECT_EQ("00000000-0000-0000-0000-000000000002", profile_guids[1]); |
1213 sql::Statement s_autofill_profiles_bounded( | 1119 sql::Statement s_autofill_profiles_bounded( |
1214 db.GetSQLConnection()->GetUniqueStatement( | 1120 db_->GetSQLConnection()->GetUniqueStatement( |
1215 "SELECT date_modified FROM autofill_profiles")); | 1121 "SELECT date_modified FROM autofill_profiles")); |
1216 ASSERT_TRUE(s_autofill_profiles_bounded.is_valid()); | 1122 ASSERT_TRUE(s_autofill_profiles_bounded.is_valid()); |
1217 ASSERT_TRUE(s_autofill_profiles_bounded.Step()); | 1123 ASSERT_TRUE(s_autofill_profiles_bounded.Step()); |
1218 EXPECT_EQ(11, s_autofill_profiles_bounded.ColumnInt64(0)); | 1124 EXPECT_EQ(11, s_autofill_profiles_bounded.ColumnInt64(0)); |
1219 ASSERT_TRUE(s_autofill_profiles_bounded.Step()); | 1125 ASSERT_TRUE(s_autofill_profiles_bounded.Step()); |
1220 EXPECT_EQ(41, s_autofill_profiles_bounded.ColumnInt64(0)); | 1126 EXPECT_EQ(41, s_autofill_profiles_bounded.ColumnInt64(0)); |
1221 ASSERT_TRUE(s_autofill_profiles_bounded.Step()); | 1127 ASSERT_TRUE(s_autofill_profiles_bounded.Step()); |
1222 EXPECT_EQ(51, s_autofill_profiles_bounded.ColumnInt64(0)); | 1128 EXPECT_EQ(51, s_autofill_profiles_bounded.ColumnInt64(0)); |
1223 ASSERT_TRUE(s_autofill_profiles_bounded.Step()); | 1129 ASSERT_TRUE(s_autofill_profiles_bounded.Step()); |
1224 EXPECT_EQ(61, s_autofill_profiles_bounded.ColumnInt64(0)); | 1130 EXPECT_EQ(61, s_autofill_profiles_bounded.ColumnInt64(0)); |
1225 EXPECT_FALSE(s_autofill_profiles_bounded.Step()); | 1131 EXPECT_FALSE(s_autofill_profiles_bounded.Step()); |
1226 ASSERT_EQ(3UL, credit_card_guids.size()); | 1132 ASSERT_EQ(3UL, credit_card_guids.size()); |
1227 EXPECT_EQ("00000000-0000-0000-0000-000000000006", credit_card_guids[0]); | 1133 EXPECT_EQ("00000000-0000-0000-0000-000000000006", credit_card_guids[0]); |
1228 EXPECT_EQ("00000000-0000-0000-0000-000000000007", credit_card_guids[1]); | 1134 EXPECT_EQ("00000000-0000-0000-0000-000000000007", credit_card_guids[1]); |
1229 EXPECT_EQ("00000000-0000-0000-0000-000000000008", credit_card_guids[2]); | 1135 EXPECT_EQ("00000000-0000-0000-0000-000000000008", credit_card_guids[2]); |
1230 sql::Statement s_credit_cards_bounded( | 1136 sql::Statement s_credit_cards_bounded( |
1231 db.GetSQLConnection()->GetUniqueStatement( | 1137 db_->GetSQLConnection()->GetUniqueStatement( |
1232 "SELECT date_modified FROM credit_cards")); | 1138 "SELECT date_modified FROM credit_cards")); |
1233 ASSERT_TRUE(s_credit_cards_bounded.is_valid()); | 1139 ASSERT_TRUE(s_credit_cards_bounded.is_valid()); |
1234 ASSERT_TRUE(s_credit_cards_bounded.Step()); | 1140 ASSERT_TRUE(s_credit_cards_bounded.Step()); |
1235 EXPECT_EQ(47, s_credit_cards_bounded.ColumnInt64(0)); | 1141 EXPECT_EQ(47, s_credit_cards_bounded.ColumnInt64(0)); |
1236 ASSERT_TRUE(s_credit_cards_bounded.Step()); | 1142 ASSERT_TRUE(s_credit_cards_bounded.Step()); |
1237 EXPECT_EQ(57, s_credit_cards_bounded.ColumnInt64(0)); | 1143 EXPECT_EQ(57, s_credit_cards_bounded.ColumnInt64(0)); |
1238 ASSERT_TRUE(s_credit_cards_bounded.Step()); | 1144 ASSERT_TRUE(s_credit_cards_bounded.Step()); |
1239 EXPECT_EQ(67, s_credit_cards_bounded.ColumnInt64(0)); | 1145 EXPECT_EQ(67, s_credit_cards_bounded.ColumnInt64(0)); |
1240 EXPECT_FALSE(s_credit_cards_bounded.Step()); | 1146 EXPECT_FALSE(s_credit_cards_bounded.Step()); |
1241 | 1147 |
1242 // Remove all entries modified on or after time 51 (unbounded range). | 1148 // Remove all entries modified on or after time 51 (unbounded range). |
1243 db.GetAutofillTable()->RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 1149 table_->RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
1244 Time::FromTimeT(51), Time(), | 1150 Time::FromTimeT(51), Time(), |
1245 &profile_guids, &credit_card_guids); | 1151 &profile_guids, &credit_card_guids); |
1246 ASSERT_EQ(2UL, profile_guids.size()); | 1152 ASSERT_EQ(2UL, profile_guids.size()); |
1247 EXPECT_EQ("00000000-0000-0000-0000-000000000004", profile_guids[0]); | 1153 EXPECT_EQ("00000000-0000-0000-0000-000000000004", profile_guids[0]); |
1248 EXPECT_EQ("00000000-0000-0000-0000-000000000005", profile_guids[1]); | 1154 EXPECT_EQ("00000000-0000-0000-0000-000000000005", profile_guids[1]); |
1249 sql::Statement s_autofill_profiles_unbounded( | 1155 sql::Statement s_autofill_profiles_unbounded( |
1250 db.GetSQLConnection()->GetUniqueStatement( | 1156 db_->GetSQLConnection()->GetUniqueStatement( |
1251 "SELECT date_modified FROM autofill_profiles")); | 1157 "SELECT date_modified FROM autofill_profiles")); |
1252 ASSERT_TRUE(s_autofill_profiles_unbounded.is_valid()); | 1158 ASSERT_TRUE(s_autofill_profiles_unbounded.is_valid()); |
1253 ASSERT_TRUE(s_autofill_profiles_unbounded.Step()); | 1159 ASSERT_TRUE(s_autofill_profiles_unbounded.Step()); |
1254 EXPECT_EQ(11, s_autofill_profiles_unbounded.ColumnInt64(0)); | 1160 EXPECT_EQ(11, s_autofill_profiles_unbounded.ColumnInt64(0)); |
1255 ASSERT_TRUE(s_autofill_profiles_unbounded.Step()); | 1161 ASSERT_TRUE(s_autofill_profiles_unbounded.Step()); |
1256 EXPECT_EQ(41, s_autofill_profiles_unbounded.ColumnInt64(0)); | 1162 EXPECT_EQ(41, s_autofill_profiles_unbounded.ColumnInt64(0)); |
1257 EXPECT_FALSE(s_autofill_profiles_unbounded.Step()); | 1163 EXPECT_FALSE(s_autofill_profiles_unbounded.Step()); |
1258 ASSERT_EQ(2UL, credit_card_guids.size()); | 1164 ASSERT_EQ(2UL, credit_card_guids.size()); |
1259 EXPECT_EQ("00000000-0000-0000-0000-000000000010", credit_card_guids[0]); | 1165 EXPECT_EQ("00000000-0000-0000-0000-000000000010", credit_card_guids[0]); |
1260 EXPECT_EQ("00000000-0000-0000-0000-000000000011", credit_card_guids[1]); | 1166 EXPECT_EQ("00000000-0000-0000-0000-000000000011", credit_card_guids[1]); |
1261 sql::Statement s_credit_cards_unbounded( | 1167 sql::Statement s_credit_cards_unbounded( |
1262 db.GetSQLConnection()->GetUniqueStatement( | 1168 db_->GetSQLConnection()->GetUniqueStatement( |
1263 "SELECT date_modified FROM credit_cards")); | 1169 "SELECT date_modified FROM credit_cards")); |
1264 ASSERT_TRUE(s_credit_cards_unbounded.is_valid()); | 1170 ASSERT_TRUE(s_credit_cards_unbounded.is_valid()); |
1265 ASSERT_TRUE(s_credit_cards_unbounded.Step()); | 1171 ASSERT_TRUE(s_credit_cards_unbounded.Step()); |
1266 EXPECT_EQ(47, s_credit_cards_unbounded.ColumnInt64(0)); | 1172 EXPECT_EQ(47, s_credit_cards_unbounded.ColumnInt64(0)); |
1267 EXPECT_FALSE(s_credit_cards_unbounded.Step()); | 1173 EXPECT_FALSE(s_credit_cards_unbounded.Step()); |
1268 | 1174 |
1269 // Remove all remaining entries. | 1175 // Remove all remaining entries. |
1270 db.GetAutofillTable()->RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 1176 table_->RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
1271 Time(), Time(), | 1177 Time(), Time(), |
1272 &profile_guids, &credit_card_guids); | 1178 &profile_guids, &credit_card_guids); |
1273 ASSERT_EQ(2UL, profile_guids.size()); | 1179 ASSERT_EQ(2UL, profile_guids.size()); |
1274 EXPECT_EQ("00000000-0000-0000-0000-000000000000", profile_guids[0]); | 1180 EXPECT_EQ("00000000-0000-0000-0000-000000000000", profile_guids[0]); |
1275 EXPECT_EQ("00000000-0000-0000-0000-000000000003", profile_guids[1]); | 1181 EXPECT_EQ("00000000-0000-0000-0000-000000000003", profile_guids[1]); |
1276 sql::Statement s_autofill_profiles_empty( | 1182 sql::Statement s_autofill_profiles_empty( |
1277 db.GetSQLConnection()->GetUniqueStatement( | 1183 db_->GetSQLConnection()->GetUniqueStatement( |
1278 "SELECT date_modified FROM autofill_profiles")); | 1184 "SELECT date_modified FROM autofill_profiles")); |
1279 ASSERT_TRUE(s_autofill_profiles_empty.is_valid()); | 1185 ASSERT_TRUE(s_autofill_profiles_empty.is_valid()); |
1280 EXPECT_FALSE(s_autofill_profiles_empty.Step()); | 1186 EXPECT_FALSE(s_autofill_profiles_empty.Step()); |
1281 ASSERT_EQ(1UL, credit_card_guids.size()); | 1187 ASSERT_EQ(1UL, credit_card_guids.size()); |
1282 EXPECT_EQ("00000000-0000-0000-0000-000000000009", credit_card_guids[0]); | 1188 EXPECT_EQ("00000000-0000-0000-0000-000000000009", credit_card_guids[0]); |
1283 sql::Statement s_credit_cards_empty( | 1189 sql::Statement s_credit_cards_empty( |
1284 db.GetSQLConnection()->GetUniqueStatement( | 1190 db_->GetSQLConnection()->GetUniqueStatement( |
1285 "SELECT date_modified FROM credit_cards")); | 1191 "SELECT date_modified FROM credit_cards")); |
1286 ASSERT_TRUE(s_credit_cards_empty.is_valid()); | 1192 ASSERT_TRUE(s_credit_cards_empty.is_valid()); |
1287 EXPECT_FALSE(s_credit_cards_empty.Step()); | 1193 EXPECT_FALSE(s_credit_cards_empty.Step()); |
1288 } | 1194 } |
1289 | 1195 |
1290 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_NoResults) { | 1196 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_NoResults) { |
1291 WebDatabase db; | |
1292 | |
1293 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
1294 | |
1295 std::vector<AutofillEntry> entries; | 1197 std::vector<AutofillEntry> entries; |
1296 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries)); | 1198 ASSERT_TRUE(table_->GetAllAutofillEntries(&entries)); |
1297 | 1199 |
1298 EXPECT_EQ(0U, entries.size()); | 1200 EXPECT_EQ(0U, entries.size()); |
1299 } | 1201 } |
1300 | 1202 |
1301 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) { | 1203 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) { |
1302 WebDatabase db; | |
1303 | |
1304 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
1305 | |
1306 AutofillChangeList changes; | 1204 AutofillChangeList changes; |
1307 std::map<std::string, std::vector<Time> > name_value_times_map; | 1205 std::map<std::string, std::vector<Time> > name_value_times_map; |
1308 | 1206 |
1309 time_t start = 0; | 1207 time_t start = 0; |
1310 std::vector<Time> timestamps1; | 1208 std::vector<Time> timestamps1; |
1311 FormFieldData field; | 1209 FormFieldData field; |
1312 field.name = ASCIIToUTF16("Name"); | 1210 field.name = ASCIIToUTF16("Name"); |
1313 field.value = ASCIIToUTF16("Superman"); | 1211 field.value = ASCIIToUTF16("Superman"); |
1314 EXPECT_TRUE( | 1212 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, |
1315 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, | 1213 Time::FromTimeT(start))); |
1316 Time::FromTimeT(start))); | |
1317 timestamps1.push_back(Time::FromTimeT(start)); | 1214 timestamps1.push_back(Time::FromTimeT(start)); |
1318 std::string key1("NameSuperman"); | 1215 std::string key1("NameSuperman"); |
1319 name_value_times_map.insert(std::pair<std::string, | 1216 name_value_times_map.insert(std::pair<std::string, |
1320 std::vector<Time> > (key1, timestamps1)); | 1217 std::vector<Time> > (key1, timestamps1)); |
1321 | 1218 |
1322 AutofillEntrySet expected_entries(CompareAutofillEntries); | 1219 AutofillEntrySet expected_entries(CompareAutofillEntries); |
1323 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); | 1220 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); |
1324 AutofillEntry ae1(ak1, timestamps1); | 1221 AutofillEntry ae1(ak1, timestamps1); |
1325 | 1222 |
1326 expected_entries.insert(ae1); | 1223 expected_entries.insert(ae1); |
1327 | 1224 |
1328 std::vector<AutofillEntry> entries; | 1225 std::vector<AutofillEntry> entries; |
1329 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries)); | 1226 ASSERT_TRUE(table_->GetAllAutofillEntries(&entries)); |
1330 AutofillEntrySet entry_set(entries.begin(), entries.end(), | 1227 AutofillEntrySet entry_set(entries.begin(), entries.end(), |
1331 CompareAutofillEntries); | 1228 CompareAutofillEntries); |
1332 | 1229 |
1333 // make sure the lists of entries match | 1230 // make sure the lists of entries match |
1334 ASSERT_EQ(expected_entries.size(), entry_set.size()); | 1231 ASSERT_EQ(expected_entries.size(), entry_set.size()); |
1335 AutofillEntrySetIterator it; | 1232 AutofillEntrySetIterator it; |
1336 for (it = entry_set.begin(); it != entry_set.end(); it++) { | 1233 for (it = entry_set.begin(); it != entry_set.end(); it++) { |
1337 expected_entries.erase(*it); | 1234 expected_entries.erase(*it); |
1338 } | 1235 } |
1339 | 1236 |
1340 EXPECT_EQ(0U, expected_entries.size()); | 1237 EXPECT_EQ(0U, expected_entries.size()); |
1341 } | 1238 } |
1342 | 1239 |
1343 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) { | 1240 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) { |
1344 WebDatabase db; | |
1345 | |
1346 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
1347 | |
1348 AutofillChangeList changes; | 1241 AutofillChangeList changes; |
1349 std::map<std::string, std::vector<Time> > name_value_times_map; | 1242 std::map<std::string, std::vector<Time> > name_value_times_map; |
1350 time_t start = 0; | 1243 time_t start = 0; |
1351 | 1244 |
1352 std::vector<Time> timestamps1; | 1245 std::vector<Time> timestamps1; |
1353 FormFieldData field; | 1246 FormFieldData field; |
1354 field.name = ASCIIToUTF16("Name"); | 1247 field.name = ASCIIToUTF16("Name"); |
1355 field.value = ASCIIToUTF16("Superman"); | 1248 field.value = ASCIIToUTF16("Superman"); |
1356 EXPECT_TRUE( | 1249 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, |
1357 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, | 1250 Time::FromTimeT(start))); |
1358 Time::FromTimeT(start))); | |
1359 timestamps1.push_back(Time::FromTimeT(start)); | 1251 timestamps1.push_back(Time::FromTimeT(start)); |
1360 std::string key1("NameSuperman"); | 1252 std::string key1("NameSuperman"); |
1361 name_value_times_map.insert(std::pair<std::string, | 1253 name_value_times_map.insert(std::pair<std::string, |
1362 std::vector<Time> > (key1, timestamps1)); | 1254 std::vector<Time> > (key1, timestamps1)); |
1363 | 1255 |
1364 start++; | 1256 start++; |
1365 std::vector<Time> timestamps2; | 1257 std::vector<Time> timestamps2; |
1366 field.name = ASCIIToUTF16("Name"); | 1258 field.name = ASCIIToUTF16("Name"); |
1367 field.value = ASCIIToUTF16("Clark Kent"); | 1259 field.value = ASCIIToUTF16("Clark Kent"); |
1368 EXPECT_TRUE( | 1260 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, |
1369 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, | 1261 Time::FromTimeT(start))); |
1370 Time::FromTimeT(start))); | |
1371 timestamps2.push_back(Time::FromTimeT(start)); | 1262 timestamps2.push_back(Time::FromTimeT(start)); |
1372 std::string key2("NameClark Kent"); | 1263 std::string key2("NameClark Kent"); |
1373 name_value_times_map.insert(std::pair<std::string, | 1264 name_value_times_map.insert(std::pair<std::string, |
1374 std::vector<Time> > (key2, timestamps2)); | 1265 std::vector<Time> > (key2, timestamps2)); |
1375 | 1266 |
1376 AutofillEntrySet expected_entries(CompareAutofillEntries); | 1267 AutofillEntrySet expected_entries(CompareAutofillEntries); |
1377 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); | 1268 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); |
1378 AutofillKey ak2(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")); | 1269 AutofillKey ak2(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")); |
1379 AutofillEntry ae1(ak1, timestamps1); | 1270 AutofillEntry ae1(ak1, timestamps1); |
1380 AutofillEntry ae2(ak2, timestamps2); | 1271 AutofillEntry ae2(ak2, timestamps2); |
1381 | 1272 |
1382 expected_entries.insert(ae1); | 1273 expected_entries.insert(ae1); |
1383 expected_entries.insert(ae2); | 1274 expected_entries.insert(ae2); |
1384 | 1275 |
1385 std::vector<AutofillEntry> entries; | 1276 std::vector<AutofillEntry> entries; |
1386 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries)); | 1277 ASSERT_TRUE(table_->GetAllAutofillEntries(&entries)); |
1387 AutofillEntrySet entry_set(entries.begin(), entries.end(), | 1278 AutofillEntrySet entry_set(entries.begin(), entries.end(), |
1388 CompareAutofillEntries); | 1279 CompareAutofillEntries); |
1389 | 1280 |
1390 // make sure the lists of entries match | 1281 // make sure the lists of entries match |
1391 ASSERT_EQ(expected_entries.size(), entry_set.size()); | 1282 ASSERT_EQ(expected_entries.size(), entry_set.size()); |
1392 AutofillEntrySetIterator it; | 1283 AutofillEntrySetIterator it; |
1393 for (it = entry_set.begin(); it != entry_set.end(); it++) { | 1284 for (it = entry_set.begin(); it != entry_set.end(); it++) { |
1394 expected_entries.erase(*it); | 1285 expected_entries.erase(*it); |
1395 } | 1286 } |
1396 | 1287 |
1397 EXPECT_EQ(0U, expected_entries.size()); | 1288 EXPECT_EQ(0U, expected_entries.size()); |
1398 } | 1289 } |
1399 | 1290 |
1400 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoSame) { | 1291 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoSame) { |
1401 WebDatabase db; | |
1402 | |
1403 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); | |
1404 | |
1405 AutofillChangeList changes; | 1292 AutofillChangeList changes; |
1406 std::map<std::string, std::vector<Time> > name_value_times_map; | 1293 std::map<std::string, std::vector<Time> > name_value_times_map; |
1407 | 1294 |
1408 time_t start = 0; | 1295 time_t start = 0; |
1409 std::vector<Time> timestamps; | 1296 std::vector<Time> timestamps; |
1410 for (int i = 0; i < 2; i++) { | 1297 for (int i = 0; i < 2; i++) { |
1411 FormFieldData field; | 1298 FormFieldData field; |
1412 field.name = ASCIIToUTF16("Name"); | 1299 field.name = ASCIIToUTF16("Name"); |
1413 field.value = ASCIIToUTF16("Superman"); | 1300 field.value = ASCIIToUTF16("Superman"); |
1414 EXPECT_TRUE( | 1301 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, |
1415 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, | 1302 Time::FromTimeT(start))); |
1416 Time::FromTimeT(start))); | |
1417 timestamps.push_back(Time::FromTimeT(start)); | 1303 timestamps.push_back(Time::FromTimeT(start)); |
1418 start++; | 1304 start++; |
1419 } | 1305 } |
1420 | 1306 |
1421 std::string key("NameSuperman"); | 1307 std::string key("NameSuperman"); |
1422 name_value_times_map.insert(std::pair<std::string, | 1308 name_value_times_map.insert(std::pair<std::string, |
1423 std::vector<Time> > (key, timestamps)); | 1309 std::vector<Time> > (key, timestamps)); |
1424 | 1310 |
1425 AutofillEntrySet expected_entries(CompareAutofillEntries); | 1311 AutofillEntrySet expected_entries(CompareAutofillEntries); |
1426 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); | 1312 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); |
1427 AutofillEntry ae1(ak1, timestamps); | 1313 AutofillEntry ae1(ak1, timestamps); |
1428 | 1314 |
1429 expected_entries.insert(ae1); | 1315 expected_entries.insert(ae1); |
1430 | 1316 |
1431 std::vector<AutofillEntry> entries; | 1317 std::vector<AutofillEntry> entries; |
1432 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries)); | 1318 ASSERT_TRUE(table_->GetAllAutofillEntries(&entries)); |
1433 AutofillEntrySet entry_set(entries.begin(), entries.end(), | 1319 AutofillEntrySet entry_set(entries.begin(), entries.end(), |
1434 CompareAutofillEntries); | 1320 CompareAutofillEntries); |
1435 | 1321 |
1436 // make sure the lists of entries match | 1322 // make sure the lists of entries match |
1437 ASSERT_EQ(expected_entries.size(), entry_set.size()); | 1323 ASSERT_EQ(expected_entries.size(), entry_set.size()); |
1438 AutofillEntrySetIterator it; | 1324 AutofillEntrySetIterator it; |
1439 for (it = entry_set.begin(); it != entry_set.end(); it++) { | 1325 for (it = entry_set.begin(); it != entry_set.end(); it++) { |
1440 expected_entries.erase(*it); | 1326 expected_entries.erase(*it); |
1441 } | 1327 } |
1442 | 1328 |
1443 EXPECT_EQ(0U, expected_entries.size()); | 1329 EXPECT_EQ(0U, expected_entries.size()); |
1444 } | 1330 } |
OLD | NEW |