ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / components / autofill / core / browser / webdata / autofill_table_unittest.cc
blob75eec072f4b7ac9523a5cfd3901ec561c77a7098
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <utility>
6 #include <vector>
8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/guid.h"
11 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h"
16 #include "components/autofill/core/browser/autofill_profile.h"
17 #include "components/autofill/core/browser/autofill_type.h"
18 #include "components/autofill/core/browser/credit_card.h"
19 #include "components/autofill/core/browser/webdata/autofill_change.h"
20 #include "components/autofill/core/browser/webdata/autofill_entry.h"
21 #include "components/autofill/core/browser/webdata/autofill_table.h"
22 #include "components/autofill/core/common/form_field_data.h"
23 #include "components/os_crypt/os_crypt.h"
24 #include "components/webdata/common/web_database.h"
25 #include "sql/statement.h"
26 #include "testing/gtest/include/gtest/gtest.h"
28 using base::ASCIIToUTF16;
29 using base::Time;
30 using base::TimeDelta;
32 namespace autofill {
34 // So we can compare AutofillKeys with EXPECT_EQ().
35 std::ostream& operator<<(std::ostream& os, const AutofillKey& key) {
36 return os << base::UTF16ToASCII(key.name()) << ", "
37 << base::UTF16ToASCII(key.value());
40 // So we can compare AutofillChanges with EXPECT_EQ().
41 std::ostream& operator<<(std::ostream& os, const AutofillChange& change) {
42 switch (change.type()) {
43 case AutofillChange::ADD: {
44 os << "ADD";
45 break;
47 case AutofillChange::UPDATE: {
48 os << "UPDATE";
49 break;
51 case AutofillChange::REMOVE: {
52 os << "REMOVE";
53 break;
56 return os << " " << change.key();
59 namespace {
61 typedef std::set<AutofillEntry,
62 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet;
63 typedef AutofillEntrySet::iterator AutofillEntrySetIterator;
65 bool CompareAutofillEntries(const AutofillEntry& a, const AutofillEntry& b) {
66 int compVal = a.key().name().compare(b.key().name());
67 if (compVal != 0)
68 return compVal < 0;
70 compVal = a.key().value().compare(b.key().value());
71 if (compVal != 0)
72 return compVal < 0;
74 if (a.date_created() != b.date_created())
75 return a.date_created() < b.date_created();
77 return a.date_last_used() < b.date_last_used();
80 AutofillEntry MakeAutofillEntry(const char* name,
81 const char* value,
82 time_t date_created,
83 time_t date_last_used) {
84 if (date_last_used < 0)
85 date_last_used = date_created;
86 return AutofillEntry(AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)),
87 Time::FromTimeT(date_created),
88 Time::FromTimeT(date_last_used));
91 // Checks |actual| and |expected| contain the same elements.
92 void CompareAutofillEntrySets(const AutofillEntrySet& actual,
93 const AutofillEntrySet& expected) {
94 ASSERT_EQ(expected.size(), actual.size());
95 size_t count = 0;
96 for (AutofillEntrySet::const_iterator it = actual.begin();
97 it != actual.end(); ++it) {
98 count += expected.count(*it);
100 EXPECT_EQ(actual.size(), count);
103 int GetAutofillEntryCount(const base::string16& name,
104 const base::string16& value,
105 WebDatabase* db) {
106 sql::Statement s(db->GetSQLConnection()->GetUniqueStatement(
107 "SELECT count FROM autofill WHERE name = ? AND value = ?"));
108 s.BindString16(0, name);
109 s.BindString16(1, value);
110 s.Step();
111 return s.ColumnInt(0);
114 } // namespace
116 class AutofillTableTest : public testing::Test {
117 public:
118 AutofillTableTest() {}
119 ~AutofillTableTest() override {}
121 protected:
122 void SetUp() override {
123 #if defined(OS_MACOSX)
124 OSCrypt::UseMockKeychain(true);
125 #endif
126 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
127 file_ = temp_dir_.path().AppendASCII("TestWebDatabase");
129 table_.reset(new AutofillTable("en-US"));
130 db_.reset(new WebDatabase);
131 db_->AddTable(table_.get());
132 ASSERT_EQ(sql::INIT_OK, db_->Init(file_));
135 base::FilePath file_;
136 base::ScopedTempDir temp_dir_;
137 scoped_ptr<AutofillTable> table_;
138 scoped_ptr<WebDatabase> db_;
140 private:
141 DISALLOW_COPY_AND_ASSIGN(AutofillTableTest);
144 TEST_F(AutofillTableTest, Autofill) {
145 Time t1 = Time::Now();
147 // Simulate the submission of a handful of entries in a field called "Name",
148 // some more often than others.
149 AutofillChangeList changes;
150 FormFieldData field;
151 field.name = ASCIIToUTF16("Name");
152 field.value = ASCIIToUTF16("Superman");
153 base::Time now = base::Time::Now();
154 base::TimeDelta two_seconds = base::TimeDelta::FromSeconds(2);
155 EXPECT_FALSE(table_->HasFormElements());
156 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
157 EXPECT_TRUE(table_->HasFormElements());
158 std::vector<base::string16> v;
159 for (int i = 0; i < 5; ++i) {
160 field.value = ASCIIToUTF16("Clark Kent");
161 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
162 now + i * two_seconds));
164 for (int i = 0; i < 3; ++i) {
165 field.value = ASCIIToUTF16("Clark Sutter");
166 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
167 now + i * two_seconds));
169 for (int i = 0; i < 2; ++i) {
170 field.name = ASCIIToUTF16("Favorite Color");
171 field.value = ASCIIToUTF16("Green");
172 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
173 now + i * two_seconds));
176 // We have added the name Clark Kent 5 times, so count should be 5.
177 EXPECT_EQ(5, GetAutofillEntryCount(ASCIIToUTF16("Name"),
178 ASCIIToUTF16("Clark Kent"), db_.get()));
180 // Storing in the data base should be case sensitive, so there should be no
181 // database entry for clark kent lowercase.
182 EXPECT_EQ(0, GetAutofillEntryCount(ASCIIToUTF16("Name"),
183 ASCIIToUTF16("clark kent"), db_.get()));
185 EXPECT_EQ(2, GetAutofillEntryCount(ASCIIToUTF16("Favorite Color"),
186 ASCIIToUTF16("Green"), db_.get()));
188 // This is meant to get a list of suggestions for Name. The empty prefix
189 // in the second argument means it should return all suggestions for a name
190 // no matter what they start with. The order that the names occur in the list
191 // should be decreasing order by count.
192 EXPECT_TRUE(table_->GetFormValuesForElementName(
193 ASCIIToUTF16("Name"), base::string16(), &v, 6));
194 EXPECT_EQ(3U, v.size());
195 if (v.size() == 3) {
196 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
197 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]);
198 EXPECT_EQ(ASCIIToUTF16("Superman"), v[2]);
201 // If we query again limiting the list size to 1, we should only get the most
202 // frequent entry.
203 EXPECT_TRUE(table_->GetFormValuesForElementName(
204 ASCIIToUTF16("Name"), base::string16(), &v, 1));
205 EXPECT_EQ(1U, v.size());
206 if (v.size() == 1) {
207 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
210 // Querying for suggestions given a prefix is case-insensitive, so the prefix
211 // "cLa" shoud get suggestions for both Clarks.
212 EXPECT_TRUE(table_->GetFormValuesForElementName(
213 ASCIIToUTF16("Name"), ASCIIToUTF16("cLa"), &v, 6));
214 EXPECT_EQ(2U, v.size());
215 if (v.size() == 2) {
216 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
217 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]);
220 // Removing all elements since the beginning of this function should remove
221 // everything from the database.
222 changes.clear();
223 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(t1, Time(), &changes));
225 const AutofillChange kExpectedChanges[] = {
226 AutofillChange(AutofillChange::REMOVE,
227 AutofillKey(ASCIIToUTF16("Name"),
228 ASCIIToUTF16("Superman"))),
229 AutofillChange(AutofillChange::REMOVE,
230 AutofillKey(ASCIIToUTF16("Name"),
231 ASCIIToUTF16("Clark Kent"))),
232 AutofillChange(AutofillChange::REMOVE,
233 AutofillKey(ASCIIToUTF16("Name"),
234 ASCIIToUTF16("Clark Sutter"))),
235 AutofillChange(AutofillChange::REMOVE,
236 AutofillKey(ASCIIToUTF16("Favorite Color"),
237 ASCIIToUTF16("Green"))),
239 EXPECT_EQ(arraysize(kExpectedChanges), changes.size());
240 for (size_t i = 0; i < arraysize(kExpectedChanges); ++i) {
241 EXPECT_EQ(kExpectedChanges[i], changes[i]);
244 EXPECT_EQ(0, GetAutofillEntryCount(ASCIIToUTF16("Name"),
245 ASCIIToUTF16("Clark Kent"), db_.get()));
247 EXPECT_TRUE(table_->GetFormValuesForElementName(
248 ASCIIToUTF16("Name"), base::string16(), &v, 6));
249 EXPECT_EQ(0U, v.size());
251 // Now add some values with empty strings.
252 const base::string16 kValue = ASCIIToUTF16(" toto ");
253 field.name = ASCIIToUTF16("blank");
254 field.value = base::string16();
255 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
256 field.name = ASCIIToUTF16("blank");
257 field.value = ASCIIToUTF16(" ");
258 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
259 field.name = ASCIIToUTF16("blank");
260 field.value = ASCIIToUTF16(" ");
261 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
262 field.name = ASCIIToUTF16("blank");
263 field.value = kValue;
264 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
266 // They should be stored normally as the DB layer does not check for empty
267 // values.
268 v.clear();
269 EXPECT_TRUE(table_->GetFormValuesForElementName(
270 ASCIIToUTF16("blank"), base::string16(), &v, 10));
271 EXPECT_EQ(4U, v.size());
274 TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) {
275 TimeDelta one_day(TimeDelta::FromDays(1));
276 Time t1 = Time::Now();
277 Time t2 = t1 + one_day;
279 AutofillChangeList changes;
280 FormFieldData field;
281 field.name = ASCIIToUTF16("Name");
282 field.value = ASCIIToUTF16("Superman");
283 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t1));
284 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t2));
286 changes.clear();
287 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(t1, t2, &changes));
288 ASSERT_EQ(1U, changes.size());
289 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE,
290 AutofillKey(ASCIIToUTF16("Name"),
291 ASCIIToUTF16("Superman"))),
292 changes[0]);
293 changes.clear();
295 EXPECT_TRUE(
296 table_->RemoveFormElementsAddedBetween(t2, t2 + one_day, &changes));
297 ASSERT_EQ(1U, changes.size());
298 EXPECT_EQ(AutofillChange(AutofillChange::REMOVE,
299 AutofillKey(ASCIIToUTF16("Name"),
300 ASCIIToUTF16("Superman"))),
301 changes[0]);
304 TEST_F(AutofillTableTest, Autofill_AddChanges) {
305 TimeDelta one_day(TimeDelta::FromDays(1));
306 Time t1 = Time::Now();
307 Time t2 = t1 + one_day;
309 AutofillChangeList changes;
310 FormFieldData field;
311 field.name = ASCIIToUTF16("Name");
312 field.value = ASCIIToUTF16("Superman");
313 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t1));
314 ASSERT_EQ(1U, changes.size());
315 EXPECT_EQ(AutofillChange(AutofillChange::ADD,
316 AutofillKey(ASCIIToUTF16("Name"),
317 ASCIIToUTF16("Superman"))),
318 changes[0]);
320 changes.clear();
321 EXPECT_TRUE(
322 table_->AddFormFieldValueTime(field, &changes, t2));
323 ASSERT_EQ(1U, changes.size());
324 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE,
325 AutofillKey(ASCIIToUTF16("Name"),
326 ASCIIToUTF16("Superman"))),
327 changes[0]);
330 TEST_F(AutofillTableTest, Autofill_UpdateOneWithOneTimestamp) {
331 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, -1));
332 std::vector<AutofillEntry> entries;
333 entries.push_back(entry);
334 ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
336 EXPECT_EQ(1, GetAutofillEntryCount(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"),
337 db_.get()));
339 std::vector<AutofillEntry> all_entries;
340 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
341 ASSERT_EQ(1U, all_entries.size());
342 EXPECT_EQ(entry, all_entries[0]);
345 TEST_F(AutofillTableTest, Autofill_UpdateOneWithTwoTimestamps) {
346 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2));
347 std::vector<AutofillEntry> entries;
348 entries.push_back(entry);
349 ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
351 EXPECT_EQ(2, GetAutofillEntryCount(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"),
352 db_.get()));
354 std::vector<AutofillEntry> all_entries;
355 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
356 ASSERT_EQ(1U, all_entries.size());
357 EXPECT_EQ(entry, all_entries[0]);
360 TEST_F(AutofillTableTest, Autofill_GetAutofillTimestamps) {
361 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2));
362 std::vector<AutofillEntry> entries;
363 entries.push_back(entry);
364 ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
366 Time date_created, date_last_used;
367 ASSERT_TRUE(table_->GetAutofillTimestamps(ASCIIToUTF16("foo"),
368 ASCIIToUTF16("bar"),
369 &date_created,
370 &date_last_used));
371 EXPECT_EQ(Time::FromTimeT(1), date_created);
372 EXPECT_EQ(Time::FromTimeT(2), date_last_used);
375 TEST_F(AutofillTableTest, Autofill_UpdateTwo) {
376 AutofillEntry entry0(MakeAutofillEntry("foo", "bar0", 1, -1));
377 AutofillEntry entry1(MakeAutofillEntry("foo", "bar1", 2, 3));
378 std::vector<AutofillEntry> entries;
379 entries.push_back(entry0);
380 entries.push_back(entry1);
381 ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
383 EXPECT_EQ(1, GetAutofillEntryCount(ASCIIToUTF16("foo"), ASCIIToUTF16("bar0"),
384 db_.get()));
385 EXPECT_EQ(2, GetAutofillEntryCount(ASCIIToUTF16("foo"), ASCIIToUTF16("bar1"),
386 db_.get()));
389 TEST_F(AutofillTableTest, Autofill_UpdateReplace) {
390 AutofillChangeList changes;
391 // Add a form field. This will be replaced.
392 FormFieldData field;
393 field.name = ASCIIToUTF16("Name");
394 field.value = ASCIIToUTF16("Superman");
395 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
397 AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2));
398 std::vector<AutofillEntry> entries;
399 entries.push_back(entry);
400 ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
402 std::vector<AutofillEntry> all_entries;
403 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
404 ASSERT_EQ(1U, all_entries.size());
405 EXPECT_EQ(entry, all_entries[0]);
408 TEST_F(AutofillTableTest, Autofill_UpdateDontReplace) {
409 Time t = Time::Now();
410 AutofillEntry existing(
411 MakeAutofillEntry("Name", "Superman", t.ToTimeT(), -1));
413 AutofillChangeList changes;
414 // Add a form field. This will NOT be replaced.
415 FormFieldData field;
416 field.name = existing.key().name();
417 field.value = existing.key().value();
418 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t));
419 AutofillEntry entry(MakeAutofillEntry("Name", "Clark Kent", 1, 2));
420 std::vector<AutofillEntry> entries;
421 entries.push_back(entry);
422 ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
424 std::vector<AutofillEntry> all_entries;
425 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
426 ASSERT_EQ(2U, all_entries.size());
427 AutofillEntrySet expected_entries(all_entries.begin(),
428 all_entries.end(),
429 CompareAutofillEntries);
430 EXPECT_EQ(1U, expected_entries.count(existing));
431 EXPECT_EQ(1U, expected_entries.count(entry));
434 TEST_F(AutofillTableTest, Autofill_AddFormFieldValues) {
435 Time t = Time::Now();
437 // Add multiple values for "firstname" and "lastname" names. Test that only
438 // first value of each gets added. Related to security issue:
439 // http://crbug.com/51727.
440 std::vector<FormFieldData> elements;
441 FormFieldData field;
442 field.name = ASCIIToUTF16("firstname");
443 field.value = ASCIIToUTF16("Joe");
444 elements.push_back(field);
446 field.name = ASCIIToUTF16("firstname");
447 field.value = ASCIIToUTF16("Jane");
448 elements.push_back(field);
450 field.name = ASCIIToUTF16("lastname");
451 field.value = ASCIIToUTF16("Smith");
452 elements.push_back(field);
454 field.name = ASCIIToUTF16("lastname");
455 field.value = ASCIIToUTF16("Jones");
456 elements.push_back(field);
458 std::vector<AutofillChange> changes;
459 table_->AddFormFieldValuesTime(elements, &changes, t);
461 ASSERT_EQ(2U, changes.size());
462 EXPECT_EQ(changes[0], AutofillChange(AutofillChange::ADD,
463 AutofillKey(ASCIIToUTF16("firstname"),
464 ASCIIToUTF16("Joe"))));
465 EXPECT_EQ(changes[1], AutofillChange(AutofillChange::ADD,
466 AutofillKey(ASCIIToUTF16("lastname"),
467 ASCIIToUTF16("Smith"))));
469 std::vector<AutofillEntry> all_entries;
470 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
471 ASSERT_EQ(2U, all_entries.size());
474 TEST_F(AutofillTableTest,
475 Autofill_RemoveFormElementsAddedBetween_UsedOnlyBefore) {
476 // Add an entry used only before the targetted range.
477 AutofillChangeList changes;
478 FormFieldData field;
479 field.name = ASCIIToUTF16("Name");
480 field.value = ASCIIToUTF16("Superman");
481 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
482 base::Time::FromTimeT(10)));
483 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
484 base::Time::FromTimeT(20)));
485 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
486 base::Time::FromTimeT(30)));
487 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
488 base::Time::FromTimeT(40)));
489 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
490 base::Time::FromTimeT(50)));
492 EXPECT_EQ(5, GetAutofillEntryCount(field.name, field.value, db_.get()));
494 changes.clear();
495 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(base::Time::FromTimeT(51),
496 base::Time::FromTimeT(60),
497 &changes));
498 EXPECT_TRUE(changes.empty());
499 EXPECT_EQ(5, GetAutofillEntryCount(field.name, field.value, db_.get()));
502 TEST_F(AutofillTableTest,
503 Autofill_RemoveFormElementsAddedBetween_UsedOnlyAfter) {
504 // Add an entry used only after the targetted range.
505 AutofillChangeList changes;
506 FormFieldData field;
507 field.name = ASCIIToUTF16("Name");
508 field.value = ASCIIToUTF16("Superman");
509 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
510 base::Time::FromTimeT(50)));
511 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
512 base::Time::FromTimeT(60)));
513 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
514 base::Time::FromTimeT(70)));
515 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
516 base::Time::FromTimeT(80)));
517 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
518 base::Time::FromTimeT(90)));
520 EXPECT_EQ(5, GetAutofillEntryCount(field.name, field.value, db_.get()));
522 changes.clear();
523 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(base::Time::FromTimeT(40),
524 base::Time::FromTimeT(50),
525 &changes));
526 EXPECT_TRUE(changes.empty());
527 EXPECT_EQ(5, GetAutofillEntryCount(field.name, field.value, db_.get()));
530 TEST_F(AutofillTableTest,
531 Autofill_RemoveFormElementsAddedBetween_UsedOnlyDuring) {
532 // Add an entry used entirely during the targetted range.
533 AutofillChangeList changes;
534 FormFieldData field;
535 field.name = ASCIIToUTF16("Name");
536 field.value = ASCIIToUTF16("Superman");
537 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
538 base::Time::FromTimeT(10)));
539 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
540 base::Time::FromTimeT(20)));
541 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
542 base::Time::FromTimeT(30)));
543 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
544 base::Time::FromTimeT(40)));
545 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
546 base::Time::FromTimeT(50)));
548 EXPECT_EQ(5, GetAutofillEntryCount(field.name, field.value, db_.get()));
550 changes.clear();
551 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(base::Time::FromTimeT(10),
552 base::Time::FromTimeT(51),
553 &changes));
554 ASSERT_EQ(1U, changes.size());
555 EXPECT_EQ(AutofillChange(AutofillChange::REMOVE,
556 AutofillKey(field.name, field.value)),
557 changes[0]);
558 EXPECT_EQ(0, GetAutofillEntryCount(field.name, field.value, db_.get()));
561 TEST_F(AutofillTableTest,
562 Autofill_RemoveFormElementsAddedBetween_UsedBeforeAndDuring) {
563 // Add an entry used both before and during the targetted range.
564 AutofillChangeList changes;
565 FormFieldData field;
566 field.name = ASCIIToUTF16("Name");
567 field.value = ASCIIToUTF16("Superman");
568 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
569 base::Time::FromTimeT(10)));
570 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
571 base::Time::FromTimeT(20)));
572 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
573 base::Time::FromTimeT(30)));
574 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
575 base::Time::FromTimeT(40)));
576 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
577 base::Time::FromTimeT(50)));
579 EXPECT_EQ(5, GetAutofillEntryCount(field.name, field.value, db_.get()));
581 changes.clear();
582 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(base::Time::FromTimeT(40),
583 base::Time::FromTimeT(60),
584 &changes));
585 ASSERT_EQ(1U, changes.size());
586 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE,
587 AutofillKey(field.name, field.value)),
588 changes[0]);
589 EXPECT_EQ(4, GetAutofillEntryCount(field.name, field.value, db_.get()));
590 base::Time date_created, date_last_used;
591 EXPECT_TRUE(
592 table_->GetAutofillTimestamps(field.name, field.value,
593 &date_created, &date_last_used));
594 EXPECT_EQ(base::Time::FromTimeT(10), date_created);
595 EXPECT_EQ(base::Time::FromTimeT(39), date_last_used);
598 TEST_F(AutofillTableTest,
599 Autofill_RemoveFormElementsAddedBetween_UsedDuringAndAfter) {
600 // Add an entry used both during and after the targetted range.
601 AutofillChangeList changes;
602 FormFieldData field;
603 field.name = ASCIIToUTF16("Name");
604 field.value = ASCIIToUTF16("Superman");
605 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
606 base::Time::FromTimeT(50)));
607 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
608 base::Time::FromTimeT(60)));
609 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
610 base::Time::FromTimeT(70)));
611 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
612 base::Time::FromTimeT(80)));
613 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
614 base::Time::FromTimeT(90)));
616 EXPECT_EQ(5, GetAutofillEntryCount(field.name, field.value, db_.get()));
618 changes.clear();
619 EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(base::Time::FromTimeT(40),
620 base::Time::FromTimeT(80),
621 &changes));
622 ASSERT_EQ(1U, changes.size());
623 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE,
624 AutofillKey(field.name, field.value)),
625 changes[0]);
626 EXPECT_EQ(2, GetAutofillEntryCount(field.name, field.value, db_.get()));
627 base::Time date_created, date_last_used;
628 EXPECT_TRUE(
629 table_->GetAutofillTimestamps(field.name, field.value,
630 &date_created, &date_last_used));
631 EXPECT_EQ(base::Time::FromTimeT(80), date_created);
632 EXPECT_EQ(base::Time::FromTimeT(90), date_last_used);
635 TEST_F(AutofillTableTest, AutofillProfile) {
636 // Add a 'Home' profile.
637 AutofillProfile home_profile;
638 home_profile.set_origin(std::string());
639 home_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
640 home_profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q."));
641 home_profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
642 home_profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz"));
643 home_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google"));
644 home_profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way"));
645 home_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5"));
646 home_profile.SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY,
647 ASCIIToUTF16("Beverly Hills"));
648 home_profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles"));
649 home_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
650 home_profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025"));
651 home_profile.SetRawInfo(ADDRESS_HOME_SORTING_CODE, ASCIIToUTF16("MAGIC ###"));
652 home_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
653 home_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567"));
654 home_profile.set_language_code("en");
656 Time pre_creation_time = Time::Now();
657 EXPECT_TRUE(table_->AddAutofillProfile(home_profile));
658 Time post_creation_time = Time::Now();
660 // Get the 'Home' profile.
661 AutofillProfile* db_profile;
662 ASSERT_TRUE(table_->GetAutofillProfile(home_profile.guid(), &db_profile));
663 EXPECT_EQ(home_profile, *db_profile);
664 sql::Statement s_home(db_->GetSQLConnection()->GetUniqueStatement(
665 "SELECT date_modified "
666 "FROM autofill_profiles WHERE guid=?"));
667 s_home.BindString(0, home_profile.guid());
668 ASSERT_TRUE(s_home.is_valid());
669 ASSERT_TRUE(s_home.Step());
670 EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT());
671 EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT());
672 EXPECT_FALSE(s_home.Step());
673 delete db_profile;
675 // Add a 'Billing' profile.
676 AutofillProfile billing_profile = home_profile;
677 billing_profile.set_guid(base::GenerateGUID());
678 billing_profile.set_origin("https://www.example.com/");
679 billing_profile.SetRawInfo(ADDRESS_HOME_LINE1,
680 ASCIIToUTF16("5678 Bottom Street"));
681 billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("suite 3"));
683 pre_creation_time = Time::Now();
684 EXPECT_TRUE(table_->AddAutofillProfile(billing_profile));
685 post_creation_time = Time::Now();
687 // Get the 'Billing' profile.
688 ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile));
689 EXPECT_EQ(billing_profile, *db_profile);
690 sql::Statement s_billing(db_->GetSQLConnection()->GetUniqueStatement(
691 "SELECT date_modified FROM autofill_profiles WHERE guid=?"));
692 s_billing.BindString(0, billing_profile.guid());
693 ASSERT_TRUE(s_billing.is_valid());
694 ASSERT_TRUE(s_billing.Step());
695 EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT());
696 EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT());
697 EXPECT_FALSE(s_billing.Step());
698 delete db_profile;
700 // Update the 'Billing' profile, name only.
701 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane"));
702 Time pre_modification_time = Time::Now();
703 EXPECT_TRUE(table_->UpdateAutofillProfile(billing_profile));
704 Time post_modification_time = Time::Now();
705 ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile));
706 EXPECT_EQ(billing_profile, *db_profile);
707 sql::Statement s_billing_updated(db_->GetSQLConnection()->GetUniqueStatement(
708 "SELECT date_modified FROM autofill_profiles WHERE guid=?"));
709 s_billing_updated.BindString(0, billing_profile.guid());
710 ASSERT_TRUE(s_billing_updated.is_valid());
711 ASSERT_TRUE(s_billing_updated.Step());
712 EXPECT_GE(s_billing_updated.ColumnInt64(0),
713 pre_modification_time.ToTimeT());
714 EXPECT_LE(s_billing_updated.ColumnInt64(0),
715 post_modification_time.ToTimeT());
716 EXPECT_FALSE(s_billing_updated.Step());
717 delete db_profile;
719 // Update the 'Billing' profile.
720 billing_profile.set_origin("Chrome settings");
721 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Janice"));
722 billing_profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("C."));
723 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Joplin"));
724 billing_profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("jane@singer.com"));
725 billing_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Indy"));
726 billing_profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("Open Road"));
727 billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Route 66"));
728 billing_profile.SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY,
729 ASCIIToUTF16("District 9"));
730 billing_profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("NFA"));
731 billing_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("NY"));
732 billing_profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("10011"));
733 billing_profile.SetRawInfo(ADDRESS_HOME_SORTING_CODE, ASCIIToUTF16("123456"));
734 billing_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
735 billing_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
736 ASCIIToUTF16("18181230000"));
737 Time pre_modification_time_2 = Time::Now();
738 EXPECT_TRUE(table_->UpdateAutofillProfile(billing_profile));
739 Time post_modification_time_2 = Time::Now();
740 ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile));
741 EXPECT_EQ(billing_profile, *db_profile);
742 sql::Statement s_billing_updated_2(
743 db_->GetSQLConnection()->GetUniqueStatement(
744 "SELECT date_modified FROM autofill_profiles WHERE guid=?"));
745 s_billing_updated_2.BindString(0, billing_profile.guid());
746 ASSERT_TRUE(s_billing_updated_2.is_valid());
747 ASSERT_TRUE(s_billing_updated_2.Step());
748 EXPECT_GE(s_billing_updated_2.ColumnInt64(0),
749 pre_modification_time_2.ToTimeT());
750 EXPECT_LE(s_billing_updated_2.ColumnInt64(0),
751 post_modification_time_2.ToTimeT());
752 EXPECT_FALSE(s_billing_updated_2.Step());
753 delete db_profile;
755 // Remove the 'Billing' profile.
756 EXPECT_TRUE(table_->RemoveAutofillProfile(billing_profile.guid()));
757 EXPECT_FALSE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile));
760 TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) {
761 AutofillProfile p;
762 const base::string16 kJohnDoe(ASCIIToUTF16("John Doe"));
763 const base::string16 kJohnPDoe(ASCIIToUTF16("John P. Doe"));
764 std::vector<base::string16> set_values;
765 set_values.push_back(kJohnDoe);
766 set_values.push_back(kJohnPDoe);
767 p.SetRawMultiInfo(NAME_FULL, set_values);
769 EXPECT_TRUE(table_->AddAutofillProfile(p));
771 AutofillProfile* db_profile;
772 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
773 EXPECT_EQ(p, *db_profile);
774 EXPECT_EQ(0, p.Compare(*db_profile));
775 delete db_profile;
777 // Update the values.
778 const base::string16 kNoOne(ASCIIToUTF16("No One"));
779 set_values[1] = kNoOne;
780 p.SetRawMultiInfo(NAME_FULL, set_values);
781 EXPECT_TRUE(table_->UpdateAutofillProfile(p));
782 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
783 EXPECT_EQ(p, *db_profile);
784 EXPECT_EQ(0, p.Compare(*db_profile));
785 delete db_profile;
787 // Delete values.
788 set_values.clear();
789 p.SetRawMultiInfo(NAME_FULL, set_values);
790 EXPECT_TRUE(table_->UpdateAutofillProfile(p));
791 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
792 EXPECT_EQ(p, *db_profile);
793 EXPECT_EQ(0, p.Compare(*db_profile));
794 EXPECT_EQ(base::string16(), db_profile->GetRawInfo(NAME_FULL));
795 delete db_profile;
798 TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) {
799 AutofillProfile p;
800 const base::string16 kJohnDoe(ASCIIToUTF16("john@doe.com"));
801 const base::string16 kJohnPDoe(ASCIIToUTF16("john_p@doe.com"));
802 std::vector<base::string16> set_values;
803 set_values.push_back(kJohnDoe);
804 set_values.push_back(kJohnPDoe);
805 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values);
807 EXPECT_TRUE(table_->AddAutofillProfile(p));
809 AutofillProfile* db_profile;
810 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
811 EXPECT_EQ(p, *db_profile);
812 EXPECT_EQ(0, p.Compare(*db_profile));
813 delete db_profile;
815 // Update the values.
816 const base::string16 kNoOne(ASCIIToUTF16("no@one.com"));
817 set_values[1] = kNoOne;
818 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values);
819 EXPECT_TRUE(table_->UpdateAutofillProfile(p));
820 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
821 EXPECT_EQ(p, *db_profile);
822 EXPECT_EQ(0, p.Compare(*db_profile));
823 delete db_profile;
825 // Delete values.
826 set_values.clear();
827 p.SetRawMultiInfo(EMAIL_ADDRESS, set_values);
828 EXPECT_TRUE(table_->UpdateAutofillProfile(p));
829 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
830 EXPECT_EQ(p, *db_profile);
831 EXPECT_EQ(0, p.Compare(*db_profile));
832 EXPECT_EQ(base::string16(), db_profile->GetRawInfo(EMAIL_ADDRESS));
833 delete db_profile;
836 TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) {
837 AutofillProfile p;
838 const base::string16 kJohnDoe(ASCIIToUTF16("4151112222"));
839 const base::string16 kJohnPDoe(ASCIIToUTF16("4151113333"));
840 std::vector<base::string16> set_values;
841 set_values.push_back(kJohnDoe);
842 set_values.push_back(kJohnPDoe);
843 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values);
845 EXPECT_TRUE(table_->AddAutofillProfile(p));
847 AutofillProfile* db_profile;
848 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
849 EXPECT_EQ(p, *db_profile);
850 EXPECT_EQ(0, p.Compare(*db_profile));
851 delete db_profile;
853 // Update the values.
854 const base::string16 kNoOne(ASCIIToUTF16("4151110000"));
855 set_values[1] = kNoOne;
856 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values);
857 EXPECT_TRUE(table_->UpdateAutofillProfile(p));
858 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
859 EXPECT_EQ(p, *db_profile);
860 EXPECT_EQ(0, p.Compare(*db_profile));
861 delete db_profile;
863 // Delete values.
864 set_values.clear();
865 p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values);
866 EXPECT_TRUE(table_->UpdateAutofillProfile(p));
867 ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
868 EXPECT_EQ(p, *db_profile);
869 EXPECT_EQ(0, p.Compare(*db_profile));
870 EXPECT_EQ(base::string16(), db_profile->GetRawInfo(EMAIL_ADDRESS));
871 delete db_profile;
874 TEST_F(AutofillTableTest, AutofillProfileTrash) {
875 std::vector<std::string> guids;
876 table_->GetAutofillProfilesInTrash(&guids);
877 EXPECT_TRUE(guids.empty());
879 ASSERT_TRUE(table_->AddAutofillGUIDToTrash(
880 "00000000-0000-0000-0000-000000000000"));
881 ASSERT_TRUE(table_->AddAutofillGUIDToTrash(
882 "00000000-0000-0000-0000-000000000001"));
883 ASSERT_TRUE(table_->GetAutofillProfilesInTrash(&guids));
884 EXPECT_EQ(2UL, guids.size());
885 EXPECT_EQ("00000000-0000-0000-0000-000000000000", guids[0]);
886 EXPECT_EQ("00000000-0000-0000-0000-000000000001", guids[1]);
888 ASSERT_TRUE(table_->EmptyAutofillProfilesTrash());
889 ASSERT_TRUE(table_->GetAutofillProfilesInTrash(&guids));
890 EXPECT_TRUE(guids.empty());
893 TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) {
894 std::vector<std::string> guids;
895 table_->GetAutofillProfilesInTrash(&guids);
896 EXPECT_TRUE(guids.empty());
898 AutofillProfile profile;
899 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
900 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q."));
901 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
902 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz"));
903 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 Main St"));
904 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles"));
905 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
906 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025"));
907 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
909 // Mark this profile as in the trash. This stops |AddAutofillProfile| from
910 // adding it.
911 EXPECT_TRUE(table_->AddAutofillGUIDToTrash(profile.guid()));
912 EXPECT_TRUE(table_->AddAutofillProfile(profile));
913 AutofillProfile* added_profile = NULL;
914 EXPECT_FALSE(table_->GetAutofillProfile(profile.guid(), &added_profile));
915 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), added_profile);
917 // Add the profile for real this time.
918 EXPECT_TRUE(table_->EmptyAutofillProfilesTrash());
919 EXPECT_TRUE(table_->GetAutofillProfilesInTrash(&guids));
920 EXPECT_TRUE(guids.empty());
921 EXPECT_TRUE(table_->AddAutofillProfile(profile));
922 EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(),
923 &added_profile));
924 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile);
925 delete added_profile;
927 // Mark this profile as in the trash. This stops |UpdateAutofillProfileMulti|
928 // from updating it. In normal operation a profile should not be both in the
929 // trash and in the profiles table simultaneously.
930 EXPECT_TRUE(table_->AddAutofillGUIDToTrash(profile.guid()));
931 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane"));
932 EXPECT_TRUE(table_->UpdateAutofillProfile(profile));
933 AutofillProfile* updated_profile = NULL;
934 EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(), &updated_profile));
935 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile);
936 EXPECT_EQ(ASCIIToUTF16("John"), updated_profile->GetRawInfo(NAME_FIRST));
937 delete updated_profile;
939 // Try to delete the trashed profile. This stops |RemoveAutofillProfile| from
940 // deleting it. In normal operation deletion is done by migration step, and
941 // removal from trash is done by |WebDataService|. |RemoveAutofillProfile|
942 // does remove the item from the trash if it is found however, so that if
943 // other clients remove it (via Sync say) then it is gone and doesn't need to
944 // be processed further by |WebDataService|.
945 EXPECT_TRUE(table_->RemoveAutofillProfile(profile.guid()));
946 AutofillProfile* removed_profile = NULL;
947 EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(), &removed_profile));
948 EXPECT_FALSE(table_->IsAutofillGUIDInTrash(profile.guid()));
949 ASSERT_NE(static_cast<AutofillProfile*>(NULL), removed_profile);
950 delete removed_profile;
952 // Check that emptying the trash now allows removal to occur.
953 EXPECT_TRUE(table_->EmptyAutofillProfilesTrash());
954 EXPECT_TRUE(table_->RemoveAutofillProfile(profile.guid()));
955 removed_profile = NULL;
956 EXPECT_FALSE(table_->GetAutofillProfile(profile.guid(), &removed_profile));
957 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), removed_profile);
960 TEST_F(AutofillTableTest, CreditCard) {
961 // Add a 'Work' credit card.
962 CreditCard work_creditcard;
963 work_creditcard.set_origin("https://www.example.com/");
964 work_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
965 work_creditcard.SetRawInfo(CREDIT_CARD_NUMBER,
966 ASCIIToUTF16("1234567890123456"));
967 work_creditcard.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04"));
968 work_creditcard.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
969 ASCIIToUTF16("2013"));
971 Time pre_creation_time = Time::Now();
972 EXPECT_TRUE(table_->AddCreditCard(work_creditcard));
973 Time post_creation_time = Time::Now();
975 // Get the 'Work' credit card.
976 CreditCard* db_creditcard;
977 ASSERT_TRUE(table_->GetCreditCard(work_creditcard.guid(), &db_creditcard));
978 EXPECT_EQ(work_creditcard, *db_creditcard);
979 sql::Statement s_work(db_->GetSQLConnection()->GetUniqueStatement(
980 "SELECT guid, name_on_card, expiration_month, expiration_year, "
981 "card_number_encrypted, date_modified "
982 "FROM credit_cards WHERE guid=?"));
983 s_work.BindString(0, work_creditcard.guid());
984 ASSERT_TRUE(s_work.is_valid());
985 ASSERT_TRUE(s_work.Step());
986 EXPECT_GE(s_work.ColumnInt64(5), pre_creation_time.ToTimeT());
987 EXPECT_LE(s_work.ColumnInt64(5), post_creation_time.ToTimeT());
988 EXPECT_FALSE(s_work.Step());
989 delete db_creditcard;
991 // Add a 'Target' credit card.
992 CreditCard target_creditcard;
993 target_creditcard.set_origin(std::string());
994 target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
995 target_creditcard.SetRawInfo(CREDIT_CARD_NUMBER,
996 ASCIIToUTF16("1111222233334444"));
997 target_creditcard.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06"));
998 target_creditcard.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
999 ASCIIToUTF16("2012"));
1001 pre_creation_time = Time::Now();
1002 EXPECT_TRUE(table_->AddCreditCard(target_creditcard));
1003 post_creation_time = Time::Now();
1004 ASSERT_TRUE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard));
1005 EXPECT_EQ(target_creditcard, *db_creditcard);
1006 sql::Statement s_target(db_->GetSQLConnection()->GetUniqueStatement(
1007 "SELECT guid, name_on_card, expiration_month, expiration_year, "
1008 "card_number_encrypted, date_modified "
1009 "FROM credit_cards WHERE guid=?"));
1010 s_target.BindString(0, target_creditcard.guid());
1011 ASSERT_TRUE(s_target.is_valid());
1012 ASSERT_TRUE(s_target.Step());
1013 EXPECT_GE(s_target.ColumnInt64(5), pre_creation_time.ToTimeT());
1014 EXPECT_LE(s_target.ColumnInt64(5), post_creation_time.ToTimeT());
1015 EXPECT_FALSE(s_target.Step());
1016 delete db_creditcard;
1018 // Update the 'Target' credit card.
1019 target_creditcard.set_origin("Interactive Autofill dialog");
1020 target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Charles Grady"));
1021 Time pre_modification_time = Time::Now();
1022 EXPECT_TRUE(table_->UpdateCreditCard(target_creditcard));
1023 Time post_modification_time = Time::Now();
1024 ASSERT_TRUE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard));
1025 EXPECT_EQ(target_creditcard, *db_creditcard);
1026 sql::Statement s_target_updated(db_->GetSQLConnection()->GetUniqueStatement(
1027 "SELECT guid, name_on_card, expiration_month, expiration_year, "
1028 "card_number_encrypted, date_modified "
1029 "FROM credit_cards WHERE guid=?"));
1030 s_target_updated.BindString(0, target_creditcard.guid());
1031 ASSERT_TRUE(s_target_updated.is_valid());
1032 ASSERT_TRUE(s_target_updated.Step());
1033 EXPECT_GE(s_target_updated.ColumnInt64(5), pre_modification_time.ToTimeT());
1034 EXPECT_LE(s_target_updated.ColumnInt64(5), post_modification_time.ToTimeT());
1035 EXPECT_FALSE(s_target_updated.Step());
1036 delete db_creditcard;
1038 // Remove the 'Target' credit card.
1039 EXPECT_TRUE(table_->RemoveCreditCard(target_creditcard.guid()));
1040 EXPECT_FALSE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard));
1043 TEST_F(AutofillTableTest, UpdateAutofillProfile) {
1044 // Add a profile to the db.
1045 AutofillProfile profile;
1046 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
1047 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q."));
1048 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1049 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@example.com"));
1050 profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google"));
1051 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way"));
1052 profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5"));
1053 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles"));
1054 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
1055 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025"));
1056 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
1057 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567"));
1058 profile.set_language_code("en");
1059 table_->AddAutofillProfile(profile);
1061 // Set a mocked value for the profile's creation time.
1062 const time_t kMockCreationDate = Time::Now().ToTimeT() - 13;
1063 sql::Statement s_mock_creation_date(
1064 db_->GetSQLConnection()->GetUniqueStatement(
1065 "UPDATE autofill_profiles SET date_modified = ?"));
1066 ASSERT_TRUE(s_mock_creation_date.is_valid());
1067 s_mock_creation_date.BindInt64(0, kMockCreationDate);
1068 ASSERT_TRUE(s_mock_creation_date.Run());
1070 // Get the profile.
1071 AutofillProfile* tmp_profile;
1072 ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile));
1073 scoped_ptr<AutofillProfile> db_profile(tmp_profile);
1074 EXPECT_EQ(profile, *db_profile);
1075 sql::Statement s_original(db_->GetSQLConnection()->GetUniqueStatement(
1076 "SELECT date_modified FROM autofill_profiles"));
1077 ASSERT_TRUE(s_original.is_valid());
1078 ASSERT_TRUE(s_original.Step());
1079 EXPECT_EQ(kMockCreationDate, s_original.ColumnInt64(0));
1080 EXPECT_FALSE(s_original.Step());
1082 // Now, update the profile and save the update to the database.
1083 // The modification date should change to reflect the update.
1084 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz"));
1085 table_->UpdateAutofillProfile(profile);
1087 // Get the profile.
1088 ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile));
1089 db_profile.reset(tmp_profile);
1090 EXPECT_EQ(profile, *db_profile);
1091 sql::Statement s_updated(db_->GetSQLConnection()->GetUniqueStatement(
1092 "SELECT date_modified FROM autofill_profiles"));
1093 ASSERT_TRUE(s_updated.is_valid());
1094 ASSERT_TRUE(s_updated.Step());
1095 EXPECT_LT(kMockCreationDate, s_updated.ColumnInt64(0));
1096 EXPECT_FALSE(s_updated.Step());
1098 // Set a mocked value for the profile's modification time.
1099 const time_t mock_modification_date = Time::Now().ToTimeT() - 7;
1100 sql::Statement s_mock_modification_date(
1101 db_->GetSQLConnection()->GetUniqueStatement(
1102 "UPDATE autofill_profiles SET date_modified = ?"));
1103 ASSERT_TRUE(s_mock_modification_date.is_valid());
1104 s_mock_modification_date.BindInt64(0, mock_modification_date);
1105 ASSERT_TRUE(s_mock_modification_date.Run());
1107 // Finally, call into |UpdateAutofillProfile()| without changing the
1108 // profile. The modification date should not change.
1109 table_->UpdateAutofillProfile(profile);
1111 // Get the profile.
1112 ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile));
1113 db_profile.reset(tmp_profile);
1114 EXPECT_EQ(profile, *db_profile);
1115 sql::Statement s_unchanged(db_->GetSQLConnection()->GetUniqueStatement(
1116 "SELECT date_modified FROM autofill_profiles"));
1117 ASSERT_TRUE(s_unchanged.is_valid());
1118 ASSERT_TRUE(s_unchanged.Step());
1119 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0));
1120 EXPECT_FALSE(s_unchanged.Step());
1123 TEST_F(AutofillTableTest, UpdateCreditCard) {
1124 // Add a credit card to the db.
1125 CreditCard credit_card;
1126 credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
1127 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234567890123456"));
1128 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04"));
1129 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2013"));
1130 table_->AddCreditCard(credit_card);
1132 // Set a mocked value for the credit card's creation time.
1133 const time_t kMockCreationDate = Time::Now().ToTimeT() - 13;
1134 sql::Statement s_mock_creation_date(
1135 db_->GetSQLConnection()->GetUniqueStatement(
1136 "UPDATE credit_cards SET date_modified = ?"));
1137 ASSERT_TRUE(s_mock_creation_date.is_valid());
1138 s_mock_creation_date.BindInt64(0, kMockCreationDate);
1139 ASSERT_TRUE(s_mock_creation_date.Run());
1141 // Get the credit card.
1142 CreditCard* tmp_credit_card;
1143 ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card));
1144 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card);
1145 EXPECT_EQ(credit_card, *db_credit_card);
1146 sql::Statement s_original(db_->GetSQLConnection()->GetUniqueStatement(
1147 "SELECT date_modified FROM credit_cards"));
1148 ASSERT_TRUE(s_original.is_valid());
1149 ASSERT_TRUE(s_original.Step());
1150 EXPECT_EQ(kMockCreationDate, s_original.ColumnInt64(0));
1151 EXPECT_FALSE(s_original.Step());
1153 // Now, update the credit card and save the update to the database.
1154 // The modification date should change to reflect the update.
1155 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01"));
1156 table_->UpdateCreditCard(credit_card);
1158 // Get the credit card.
1159 ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card));
1160 db_credit_card.reset(tmp_credit_card);
1161 EXPECT_EQ(credit_card, *db_credit_card);
1162 sql::Statement s_updated(db_->GetSQLConnection()->GetUniqueStatement(
1163 "SELECT date_modified FROM credit_cards"));
1164 ASSERT_TRUE(s_updated.is_valid());
1165 ASSERT_TRUE(s_updated.Step());
1166 EXPECT_LT(kMockCreationDate, s_updated.ColumnInt64(0));
1167 EXPECT_FALSE(s_updated.Step());
1169 // Set a mocked value for the credit card's modification time.
1170 const time_t mock_modification_date = Time::Now().ToTimeT() - 7;
1171 sql::Statement s_mock_modification_date(
1172 db_->GetSQLConnection()->GetUniqueStatement(
1173 "UPDATE credit_cards SET date_modified = ?"));
1174 ASSERT_TRUE(s_mock_modification_date.is_valid());
1175 s_mock_modification_date.BindInt64(0, mock_modification_date);
1176 ASSERT_TRUE(s_mock_modification_date.Run());
1178 // Finally, call into |UpdateCreditCard()| without changing the credit card.
1179 // The modification date should not change.
1180 table_->UpdateCreditCard(credit_card);
1182 // Get the credit card.
1183 ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card));
1184 db_credit_card.reset(tmp_credit_card);
1185 EXPECT_EQ(credit_card, *db_credit_card);
1186 sql::Statement s_unchanged(db_->GetSQLConnection()->GetUniqueStatement(
1187 "SELECT date_modified FROM credit_cards"));
1188 ASSERT_TRUE(s_unchanged.is_valid());
1189 ASSERT_TRUE(s_unchanged.Step());
1190 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0));
1191 EXPECT_FALSE(s_unchanged.Step());
1194 TEST_F(AutofillTableTest, UpdateProfileOriginOnly) {
1195 // Add a profile to the db.
1196 AutofillProfile profile;
1197 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
1198 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q."));
1199 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1200 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@example.com"));
1201 profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google"));
1202 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way"));
1203 profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5"));
1204 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles"));
1205 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
1206 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025"));
1207 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
1208 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567"));
1209 table_->AddAutofillProfile(profile);
1211 // Set a mocked value for the profile's creation time.
1212 const time_t kMockCreationDate = Time::Now().ToTimeT() - 13;
1213 sql::Statement s_mock_creation_date(
1214 db_->GetSQLConnection()->GetUniqueStatement(
1215 "UPDATE autofill_profiles SET date_modified = ?"));
1216 ASSERT_TRUE(s_mock_creation_date.is_valid());
1217 s_mock_creation_date.BindInt64(0, kMockCreationDate);
1218 ASSERT_TRUE(s_mock_creation_date.Run());
1220 // Get the profile.
1221 AutofillProfile* tmp_profile;
1222 ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile));
1223 scoped_ptr<AutofillProfile> db_profile(tmp_profile);
1224 EXPECT_EQ(profile, *db_profile);
1225 sql::Statement s_original(db_->GetSQLConnection()->GetUniqueStatement(
1226 "SELECT date_modified FROM autofill_profiles"));
1227 ASSERT_TRUE(s_original.is_valid());
1228 ASSERT_TRUE(s_original.Step());
1229 EXPECT_EQ(kMockCreationDate, s_original.ColumnInt64(0));
1230 EXPECT_FALSE(s_original.Step());
1232 // Now, update just the profile's origin and save the update to the database.
1233 // The modification date should change to reflect the update.
1234 profile.set_origin("https://www.example.com/");
1235 table_->UpdateAutofillProfile(profile);
1237 // Get the profile.
1238 ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile));
1239 db_profile.reset(tmp_profile);
1240 EXPECT_EQ(profile, *db_profile);
1241 sql::Statement s_updated(db_->GetSQLConnection()->GetUniqueStatement(
1242 "SELECT date_modified FROM autofill_profiles"));
1243 ASSERT_TRUE(s_updated.is_valid());
1244 ASSERT_TRUE(s_updated.Step());
1245 EXPECT_LT(kMockCreationDate, s_updated.ColumnInt64(0));
1246 EXPECT_FALSE(s_updated.Step());
1249 TEST_F(AutofillTableTest, UpdateCreditCardOriginOnly) {
1250 // Add a credit card to the db.
1251 CreditCard credit_card;
1252 credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
1253 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234567890123456"));
1254 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04"));
1255 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2013"));
1256 table_->AddCreditCard(credit_card);
1258 // Set a mocked value for the credit card's creation time.
1259 const time_t kMockCreationDate = Time::Now().ToTimeT() - 13;
1260 sql::Statement s_mock_creation_date(
1261 db_->GetSQLConnection()->GetUniqueStatement(
1262 "UPDATE credit_cards SET date_modified = ?"));
1263 ASSERT_TRUE(s_mock_creation_date.is_valid());
1264 s_mock_creation_date.BindInt64(0, kMockCreationDate);
1265 ASSERT_TRUE(s_mock_creation_date.Run());
1267 // Get the credit card.
1268 CreditCard* tmp_credit_card;
1269 ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card));
1270 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card);
1271 EXPECT_EQ(credit_card, *db_credit_card);
1272 sql::Statement s_original(db_->GetSQLConnection()->GetUniqueStatement(
1273 "SELECT date_modified FROM credit_cards"));
1274 ASSERT_TRUE(s_original.is_valid());
1275 ASSERT_TRUE(s_original.Step());
1276 EXPECT_EQ(kMockCreationDate, s_original.ColumnInt64(0));
1277 EXPECT_FALSE(s_original.Step());
1279 // Now, update just the credit card's origin and save the update to the
1280 // database. The modification date should change to reflect the update.
1281 credit_card.set_origin("https://www.example.com/");
1282 table_->UpdateCreditCard(credit_card);
1284 // Get the credit card.
1285 ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card));
1286 db_credit_card.reset(tmp_credit_card);
1287 EXPECT_EQ(credit_card, *db_credit_card);
1288 sql::Statement s_updated(db_->GetSQLConnection()->GetUniqueStatement(
1289 "SELECT date_modified FROM credit_cards"));
1290 ASSERT_TRUE(s_updated.is_valid());
1291 ASSERT_TRUE(s_updated.Step());
1292 EXPECT_LT(kMockCreationDate, s_updated.ColumnInt64(0));
1293 EXPECT_FALSE(s_updated.Step());
1296 TEST_F(AutofillTableTest, RemoveAutofillDataModifiedBetween) {
1297 // Populate the autofill_profiles and credit_cards tables.
1298 ASSERT_TRUE(db_->GetSQLConnection()->Execute(
1299 "INSERT INTO autofill_profiles (guid, date_modified) "
1300 "VALUES('00000000-0000-0000-0000-000000000000', 11);"
1301 "INSERT INTO autofill_profiles (guid, date_modified) "
1302 "VALUES('00000000-0000-0000-0000-000000000001', 21);"
1303 "INSERT INTO autofill_profiles (guid, date_modified) "
1304 "VALUES('00000000-0000-0000-0000-000000000002', 31);"
1305 "INSERT INTO autofill_profiles (guid, date_modified) "
1306 "VALUES('00000000-0000-0000-0000-000000000003', 41);"
1307 "INSERT INTO autofill_profiles (guid, date_modified) "
1308 "VALUES('00000000-0000-0000-0000-000000000004', 51);"
1309 "INSERT INTO autofill_profiles (guid, date_modified) "
1310 "VALUES('00000000-0000-0000-0000-000000000005', 61);"
1311 "INSERT INTO credit_cards (guid, date_modified) "
1312 "VALUES('00000000-0000-0000-0000-000000000006', 17);"
1313 "INSERT INTO credit_cards (guid, date_modified) "
1314 "VALUES('00000000-0000-0000-0000-000000000007', 27);"
1315 "INSERT INTO credit_cards (guid, date_modified) "
1316 "VALUES('00000000-0000-0000-0000-000000000008', 37);"
1317 "INSERT INTO credit_cards (guid, date_modified) "
1318 "VALUES('00000000-0000-0000-0000-000000000009', 47);"
1319 "INSERT INTO credit_cards (guid, date_modified) "
1320 "VALUES('00000000-0000-0000-0000-000000000010', 57);"
1321 "INSERT INTO credit_cards (guid, date_modified) "
1322 "VALUES('00000000-0000-0000-0000-000000000011', 67);"));
1324 // Remove all entries modified in the bounded time range [17,41).
1325 std::vector<std::string> profile_guids;
1326 std::vector<std::string> credit_card_guids;
1327 table_->RemoveAutofillDataModifiedBetween(
1328 Time::FromTimeT(17), Time::FromTimeT(41),
1329 &profile_guids, &credit_card_guids);
1330 ASSERT_EQ(2UL, profile_guids.size());
1331 EXPECT_EQ("00000000-0000-0000-0000-000000000001", profile_guids[0]);
1332 EXPECT_EQ("00000000-0000-0000-0000-000000000002", profile_guids[1]);
1333 sql::Statement s_autofill_profiles_bounded(
1334 db_->GetSQLConnection()->GetUniqueStatement(
1335 "SELECT date_modified FROM autofill_profiles"));
1336 ASSERT_TRUE(s_autofill_profiles_bounded.is_valid());
1337 ASSERT_TRUE(s_autofill_profiles_bounded.Step());
1338 EXPECT_EQ(11, s_autofill_profiles_bounded.ColumnInt64(0));
1339 ASSERT_TRUE(s_autofill_profiles_bounded.Step());
1340 EXPECT_EQ(41, s_autofill_profiles_bounded.ColumnInt64(0));
1341 ASSERT_TRUE(s_autofill_profiles_bounded.Step());
1342 EXPECT_EQ(51, s_autofill_profiles_bounded.ColumnInt64(0));
1343 ASSERT_TRUE(s_autofill_profiles_bounded.Step());
1344 EXPECT_EQ(61, s_autofill_profiles_bounded.ColumnInt64(0));
1345 EXPECT_FALSE(s_autofill_profiles_bounded.Step());
1346 ASSERT_EQ(3UL, credit_card_guids.size());
1347 EXPECT_EQ("00000000-0000-0000-0000-000000000006", credit_card_guids[0]);
1348 EXPECT_EQ("00000000-0000-0000-0000-000000000007", credit_card_guids[1]);
1349 EXPECT_EQ("00000000-0000-0000-0000-000000000008", credit_card_guids[2]);
1350 sql::Statement s_credit_cards_bounded(
1351 db_->GetSQLConnection()->GetUniqueStatement(
1352 "SELECT date_modified FROM credit_cards"));
1353 ASSERT_TRUE(s_credit_cards_bounded.is_valid());
1354 ASSERT_TRUE(s_credit_cards_bounded.Step());
1355 EXPECT_EQ(47, s_credit_cards_bounded.ColumnInt64(0));
1356 ASSERT_TRUE(s_credit_cards_bounded.Step());
1357 EXPECT_EQ(57, s_credit_cards_bounded.ColumnInt64(0));
1358 ASSERT_TRUE(s_credit_cards_bounded.Step());
1359 EXPECT_EQ(67, s_credit_cards_bounded.ColumnInt64(0));
1360 EXPECT_FALSE(s_credit_cards_bounded.Step());
1362 // Remove all entries modified on or after time 51 (unbounded range).
1363 table_->RemoveAutofillDataModifiedBetween(
1364 Time::FromTimeT(51), Time(),
1365 &profile_guids, &credit_card_guids);
1366 ASSERT_EQ(2UL, profile_guids.size());
1367 EXPECT_EQ("00000000-0000-0000-0000-000000000004", profile_guids[0]);
1368 EXPECT_EQ("00000000-0000-0000-0000-000000000005", profile_guids[1]);
1369 sql::Statement s_autofill_profiles_unbounded(
1370 db_->GetSQLConnection()->GetUniqueStatement(
1371 "SELECT date_modified FROM autofill_profiles"));
1372 ASSERT_TRUE(s_autofill_profiles_unbounded.is_valid());
1373 ASSERT_TRUE(s_autofill_profiles_unbounded.Step());
1374 EXPECT_EQ(11, s_autofill_profiles_unbounded.ColumnInt64(0));
1375 ASSERT_TRUE(s_autofill_profiles_unbounded.Step());
1376 EXPECT_EQ(41, s_autofill_profiles_unbounded.ColumnInt64(0));
1377 EXPECT_FALSE(s_autofill_profiles_unbounded.Step());
1378 ASSERT_EQ(2UL, credit_card_guids.size());
1379 EXPECT_EQ("00000000-0000-0000-0000-000000000010", credit_card_guids[0]);
1380 EXPECT_EQ("00000000-0000-0000-0000-000000000011", credit_card_guids[1]);
1381 sql::Statement s_credit_cards_unbounded(
1382 db_->GetSQLConnection()->GetUniqueStatement(
1383 "SELECT date_modified FROM credit_cards"));
1384 ASSERT_TRUE(s_credit_cards_unbounded.is_valid());
1385 ASSERT_TRUE(s_credit_cards_unbounded.Step());
1386 EXPECT_EQ(47, s_credit_cards_unbounded.ColumnInt64(0));
1387 EXPECT_FALSE(s_credit_cards_unbounded.Step());
1389 // Remove all remaining entries.
1390 table_->RemoveAutofillDataModifiedBetween(
1391 Time(), Time(),
1392 &profile_guids, &credit_card_guids);
1393 ASSERT_EQ(2UL, profile_guids.size());
1394 EXPECT_EQ("00000000-0000-0000-0000-000000000000", profile_guids[0]);
1395 EXPECT_EQ("00000000-0000-0000-0000-000000000003", profile_guids[1]);
1396 sql::Statement s_autofill_profiles_empty(
1397 db_->GetSQLConnection()->GetUniqueStatement(
1398 "SELECT date_modified FROM autofill_profiles"));
1399 ASSERT_TRUE(s_autofill_profiles_empty.is_valid());
1400 EXPECT_FALSE(s_autofill_profiles_empty.Step());
1401 ASSERT_EQ(1UL, credit_card_guids.size());
1402 EXPECT_EQ("00000000-0000-0000-0000-000000000009", credit_card_guids[0]);
1403 sql::Statement s_credit_cards_empty(
1404 db_->GetSQLConnection()->GetUniqueStatement(
1405 "SELECT date_modified FROM credit_cards"));
1406 ASSERT_TRUE(s_credit_cards_empty.is_valid());
1407 EXPECT_FALSE(s_credit_cards_empty.Step());
1410 TEST_F(AutofillTableTest, RemoveOriginURLsModifiedBetween) {
1411 // Populate the autofill_profiles and credit_cards tables.
1412 ASSERT_TRUE(db_->GetSQLConnection()->Execute(
1413 "INSERT INTO autofill_profiles (guid, origin, date_modified) "
1414 "VALUES('00000000-0000-0000-0000-000000000000', '', 11);"
1415 "INSERT INTO autofill_profiles (guid, origin, date_modified) "
1416 "VALUES('00000000-0000-0000-0000-000000000001', "
1417 " 'https://www.example.com/', 21);"
1418 "INSERT INTO autofill_profiles (guid, origin, date_modified) "
1419 "VALUES('00000000-0000-0000-0000-000000000002', 'Chrome settings', 31);"
1420 "INSERT INTO credit_cards (guid, origin, date_modified) "
1421 "VALUES('00000000-0000-0000-0000-000000000003', '', 17);"
1422 "INSERT INTO credit_cards (guid, origin, date_modified) "
1423 "VALUES('00000000-0000-0000-0000-000000000004', "
1424 " 'https://www.example.com/', 27);"
1425 "INSERT INTO credit_cards (guid, origin, date_modified) "
1426 "VALUES('00000000-0000-0000-0000-000000000005', 'Chrome settings', "
1427 " 37);"));
1429 // Remove all origin URLs set in the bounded time range [21,27).
1430 ScopedVector<AutofillProfile> profiles;
1431 table_->RemoveOriginURLsModifiedBetween(
1432 Time::FromTimeT(21), Time::FromTimeT(27), &profiles);
1433 ASSERT_EQ(1UL, profiles.size());
1434 EXPECT_EQ("00000000-0000-0000-0000-000000000001", profiles[0]->guid());
1435 sql::Statement s_autofill_profiles_bounded(
1436 db_->GetSQLConnection()->GetUniqueStatement(
1437 "SELECT date_modified, origin FROM autofill_profiles"));
1438 ASSERT_TRUE(s_autofill_profiles_bounded.is_valid());
1439 ASSERT_TRUE(s_autofill_profiles_bounded.Step());
1440 EXPECT_EQ(11, s_autofill_profiles_bounded.ColumnInt64(0));
1441 EXPECT_EQ(std::string(), s_autofill_profiles_bounded.ColumnString(1));
1442 ASSERT_TRUE(s_autofill_profiles_bounded.Step());
1443 EXPECT_EQ(21, s_autofill_profiles_bounded.ColumnInt64(0));
1444 EXPECT_EQ(std::string(), s_autofill_profiles_bounded.ColumnString(1));
1445 ASSERT_TRUE(s_autofill_profiles_bounded.Step());
1446 EXPECT_EQ(31, s_autofill_profiles_bounded.ColumnInt64(0));
1447 EXPECT_EQ("Chrome settings", s_autofill_profiles_bounded.ColumnString(1));
1448 sql::Statement s_credit_cards_bounded(
1449 db_->GetSQLConnection()->GetUniqueStatement(
1450 "SELECT date_modified, origin FROM credit_cards"));
1451 ASSERT_TRUE(s_credit_cards_bounded.is_valid());
1452 ASSERT_TRUE(s_credit_cards_bounded.Step());
1453 EXPECT_EQ(17, s_credit_cards_bounded.ColumnInt64(0));
1454 EXPECT_EQ(std::string(), s_credit_cards_bounded.ColumnString(1));
1455 ASSERT_TRUE(s_credit_cards_bounded.Step());
1456 EXPECT_EQ(27, s_credit_cards_bounded.ColumnInt64(0));
1457 EXPECT_EQ("https://www.example.com/",
1458 s_credit_cards_bounded.ColumnString(1));
1459 ASSERT_TRUE(s_credit_cards_bounded.Step());
1460 EXPECT_EQ(37, s_credit_cards_bounded.ColumnInt64(0));
1461 EXPECT_EQ("Chrome settings", s_credit_cards_bounded.ColumnString(1));
1463 // Remove all origin URLS.
1464 profiles.clear();
1465 table_->RemoveOriginURLsModifiedBetween(Time(), Time(), &profiles);
1466 EXPECT_EQ(0UL, profiles.size());
1467 sql::Statement s_autofill_profiles_all(
1468 db_->GetSQLConnection()->GetUniqueStatement(
1469 "SELECT date_modified, origin FROM autofill_profiles"));
1470 ASSERT_TRUE(s_autofill_profiles_all.is_valid());
1471 ASSERT_TRUE(s_autofill_profiles_all.Step());
1472 EXPECT_EQ(11, s_autofill_profiles_all.ColumnInt64(0));
1473 EXPECT_EQ(std::string(), s_autofill_profiles_all.ColumnString(1));
1474 ASSERT_TRUE(s_autofill_profiles_all.Step());
1475 EXPECT_EQ(21, s_autofill_profiles_all.ColumnInt64(0));
1476 EXPECT_EQ(std::string(), s_autofill_profiles_all.ColumnString(1));
1477 ASSERT_TRUE(s_autofill_profiles_all.Step());
1478 EXPECT_EQ(31, s_autofill_profiles_all.ColumnInt64(0));
1479 EXPECT_EQ("Chrome settings", s_autofill_profiles_all.ColumnString(1));
1480 sql::Statement s_credit_cards_all(
1481 db_->GetSQLConnection()->GetUniqueStatement(
1482 "SELECT date_modified, origin FROM credit_cards"));
1483 ASSERT_TRUE(s_credit_cards_all.is_valid());
1484 ASSERT_TRUE(s_credit_cards_all.Step());
1485 EXPECT_EQ(17, s_credit_cards_all.ColumnInt64(0));
1486 EXPECT_EQ(std::string(), s_credit_cards_all.ColumnString(1));
1487 ASSERT_TRUE(s_credit_cards_all.Step());
1488 EXPECT_EQ(27, s_credit_cards_all.ColumnInt64(0));
1489 EXPECT_EQ(std::string(), s_credit_cards_all.ColumnString(1));
1490 ASSERT_TRUE(s_credit_cards_all.Step());
1491 EXPECT_EQ(37, s_credit_cards_all.ColumnInt64(0));
1492 EXPECT_EQ("Chrome settings", s_credit_cards_all.ColumnString(1));
1495 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_NoResults) {
1496 std::vector<AutofillEntry> entries;
1497 ASSERT_TRUE(table_->GetAllAutofillEntries(&entries));
1499 EXPECT_EQ(0U, entries.size());
1502 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) {
1503 AutofillChangeList changes;
1504 std::map<std::string, std::vector<Time> > name_value_times_map;
1506 time_t start = 0;
1507 std::vector<Time> timestamps1;
1508 FormFieldData field;
1509 field.name = ASCIIToUTF16("Name");
1510 field.value = ASCIIToUTF16("Superman");
1511 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
1512 Time::FromTimeT(start)));
1513 timestamps1.push_back(Time::FromTimeT(start));
1514 std::string key1("NameSuperman");
1515 name_value_times_map.insert(
1516 std::pair<std::string, std::vector<Time> >(key1, timestamps1));
1518 AutofillEntrySet expected_entries(CompareAutofillEntries);
1519 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"));
1520 AutofillEntry ae1(ak1, timestamps1.front(), timestamps1.back());
1522 expected_entries.insert(ae1);
1524 std::vector<AutofillEntry> entries;
1525 ASSERT_TRUE(table_->GetAllAutofillEntries(&entries));
1526 AutofillEntrySet entry_set(entries.begin(), entries.end(),
1527 CompareAutofillEntries);
1529 CompareAutofillEntrySets(entry_set, expected_entries);
1532 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) {
1533 AutofillChangeList changes;
1534 std::map<std::string, std::vector<Time> > name_value_times_map;
1535 time_t start = 0;
1537 std::vector<Time> timestamps1;
1538 FormFieldData field;
1539 field.name = ASCIIToUTF16("Name");
1540 field.value = ASCIIToUTF16("Superman");
1541 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
1542 Time::FromTimeT(start)));
1543 timestamps1.push_back(Time::FromTimeT(start));
1544 std::string key1("NameSuperman");
1545 name_value_times_map.insert(
1546 std::pair<std::string, std::vector<Time> >(key1, timestamps1));
1548 ++start;
1549 std::vector<Time> timestamps2;
1550 field.name = ASCIIToUTF16("Name");
1551 field.value = ASCIIToUTF16("Clark Kent");
1552 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
1553 Time::FromTimeT(start)));
1554 timestamps2.push_back(Time::FromTimeT(start));
1555 std::string key2("NameClark Kent");
1556 name_value_times_map.insert(
1557 std::pair<std::string, std::vector<Time> >(key2, timestamps2));
1559 AutofillEntrySet expected_entries(CompareAutofillEntries);
1560 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"));
1561 AutofillKey ak2(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"));
1562 AutofillEntry ae1(ak1, timestamps1.front(), timestamps1.back());
1563 AutofillEntry ae2(ak2, timestamps2.front(), timestamps2.back());
1565 expected_entries.insert(ae1);
1566 expected_entries.insert(ae2);
1568 std::vector<AutofillEntry> entries;
1569 ASSERT_TRUE(table_->GetAllAutofillEntries(&entries));
1570 AutofillEntrySet entry_set(entries.begin(), entries.end(),
1571 CompareAutofillEntries);
1573 CompareAutofillEntrySets(entry_set, expected_entries);
1576 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoSame) {
1577 AutofillChangeList changes;
1578 std::map<std::string, std::vector<Time> > name_value_times_map;
1580 std::vector<Time> timestamps;
1581 time_t start = 0;
1582 for (int i = 0; i < 2; ++i, ++start) {
1583 FormFieldData field;
1584 field.name = ASCIIToUTF16("Name");
1585 field.value = ASCIIToUTF16("Superman");
1586 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
1587 Time::FromTimeT(start)));
1588 timestamps.push_back(Time::FromTimeT(start));
1591 std::string key("NameSuperman");
1592 name_value_times_map.insert(
1593 std::pair<std::string, std::vector<Time> >(key, timestamps));
1595 AutofillEntrySet expected_entries(CompareAutofillEntries);
1596 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"));
1597 AutofillEntry ae1(ak1, timestamps.front(), timestamps.back());
1599 expected_entries.insert(ae1);
1601 std::vector<AutofillEntry> entries;
1602 ASSERT_TRUE(table_->GetAllAutofillEntries(&entries));
1603 AutofillEntrySet entry_set(entries.begin(), entries.end(),
1604 CompareAutofillEntries);
1606 CompareAutofillEntrySets(entry_set, expected_entries);
1609 TEST_F(AutofillTableTest, SetGetServerCards) {
1610 std::vector<CreditCard> inputs;
1611 inputs.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "a123"));
1612 inputs[0].SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul F. Tompkins"));
1613 inputs[0].SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1"));
1614 inputs[0].SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020"));
1615 inputs[0].SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111"));
1617 inputs.push_back(
1618 CreditCard(CreditCard::MASKED_SERVER_CARD, "b456"));
1619 inputs[1].SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Rick Roman"));
1620 inputs[1].SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("12"));
1621 inputs[1].SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("1997"));
1622 inputs[1].SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1111"));
1623 inputs[1].SetTypeForMaskedCard(kVisaCard);
1624 inputs[1].SetServerStatus(CreditCard::EXPIRED);
1626 table_->SetServerCreditCards(inputs);
1628 std::vector<CreditCard*> outputs;
1629 ASSERT_TRUE(table_->GetServerCreditCards(&outputs));
1630 ASSERT_EQ(inputs.size(), outputs.size());
1632 // Ordering isn't guaranteed, so fix the ordering if it's backwards.
1633 if (outputs[1]->server_id() == inputs[0].server_id())
1634 std::swap(outputs[0], outputs[1]);
1636 // GUIDs for server cards are dynamically generated so will be different
1637 // after reading from the DB. Check they're valid, but otherwise don't count
1638 // them in the comparison.
1639 inputs[0].set_guid(std::string());
1640 inputs[1].set_guid(std::string());
1641 outputs[0]->set_guid(std::string());
1642 outputs[1]->set_guid(std::string());
1644 EXPECT_EQ(inputs[0], *outputs[0]);
1645 EXPECT_EQ(inputs[1], *outputs[1]);
1647 EXPECT_EQ(CreditCard::OK, outputs[0]->GetServerStatus());
1648 EXPECT_EQ(CreditCard::EXPIRED, outputs[1]->GetServerStatus());
1650 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1653 TEST_F(AutofillTableTest, MaskUnmaskServerCards) {
1654 base::string16 masked_number(ASCIIToUTF16("1111"));
1655 std::vector<CreditCard> inputs;
1656 inputs.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
1657 inputs[0].SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jay Johnson"));
1658 inputs[0].SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1"));
1659 inputs[0].SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020"));
1660 inputs[0].SetRawInfo(CREDIT_CARD_NUMBER, masked_number);
1661 inputs[0].SetTypeForMaskedCard(kVisaCard);
1662 table_->SetServerCreditCards(inputs);
1664 // Unmask the number. The full number should be available.
1665 base::string16 full_number(ASCIIToUTF16("4111111111111111"));
1666 ASSERT_TRUE(table_->UnmaskServerCreditCard(inputs[0].server_id(),
1667 full_number));
1669 std::vector<CreditCard*> outputs;
1670 table_->GetServerCreditCards(&outputs);
1671 ASSERT_EQ(1u, outputs.size());
1672 EXPECT_TRUE(CreditCard::FULL_SERVER_CARD == outputs[0]->record_type());
1673 EXPECT_EQ(full_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1675 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1676 outputs.clear();
1678 // Re-mask the number, we should only get the last 4 digits out.
1679 ASSERT_TRUE(table_->MaskServerCreditCard(inputs[0].server_id()));
1680 table_->GetServerCreditCards(&outputs);
1681 ASSERT_EQ(1u, outputs.size());
1682 EXPECT_TRUE(CreditCard::MASKED_SERVER_CARD == outputs[0]->record_type());
1683 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1685 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1686 outputs.clear();
1689 // Calling SetServerCreditCards should replace all existing cards, but unmasked
1690 // cards should not be re-masked.
1691 TEST_F(AutofillTableTest, SetServerCardModify) {
1692 // Add a masked card.
1693 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123");
1694 masked_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul F. Tompkins"));
1695 masked_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1"));
1696 masked_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020"));
1697 masked_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1111"));
1698 masked_card.SetTypeForMaskedCard(kVisaCard);
1700 std::vector<CreditCard> inputs;
1701 inputs.push_back(masked_card);
1702 table_->SetServerCreditCards(inputs);
1704 // Now call Set with the full number.
1705 base::string16 full_number = ASCIIToUTF16("4111111111111111");
1706 inputs[0].set_record_type(CreditCard::FULL_SERVER_CARD);
1707 inputs[0].SetRawInfo(CREDIT_CARD_NUMBER, full_number);
1708 table_->SetServerCreditCards(inputs);
1710 // The card should now be unmasked.
1711 std::vector<CreditCard*> outputs;
1712 table_->GetServerCreditCards(&outputs);
1713 ASSERT_EQ(1u, outputs.size());
1714 EXPECT_TRUE(outputs[0]->record_type() == CreditCard::FULL_SERVER_CARD);
1715 EXPECT_EQ(full_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1717 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1718 outputs.clear();
1720 // Call set again with the masked number.
1721 inputs[0] = masked_card;
1722 table_->SetServerCreditCards(inputs);
1724 // The card should stay unmasked.
1725 table_->GetServerCreditCards(&outputs);
1726 ASSERT_EQ(1u, outputs.size());
1727 EXPECT_TRUE(outputs[0]->record_type() == CreditCard::FULL_SERVER_CARD);
1728 EXPECT_EQ(full_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1730 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1731 outputs.clear();
1733 // Set inputs that do not include our old card.
1734 CreditCard random_card(CreditCard::MASKED_SERVER_CARD, "b456");
1735 random_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Rick Roman"));
1736 random_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("12"));
1737 random_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("1997"));
1738 random_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("2222"));
1739 random_card.SetTypeForMaskedCard(kVisaCard);
1740 inputs[0] = random_card;
1741 table_->SetServerCreditCards(inputs);
1743 // We should have only the new card, the other one should have been deleted.
1744 table_->GetServerCreditCards(&outputs);
1745 ASSERT_EQ(1u, outputs.size());
1746 EXPECT_TRUE(outputs[0]->record_type() == CreditCard::MASKED_SERVER_CARD);
1747 EXPECT_EQ(random_card.server_id(), outputs[0]->server_id());
1748 EXPECT_EQ(ASCIIToUTF16("2222"), outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1750 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1751 outputs.clear();
1753 // Putting back the original card masked should make it masked (this tests
1754 // that the unmasked data was really deleted).
1755 inputs[0] = masked_card;
1756 table_->SetServerCreditCards(inputs);
1757 table_->GetServerCreditCards(&outputs);
1758 ASSERT_EQ(1u, outputs.size());
1759 EXPECT_TRUE(outputs[0]->record_type() == CreditCard::MASKED_SERVER_CARD);
1760 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id());
1761 EXPECT_EQ(ASCIIToUTF16("1111"), outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1763 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1764 outputs.clear();
1767 TEST_F(AutofillTableTest, SetServerProfile) {
1768 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123");
1769 std::vector<AutofillProfile> inputs;
1770 inputs.push_back(one);
1771 table_->SetAutofillServerProfiles(inputs);
1773 std::vector<AutofillProfile*> outputs;
1774 table_->GetAutofillServerProfiles(&outputs);
1775 ASSERT_EQ(1u, outputs.size());
1776 EXPECT_EQ(one.server_id(), outputs[0]->server_id());
1778 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1779 outputs.clear();
1781 // Set a different profile.
1782 AutofillProfile two(AutofillProfile::SERVER_PROFILE, "b456");
1783 inputs[0] = two;
1784 table_->SetAutofillServerProfiles(inputs);
1786 // The original one should have been replaced.
1787 table_->GetAutofillServerProfiles(&outputs);
1788 ASSERT_EQ(1u, outputs.size());
1789 EXPECT_EQ(two.server_id(), outputs[0]->server_id());
1791 STLDeleteContainerPointers(outputs.begin(), outputs.end());
1792 outputs.clear();
1795 } // namespace autofill