| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet; | 78 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet; |
| 79 typedef AutofillEntrySet::iterator AutofillEntrySetIterator; | 79 typedef AutofillEntrySet::iterator AutofillEntrySetIterator; |
| 80 | 80 |
| 81 bool CompareAutofillEntries(const AutofillEntry& a, const AutofillEntry& b) { | 81 bool CompareAutofillEntries(const AutofillEntry& a, const AutofillEntry& b) { |
| 82 return std::tie(a.key().name(), a.key().value(), | 82 return std::tie(a.key().name(), a.key().value(), |
| 83 a.date_created(), a.date_last_used()) < | 83 a.date_created(), a.date_last_used()) < |
| 84 std::tie(b.key().name(), b.key().value(), | 84 std::tie(b.key().name(), b.key().value(), |
| 85 b.date_created(), b.date_last_used()); | 85 b.date_created(), b.date_last_used()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 AutofillEntry MakeAutofillEntry(const char* name, | 88 AutofillEntry MakeAutofillEntry(const std::string& name, |
| 89 const char* value, | 89 const std::string& value, |
| 90 time_t date_created, | 90 time_t date_created, |
| 91 time_t date_last_used) { | 91 time_t date_last_used) { |
| 92 if (date_last_used < 0) | 92 if (date_last_used < 0) |
| 93 date_last_used = date_created; | 93 date_last_used = date_created; |
| 94 return AutofillEntry(AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), | 94 return AutofillEntry(AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), |
| 95 Time::FromTimeT(date_created), | 95 Time::FromTimeT(date_created), |
| 96 Time::FromTimeT(date_last_used)); | 96 Time::FromTimeT(date_last_used)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Checks |actual| and |expected| contain the same elements. | 99 // Checks |actual| and |expected| contain the same elements. |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 entries.push_back(entry0); | 456 entries.push_back(entry0); |
| 457 entries.push_back(entry1); | 457 entries.push_back(entry1); |
| 458 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); | 458 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); |
| 459 | 459 |
| 460 EXPECT_EQ(1, GetAutofillEntryCount(ASCIIToUTF16("foo"), ASCIIToUTF16("bar0"), | 460 EXPECT_EQ(1, GetAutofillEntryCount(ASCIIToUTF16("foo"), ASCIIToUTF16("bar0"), |
| 461 db_.get())); | 461 db_.get())); |
| 462 EXPECT_EQ(2, GetAutofillEntryCount(ASCIIToUTF16("foo"), ASCIIToUTF16("bar1"), | 462 EXPECT_EQ(2, GetAutofillEntryCount(ASCIIToUTF16("foo"), ASCIIToUTF16("bar1"), |
| 463 db_.get())); | 463 db_.get())); |
| 464 } | 464 } |
| 465 | 465 |
| 466 TEST_F(AutofillTableTest, Autofill_UpdateNullTerminated) { |
| 467 const char kName[] = "foo"; |
| 468 const char kValue[] = "bar"; |
| 469 // A value which contains terminating character. |
| 470 std::string value(kValue, arraysize(kValue)); |
| 471 |
| 472 AutofillEntry entry0(MakeAutofillEntry(kName, kValue, 1, -1)); |
| 473 AutofillEntry entry1(MakeAutofillEntry(kName, value, 2, 3)); |
| 474 std::vector<AutofillEntry> entries; |
| 475 entries.push_back(entry0); |
| 476 entries.push_back(entry1); |
| 477 ASSERT_TRUE(table_->UpdateAutofillEntries(entries)); |
| 478 |
| 479 EXPECT_EQ(1, GetAutofillEntryCount(ASCIIToUTF16(kName), ASCIIToUTF16(kValue), |
| 480 db_.get())); |
| 481 EXPECT_EQ(2, GetAutofillEntryCount(ASCIIToUTF16(kName), ASCIIToUTF16(value), |
| 482 db_.get())); |
| 483 |
| 484 std::vector<AutofillEntry> all_entries; |
| 485 ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries)); |
| 486 ASSERT_EQ(2U, all_entries.size()); |
| 487 EXPECT_EQ(entry0, all_entries[0]); |
| 488 EXPECT_EQ(entry1, all_entries[1]); |
| 489 } |
| 490 |
| 466 TEST_F(AutofillTableTest, Autofill_UpdateReplace) { | 491 TEST_F(AutofillTableTest, Autofill_UpdateReplace) { |
| 467 AutofillChangeList changes; | 492 AutofillChangeList changes; |
| 468 // Add a form field. This will be replaced. | 493 // Add a form field. This will be replaced. |
| 469 FormFieldData field; | 494 FormFieldData field; |
| 470 field.name = ASCIIToUTF16("Name"); | 495 field.name = ASCIIToUTF16("Name"); |
| 471 field.value = ASCIIToUTF16("Superman"); | 496 field.value = ASCIIToUTF16("Superman"); |
| 472 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); | 497 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); |
| 473 | 498 |
| 474 AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2)); | 499 AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2)); |
| 475 std::vector<AutofillEntry> entries; | 500 std::vector<AutofillEntry> entries; |
| (...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2098 "(rowid, value) VALUES(1, ?)")); | 2123 "(rowid, value) VALUES(1, ?)")); |
| 2099 s2.BindString(0, "unparseable"); | 2124 s2.BindString(0, "unparseable"); |
| 2100 | 2125 |
| 2101 EXPECT_TRUE(s.Run()); | 2126 EXPECT_TRUE(s.Run()); |
| 2102 EXPECT_TRUE(s2.Run()); | 2127 EXPECT_TRUE(s2.Run()); |
| 2103 | 2128 |
| 2104 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 2129 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); |
| 2105 } | 2130 } |
| 2106 | 2131 |
| 2107 } // namespace autofill | 2132 } // namespace autofill |
| OLD | NEW |