| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <list> | 5 #include <list> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 AutofillProfile* profile, | 98 AutofillProfile* profile, |
| 99 string16* label, | 99 string16* label, |
| 100 int* unique_id, | 100 int* unique_id, |
| 101 int64* date_modified) { | 101 int64* date_modified) { |
| 102 DCHECK(profile); | 102 DCHECK(profile); |
| 103 DCHECK(label); | 103 DCHECK(label); |
| 104 DCHECK(unique_id); | 104 DCHECK(unique_id); |
| 105 DCHECK(date_modified); | 105 DCHECK(date_modified); |
| 106 *label = s.ColumnString16(0); | 106 *label = s.ColumnString16(0); |
| 107 *unique_id = s.ColumnInt(1); | 107 *unique_id = s.ColumnInt(1); |
| 108 profile->SetInfo(AutofillType(NAME_FIRST), s.ColumnString16(2)); | 108 profile->SetInfo(NAME_FIRST, s.ColumnString16(2)); |
| 109 profile->SetInfo(AutofillType(NAME_MIDDLE), s.ColumnString16(3)); | 109 profile->SetInfo(NAME_MIDDLE, s.ColumnString16(3)); |
| 110 profile->SetInfo(AutofillType(NAME_LAST),s.ColumnString16(4)); | 110 profile->SetInfo(NAME_LAST,s.ColumnString16(4)); |
| 111 profile->SetInfo(AutofillType(EMAIL_ADDRESS), s.ColumnString16(5)); | 111 profile->SetInfo(EMAIL_ADDRESS, s.ColumnString16(5)); |
| 112 profile->SetInfo(AutofillType(COMPANY_NAME), s.ColumnString16(6)); | 112 profile->SetInfo(COMPANY_NAME, s.ColumnString16(6)); |
| 113 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE1), s.ColumnString16(7)); | 113 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(7)); |
| 114 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE2), s.ColumnString16(8)); | 114 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(8)); |
| 115 profile->SetInfo(AutofillType(ADDRESS_HOME_CITY), s.ColumnString16(9)); | 115 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(9)); |
| 116 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), s.ColumnString16(10)); | 116 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(10)); |
| 117 profile->SetInfo(AutofillType(ADDRESS_HOME_ZIP), s.ColumnString16(11)); | 117 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(11)); |
| 118 profile->SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(12)); | 118 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(12)); |
| 119 profile->SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(13)); | 119 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(13)); |
| 120 profile->SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(14)); | 120 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, s.ColumnString16(14)); |
| 121 *date_modified = s.ColumnInt64(15); | 121 *date_modified = s.ColumnInt64(15); |
| 122 profile->set_guid(s.ColumnString(16)); | 122 profile->set_guid(s.ColumnString(16)); |
| 123 EXPECT_TRUE(guid::IsValidGUID(profile->guid())); | 123 EXPECT_TRUE(guid::IsValidGUID(profile->guid())); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void AutofillProfile32FromStatement(const sql::Statement& s, | 126 void AutofillProfile32FromStatement(const sql::Statement& s, |
| 127 AutofillProfile* profile, | 127 AutofillProfile* profile, |
| 128 string16* label, | 128 string16* label, |
| 129 int64* date_modified) { | 129 int64* date_modified) { |
| 130 DCHECK(profile); | 130 DCHECK(profile); |
| 131 DCHECK(label); | 131 DCHECK(label); |
| 132 DCHECK(date_modified); | 132 DCHECK(date_modified); |
| 133 profile->set_guid(s.ColumnString(0)); | 133 profile->set_guid(s.ColumnString(0)); |
| 134 EXPECT_TRUE(guid::IsValidGUID(profile->guid())); | 134 EXPECT_TRUE(guid::IsValidGUID(profile->guid())); |
| 135 *label = s.ColumnString16(1); | 135 *label = s.ColumnString16(1); |
| 136 profile->SetInfo(AutofillType(NAME_FIRST), s.ColumnString16(2)); | 136 profile->SetInfo(NAME_FIRST, s.ColumnString16(2)); |
| 137 profile->SetInfo(AutofillType(NAME_MIDDLE), s.ColumnString16(3)); | 137 profile->SetInfo(NAME_MIDDLE, s.ColumnString16(3)); |
| 138 profile->SetInfo(AutofillType(NAME_LAST),s.ColumnString16(4)); | 138 profile->SetInfo(NAME_LAST,s.ColumnString16(4)); |
| 139 profile->SetInfo(AutofillType(EMAIL_ADDRESS), s.ColumnString16(5)); | 139 profile->SetInfo(EMAIL_ADDRESS, s.ColumnString16(5)); |
| 140 profile->SetInfo(AutofillType(COMPANY_NAME), s.ColumnString16(6)); | 140 profile->SetInfo(COMPANY_NAME, s.ColumnString16(6)); |
| 141 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE1), s.ColumnString16(7)); | 141 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(7)); |
| 142 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE2), s.ColumnString16(8)); | 142 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(8)); |
| 143 profile->SetInfo(AutofillType(ADDRESS_HOME_CITY), s.ColumnString16(9)); | 143 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(9)); |
| 144 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), s.ColumnString16(10)); | 144 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(10)); |
| 145 profile->SetInfo(AutofillType(ADDRESS_HOME_ZIP), s.ColumnString16(11)); | 145 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(11)); |
| 146 profile->SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(12)); | 146 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(12)); |
| 147 profile->SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(13)); | 147 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(13)); |
| 148 profile->SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(14)); | 148 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, s.ColumnString16(14)); |
| 149 *date_modified = s.ColumnInt64(15); | 149 *date_modified = s.ColumnInt64(15); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void AutofillProfile33FromStatement(const sql::Statement& s, | 152 void AutofillProfile33FromStatement(const sql::Statement& s, |
| 153 AutofillProfile* profile, | 153 AutofillProfile* profile, |
| 154 int64* date_modified) { | 154 int64* date_modified) { |
| 155 DCHECK(profile); | 155 DCHECK(profile); |
| 156 DCHECK(date_modified); | 156 DCHECK(date_modified); |
| 157 profile->set_guid(s.ColumnString(0)); | 157 profile->set_guid(s.ColumnString(0)); |
| 158 EXPECT_TRUE(guid::IsValidGUID(profile->guid())); | 158 EXPECT_TRUE(guid::IsValidGUID(profile->guid())); |
| 159 profile->SetInfo(AutofillType(COMPANY_NAME), s.ColumnString16(1)); | 159 profile->SetInfo(COMPANY_NAME, s.ColumnString16(1)); |
| 160 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE1), s.ColumnString16(2)); | 160 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); |
| 161 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE2), s.ColumnString16(3)); | 161 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); |
| 162 profile->SetInfo(AutofillType(ADDRESS_HOME_CITY), s.ColumnString16(4)); | 162 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); |
| 163 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), s.ColumnString16(5)); | 163 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); |
| 164 profile->SetInfo(AutofillType(ADDRESS_HOME_ZIP), s.ColumnString16(6)); | 164 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); |
| 165 profile->SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(7)); | 165 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(7)); |
| 166 *date_modified = s.ColumnInt64(8); | 166 *date_modified = s.ColumnInt64(8); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void CreditCard31FromStatement(const sql::Statement& s, | 169 void CreditCard31FromStatement(const sql::Statement& s, |
| 170 CreditCard* credit_card, | 170 CreditCard* credit_card, |
| 171 string16* label, | 171 string16* label, |
| 172 int* unique_id, | 172 int* unique_id, |
| 173 std::string* encrypted_number, | 173 std::string* encrypted_number, |
| 174 int64* date_modified) { | 174 int64* date_modified) { |
| 175 DCHECK(credit_card); | 175 DCHECK(credit_card); |
| 176 DCHECK(label); | 176 DCHECK(label); |
| 177 DCHECK(unique_id); | 177 DCHECK(unique_id); |
| 178 DCHECK(encrypted_number); | 178 DCHECK(encrypted_number); |
| 179 DCHECK(date_modified); | 179 DCHECK(date_modified); |
| 180 *label = s.ColumnString16(0); | 180 *label = s.ColumnString16(0); |
| 181 *unique_id = s.ColumnInt(1); | 181 *unique_id = s.ColumnInt(1); |
| 182 credit_card->SetInfo(AutofillType(CREDIT_CARD_NAME), s.ColumnString16(2)); | 182 credit_card->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(2)); |
| 183 credit_card->SetInfo(AutofillType(CREDIT_CARD_TYPE), s.ColumnString16(3)); | 183 credit_card->SetInfo(CREDIT_CARD_TYPE, s.ColumnString16(3)); |
| 184 credit_card->SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), | 184 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, |
| 185 s.ColumnString16(5)); | 185 s.ColumnString16(5)); |
| 186 credit_card->SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 186 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 187 s.ColumnString16(6)); | 187 s.ColumnString16(6)); |
| 188 int encrypted_number_len = s.ColumnByteLength(10); | 188 int encrypted_number_len = s.ColumnByteLength(10); |
| 189 if (encrypted_number_len) { | 189 if (encrypted_number_len) { |
| 190 encrypted_number->resize(encrypted_number_len); | 190 encrypted_number->resize(encrypted_number_len); |
| 191 memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len); | 191 memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len); |
| 192 } | 192 } |
| 193 *date_modified = s.ColumnInt64(12); | 193 *date_modified = s.ColumnInt64(12); |
| 194 credit_card->set_guid(s.ColumnString(13)); | 194 credit_card->set_guid(s.ColumnString(13)); |
| 195 EXPECT_TRUE(guid::IsValidGUID(credit_card->guid())); | 195 EXPECT_TRUE(guid::IsValidGUID(credit_card->guid())); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void CreditCard32FromStatement(const sql::Statement& s, | 198 void CreditCard32FromStatement(const sql::Statement& s, |
| 199 CreditCard* credit_card, | 199 CreditCard* credit_card, |
| 200 std::string* encrypted_number, | 200 std::string* encrypted_number, |
| 201 int64* date_modified) { | 201 int64* date_modified) { |
| 202 DCHECK(credit_card); | 202 DCHECK(credit_card); |
| 203 DCHECK(encrypted_number); | 203 DCHECK(encrypted_number); |
| 204 DCHECK(date_modified); | 204 DCHECK(date_modified); |
| 205 credit_card->set_guid(s.ColumnString(0)); | 205 credit_card->set_guid(s.ColumnString(0)); |
| 206 EXPECT_TRUE(guid::IsValidGUID(credit_card->guid())); | 206 EXPECT_TRUE(guid::IsValidGUID(credit_card->guid())); |
| 207 credit_card->SetInfo(AutofillType(CREDIT_CARD_NAME), s.ColumnString16(1)); | 207 credit_card->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); |
| 208 credit_card->SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), | 208 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, |
| 209 s.ColumnString16(2)); | 209 s.ColumnString16(2)); |
| 210 credit_card->SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 210 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 211 s.ColumnString16(3)); | 211 s.ColumnString16(3)); |
| 212 int encrypted_number_len = s.ColumnByteLength(4); | 212 int encrypted_number_len = s.ColumnByteLength(4); |
| 213 if (encrypted_number_len) { | 213 if (encrypted_number_len) { |
| 214 encrypted_number->resize(encrypted_number_len); | 214 encrypted_number->resize(encrypted_number_len); |
| 215 memcpy(&(*encrypted_number)[0], s.ColumnBlob(4), encrypted_number_len); | 215 memcpy(&(*encrypted_number)[0], s.ColumnBlob(4), encrypted_number_len); |
| 216 } | 216 } |
| 217 *date_modified = s.ColumnInt64(5); | 217 *date_modified = s.ColumnInt64(5); |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace | 220 } // namespace |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 EXPECT_EQ(out_map.find(service)->second, "ham"); | 1401 EXPECT_EQ(out_map.find(service)->second, "ham"); |
| 1402 } | 1402 } |
| 1403 | 1403 |
| 1404 TEST_F(WebDatabaseTest, AutofillProfile) { | 1404 TEST_F(WebDatabaseTest, AutofillProfile) { |
| 1405 WebDatabase db; | 1405 WebDatabase db; |
| 1406 | 1406 |
| 1407 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 1407 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| 1408 | 1408 |
| 1409 // Add a 'Home' profile. | 1409 // Add a 'Home' profile. |
| 1410 AutofillProfile home_profile; | 1410 AutofillProfile home_profile; |
| 1411 home_profile.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("John")); | 1411 home_profile.SetInfo(NAME_FIRST, ASCIIToUTF16("John")); |
| 1412 home_profile.SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Q.")); | 1412 home_profile.SetInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); |
| 1413 home_profile.SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Smith")); | 1413 home_profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); |
| 1414 home_profile.SetInfo(AutofillType(EMAIL_ADDRESS), | 1414 home_profile.SetInfo(EMAIL_ADDRESS, |
| 1415 ASCIIToUTF16("js@smith.xyz")); | 1415 ASCIIToUTF16("js@smith.xyz")); |
| 1416 home_profile.SetInfo(AutofillType(COMPANY_NAME), ASCIIToUTF16("Google")); | 1416 home_profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Google")); |
| 1417 home_profile.SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1417 home_profile.SetInfo(ADDRESS_HOME_LINE1, |
| 1418 ASCIIToUTF16("1234 Apple Way")); | 1418 ASCIIToUTF16("1234 Apple Way")); |
| 1419 home_profile.SetInfo(AutofillType(ADDRESS_HOME_LINE2), | 1419 home_profile.SetInfo(ADDRESS_HOME_LINE2, |
| 1420 ASCIIToUTF16("unit 5")); | 1420 ASCIIToUTF16("unit 5")); |
| 1421 home_profile.SetInfo(AutofillType(ADDRESS_HOME_CITY), | 1421 home_profile.SetInfo(ADDRESS_HOME_CITY, |
| 1422 ASCIIToUTF16("Los Angeles")); | 1422 ASCIIToUTF16("Los Angeles")); |
| 1423 home_profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA")); | 1423 home_profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
| 1424 home_profile.SetInfo(AutofillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("90025")); | 1424 home_profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); |
| 1425 home_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("US")); | 1425 home_profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
| 1426 home_profile.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), | 1426 home_profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, |
| 1427 ASCIIToUTF16("18181234567")); | 1427 ASCIIToUTF16("18181234567")); |
| 1428 home_profile.SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), | 1428 home_profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, |
| 1429 ASCIIToUTF16("1915243678")); | 1429 ASCIIToUTF16("1915243678")); |
| 1430 | 1430 |
| 1431 Time pre_creation_time = Time::Now(); | 1431 Time pre_creation_time = Time::Now(); |
| 1432 EXPECT_TRUE(db.AddAutofillProfile(home_profile)); | 1432 EXPECT_TRUE(db.AddAutofillProfile(home_profile)); |
| 1433 Time post_creation_time = Time::Now(); | 1433 Time post_creation_time = Time::Now(); |
| 1434 | 1434 |
| 1435 // Get the 'Home' profile. | 1435 // Get the 'Home' profile. |
| 1436 AutofillProfile* db_profile; | 1436 AutofillProfile* db_profile; |
| 1437 ASSERT_TRUE(db.GetAutofillProfile(home_profile.guid(), &db_profile)); | 1437 ASSERT_TRUE(db.GetAutofillProfile(home_profile.guid(), &db_profile)); |
| 1438 EXPECT_EQ(home_profile, *db_profile); | 1438 EXPECT_EQ(home_profile, *db_profile); |
| 1439 sql::Statement s_home(db.db_.GetUniqueStatement( | 1439 sql::Statement s_home(db.db_.GetUniqueStatement( |
| 1440 "SELECT date_modified " | 1440 "SELECT date_modified " |
| 1441 "FROM autofill_profiles WHERE guid=?")); | 1441 "FROM autofill_profiles WHERE guid=?")); |
| 1442 s_home.BindString(0, home_profile.guid()); | 1442 s_home.BindString(0, home_profile.guid()); |
| 1443 ASSERT_TRUE(s_home); | 1443 ASSERT_TRUE(s_home); |
| 1444 ASSERT_TRUE(s_home.Step()); | 1444 ASSERT_TRUE(s_home.Step()); |
| 1445 EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT()); | 1445 EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT()); |
| 1446 EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT()); | 1446 EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT()); |
| 1447 EXPECT_FALSE(s_home.Step()); | 1447 EXPECT_FALSE(s_home.Step()); |
| 1448 delete db_profile; | 1448 delete db_profile; |
| 1449 | 1449 |
| 1450 // Add a 'Billing' profile. | 1450 // Add a 'Billing' profile. |
| 1451 AutofillProfile billing_profile = home_profile; | 1451 AutofillProfile billing_profile = home_profile; |
| 1452 billing_profile.set_guid(guid::GenerateGUID()); | 1452 billing_profile.set_guid(guid::GenerateGUID()); |
| 1453 billing_profile.SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1453 billing_profile.SetInfo(ADDRESS_HOME_LINE1, |
| 1454 ASCIIToUTF16("5678 Bottom Street")); | 1454 ASCIIToUTF16("5678 Bottom Street")); |
| 1455 billing_profile.SetInfo(AutofillType(ADDRESS_HOME_LINE2), | 1455 billing_profile.SetInfo(ADDRESS_HOME_LINE2, |
| 1456 ASCIIToUTF16("suite 3")); | 1456 ASCIIToUTF16("suite 3")); |
| 1457 | 1457 |
| 1458 pre_creation_time = Time::Now(); | 1458 pre_creation_time = Time::Now(); |
| 1459 EXPECT_TRUE(db.AddAutofillProfile(billing_profile)); | 1459 EXPECT_TRUE(db.AddAutofillProfile(billing_profile)); |
| 1460 post_creation_time = Time::Now(); | 1460 post_creation_time = Time::Now(); |
| 1461 | 1461 |
| 1462 // Get the 'Billing' profile. | 1462 // Get the 'Billing' profile. |
| 1463 ASSERT_TRUE(db.GetAutofillProfile(billing_profile.guid(), &db_profile)); | 1463 ASSERT_TRUE(db.GetAutofillProfile(billing_profile.guid(), &db_profile)); |
| 1464 EXPECT_EQ(billing_profile, *db_profile); | 1464 EXPECT_EQ(billing_profile, *db_profile); |
| 1465 sql::Statement s_billing(db.db_.GetUniqueStatement( | 1465 sql::Statement s_billing(db.db_.GetUniqueStatement( |
| 1466 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); | 1466 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); |
| 1467 s_billing.BindString(0, billing_profile.guid()); | 1467 s_billing.BindString(0, billing_profile.guid()); |
| 1468 ASSERT_TRUE(s_billing); | 1468 ASSERT_TRUE(s_billing); |
| 1469 ASSERT_TRUE(s_billing.Step()); | 1469 ASSERT_TRUE(s_billing.Step()); |
| 1470 EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT()); | 1470 EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT()); |
| 1471 EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT()); | 1471 EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT()); |
| 1472 EXPECT_FALSE(s_billing.Step()); | 1472 EXPECT_FALSE(s_billing.Step()); |
| 1473 delete db_profile; | 1473 delete db_profile; |
| 1474 | 1474 |
| 1475 // Update the 'Billing' profile, name only. | 1475 // Update the 'Billing' profile, name only. |
| 1476 billing_profile.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Jane")); | 1476 billing_profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Jane")); |
| 1477 Time pre_modification_time = Time::Now(); | 1477 Time pre_modification_time = Time::Now(); |
| 1478 EXPECT_TRUE(db.UpdateAutofillProfile(billing_profile)); | 1478 EXPECT_TRUE(db.UpdateAutofillProfile(billing_profile)); |
| 1479 Time post_modification_time = Time::Now(); | 1479 Time post_modification_time = Time::Now(); |
| 1480 ASSERT_TRUE(db.GetAutofillProfile(billing_profile.guid(), &db_profile)); | 1480 ASSERT_TRUE(db.GetAutofillProfile(billing_profile.guid(), &db_profile)); |
| 1481 EXPECT_EQ(billing_profile, *db_profile); | 1481 EXPECT_EQ(billing_profile, *db_profile); |
| 1482 sql::Statement s_billing_updated(db.db_.GetUniqueStatement( | 1482 sql::Statement s_billing_updated(db.db_.GetUniqueStatement( |
| 1483 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); | 1483 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); |
| 1484 s_billing_updated.BindString(0, billing_profile.guid()); | 1484 s_billing_updated.BindString(0, billing_profile.guid()); |
| 1485 ASSERT_TRUE(s_billing_updated); | 1485 ASSERT_TRUE(s_billing_updated); |
| 1486 ASSERT_TRUE(s_billing_updated.Step()); | 1486 ASSERT_TRUE(s_billing_updated.Step()); |
| 1487 EXPECT_GE(s_billing_updated.ColumnInt64(0), | 1487 EXPECT_GE(s_billing_updated.ColumnInt64(0), |
| 1488 pre_modification_time.ToTimeT()); | 1488 pre_modification_time.ToTimeT()); |
| 1489 EXPECT_LE(s_billing_updated.ColumnInt64(0), | 1489 EXPECT_LE(s_billing_updated.ColumnInt64(0), |
| 1490 post_modification_time.ToTimeT()); | 1490 post_modification_time.ToTimeT()); |
| 1491 EXPECT_FALSE(s_billing_updated.Step()); | 1491 EXPECT_FALSE(s_billing_updated.Step()); |
| 1492 delete db_profile; | 1492 delete db_profile; |
| 1493 | 1493 |
| 1494 // Update the 'Billing' profile. | 1494 // Update the 'Billing' profile. |
| 1495 billing_profile.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Janice")); | 1495 billing_profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Janice")); |
| 1496 billing_profile.SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("C.")); | 1496 billing_profile.SetInfo(NAME_MIDDLE, ASCIIToUTF16("C.")); |
| 1497 billing_profile.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Joplin")); | 1497 billing_profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Joplin")); |
| 1498 billing_profile.SetInfo(AutofillType(EMAIL_ADDRESS), | 1498 billing_profile.SetInfo(EMAIL_ADDRESS, |
| 1499 ASCIIToUTF16("jane@singer.com")); | 1499 ASCIIToUTF16("jane@singer.com")); |
| 1500 billing_profile.SetInfo(AutofillType(COMPANY_NAME), ASCIIToUTF16("Indy")); | 1500 billing_profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Indy")); |
| 1501 billing_profile.SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1501 billing_profile.SetInfo(ADDRESS_HOME_LINE1, |
| 1502 ASCIIToUTF16("Open Road")); | 1502 ASCIIToUTF16("Open Road")); |
| 1503 billing_profile.SetInfo(AutofillType(ADDRESS_HOME_LINE2), | 1503 billing_profile.SetInfo(ADDRESS_HOME_LINE2, |
| 1504 ASCIIToUTF16("Route 66")); | 1504 ASCIIToUTF16("Route 66")); |
| 1505 billing_profile.SetInfo(AutofillType(ADDRESS_HOME_CITY), | 1505 billing_profile.SetInfo(ADDRESS_HOME_CITY, |
| 1506 ASCIIToUTF16("NFA")); | 1506 ASCIIToUTF16("NFA")); |
| 1507 billing_profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), ASCIIToUTF16("NY")); | 1507 billing_profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("NY")); |
| 1508 billing_profile.SetInfo(AutofillType(ADDRESS_HOME_ZIP), | 1508 billing_profile.SetInfo(ADDRESS_HOME_ZIP, |
| 1509 ASCIIToUTF16("10011")); | 1509 ASCIIToUTF16("10011")); |
| 1510 billing_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), | 1510 billing_profile.SetInfo(ADDRESS_HOME_COUNTRY, |
| 1511 ASCIIToUTF16("United States")); | 1511 ASCIIToUTF16("United States")); |
| 1512 billing_profile.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), | 1512 billing_profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, |
| 1513 ASCIIToUTF16("18181230000")); | 1513 ASCIIToUTF16("18181230000")); |
| 1514 billing_profile.SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), | 1514 billing_profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, |
| 1515 ASCIIToUTF16("1915240000")); | 1515 ASCIIToUTF16("1915240000")); |
| 1516 Time pre_modification_time_2 = Time::Now(); | 1516 Time pre_modification_time_2 = Time::Now(); |
| 1517 EXPECT_TRUE(db.UpdateAutofillProfile(billing_profile)); | 1517 EXPECT_TRUE(db.UpdateAutofillProfile(billing_profile)); |
| 1518 Time post_modification_time_2 = Time::Now(); | 1518 Time post_modification_time_2 = Time::Now(); |
| 1519 ASSERT_TRUE(db.GetAutofillProfile(billing_profile.guid(), &db_profile)); | 1519 ASSERT_TRUE(db.GetAutofillProfile(billing_profile.guid(), &db_profile)); |
| 1520 EXPECT_EQ(billing_profile, *db_profile); | 1520 EXPECT_EQ(billing_profile, *db_profile); |
| 1521 sql::Statement s_billing_updated_2(db.db_.GetUniqueStatement( | 1521 sql::Statement s_billing_updated_2(db.db_.GetUniqueStatement( |
| 1522 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); | 1522 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); |
| 1523 s_billing_updated_2.BindString(0, billing_profile.guid()); | 1523 s_billing_updated_2.BindString(0, billing_profile.guid()); |
| 1524 ASSERT_TRUE(s_billing_updated_2); | 1524 ASSERT_TRUE(s_billing_updated_2); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1535 EXPECT_FALSE(db.GetAutofillProfile(billing_profile.guid(), &db_profile)); | 1535 EXPECT_FALSE(db.GetAutofillProfile(billing_profile.guid(), &db_profile)); |
| 1536 } | 1536 } |
| 1537 | 1537 |
| 1538 TEST_F(WebDatabaseTest, CreditCard) { | 1538 TEST_F(WebDatabaseTest, CreditCard) { |
| 1539 WebDatabase db; | 1539 WebDatabase db; |
| 1540 | 1540 |
| 1541 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 1541 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| 1542 | 1542 |
| 1543 // Add a 'Work' credit card. | 1543 // Add a 'Work' credit card. |
| 1544 CreditCard work_creditcard; | 1544 CreditCard work_creditcard; |
| 1545 work_creditcard.SetInfo(AutofillType(CREDIT_CARD_NAME), | 1545 work_creditcard.SetInfo(CREDIT_CARD_NAME, |
| 1546 ASCIIToUTF16("Jack Torrance")); | 1546 ASCIIToUTF16("Jack Torrance")); |
| 1547 work_creditcard.SetInfo(AutofillType(CREDIT_CARD_NUMBER), | 1547 work_creditcard.SetInfo(CREDIT_CARD_NUMBER, |
| 1548 ASCIIToUTF16("1234567890123456")); | 1548 ASCIIToUTF16("1234567890123456")); |
| 1549 work_creditcard.SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), | 1549 work_creditcard.SetInfo(CREDIT_CARD_EXP_MONTH, |
| 1550 ASCIIToUTF16("04")); | 1550 ASCIIToUTF16("04")); |
| 1551 work_creditcard.SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 1551 work_creditcard.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1552 ASCIIToUTF16("2013")); | 1552 ASCIIToUTF16("2013")); |
| 1553 | 1553 |
| 1554 Time pre_creation_time = Time::Now(); | 1554 Time pre_creation_time = Time::Now(); |
| 1555 EXPECT_TRUE(db.AddCreditCard(work_creditcard)); | 1555 EXPECT_TRUE(db.AddCreditCard(work_creditcard)); |
| 1556 Time post_creation_time = Time::Now(); | 1556 Time post_creation_time = Time::Now(); |
| 1557 | 1557 |
| 1558 // Get the 'Work' credit card. | 1558 // Get the 'Work' credit card. |
| 1559 CreditCard* db_creditcard; | 1559 CreditCard* db_creditcard; |
| 1560 ASSERT_TRUE(db.GetCreditCard(work_creditcard.guid(), &db_creditcard)); | 1560 ASSERT_TRUE(db.GetCreditCard(work_creditcard.guid(), &db_creditcard)); |
| 1561 EXPECT_EQ(work_creditcard, *db_creditcard); | 1561 EXPECT_EQ(work_creditcard, *db_creditcard); |
| 1562 sql::Statement s_work(db.db_.GetUniqueStatement( | 1562 sql::Statement s_work(db.db_.GetUniqueStatement( |
| 1563 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 1563 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
| 1564 "card_number_encrypted, date_modified " | 1564 "card_number_encrypted, date_modified " |
| 1565 "FROM credit_cards WHERE guid=?")); | 1565 "FROM credit_cards WHERE guid=?")); |
| 1566 s_work.BindString(0, work_creditcard.guid()); | 1566 s_work.BindString(0, work_creditcard.guid()); |
| 1567 ASSERT_TRUE(s_work); | 1567 ASSERT_TRUE(s_work); |
| 1568 ASSERT_TRUE(s_work.Step()); | 1568 ASSERT_TRUE(s_work.Step()); |
| 1569 EXPECT_GE(s_work.ColumnInt64(5), pre_creation_time.ToTimeT()); | 1569 EXPECT_GE(s_work.ColumnInt64(5), pre_creation_time.ToTimeT()); |
| 1570 EXPECT_LE(s_work.ColumnInt64(5), post_creation_time.ToTimeT()); | 1570 EXPECT_LE(s_work.ColumnInt64(5), post_creation_time.ToTimeT()); |
| 1571 EXPECT_FALSE(s_work.Step()); | 1571 EXPECT_FALSE(s_work.Step()); |
| 1572 delete db_creditcard; | 1572 delete db_creditcard; |
| 1573 | 1573 |
| 1574 // Add a 'Target' credit card. | 1574 // Add a 'Target' credit card. |
| 1575 CreditCard target_creditcard; | 1575 CreditCard target_creditcard; |
| 1576 target_creditcard.SetInfo(AutofillType(CREDIT_CARD_NAME), | 1576 target_creditcard.SetInfo(CREDIT_CARD_NAME, |
| 1577 ASCIIToUTF16("Jack Torrance")); | 1577 ASCIIToUTF16("Jack Torrance")); |
| 1578 target_creditcard.SetInfo(AutofillType(CREDIT_CARD_NUMBER), | 1578 target_creditcard.SetInfo(CREDIT_CARD_NUMBER, |
| 1579 ASCIIToUTF16("1111222233334444")); | 1579 ASCIIToUTF16("1111222233334444")); |
| 1580 target_creditcard.SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), | 1580 target_creditcard.SetInfo(CREDIT_CARD_EXP_MONTH, |
| 1581 ASCIIToUTF16("06")); | 1581 ASCIIToUTF16("06")); |
| 1582 target_creditcard.SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 1582 target_creditcard.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1583 ASCIIToUTF16("2012")); | 1583 ASCIIToUTF16("2012")); |
| 1584 | 1584 |
| 1585 pre_creation_time = Time::Now(); | 1585 pre_creation_time = Time::Now(); |
| 1586 EXPECT_TRUE(db.AddCreditCard(target_creditcard)); | 1586 EXPECT_TRUE(db.AddCreditCard(target_creditcard)); |
| 1587 post_creation_time = Time::Now(); | 1587 post_creation_time = Time::Now(); |
| 1588 ASSERT_TRUE(db.GetCreditCard(target_creditcard.guid(), &db_creditcard)); | 1588 ASSERT_TRUE(db.GetCreditCard(target_creditcard.guid(), &db_creditcard)); |
| 1589 EXPECT_EQ(target_creditcard, *db_creditcard); | 1589 EXPECT_EQ(target_creditcard, *db_creditcard); |
| 1590 sql::Statement s_target(db.db_.GetUniqueStatement( | 1590 sql::Statement s_target(db.db_.GetUniqueStatement( |
| 1591 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 1591 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
| 1592 "card_number_encrypted, date_modified " | 1592 "card_number_encrypted, date_modified " |
| 1593 "FROM credit_cards WHERE guid=?")); | 1593 "FROM credit_cards WHERE guid=?")); |
| 1594 s_target.BindString(0, target_creditcard.guid()); | 1594 s_target.BindString(0, target_creditcard.guid()); |
| 1595 ASSERT_TRUE(s_target); | 1595 ASSERT_TRUE(s_target); |
| 1596 ASSERT_TRUE(s_target.Step()); | 1596 ASSERT_TRUE(s_target.Step()); |
| 1597 EXPECT_GE(s_target.ColumnInt64(5), pre_creation_time.ToTimeT()); | 1597 EXPECT_GE(s_target.ColumnInt64(5), pre_creation_time.ToTimeT()); |
| 1598 EXPECT_LE(s_target.ColumnInt64(5), post_creation_time.ToTimeT()); | 1598 EXPECT_LE(s_target.ColumnInt64(5), post_creation_time.ToTimeT()); |
| 1599 EXPECT_FALSE(s_target.Step()); | 1599 EXPECT_FALSE(s_target.Step()); |
| 1600 delete db_creditcard; | 1600 delete db_creditcard; |
| 1601 | 1601 |
| 1602 // Update the 'Target' credit card. | 1602 // Update the 'Target' credit card. |
| 1603 target_creditcard.SetInfo(AutofillType(CREDIT_CARD_NAME), | 1603 target_creditcard.SetInfo(CREDIT_CARD_NAME, |
| 1604 ASCIIToUTF16("Charles Grady")); | 1604 ASCIIToUTF16("Charles Grady")); |
| 1605 Time pre_modification_time = Time::Now(); | 1605 Time pre_modification_time = Time::Now(); |
| 1606 EXPECT_TRUE(db.UpdateCreditCard(target_creditcard)); | 1606 EXPECT_TRUE(db.UpdateCreditCard(target_creditcard)); |
| 1607 Time post_modification_time = Time::Now(); | 1607 Time post_modification_time = Time::Now(); |
| 1608 ASSERT_TRUE(db.GetCreditCard(target_creditcard.guid(), &db_creditcard)); | 1608 ASSERT_TRUE(db.GetCreditCard(target_creditcard.guid(), &db_creditcard)); |
| 1609 EXPECT_EQ(target_creditcard, *db_creditcard); | 1609 EXPECT_EQ(target_creditcard, *db_creditcard); |
| 1610 sql::Statement s_target_updated(db.db_.GetUniqueStatement( | 1610 sql::Statement s_target_updated(db.db_.GetUniqueStatement( |
| 1611 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 1611 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
| 1612 "card_number_encrypted, date_modified " | 1612 "card_number_encrypted, date_modified " |
| 1613 "FROM credit_cards WHERE guid=?")); | 1613 "FROM credit_cards WHERE guid=?")); |
| 1614 s_target_updated.BindString(0, target_creditcard.guid()); | 1614 s_target_updated.BindString(0, target_creditcard.guid()); |
| 1615 ASSERT_TRUE(s_target_updated); | 1615 ASSERT_TRUE(s_target_updated); |
| 1616 ASSERT_TRUE(s_target_updated.Step()); | 1616 ASSERT_TRUE(s_target_updated.Step()); |
| 1617 EXPECT_GE(s_target_updated.ColumnInt64(5), pre_modification_time.ToTimeT()); | 1617 EXPECT_GE(s_target_updated.ColumnInt64(5), pre_modification_time.ToTimeT()); |
| 1618 EXPECT_LE(s_target_updated.ColumnInt64(5), post_modification_time.ToTimeT()); | 1618 EXPECT_LE(s_target_updated.ColumnInt64(5), post_modification_time.ToTimeT()); |
| 1619 EXPECT_FALSE(s_target_updated.Step()); | 1619 EXPECT_FALSE(s_target_updated.Step()); |
| 1620 delete db_creditcard; | 1620 delete db_creditcard; |
| 1621 | 1621 |
| 1622 // Remove the 'Target' credit card. | 1622 // Remove the 'Target' credit card. |
| 1623 EXPECT_TRUE(db.RemoveCreditCard(target_creditcard.guid())); | 1623 EXPECT_TRUE(db.RemoveCreditCard(target_creditcard.guid())); |
| 1624 EXPECT_FALSE(db.GetCreditCard(target_creditcard.guid(), &db_creditcard)); | 1624 EXPECT_FALSE(db.GetCreditCard(target_creditcard.guid(), &db_creditcard)); |
| 1625 } | 1625 } |
| 1626 | 1626 |
| 1627 TEST_F(WebDatabaseTest, UpdateAutofillProfile) { | 1627 TEST_F(WebDatabaseTest, UpdateAutofillProfile) { |
| 1628 WebDatabase db; | 1628 WebDatabase db; |
| 1629 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 1629 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| 1630 | 1630 |
| 1631 // Add a profile to the db. | 1631 // Add a profile to the db. |
| 1632 AutofillProfile profile; | 1632 AutofillProfile profile; |
| 1633 profile.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("John")); | 1633 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("John")); |
| 1634 profile.SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Q.")); | 1634 profile.SetInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); |
| 1635 profile.SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Smith")); | 1635 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); |
| 1636 profile.SetInfo(AutofillType(EMAIL_ADDRESS), ASCIIToUTF16("js@example.com")); | 1636 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@example.com")); |
| 1637 profile.SetInfo(AutofillType(COMPANY_NAME), ASCIIToUTF16("Google")); | 1637 profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Google")); |
| 1638 profile.SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1638 profile.SetInfo(ADDRESS_HOME_LINE1, |
| 1639 ASCIIToUTF16("1234 Apple Way")); | 1639 ASCIIToUTF16("1234 Apple Way")); |
| 1640 profile.SetInfo(AutofillType(ADDRESS_HOME_LINE2), ASCIIToUTF16("unit 5")); | 1640 profile.SetInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5")); |
| 1641 profile.SetInfo(AutofillType(ADDRESS_HOME_CITY), ASCIIToUTF16("Los Angeles")); | 1641 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); |
| 1642 profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA")); | 1642 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
| 1643 profile.SetInfo(AutofillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("90025")); | 1643 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); |
| 1644 profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("US")); | 1644 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
| 1645 profile.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), | 1645 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, |
| 1646 ASCIIToUTF16("18181234567")); | 1646 ASCIIToUTF16("18181234567")); |
| 1647 profile.SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), | 1647 profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, |
| 1648 ASCIIToUTF16("1915243678")); | 1648 ASCIIToUTF16("1915243678")); |
| 1649 db.AddAutofillProfile(profile); | 1649 db.AddAutofillProfile(profile); |
| 1650 | 1650 |
| 1651 // Set a mocked value for the profile's creation time. | 1651 // Set a mocked value for the profile's creation time. |
| 1652 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; | 1652 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; |
| 1653 sql::Statement s_mock_creation_date(db.db_.GetUniqueStatement( | 1653 sql::Statement s_mock_creation_date(db.db_.GetUniqueStatement( |
| 1654 "UPDATE autofill_profiles SET date_modified = ?")); | 1654 "UPDATE autofill_profiles SET date_modified = ?")); |
| 1655 ASSERT_TRUE(s_mock_creation_date); | 1655 ASSERT_TRUE(s_mock_creation_date); |
| 1656 s_mock_creation_date.BindInt64(0, mock_creation_date); | 1656 s_mock_creation_date.BindInt64(0, mock_creation_date); |
| 1657 ASSERT_TRUE(s_mock_creation_date.Run()); | 1657 ASSERT_TRUE(s_mock_creation_date.Run()); |
| 1658 | 1658 |
| 1659 // Get the profile. | 1659 // Get the profile. |
| 1660 AutofillProfile* tmp_profile; | 1660 AutofillProfile* tmp_profile; |
| 1661 ASSERT_TRUE(db.GetAutofillProfile(profile.guid(), &tmp_profile)); | 1661 ASSERT_TRUE(db.GetAutofillProfile(profile.guid(), &tmp_profile)); |
| 1662 scoped_ptr<AutofillProfile> db_profile(tmp_profile); | 1662 scoped_ptr<AutofillProfile> db_profile(tmp_profile); |
| 1663 EXPECT_EQ(profile, *db_profile); | 1663 EXPECT_EQ(profile, *db_profile); |
| 1664 sql::Statement s_original(db.db_.GetUniqueStatement( | 1664 sql::Statement s_original(db.db_.GetUniqueStatement( |
| 1665 "SELECT date_modified FROM autofill_profiles")); | 1665 "SELECT date_modified FROM autofill_profiles")); |
| 1666 ASSERT_TRUE(s_original); | 1666 ASSERT_TRUE(s_original); |
| 1667 ASSERT_TRUE(s_original.Step()); | 1667 ASSERT_TRUE(s_original.Step()); |
| 1668 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); | 1668 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); |
| 1669 EXPECT_FALSE(s_original.Step()); | 1669 EXPECT_FALSE(s_original.Step()); |
| 1670 | 1670 |
| 1671 // Now, update the profile and save the update to the database. | 1671 // Now, update the profile and save the update to the database. |
| 1672 // The modification date should change to reflect the update. | 1672 // The modification date should change to reflect the update. |
| 1673 profile.SetInfo(AutofillType(EMAIL_ADDRESS), ASCIIToUTF16("js@smith.xyz")); | 1673 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz")); |
| 1674 db.UpdateAutofillProfile(profile); | 1674 db.UpdateAutofillProfile(profile); |
| 1675 | 1675 |
| 1676 // Get the profile. | 1676 // Get the profile. |
| 1677 ASSERT_TRUE(db.GetAutofillProfile(profile.guid(), &tmp_profile)); | 1677 ASSERT_TRUE(db.GetAutofillProfile(profile.guid(), &tmp_profile)); |
| 1678 db_profile.reset(tmp_profile); | 1678 db_profile.reset(tmp_profile); |
| 1679 EXPECT_EQ(profile, *db_profile); | 1679 EXPECT_EQ(profile, *db_profile); |
| 1680 sql::Statement s_updated(db.db_.GetUniqueStatement( | 1680 sql::Statement s_updated(db.db_.GetUniqueStatement( |
| 1681 "SELECT date_modified FROM autofill_profiles")); | 1681 "SELECT date_modified FROM autofill_profiles")); |
| 1682 ASSERT_TRUE(s_updated); | 1682 ASSERT_TRUE(s_updated); |
| 1683 ASSERT_TRUE(s_updated.Step()); | 1683 ASSERT_TRUE(s_updated.Step()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1707 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); | 1707 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); |
| 1708 EXPECT_FALSE(s_unchanged.Step()); | 1708 EXPECT_FALSE(s_unchanged.Step()); |
| 1709 } | 1709 } |
| 1710 | 1710 |
| 1711 TEST_F(WebDatabaseTest, UpdateCreditCard) { | 1711 TEST_F(WebDatabaseTest, UpdateCreditCard) { |
| 1712 WebDatabase db; | 1712 WebDatabase db; |
| 1713 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 1713 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| 1714 | 1714 |
| 1715 // Add a credit card to the db. | 1715 // Add a credit card to the db. |
| 1716 CreditCard credit_card; | 1716 CreditCard credit_card; |
| 1717 credit_card.SetInfo(AutofillType(CREDIT_CARD_NAME), | 1717 credit_card.SetInfo(CREDIT_CARD_NAME, |
| 1718 ASCIIToUTF16("Jack Torrance")); | 1718 ASCIIToUTF16("Jack Torrance")); |
| 1719 credit_card.SetInfo(AutofillType(CREDIT_CARD_NUMBER), | 1719 credit_card.SetInfo(CREDIT_CARD_NUMBER, |
| 1720 ASCIIToUTF16("1234567890123456")); | 1720 ASCIIToUTF16("1234567890123456")); |
| 1721 credit_card.SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), | 1721 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, |
| 1722 ASCIIToUTF16("04")); | 1722 ASCIIToUTF16("04")); |
| 1723 credit_card.SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 1723 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1724 ASCIIToUTF16("2013")); | 1724 ASCIIToUTF16("2013")); |
| 1725 db.AddCreditCard(credit_card); | 1725 db.AddCreditCard(credit_card); |
| 1726 | 1726 |
| 1727 // Set a mocked value for the credit card's creation time. | 1727 // Set a mocked value for the credit card's creation time. |
| 1728 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; | 1728 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; |
| 1729 sql::Statement s_mock_creation_date(db.db_.GetUniqueStatement( | 1729 sql::Statement s_mock_creation_date(db.db_.GetUniqueStatement( |
| 1730 "UPDATE credit_cards SET date_modified = ?")); | 1730 "UPDATE credit_cards SET date_modified = ?")); |
| 1731 ASSERT_TRUE(s_mock_creation_date); | 1731 ASSERT_TRUE(s_mock_creation_date); |
| 1732 s_mock_creation_date.BindInt64(0, mock_creation_date); | 1732 s_mock_creation_date.BindInt64(0, mock_creation_date); |
| 1733 ASSERT_TRUE(s_mock_creation_date.Run()); | 1733 ASSERT_TRUE(s_mock_creation_date.Run()); |
| 1734 | 1734 |
| 1735 // Get the credit card. | 1735 // Get the credit card. |
| 1736 CreditCard* tmp_credit_card; | 1736 CreditCard* tmp_credit_card; |
| 1737 ASSERT_TRUE(db.GetCreditCard(credit_card.guid(), &tmp_credit_card)); | 1737 ASSERT_TRUE(db.GetCreditCard(credit_card.guid(), &tmp_credit_card)); |
| 1738 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card); | 1738 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card); |
| 1739 EXPECT_EQ(credit_card, *db_credit_card); | 1739 EXPECT_EQ(credit_card, *db_credit_card); |
| 1740 sql::Statement s_original(db.db_.GetUniqueStatement( | 1740 sql::Statement s_original(db.db_.GetUniqueStatement( |
| 1741 "SELECT date_modified FROM credit_cards")); | 1741 "SELECT date_modified FROM credit_cards")); |
| 1742 ASSERT_TRUE(s_original); | 1742 ASSERT_TRUE(s_original); |
| 1743 ASSERT_TRUE(s_original.Step()); | 1743 ASSERT_TRUE(s_original.Step()); |
| 1744 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); | 1744 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); |
| 1745 EXPECT_FALSE(s_original.Step()); | 1745 EXPECT_FALSE(s_original.Step()); |
| 1746 | 1746 |
| 1747 // Now, update the credit card and save the update to the database. | 1747 // Now, update the credit card and save the update to the database. |
| 1748 // The modification date should change to reflect the update. | 1748 // The modification date should change to reflect the update. |
| 1749 credit_card.SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), ASCIIToUTF16("01")); | 1749 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
| 1750 db.UpdateCreditCard(credit_card); | 1750 db.UpdateCreditCard(credit_card); |
| 1751 | 1751 |
| 1752 // Get the credit card. | 1752 // Get the credit card. |
| 1753 ASSERT_TRUE(db.GetCreditCard(credit_card.guid(), &tmp_credit_card)); | 1753 ASSERT_TRUE(db.GetCreditCard(credit_card.guid(), &tmp_credit_card)); |
| 1754 db_credit_card.reset(tmp_credit_card); | 1754 db_credit_card.reset(tmp_credit_card); |
| 1755 EXPECT_EQ(credit_card, *db_credit_card); | 1755 EXPECT_EQ(credit_card, *db_credit_card); |
| 1756 sql::Statement s_updated(db.db_.GetUniqueStatement( | 1756 sql::Statement s_updated(db.db_.GetUniqueStatement( |
| 1757 "SELECT date_modified FROM credit_cards")); | 1757 "SELECT date_modified FROM credit_cards")); |
| 1758 ASSERT_TRUE(s_updated); | 1758 ASSERT_TRUE(s_updated); |
| 1759 ASSERT_TRUE(s_updated.Step()); | 1759 ASSERT_TRUE(s_updated.Step()); |
| (...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2781 "SELECT guid, company_name, address_line_1, address_line_2, " | 2781 "SELECT guid, company_name, address_line_1, address_line_2, " |
| 2782 "city, state, zipcode, country, date_modified " | 2782 "city, state, zipcode, country, date_modified " |
| 2783 "FROM autofill_profiles")); | 2783 "FROM autofill_profiles")); |
| 2784 ASSERT_TRUE(s1.Step()); | 2784 ASSERT_TRUE(s1.Step()); |
| 2785 | 2785 |
| 2786 AutofillProfile profile_a; | 2786 AutofillProfile profile_a; |
| 2787 int64 profile_date_modified_a = 0; | 2787 int64 profile_date_modified_a = 0; |
| 2788 EXPECT_NO_FATAL_FAILURE(AutofillProfile33FromStatement( | 2788 EXPECT_NO_FATAL_FAILURE(AutofillProfile33FromStatement( |
| 2789 s1, &profile_a, &profile_date_modified_a)); | 2789 s1, &profile_a, &profile_date_modified_a)); |
| 2790 EXPECT_EQ(profile.guid(), profile_a.guid()); | 2790 EXPECT_EQ(profile.guid(), profile_a.guid()); |
| 2791 EXPECT_EQ(profile.GetFieldText(AutofillType(COMPANY_NAME)), | 2791 EXPECT_EQ(profile.GetFieldText(COMPANY_NAME), |
| 2792 profile_a.GetFieldText(AutofillType(COMPANY_NAME))); | 2792 profile_a.GetFieldText(COMPANY_NAME)); |
| 2793 EXPECT_EQ(profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE1)), | 2793 EXPECT_EQ(profile.GetFieldText(ADDRESS_HOME_LINE1), |
| 2794 profile_a.GetFieldText(AutofillType(ADDRESS_HOME_LINE1))); | 2794 profile_a.GetFieldText(ADDRESS_HOME_LINE1)); |
| 2795 EXPECT_EQ(profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE2)), | 2795 EXPECT_EQ(profile.GetFieldText(ADDRESS_HOME_LINE2), |
| 2796 profile_a.GetFieldText(AutofillType(ADDRESS_HOME_LINE2))); | 2796 profile_a.GetFieldText(ADDRESS_HOME_LINE2)); |
| 2797 EXPECT_EQ(profile.GetFieldText(AutofillType(ADDRESS_HOME_CITY)), | 2797 EXPECT_EQ(profile.GetFieldText(ADDRESS_HOME_CITY), |
| 2798 profile_a.GetFieldText(AutofillType(ADDRESS_HOME_CITY))); | 2798 profile_a.GetFieldText(ADDRESS_HOME_CITY)); |
| 2799 EXPECT_EQ(profile.GetFieldText(AutofillType(ADDRESS_HOME_STATE)), | 2799 EXPECT_EQ(profile.GetFieldText(ADDRESS_HOME_STATE), |
| 2800 profile_a.GetFieldText(AutofillType(ADDRESS_HOME_STATE))); | 2800 profile_a.GetFieldText(ADDRESS_HOME_STATE)); |
| 2801 EXPECT_EQ(profile.GetFieldText(AutofillType(ADDRESS_HOME_ZIP)), | 2801 EXPECT_EQ(profile.GetFieldText(ADDRESS_HOME_ZIP), |
| 2802 profile_a.GetFieldText(AutofillType(ADDRESS_HOME_ZIP))); | 2802 profile_a.GetFieldText(ADDRESS_HOME_ZIP)); |
| 2803 EXPECT_EQ(profile.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)), | 2803 EXPECT_EQ(profile.GetFieldText(ADDRESS_HOME_COUNTRY), |
| 2804 profile_a.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY))); | 2804 profile_a.GetFieldText(ADDRESS_HOME_COUNTRY)); |
| 2805 EXPECT_EQ(profile_date_modified, profile_date_modified_a); | 2805 EXPECT_EQ(profile_date_modified, profile_date_modified_a); |
| 2806 | 2806 |
| 2807 sql::Statement s2( | 2807 sql::Statement s2( |
| 2808 connection.GetUniqueStatement( | 2808 connection.GetUniqueStatement( |
| 2809 "SELECT guid, name_on_card, expiration_month, " | 2809 "SELECT guid, name_on_card, expiration_month, " |
| 2810 "expiration_year, card_number_encrypted, date_modified " | 2810 "expiration_year, card_number_encrypted, date_modified " |
| 2811 "FROM credit_cards")); | 2811 "FROM credit_cards")); |
| 2812 ASSERT_TRUE(s2.Step()); | 2812 ASSERT_TRUE(s2.Step()); |
| 2813 | 2813 |
| 2814 CreditCard credit_card_a; | 2814 CreditCard credit_card_a; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3224 "SELECT country_code FROM autofill_profiles")); | 3224 "SELECT country_code FROM autofill_profiles")); |
| 3225 | 3225 |
| 3226 ASSERT_TRUE(s.Step()); | 3226 ASSERT_TRUE(s.Step()); |
| 3227 std::string country_code = s.ColumnString(0); | 3227 std::string country_code = s.ColumnString(0); |
| 3228 EXPECT_EQ("GB", country_code); | 3228 EXPECT_EQ("GB", country_code); |
| 3229 | 3229 |
| 3230 // Should have only one. | 3230 // Should have only one. |
| 3231 ASSERT_FALSE(s.Step()); | 3231 ASSERT_FALSE(s.Step()); |
| 3232 } | 3232 } |
| 3233 } | 3233 } |
| OLD | NEW |