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

Unified Diff: chrome/browser/webdata/autofill_table_unittest.cc

Issue 12543034: Move creation of the various WebDatabaseTable types out of WebDatabase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Windows release builds (COMDAT folding combined static functions being used for keys. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/webdata/autofill_table.cc ('k') | chrome/browser/webdata/keyword_table.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/webdata/autofill_table_unittest.cc
diff --git a/chrome/browser/webdata/autofill_table_unittest.cc b/chrome/browser/webdata/autofill_table_unittest.cc
index b0af88d092f184e4811b481e5168bd14cb47a118..92de23dd210c349d646d48ea413bb79b23974cd4 100644
--- a/chrome/browser/webdata/autofill_table_unittest.cc
+++ b/chrome/browser/webdata/autofill_table_unittest.cc
@@ -99,6 +99,11 @@ class AutofillTableTest : public testing::Test {
#endif
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
file_ = temp_dir_.path().AppendASCII("TestWebDatabase");
+
+ table_.reset(new AutofillTable);
+ db_.reset(new WebDatabase);
+ db_->AddTable(table_.get());
+ ASSERT_EQ(sql::INIT_OK, db_->Init(file_, std::string()));
}
static AutofillEntry MakeAutofillEntry(const char* name,
@@ -116,16 +121,14 @@ class AutofillTableTest : public testing::Test {
base::FilePath file_;
base::ScopedTempDir temp_dir_;
+ scoped_ptr<AutofillTable> table_;
+ scoped_ptr<WebDatabase> db_;
private:
DISALLOW_COPY_AND_ASSIGN(AutofillTableTest);
};
TEST_F(AutofillTableTest, Autofill) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
Time t1 = Time::Now();
// Simulate the submission of a handful of entries in a field called "Name",
@@ -136,23 +139,23 @@ TEST_F(AutofillTableTest, Autofill) {
field.value = ASCIIToUTF16("Superman");
base::Time now = base::Time::Now();
base::TimeDelta two_seconds = base::TimeDelta::FromSeconds(2);
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
+ EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
std::vector<string16> v;
for (int i = 0; i < 5; i++) {
field.value = ASCIIToUTF16("Clark Kent");
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
- now + i * two_seconds));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
+ now + i * two_seconds));
}
for (int i = 0; i < 3; i++) {
field.value = ASCIIToUTF16("Clark Sutter");
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
- now + i * two_seconds));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
+ now + i * two_seconds));
}
for (int i = 0; i < 2; i++) {
field.name = ASCIIToUTF16("Favorite Color");
field.value = ASCIIToUTF16("Green");
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
- now + i * two_seconds));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
+ now + i * two_seconds));
}
int count = 0;
@@ -162,29 +165,26 @@ TEST_F(AutofillTableTest, Autofill) {
// should be somthing non-zero.
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Clark Kent");
- EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id,
- &count));
+ EXPECT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count));
EXPECT_EQ(5, count);
EXPECT_NE(0, pair_id);
// Storing in the data base should be case sensitive, so there should be no
// database entry for clark kent lowercase.
field.value = ASCIIToUTF16("clark kent");
- EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id,
- &count));
+ EXPECT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count));
EXPECT_EQ(0, count);
field.name = ASCIIToUTF16("Favorite Color");
field.value = ASCIIToUTF16("Green");
- EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id,
- &count));
+ EXPECT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count));
EXPECT_EQ(2, count);
// This is meant to get a list of suggestions for Name. The empty prefix
// in the second argument means it should return all suggestions for a name
// no matter what they start with. The order that the names occur in the list
// should be decreasing order by count.
- EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
+ EXPECT_TRUE(table_->GetFormValuesForElementName(
ASCIIToUTF16("Name"), string16(), &v, 6));
EXPECT_EQ(3U, v.size());
if (v.size() == 3) {
@@ -195,7 +195,7 @@ TEST_F(AutofillTableTest, Autofill) {
// If we query again limiting the list size to 1, we should only get the most
// frequent entry.
- EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
+ EXPECT_TRUE(table_->GetFormValuesForElementName(
ASCIIToUTF16("Name"), string16(), &v, 1));
EXPECT_EQ(1U, v.size());
if (v.size() == 1) {
@@ -204,7 +204,7 @@ TEST_F(AutofillTableTest, Autofill) {
// Querying for suggestions given a prefix is case-insensitive, so the prefix
// "cLa" shoud get suggestions for both Clarks.
- EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
+ EXPECT_TRUE(table_->GetFormValuesForElementName(
ASCIIToUTF16("Name"), ASCIIToUTF16("cLa"), &v, 6));
EXPECT_EQ(2U, v.size());
if (v.size() == 2) {
@@ -215,8 +215,7 @@ TEST_F(AutofillTableTest, Autofill) {
// Removing all elements since the beginning of this function should remove
// everything from the database.
changes.clear();
- EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween(
- t1, Time(), &changes));
+ EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(t1, Time(), &changes));
const AutofillChange expected_changes[] = {
AutofillChange(AutofillChange::REMOVE,
@@ -239,11 +238,10 @@ TEST_F(AutofillTableTest, Autofill) {
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Clark Kent");
- EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id,
- &count));
+ EXPECT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count));
EXPECT_EQ(0, count);
- EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
+ EXPECT_TRUE(table_->GetFormValuesForElementName(
ASCIIToUTF16("Name"), string16(), &v, 6));
EXPECT_EQ(0U, v.size());
@@ -251,29 +249,29 @@ TEST_F(AutofillTableTest, Autofill) {
const string16 kValue = ASCIIToUTF16(" toto ");
field.name = ASCIIToUTF16("blank");
field.value = string16();
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
+ EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
field.name = ASCIIToUTF16("blank");
field.value = ASCIIToUTF16(" ");
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
+ EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
field.name = ASCIIToUTF16("blank");
field.value = ASCIIToUTF16(" ");
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
+ EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
field.name = ASCIIToUTF16("blank");
field.value = kValue;
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
+ EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
// They should be stored normally as the DB layer does not check for empty
// values.
v.clear();
- EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
+ EXPECT_TRUE(table_->GetFormValuesForElementName(
ASCIIToUTF16("blank"), string16(), &v, 10));
EXPECT_EQ(4U, v.size());
// Now we'll check that ClearAutofillEmptyValueElements() works as expected.
- db.GetAutofillTable()->ClearAutofillEmptyValueElements();
+ table_->ClearAutofillEmptyValueElements();
v.clear();
- EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
+ EXPECT_TRUE(table_->GetFormValuesForElementName(
ASCIIToUTF16("blank"), string16(), &v, 10));
ASSERT_EQ(1U, v.size());
@@ -281,9 +279,6 @@ TEST_F(AutofillTableTest, Autofill) {
}
TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
TimeDelta one_day(TimeDelta::FromDays(1));
Time t1 = Time::Now();
Time t2 = t1 + one_day;
@@ -292,14 +287,11 @@ TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) {
FormFieldData field;
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Superman");
- EXPECT_TRUE(
- db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t1));
- EXPECT_TRUE(
- db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t2));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t1));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t2));
changes.clear();
- EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween(
- t1, t2, &changes));
+ EXPECT_TRUE(table_->RemoveFormElementsAddedBetween(t1, t2, &changes));
ASSERT_EQ(1U, changes.size());
EXPECT_EQ(AutofillChange(AutofillChange::UPDATE,
AutofillKey(ASCIIToUTF16("Name"),
@@ -307,8 +299,8 @@ TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) {
changes[0]);
changes.clear();
- EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween(
- t2, t2 + one_day, &changes));
+ EXPECT_TRUE(
+ table_->RemoveFormElementsAddedBetween(t2, t2 + one_day, &changes));
ASSERT_EQ(1U, changes.size());
EXPECT_EQ(AutofillChange(AutofillChange::REMOVE,
AutofillKey(ASCIIToUTF16("Name"),
@@ -317,9 +309,6 @@ TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) {
}
TEST_F(AutofillTableTest, Autofill_AddChanges) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
TimeDelta one_day(TimeDelta::FromDays(1));
Time t1 = Time::Now();
Time t2 = t1 + one_day;
@@ -328,8 +317,7 @@ TEST_F(AutofillTableTest, Autofill_AddChanges) {
FormFieldData field;
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Superman");
- EXPECT_TRUE(
- db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t1));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t1));
ASSERT_EQ(1U, changes.size());
EXPECT_EQ(AutofillChange(AutofillChange::ADD,
AutofillKey(ASCIIToUTF16("Name"),
@@ -338,7 +326,7 @@ TEST_F(AutofillTableTest, Autofill_AddChanges) {
changes.clear();
EXPECT_TRUE(
- db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t2));
+ table_->AddFormFieldValueTime(field, &changes, t2));
ASSERT_EQ(1U, changes.size());
EXPECT_EQ(AutofillChange(AutofillChange::UPDATE,
AutofillKey(ASCIIToUTF16("Name"),
@@ -347,129 +335,107 @@ TEST_F(AutofillTableTest, Autofill_AddChanges) {
}
TEST_F(AutofillTableTest, Autofill_UpdateOneWithOneTimestamp) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, -1));
std::vector<AutofillEntry> entries;
entries.push_back(entry);
- ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
+ ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
FormFieldData field;
field.name = ASCIIToUTF16("foo");
field.value = ASCIIToUTF16("bar");
int64 pair_id;
int count;
- ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(
- field, &pair_id, &count));
+ ASSERT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count));
EXPECT_LE(0, pair_id);
EXPECT_EQ(1, count);
std::vector<AutofillEntry> all_entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
ASSERT_EQ(1U, all_entries.size());
EXPECT_TRUE(entry == all_entries[0]);
}
TEST_F(AutofillTableTest, Autofill_UpdateOneWithTwoTimestamps) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2));
std::vector<AutofillEntry> entries;
entries.push_back(entry);
- ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
+ ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
FormFieldData field;
field.name = ASCIIToUTF16("foo");
field.value = ASCIIToUTF16("bar");
int64 pair_id;
int count;
- ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(
- field, &pair_id, &count));
+ ASSERT_TRUE(table_->GetIDAndCountOfFormElement(field, &pair_id, &count));
EXPECT_LE(0, pair_id);
EXPECT_EQ(2, count);
std::vector<AutofillEntry> all_entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
ASSERT_EQ(1U, all_entries.size());
EXPECT_TRUE(entry == all_entries[0]);
}
TEST_F(AutofillTableTest, Autofill_GetAutofillTimestamps) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2));
std::vector<AutofillEntry> entries;
entries.push_back(entry);
- ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
+ ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
std::vector<Time> timestamps;
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillTimestamps(ASCIIToUTF16("foo"),
- ASCIIToUTF16("bar"),
- &timestamps));
+ ASSERT_TRUE(table_->GetAutofillTimestamps(ASCIIToUTF16("foo"),
+ ASCIIToUTF16("bar"),
+ &timestamps));
ASSERT_EQ(2U, timestamps.size());
EXPECT_TRUE(Time::FromTimeT(1) == timestamps[0]);
EXPECT_TRUE(Time::FromTimeT(2) == timestamps[1]);
}
TEST_F(AutofillTableTest, Autofill_UpdateTwo) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillEntry entry0(MakeAutofillEntry("foo", "bar0", 1, -1));
AutofillEntry entry1(MakeAutofillEntry("foo", "bar1", 2, 3));
std::vector<AutofillEntry> entries;
entries.push_back(entry0);
entries.push_back(entry1);
- ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
+ ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
FormFieldData field0;
field0.name = ASCIIToUTF16("foo");
field0.value = ASCIIToUTF16("bar0");
int64 pair_id;
int count;
- ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(
- field0, &pair_id, &count));
+ ASSERT_TRUE(table_->GetIDAndCountOfFormElement(field0, &pair_id, &count));
EXPECT_LE(0, pair_id);
EXPECT_EQ(1, count);
FormFieldData field1;
field1.name = ASCIIToUTF16("foo");
field1.value = ASCIIToUTF16("bar1");
- ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(
- field1, &pair_id, &count));
+ ASSERT_TRUE(table_->GetIDAndCountOfFormElement(field1, &pair_id, &count));
EXPECT_LE(0, pair_id);
EXPECT_EQ(2, count);
}
TEST_F(AutofillTableTest, Autofill_UpdateReplace) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillChangeList changes;
// Add a form field. This will be replaced.
FormFieldData field;
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Superman");
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
+ EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2));
std::vector<AutofillEntry> entries;
entries.push_back(entry);
- ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
+ ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
std::vector<AutofillEntry> all_entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
ASSERT_EQ(1U, all_entries.size());
EXPECT_TRUE(entry == all_entries[0]);
}
TEST_F(AutofillTableTest, Autofill_UpdateDontReplace) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
Time t = Time::Now();
AutofillEntry existing(
MakeAutofillEntry("Name", "Superman", t.ToTimeT(), -1));
@@ -479,14 +445,14 @@ TEST_F(AutofillTableTest, Autofill_UpdateDontReplace) {
FormFieldData field;
field.name = existing.key().name();
field.value = existing.key().value();
- EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, t));
AutofillEntry entry(MakeAutofillEntry("Name", "Clark Kent", 1, 2));
std::vector<AutofillEntry> entries;
entries.push_back(entry);
- ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
+ ASSERT_TRUE(table_->UpdateAutofillEntries(entries));
std::vector<AutofillEntry> all_entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
ASSERT_EQ(2U, all_entries.size());
AutofillEntrySet expected_entries(all_entries.begin(),
all_entries.end(),
@@ -496,9 +462,6 @@ TEST_F(AutofillTableTest, Autofill_UpdateDontReplace) {
}
TEST_F(AutofillTableTest, Autofill_AddFormFieldValues) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
Time t = Time::Now();
// Add multiple values for "firstname" and "lastname" names. Test that only
@@ -523,7 +486,7 @@ TEST_F(AutofillTableTest, Autofill_AddFormFieldValues) {
elements.push_back(field);
std::vector<AutofillChange> changes;
- db.GetAutofillTable()->AddFormFieldValuesTime(elements, &changes, t);
+ table_->AddFormFieldValuesTime(elements, &changes, t);
ASSERT_EQ(2U, changes.size());
EXPECT_EQ(changes[0], AutofillChange(AutofillChange::ADD,
@@ -534,15 +497,11 @@ TEST_F(AutofillTableTest, Autofill_AddFormFieldValues) {
ASCIIToUTF16("Smith"))));
std::vector<AutofillEntry> all_entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&all_entries));
ASSERT_EQ(2U, all_entries.size());
}
TEST_F(AutofillTableTest, AutofillProfile) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
// Add a 'Home' profile.
AutofillProfile home_profile;
home_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
@@ -559,15 +518,14 @@ TEST_F(AutofillTableTest, AutofillProfile) {
home_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567"));
Time pre_creation_time = Time::Now();
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(home_profile));
+ EXPECT_TRUE(table_->AddAutofillProfile(home_profile));
Time post_creation_time = Time::Now();
// Get the 'Home' profile.
AutofillProfile* db_profile;
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
- home_profile.guid(), &db_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(home_profile.guid(), &db_profile));
EXPECT_EQ(home_profile, *db_profile);
- sql::Statement s_home(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_home(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified "
"FROM autofill_profiles WHERE guid=?"));
s_home.BindString(0, home_profile.guid());
@@ -586,14 +544,13 @@ TEST_F(AutofillTableTest, AutofillProfile) {
billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("suite 3"));
pre_creation_time = Time::Now();
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(billing_profile));
+ EXPECT_TRUE(table_->AddAutofillProfile(billing_profile));
post_creation_time = Time::Now();
// Get the 'Billing' profile.
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
- billing_profile.guid(), &db_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile));
EXPECT_EQ(billing_profile, *db_profile);
- sql::Statement s_billing(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_billing(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM autofill_profiles WHERE guid=?"));
s_billing.BindString(0, billing_profile.guid());
ASSERT_TRUE(s_billing.is_valid());
@@ -606,13 +563,11 @@ TEST_F(AutofillTableTest, AutofillProfile) {
// Update the 'Billing' profile, name only.
billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane"));
Time pre_modification_time = Time::Now();
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(
- billing_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(billing_profile));
Time post_modification_time = Time::Now();
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
- billing_profile.guid(), &db_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile));
EXPECT_EQ(billing_profile, *db_profile);
- sql::Statement s_billing_updated(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_billing_updated(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM autofill_profiles WHERE guid=?"));
s_billing_updated.BindString(0, billing_profile.guid());
ASSERT_TRUE(s_billing_updated.is_valid());
@@ -639,14 +594,13 @@ TEST_F(AutofillTableTest, AutofillProfile) {
billing_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
ASCIIToUTF16("18181230000"));
Time pre_modification_time_2 = Time::Now();
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(
- billing_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(billing_profile));
Time post_modification_time_2 = Time::Now();
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
- billing_profile.guid(), &db_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile));
EXPECT_EQ(billing_profile, *db_profile);
- sql::Statement s_billing_updated_2(db.GetSQLConnection()->GetUniqueStatement(
- "SELECT date_modified FROM autofill_profiles WHERE guid=?"));
+ sql::Statement s_billing_updated_2(
+ db_->GetSQLConnection()->GetUniqueStatement(
+ "SELECT date_modified FROM autofill_profiles WHERE guid=?"));
s_billing_updated_2.BindString(0, billing_profile.guid());
ASSERT_TRUE(s_billing_updated_2.is_valid());
ASSERT_TRUE(s_billing_updated_2.Step());
@@ -658,16 +612,11 @@ TEST_F(AutofillTableTest, AutofillProfile) {
delete db_profile;
// Remove the 'Billing' profile.
- EXPECT_TRUE(db.GetAutofillTable()->RemoveAutofillProfile(
- billing_profile.guid()));
- EXPECT_FALSE(db.GetAutofillTable()->GetAutofillProfile(
- billing_profile.guid(), &db_profile));
+ EXPECT_TRUE(table_->RemoveAutofillProfile(billing_profile.guid()));
+ EXPECT_FALSE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile));
}
TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillProfile p;
const string16 kJohnDoe(ASCIIToUTF16("John Doe"));
const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe"));
@@ -676,10 +625,10 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) {
set_values.push_back(kJohnPDoe);
p.SetRawMultiInfo(NAME_FULL, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(p));
+ EXPECT_TRUE(table_->AddAutofillProfile(p));
AutofillProfile* db_profile;
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
delete db_profile;
@@ -688,8 +637,8 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) {
const string16 kNoOne(ASCIIToUTF16("No One"));
set_values[1] = kNoOne;
p.SetRawMultiInfo(NAME_FULL, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
delete db_profile;
@@ -697,8 +646,8 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) {
// Delete values.
set_values.clear();
p.SetRawMultiInfo(NAME_FULL, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
EXPECT_EQ(string16(), db_profile->GetRawInfo(NAME_FULL));
@@ -706,9 +655,6 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) {
}
TEST_F(AutofillTableTest, AutofillProfileSingleValue) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillProfile p;
const string16 kJohnDoe(ASCIIToUTF16("John Doe"));
const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe"));
@@ -717,10 +663,10 @@ TEST_F(AutofillTableTest, AutofillProfileSingleValue) {
set_values.push_back(kJohnPDoe);
p.SetRawMultiInfo(NAME_FULL, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(p));
+ EXPECT_TRUE(table_->AddAutofillProfile(p));
AutofillProfile* db_profile;
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
delete db_profile;
@@ -729,8 +675,8 @@ TEST_F(AutofillTableTest, AutofillProfileSingleValue) {
set_values.resize(1);
set_values[0] = kNoOne;
p.SetRawMultiInfo(NAME_FULL, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfile(p));
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfile(p));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p.PrimaryValue(), db_profile->PrimaryValue());
EXPECT_EQ(p.guid(), db_profile->guid());
EXPECT_NE(0, p.Compare(*db_profile));
@@ -742,9 +688,6 @@ TEST_F(AutofillTableTest, AutofillProfileSingleValue) {
}
TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillProfile p;
const string16 kJohnDoe(ASCIIToUTF16("john@doe.com"));
const string16 kJohnPDoe(ASCIIToUTF16("john_p@doe.com"));
@@ -753,10 +696,10 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) {
set_values.push_back(kJohnPDoe);
p.SetRawMultiInfo(EMAIL_ADDRESS, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(p));
+ EXPECT_TRUE(table_->AddAutofillProfile(p));
AutofillProfile* db_profile;
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
delete db_profile;
@@ -765,8 +708,8 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) {
const string16 kNoOne(ASCIIToUTF16("no@one.com"));
set_values[1] = kNoOne;
p.SetRawMultiInfo(EMAIL_ADDRESS, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
delete db_profile;
@@ -774,8 +717,8 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) {
// Delete values.
set_values.clear();
p.SetRawMultiInfo(EMAIL_ADDRESS, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
EXPECT_EQ(string16(), db_profile->GetRawInfo(EMAIL_ADDRESS));
@@ -783,9 +726,6 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) {
}
TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillProfile p;
const string16 kJohnDoe(ASCIIToUTF16("4151112222"));
const string16 kJohnPDoe(ASCIIToUTF16("4151113333"));
@@ -794,10 +734,10 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) {
set_values.push_back(kJohnPDoe);
p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(p));
+ EXPECT_TRUE(table_->AddAutofillProfile(p));
AutofillProfile* db_profile;
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
delete db_profile;
@@ -806,8 +746,8 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) {
const string16 kNoOne(ASCIIToUTF16("4151110000"));
set_values[1] = kNoOne;
p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
delete db_profile;
@@ -815,8 +755,8 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) {
// Delete values.
set_values.clear();
p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values);
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(p));
+ ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile));
EXPECT_EQ(p, *db_profile);
EXPECT_EQ(0, p.Compare(*db_profile));
EXPECT_EQ(string16(), db_profile->GetRawInfo(EMAIL_ADDRESS));
@@ -824,35 +764,27 @@ TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) {
}
TEST_F(AutofillTableTest, AutofillProfileTrash) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
std::vector<std::string> guids;
- db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids);
+ table_->GetAutofillProfilesInTrash(&guids);
EXPECT_TRUE(guids.empty());
- ASSERT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(
+ ASSERT_TRUE(table_->AddAutofillGUIDToTrash(
"00000000-0000-0000-0000-000000000000"));
- ASSERT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(
+ ASSERT_TRUE(table_->AddAutofillGUIDToTrash(
"00000000-0000-0000-0000-000000000001"));
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids));
+ ASSERT_TRUE(table_->GetAutofillProfilesInTrash(&guids));
EXPECT_EQ(2UL, guids.size());
EXPECT_EQ("00000000-0000-0000-0000-000000000000", guids[0]);
EXPECT_EQ("00000000-0000-0000-0000-000000000001", guids[1]);
- ASSERT_TRUE(db.GetAutofillTable()->EmptyAutofillProfilesTrash());
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids));
+ ASSERT_TRUE(table_->EmptyAutofillProfilesTrash());
+ ASSERT_TRUE(table_->GetAutofillProfilesInTrash(&guids));
EXPECT_TRUE(guids.empty());
}
TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
std::vector<std::string> guids;
- db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids);
+ table_->GetAutofillProfilesInTrash(&guids);
EXPECT_TRUE(guids.empty());
AutofillProfile profile;
@@ -868,19 +800,18 @@ TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) {
// Mark this profile as in the trash. This stops |AddAutofillProfile| from
// adding it.
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(profile.guid()));
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(profile));
+ EXPECT_TRUE(table_->AddAutofillGUIDToTrash(profile.guid()));
+ EXPECT_TRUE(table_->AddAutofillProfile(profile));
AutofillProfile* added_profile = NULL;
- EXPECT_FALSE(db.GetAutofillTable()->GetAutofillProfile(
- profile.guid(), &added_profile));
+ EXPECT_FALSE(table_->GetAutofillProfile(profile.guid(), &added_profile));
EXPECT_EQ(static_cast<AutofillProfile*>(NULL), added_profile);
// Add the profile for real this time.
- EXPECT_TRUE(db.GetAutofillTable()->EmptyAutofillProfilesTrash());
- EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids));
+ EXPECT_TRUE(table_->EmptyAutofillProfilesTrash());
+ EXPECT_TRUE(table_->GetAutofillProfilesInTrash(&guids));
EXPECT_TRUE(guids.empty());
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(profile));
- EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
+ EXPECT_TRUE(table_->AddAutofillProfile(profile));
+ EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(),
&added_profile));
ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile);
delete added_profile;
@@ -888,12 +819,11 @@ TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) {
// Mark this profile as in the trash. This stops |UpdateAutofillProfileMulti|
// from updating it. In normal operation a profile should not be both in the
// trash and in the profiles table simultaneously.
- EXPECT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(profile.guid()));
+ EXPECT_TRUE(table_->AddAutofillGUIDToTrash(profile.guid()));
profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane"));
- EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(profile));
+ EXPECT_TRUE(table_->UpdateAutofillProfileMulti(profile));
AutofillProfile* updated_profile = NULL;
- EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
- profile.guid(), &updated_profile));
+ EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(), &updated_profile));
ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile);
EXPECT_EQ(ASCIIToUTF16("John"), updated_profile->GetRawInfo(NAME_FIRST));
delete updated_profile;
@@ -904,28 +834,22 @@ TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) {
// does remove the item from the trash if it is found however, so that if
// other clients remove it (via Sync say) then it is gone and doesn't need to
// be processed further by |WebDataService|.
- EXPECT_TRUE(db.GetAutofillTable()->RemoveAutofillProfile(profile.guid()));
+ EXPECT_TRUE(table_->RemoveAutofillProfile(profile.guid()));
AutofillProfile* removed_profile = NULL;
- EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
- &removed_profile));
- EXPECT_FALSE(db.GetAutofillTable()->IsAutofillGUIDInTrash(profile.guid()));
+ EXPECT_TRUE(table_->GetAutofillProfile(profile.guid(), &removed_profile));
+ EXPECT_FALSE(table_->IsAutofillGUIDInTrash(profile.guid()));
ASSERT_NE(static_cast<AutofillProfile*>(NULL), removed_profile);
delete removed_profile;
// Check that emptying the trash now allows removal to occur.
- EXPECT_TRUE(db.GetAutofillTable()->EmptyAutofillProfilesTrash());
- EXPECT_TRUE(db.GetAutofillTable()->RemoveAutofillProfile(profile.guid()));
+ EXPECT_TRUE(table_->EmptyAutofillProfilesTrash());
+ EXPECT_TRUE(table_->RemoveAutofillProfile(profile.guid()));
removed_profile = NULL;
- EXPECT_FALSE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
- &removed_profile));
+ EXPECT_FALSE(table_->GetAutofillProfile(profile.guid(), &removed_profile));
EXPECT_EQ(static_cast<AutofillProfile*>(NULL), removed_profile);
}
TEST_F(AutofillTableTest, CreditCard) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
// Add a 'Work' credit card.
CreditCard work_creditcard;
work_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
@@ -936,15 +860,14 @@ TEST_F(AutofillTableTest, CreditCard) {
ASCIIToUTF16("2013"));
Time pre_creation_time = Time::Now();
- EXPECT_TRUE(db.GetAutofillTable()->AddCreditCard(work_creditcard));
+ EXPECT_TRUE(table_->AddCreditCard(work_creditcard));
Time post_creation_time = Time::Now();
// Get the 'Work' credit card.
CreditCard* db_creditcard;
- ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(work_creditcard.guid(),
- &db_creditcard));
+ ASSERT_TRUE(table_->GetCreditCard(work_creditcard.guid(), &db_creditcard));
EXPECT_EQ(work_creditcard, *db_creditcard);
- sql::Statement s_work(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_work(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT guid, name_on_card, expiration_month, expiration_year, "
"card_number_encrypted, date_modified "
"FROM credit_cards WHERE guid=?"));
@@ -966,12 +889,11 @@ TEST_F(AutofillTableTest, CreditCard) {
ASCIIToUTF16("2012"));
pre_creation_time = Time::Now();
- EXPECT_TRUE(db.GetAutofillTable()->AddCreditCard(target_creditcard));
+ EXPECT_TRUE(table_->AddCreditCard(target_creditcard));
post_creation_time = Time::Now();
- ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(),
- &db_creditcard));
+ ASSERT_TRUE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard));
EXPECT_EQ(target_creditcard, *db_creditcard);
- sql::Statement s_target(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_target(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT guid, name_on_card, expiration_month, expiration_year, "
"card_number_encrypted, date_modified "
"FROM credit_cards WHERE guid=?"));
@@ -986,12 +908,11 @@ TEST_F(AutofillTableTest, CreditCard) {
// Update the 'Target' credit card.
target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Charles Grady"));
Time pre_modification_time = Time::Now();
- EXPECT_TRUE(db.GetAutofillTable()->UpdateCreditCard(target_creditcard));
+ EXPECT_TRUE(table_->UpdateCreditCard(target_creditcard));
Time post_modification_time = Time::Now();
- ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(),
- &db_creditcard));
+ ASSERT_TRUE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard));
EXPECT_EQ(target_creditcard, *db_creditcard);
- sql::Statement s_target_updated(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_target_updated(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT guid, name_on_card, expiration_month, expiration_year, "
"card_number_encrypted, date_modified "
"FROM credit_cards WHERE guid=?"));
@@ -1004,16 +925,11 @@ TEST_F(AutofillTableTest, CreditCard) {
delete db_creditcard;
// Remove the 'Target' credit card.
- EXPECT_TRUE(db.GetAutofillTable()->RemoveCreditCard(
- target_creditcard.guid()));
- EXPECT_FALSE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(),
- &db_creditcard));
+ EXPECT_TRUE(table_->RemoveCreditCard(target_creditcard.guid()));
+ EXPECT_FALSE(table_->GetCreditCard(target_creditcard.guid(), &db_creditcard));
}
TEST_F(AutofillTableTest, UpdateAutofillProfile) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
// Add a profile to the db.
AutofillProfile profile;
profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
@@ -1028,23 +944,23 @@ TEST_F(AutofillTableTest, UpdateAutofillProfile) {
profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025"));
profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567"));
- db.GetAutofillTable()->AddAutofillProfile(profile);
+ table_->AddAutofillProfile(profile);
// Set a mocked value for the profile's creation time.
const time_t mock_creation_date = Time::Now().ToTimeT() - 13;
- sql::Statement s_mock_creation_date(db.GetSQLConnection()->GetUniqueStatement(
- "UPDATE autofill_profiles SET date_modified = ?"));
+ sql::Statement s_mock_creation_date(
+ db_->GetSQLConnection()->GetUniqueStatement(
+ "UPDATE autofill_profiles SET date_modified = ?"));
ASSERT_TRUE(s_mock_creation_date.is_valid());
s_mock_creation_date.BindInt64(0, mock_creation_date);
ASSERT_TRUE(s_mock_creation_date.Run());
// Get the profile.
AutofillProfile* tmp_profile;
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
- &tmp_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile));
scoped_ptr<AutofillProfile> db_profile(tmp_profile);
EXPECT_EQ(profile, *db_profile);
- sql::Statement s_original(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_original(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_original.is_valid());
ASSERT_TRUE(s_original.Step());
@@ -1054,14 +970,13 @@ TEST_F(AutofillTableTest, UpdateAutofillProfile) {
// Now, update the profile and save the update to the database.
// The modification date should change to reflect the update.
profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz"));
- db.GetAutofillTable()->UpdateAutofillProfileMulti(profile);
+ table_->UpdateAutofillProfileMulti(profile);
// Get the profile.
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
- &tmp_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile));
db_profile.reset(tmp_profile);
EXPECT_EQ(profile, *db_profile);
- sql::Statement s_updated(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_updated(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_updated.is_valid());
ASSERT_TRUE(s_updated.Step());
@@ -1071,7 +986,7 @@ TEST_F(AutofillTableTest, UpdateAutofillProfile) {
// Set a mocked value for the profile's modification time.
const time_t mock_modification_date = Time::Now().ToTimeT() - 7;
sql::Statement s_mock_modification_date(
- db.GetSQLConnection()->GetUniqueStatement(
+ db_->GetSQLConnection()->GetUniqueStatement(
"UPDATE autofill_profiles SET date_modified = ?"));
ASSERT_TRUE(s_mock_modification_date.is_valid());
s_mock_modification_date.BindInt64(0, mock_modification_date);
@@ -1079,14 +994,13 @@ TEST_F(AutofillTableTest, UpdateAutofillProfile) {
// Finally, call into |UpdateAutofillProfileMulti()| without changing the
// profile. The modification date should not change.
- db.GetAutofillTable()->UpdateAutofillProfileMulti(profile);
+ table_->UpdateAutofillProfileMulti(profile);
// Get the profile.
- ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
- &tmp_profile));
+ ASSERT_TRUE(table_->GetAutofillProfile(profile.guid(), &tmp_profile));
db_profile.reset(tmp_profile);
EXPECT_EQ(profile, *db_profile);
- sql::Statement s_unchanged(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_unchanged(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_unchanged.is_valid());
ASSERT_TRUE(s_unchanged.Step());
@@ -1095,32 +1009,29 @@ TEST_F(AutofillTableTest, UpdateAutofillProfile) {
}
TEST_F(AutofillTableTest, UpdateCreditCard) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
// Add a credit card to the db.
CreditCard credit_card;
credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
credit_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234567890123456"));
credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04"));
credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2013"));
- db.GetAutofillTable()->AddCreditCard(credit_card);
+ table_->AddCreditCard(credit_card);
// Set a mocked value for the credit card's creation time.
const time_t mock_creation_date = Time::Now().ToTimeT() - 13;
- sql::Statement s_mock_creation_date(db.GetSQLConnection()->GetUniqueStatement(
- "UPDATE credit_cards SET date_modified = ?"));
+ sql::Statement s_mock_creation_date(
+ db_->GetSQLConnection()->GetUniqueStatement(
+ "UPDATE credit_cards SET date_modified = ?"));
ASSERT_TRUE(s_mock_creation_date.is_valid());
s_mock_creation_date.BindInt64(0, mock_creation_date);
ASSERT_TRUE(s_mock_creation_date.Run());
// Get the credit card.
CreditCard* tmp_credit_card;
- ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(),
- &tmp_credit_card));
+ ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card));
scoped_ptr<CreditCard> db_credit_card(tmp_credit_card);
EXPECT_EQ(credit_card, *db_credit_card);
- sql::Statement s_original(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_original(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_original.is_valid());
ASSERT_TRUE(s_original.Step());
@@ -1130,14 +1041,13 @@ TEST_F(AutofillTableTest, UpdateCreditCard) {
// Now, update the credit card and save the update to the database.
// The modification date should change to reflect the update.
credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01"));
- db.GetAutofillTable()->UpdateCreditCard(credit_card);
+ table_->UpdateCreditCard(credit_card);
// Get the credit card.
- ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(),
- &tmp_credit_card));
+ ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card));
db_credit_card.reset(tmp_credit_card);
EXPECT_EQ(credit_card, *db_credit_card);
- sql::Statement s_updated(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_updated(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_updated.is_valid());
ASSERT_TRUE(s_updated.Step());
@@ -1147,7 +1057,7 @@ TEST_F(AutofillTableTest, UpdateCreditCard) {
// Set a mocked value for the credit card's modification time.
const time_t mock_modification_date = Time::Now().ToTimeT() - 7;
sql::Statement s_mock_modification_date(
- db.GetSQLConnection()->GetUniqueStatement(
+ db_->GetSQLConnection()->GetUniqueStatement(
"UPDATE credit_cards SET date_modified = ?"));
ASSERT_TRUE(s_mock_modification_date.is_valid());
s_mock_modification_date.BindInt64(0, mock_modification_date);
@@ -1155,14 +1065,13 @@ TEST_F(AutofillTableTest, UpdateCreditCard) {
// Finally, call into |UpdateCreditCard()| without changing the credit card.
// The modification date should not change.
- db.GetAutofillTable()->UpdateCreditCard(credit_card);
+ table_->UpdateCreditCard(credit_card);
// Get the profile.
- ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(),
- &tmp_credit_card));
+ ASSERT_TRUE(table_->GetCreditCard(credit_card.guid(), &tmp_credit_card));
db_credit_card.reset(tmp_credit_card);
EXPECT_EQ(credit_card, *db_credit_card);
- sql::Statement s_unchanged(db.GetSQLConnection()->GetUniqueStatement(
+ sql::Statement s_unchanged(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_unchanged.is_valid());
ASSERT_TRUE(s_unchanged.Step());
@@ -1171,11 +1080,8 @@ TEST_F(AutofillTableTest, UpdateCreditCard) {
}
TEST_F(AutofillTableTest, RemoveAutofillProfilesAndCreditCardsModifiedBetween) {
- WebDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
// Populate the autofill_profiles and credit_cards tables.
- ASSERT_TRUE(db.GetSQLConnection()->Execute(
+ ASSERT_TRUE(db_->GetSQLConnection()->Execute(
"INSERT INTO autofill_profiles (guid, date_modified) "
"VALUES('00000000-0000-0000-0000-000000000000', 11);"
"INSERT INTO autofill_profiles (guid, date_modified) "
@@ -1204,14 +1110,14 @@ TEST_F(AutofillTableTest, RemoveAutofillProfilesAndCreditCardsModifiedBetween) {
// Remove all entries modified in the bounded time range [17,41).
std::vector<std::string> profile_guids;
std::vector<std::string> credit_card_guids;
- db.GetAutofillTable()->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
+ table_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
Time::FromTimeT(17), Time::FromTimeT(41),
&profile_guids, &credit_card_guids);
ASSERT_EQ(2UL, profile_guids.size());
EXPECT_EQ("00000000-0000-0000-0000-000000000001", profile_guids[0]);
EXPECT_EQ("00000000-0000-0000-0000-000000000002", profile_guids[1]);
sql::Statement s_autofill_profiles_bounded(
- db.GetSQLConnection()->GetUniqueStatement(
+ db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_autofill_profiles_bounded.is_valid());
ASSERT_TRUE(s_autofill_profiles_bounded.Step());
@@ -1228,7 +1134,7 @@ TEST_F(AutofillTableTest, RemoveAutofillProfilesAndCreditCardsModifiedBetween) {
EXPECT_EQ("00000000-0000-0000-0000-000000000007", credit_card_guids[1]);
EXPECT_EQ("00000000-0000-0000-0000-000000000008", credit_card_guids[2]);
sql::Statement s_credit_cards_bounded(
- db.GetSQLConnection()->GetUniqueStatement(
+ db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_credit_cards_bounded.is_valid());
ASSERT_TRUE(s_credit_cards_bounded.Step());
@@ -1240,14 +1146,14 @@ TEST_F(AutofillTableTest, RemoveAutofillProfilesAndCreditCardsModifiedBetween) {
EXPECT_FALSE(s_credit_cards_bounded.Step());
// Remove all entries modified on or after time 51 (unbounded range).
- db.GetAutofillTable()->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
+ table_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
Time::FromTimeT(51), Time(),
&profile_guids, &credit_card_guids);
ASSERT_EQ(2UL, profile_guids.size());
EXPECT_EQ("00000000-0000-0000-0000-000000000004", profile_guids[0]);
EXPECT_EQ("00000000-0000-0000-0000-000000000005", profile_guids[1]);
sql::Statement s_autofill_profiles_unbounded(
- db.GetSQLConnection()->GetUniqueStatement(
+ db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_autofill_profiles_unbounded.is_valid());
ASSERT_TRUE(s_autofill_profiles_unbounded.Step());
@@ -1259,7 +1165,7 @@ TEST_F(AutofillTableTest, RemoveAutofillProfilesAndCreditCardsModifiedBetween) {
EXPECT_EQ("00000000-0000-0000-0000-000000000010", credit_card_guids[0]);
EXPECT_EQ("00000000-0000-0000-0000-000000000011", credit_card_guids[1]);
sql::Statement s_credit_cards_unbounded(
- db.GetSQLConnection()->GetUniqueStatement(
+ db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_credit_cards_unbounded.is_valid());
ASSERT_TRUE(s_credit_cards_unbounded.Step());
@@ -1267,42 +1173,34 @@ TEST_F(AutofillTableTest, RemoveAutofillProfilesAndCreditCardsModifiedBetween) {
EXPECT_FALSE(s_credit_cards_unbounded.Step());
// Remove all remaining entries.
- db.GetAutofillTable()->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
+ table_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
Time(), Time(),
&profile_guids, &credit_card_guids);
ASSERT_EQ(2UL, profile_guids.size());
EXPECT_EQ("00000000-0000-0000-0000-000000000000", profile_guids[0]);
EXPECT_EQ("00000000-0000-0000-0000-000000000003", profile_guids[1]);
sql::Statement s_autofill_profiles_empty(
- db.GetSQLConnection()->GetUniqueStatement(
+ db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_autofill_profiles_empty.is_valid());
EXPECT_FALSE(s_autofill_profiles_empty.Step());
ASSERT_EQ(1UL, credit_card_guids.size());
EXPECT_EQ("00000000-0000-0000-0000-000000000009", credit_card_guids[0]);
sql::Statement s_credit_cards_empty(
- db.GetSQLConnection()->GetUniqueStatement(
+ db_->GetSQLConnection()->GetUniqueStatement(
"SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_credit_cards_empty.is_valid());
EXPECT_FALSE(s_credit_cards_empty.Step());
}
TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_NoResults) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
std::vector<AutofillEntry> entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&entries));
EXPECT_EQ(0U, entries.size());
}
TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillChangeList changes;
std::map<std::string, std::vector<Time> > name_value_times_map;
@@ -1311,9 +1209,8 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) {
FormFieldData field;
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Superman");
- EXPECT_TRUE(
- db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
- Time::FromTimeT(start)));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
+ Time::FromTimeT(start)));
timestamps1.push_back(Time::FromTimeT(start));
std::string key1("NameSuperman");
name_value_times_map.insert(std::pair<std::string,
@@ -1326,7 +1223,7 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) {
expected_entries.insert(ae1);
std::vector<AutofillEntry> entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&entries));
AutofillEntrySet entry_set(entries.begin(), entries.end(),
CompareAutofillEntries);
@@ -1341,10 +1238,6 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) {
}
TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillChangeList changes;
std::map<std::string, std::vector<Time> > name_value_times_map;
time_t start = 0;
@@ -1353,9 +1246,8 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) {
FormFieldData field;
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Superman");
- EXPECT_TRUE(
- db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
- Time::FromTimeT(start)));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
+ Time::FromTimeT(start)));
timestamps1.push_back(Time::FromTimeT(start));
std::string key1("NameSuperman");
name_value_times_map.insert(std::pair<std::string,
@@ -1365,9 +1257,8 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) {
std::vector<Time> timestamps2;
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Clark Kent");
- EXPECT_TRUE(
- db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
- Time::FromTimeT(start)));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
+ Time::FromTimeT(start)));
timestamps2.push_back(Time::FromTimeT(start));
std::string key2("NameClark Kent");
name_value_times_map.insert(std::pair<std::string,
@@ -1383,7 +1274,7 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) {
expected_entries.insert(ae2);
std::vector<AutofillEntry> entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&entries));
AutofillEntrySet entry_set(entries.begin(), entries.end(),
CompareAutofillEntries);
@@ -1398,10 +1289,6 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) {
}
TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoSame) {
- WebDatabase db;
-
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
-
AutofillChangeList changes;
std::map<std::string, std::vector<Time> > name_value_times_map;
@@ -1411,9 +1298,8 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoSame) {
FormFieldData field;
field.name = ASCIIToUTF16("Name");
field.value = ASCIIToUTF16("Superman");
- EXPECT_TRUE(
- db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
- Time::FromTimeT(start)));
+ EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
+ Time::FromTimeT(start)));
timestamps.push_back(Time::FromTimeT(start));
start++;
}
@@ -1429,7 +1315,7 @@ TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoSame) {
expected_entries.insert(ae1);
std::vector<AutofillEntry> entries;
- ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries));
+ ASSERT_TRUE(table_->GetAllAutofillEntries(&entries));
AutofillEntrySet entry_set(entries.begin(), entries.end(),
CompareAutofillEntries);
« no previous file with comments | « chrome/browser/webdata/autofill_table.cc ('k') | chrome/browser/webdata/keyword_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698