OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 AutofillProfile* profile, | 37 AutofillProfile* profile, |
38 string16* label, | 38 string16* label, |
39 int* unique_id, | 39 int* unique_id, |
40 int64* date_modified) { | 40 int64* date_modified) { |
41 DCHECK(profile); | 41 DCHECK(profile); |
42 DCHECK(label); | 42 DCHECK(label); |
43 DCHECK(unique_id); | 43 DCHECK(unique_id); |
44 DCHECK(date_modified); | 44 DCHECK(date_modified); |
45 *label = s.ColumnString16(0); | 45 *label = s.ColumnString16(0); |
46 *unique_id = s.ColumnInt(1); | 46 *unique_id = s.ColumnInt(1); |
47 profile->SetInfo(NAME_FIRST, s.ColumnString16(2)); | 47 profile->SetRawInfo(NAME_FIRST, s.ColumnString16(2)); |
48 profile->SetInfo(NAME_MIDDLE, s.ColumnString16(3)); | 48 profile->SetRawInfo(NAME_MIDDLE, s.ColumnString16(3)); |
49 profile->SetInfo(NAME_LAST, s.ColumnString16(4)); | 49 profile->SetRawInfo(NAME_LAST, s.ColumnString16(4)); |
50 profile->SetInfo(EMAIL_ADDRESS, s.ColumnString16(5)); | 50 profile->SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(5)); |
51 profile->SetInfo(COMPANY_NAME, s.ColumnString16(6)); | 51 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(6)); |
52 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(7)); | 52 profile->SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(7)); |
53 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(8)); | 53 profile->SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(8)); |
54 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(9)); | 54 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(9)); |
55 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(10)); | 55 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(10)); |
56 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(11)); | 56 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(11)); |
57 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(12)); | 57 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(12)); |
58 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(13)); | 58 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(13)); |
59 *date_modified = s.ColumnInt64(15); | 59 *date_modified = s.ColumnInt64(15); |
60 profile->set_guid(s.ColumnString(16)); | 60 profile->set_guid(s.ColumnString(16)); |
61 EXPECT_TRUE(base::IsValidGUID(profile->guid())); | 61 EXPECT_TRUE(base::IsValidGUID(profile->guid())); |
62 } | 62 } |
63 | 63 |
64 void AutofillProfile33FromStatement(const sql::Statement& s, | 64 void AutofillProfile33FromStatement(const sql::Statement& s, |
65 AutofillProfile* profile, | 65 AutofillProfile* profile, |
66 int64* date_modified) { | 66 int64* date_modified) { |
67 DCHECK(profile); | 67 DCHECK(profile); |
68 DCHECK(date_modified); | 68 DCHECK(date_modified); |
69 profile->set_guid(s.ColumnString(0)); | 69 profile->set_guid(s.ColumnString(0)); |
70 EXPECT_TRUE(base::IsValidGUID(profile->guid())); | 70 EXPECT_TRUE(base::IsValidGUID(profile->guid())); |
71 profile->SetInfo(COMPANY_NAME, s.ColumnString16(1)); | 71 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(1)); |
72 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); | 72 profile->SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); |
73 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); | 73 profile->SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); |
74 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); | 74 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); |
75 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); | 75 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); |
76 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); | 76 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); |
77 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(7)); | 77 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(7)); |
78 *date_modified = s.ColumnInt64(8); | 78 *date_modified = s.ColumnInt64(8); |
79 } | 79 } |
80 | 80 |
81 void CreditCard31FromStatement(const sql::Statement& s, | 81 void CreditCard31FromStatement(const sql::Statement& s, |
82 CreditCard* credit_card, | 82 CreditCard* credit_card, |
83 string16* label, | 83 string16* label, |
84 int* unique_id, | 84 int* unique_id, |
85 std::string* encrypted_number, | 85 std::string* encrypted_number, |
86 int64* date_modified) { | 86 int64* date_modified) { |
87 DCHECK(credit_card); | 87 DCHECK(credit_card); |
88 DCHECK(label); | 88 DCHECK(label); |
89 DCHECK(unique_id); | 89 DCHECK(unique_id); |
90 DCHECK(encrypted_number); | 90 DCHECK(encrypted_number); |
91 DCHECK(date_modified); | 91 DCHECK(date_modified); |
92 *label = s.ColumnString16(0); | 92 *label = s.ColumnString16(0); |
93 *unique_id = s.ColumnInt(1); | 93 *unique_id = s.ColumnInt(1); |
94 credit_card->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(2)); | 94 credit_card->SetRawInfo(CREDIT_CARD_NAME, s.ColumnString16(2)); |
95 credit_card->SetInfo(CREDIT_CARD_TYPE, s.ColumnString16(3)); | 95 credit_card->SetRawInfo(CREDIT_CARD_TYPE, s.ColumnString16(3)); |
96 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(5)); | 96 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(5)); |
97 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(6)); | 97 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(6)); |
98 int encrypted_number_len = s.ColumnByteLength(10); | 98 int encrypted_number_len = s.ColumnByteLength(10); |
99 if (encrypted_number_len) { | 99 if (encrypted_number_len) { |
100 encrypted_number->resize(encrypted_number_len); | 100 encrypted_number->resize(encrypted_number_len); |
101 memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len); | 101 memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len); |
102 } | 102 } |
103 *date_modified = s.ColumnInt64(12); | 103 *date_modified = s.ColumnInt64(12); |
104 credit_card->set_guid(s.ColumnString(13)); | 104 credit_card->set_guid(s.ColumnString(13)); |
105 EXPECT_TRUE(base::IsValidGUID(credit_card->guid())); | 105 EXPECT_TRUE(base::IsValidGUID(credit_card->guid())); |
106 } | 106 } |
107 | 107 |
108 void CreditCard32FromStatement(const sql::Statement& s, | 108 void CreditCard32FromStatement(const sql::Statement& s, |
109 CreditCard* credit_card, | 109 CreditCard* credit_card, |
110 std::string* encrypted_number, | 110 std::string* encrypted_number, |
111 int64* date_modified) { | 111 int64* date_modified) { |
112 DCHECK(credit_card); | 112 DCHECK(credit_card); |
113 DCHECK(encrypted_number); | 113 DCHECK(encrypted_number); |
114 DCHECK(date_modified); | 114 DCHECK(date_modified); |
115 credit_card->set_guid(s.ColumnString(0)); | 115 credit_card->set_guid(s.ColumnString(0)); |
116 EXPECT_TRUE(base::IsValidGUID(credit_card->guid())); | 116 EXPECT_TRUE(base::IsValidGUID(credit_card->guid())); |
117 credit_card->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); | 117 credit_card->SetRawInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); |
118 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); | 118 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); |
119 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); | 119 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); |
120 int encrypted_number_len = s.ColumnByteLength(4); | 120 int encrypted_number_len = s.ColumnByteLength(4); |
121 if (encrypted_number_len) { | 121 if (encrypted_number_len) { |
122 encrypted_number->resize(encrypted_number_len); | 122 encrypted_number->resize(encrypted_number_len); |
123 memcpy(&(*encrypted_number)[0], s.ColumnBlob(4), encrypted_number_len); | 123 memcpy(&(*encrypted_number)[0], s.ColumnBlob(4), encrypted_number_len); |
124 } | 124 } |
125 *date_modified = s.ColumnInt64(5); | 125 *date_modified = s.ColumnInt64(5); |
126 } | 126 } |
127 | 127 |
128 } // anonymous namespace | 128 } // anonymous namespace |
129 | 129 |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 "SELECT guid, company_name, address_line_1, address_line_2, " | 805 "SELECT guid, company_name, address_line_1, address_line_2, " |
806 "city, state, zipcode, country, date_modified " | 806 "city, state, zipcode, country, date_modified " |
807 "FROM autofill_profiles")); | 807 "FROM autofill_profiles")); |
808 ASSERT_TRUE(s1.Step()); | 808 ASSERT_TRUE(s1.Step()); |
809 | 809 |
810 AutofillProfile profile_a; | 810 AutofillProfile profile_a; |
811 int64 profile_date_modified_a = 0; | 811 int64 profile_date_modified_a = 0; |
812 EXPECT_NO_FATAL_FAILURE(AutofillProfile33FromStatement( | 812 EXPECT_NO_FATAL_FAILURE(AutofillProfile33FromStatement( |
813 s1, &profile_a, &profile_date_modified_a)); | 813 s1, &profile_a, &profile_date_modified_a)); |
814 EXPECT_EQ(profile.guid(), profile_a.guid()); | 814 EXPECT_EQ(profile.guid(), profile_a.guid()); |
815 EXPECT_EQ(profile.GetInfo(COMPANY_NAME), | 815 EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), |
816 profile_a.GetInfo(COMPANY_NAME)); | 816 profile_a.GetRawInfo(COMPANY_NAME)); |
817 EXPECT_EQ(profile.GetInfo(ADDRESS_HOME_LINE1), | 817 EXPECT_EQ(profile.GetRawInfo(ADDRESS_HOME_LINE1), |
818 profile_a.GetInfo(ADDRESS_HOME_LINE1)); | 818 profile_a.GetRawInfo(ADDRESS_HOME_LINE1)); |
819 EXPECT_EQ(profile.GetInfo(ADDRESS_HOME_LINE2), | 819 EXPECT_EQ(profile.GetRawInfo(ADDRESS_HOME_LINE2), |
820 profile_a.GetInfo(ADDRESS_HOME_LINE2)); | 820 profile_a.GetRawInfo(ADDRESS_HOME_LINE2)); |
821 EXPECT_EQ(profile.GetInfo(ADDRESS_HOME_CITY), | 821 EXPECT_EQ(profile.GetRawInfo(ADDRESS_HOME_CITY), |
822 profile_a.GetInfo(ADDRESS_HOME_CITY)); | 822 profile_a.GetRawInfo(ADDRESS_HOME_CITY)); |
823 EXPECT_EQ(profile.GetInfo(ADDRESS_HOME_STATE), | 823 EXPECT_EQ(profile.GetRawInfo(ADDRESS_HOME_STATE), |
824 profile_a.GetInfo(ADDRESS_HOME_STATE)); | 824 profile_a.GetRawInfo(ADDRESS_HOME_STATE)); |
825 EXPECT_EQ(profile.GetInfo(ADDRESS_HOME_ZIP), | 825 EXPECT_EQ(profile.GetRawInfo(ADDRESS_HOME_ZIP), |
826 profile_a.GetInfo(ADDRESS_HOME_ZIP)); | 826 profile_a.GetRawInfo(ADDRESS_HOME_ZIP)); |
827 EXPECT_EQ(profile.GetInfo(ADDRESS_HOME_COUNTRY), | 827 EXPECT_EQ(profile.GetRawInfo(ADDRESS_HOME_COUNTRY), |
828 profile_a.GetInfo(ADDRESS_HOME_COUNTRY)); | 828 profile_a.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
829 EXPECT_EQ(profile_date_modified, profile_date_modified_a); | 829 EXPECT_EQ(profile_date_modified, profile_date_modified_a); |
830 | 830 |
831 sql::Statement s2( | 831 sql::Statement s2( |
832 connection.GetUniqueStatement( | 832 connection.GetUniqueStatement( |
833 "SELECT guid, name_on_card, expiration_month, " | 833 "SELECT guid, name_on_card, expiration_month, " |
834 "expiration_year, card_number_encrypted, date_modified " | 834 "expiration_year, card_number_encrypted, date_modified " |
835 "FROM credit_cards")); | 835 "FROM credit_cards")); |
836 ASSERT_TRUE(s2.Step()); | 836 ASSERT_TRUE(s2.Step()); |
837 | 837 |
838 CreditCard credit_card_a; | 838 CreditCard credit_card_a; |
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2305 // Check version. | 2305 // Check version. |
2306 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 2306 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
2307 | 2307 |
2308 // A new column should have been created. | 2308 // A new column should have been created. |
2309 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls")); | 2309 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls")); |
2310 | 2310 |
2311 // The backup table should be gone. | 2311 // The backup table should be gone. |
2312 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); | 2312 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); |
2313 } | 2313 } |
2314 } | 2314 } |
OLD | NEW |