OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
11 | 11 |
12 #include "app/sql/statement.h" | 12 #include "app/sql/statement.h" |
| 13 #include "base/guid.h" |
13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
16 #include "base/stl_util-inl.h" | 17 #include "base/stl_util-inl.h" |
17 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
18 #include "base/string16.h" | 19 #include "base/string16.h" |
19 #include "base/time.h" | 20 #include "base/time.h" |
20 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 #include "chrome/browser/autofill/autofill_profile.h" | 23 #include "chrome/browser/autofill/autofill_profile.h" |
23 #include "chrome/browser/autofill/autofill_type.h" | 24 #include "chrome/browser/autofill/autofill_type.h" |
24 #include "chrome/browser/autofill/credit_card.h" | 25 #include "chrome/browser/autofill/credit_card.h" |
25 #include "chrome/browser/guid.h" | |
26 #include "chrome/browser/search_engines/template_url.h" | 26 #include "chrome/browser/search_engines/template_url.h" |
27 #include "chrome/browser/password_manager/encryptor.h" | 27 #include "chrome/browser/password_manager/encryptor.h" |
28 #include "chrome/browser/webdata/autofill_change.h" | 28 #include "chrome/browser/webdata/autofill_change.h" |
29 #include "chrome/browser/webdata/autofill_entry.h" | 29 #include "chrome/browser/webdata/autofill_entry.h" |
30 #include "chrome/browser/webdata/web_database.h" | 30 #include "chrome/browser/webdata/web_database.h" |
31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/test/ui_test_utils.h" | 32 #include "chrome/test/ui_test_utils.h" |
33 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "webkit/glue/form_field.h" | 35 #include "webkit/glue/form_field.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), s.ColumnString16(7)); | 113 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), s.ColumnString16(7)); |
114 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), s.ColumnString16(8)); | 114 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), s.ColumnString16(8)); |
115 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(9)); | 115 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(9)); |
116 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(10)); | 116 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(10)); |
117 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), s.ColumnString16(11)); | 117 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), s.ColumnString16(11)); |
118 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(12)); | 118 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(12)); |
119 profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(13)); | 119 profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(13)); |
120 profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(14)); | 120 profile->SetInfo(AutoFillType(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(base::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(base::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(AutoFillType(NAME_FIRST), s.ColumnString16(2)); |
137 profile->SetInfo(AutoFillType(NAME_MIDDLE), s.ColumnString16(3)); | 137 profile->SetInfo(AutoFillType(NAME_MIDDLE), s.ColumnString16(3)); |
138 profile->SetInfo(AutoFillType(NAME_LAST),s.ColumnString16(4)); | 138 profile->SetInfo(AutoFillType(NAME_LAST),s.ColumnString16(4)); |
139 profile->SetInfo(AutoFillType(EMAIL_ADDRESS), s.ColumnString16(5)); | 139 profile->SetInfo(AutoFillType(EMAIL_ADDRESS), s.ColumnString16(5)); |
140 profile->SetInfo(AutoFillType(COMPANY_NAME), s.ColumnString16(6)); | 140 profile->SetInfo(AutoFillType(COMPANY_NAME), s.ColumnString16(6)); |
141 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), s.ColumnString16(7)); | 141 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), s.ColumnString16(7)); |
142 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), s.ColumnString16(8)); | 142 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), s.ColumnString16(8)); |
143 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(9)); | 143 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(9)); |
144 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(10)); | 144 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(10)); |
(...skipping 23 matching lines...) Expand all Loading... |
168 s.ColumnString16(5)); | 168 s.ColumnString16(5)); |
169 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 169 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
170 s.ColumnString16(6)); | 170 s.ColumnString16(6)); |
171 int encrypted_number_len = s.ColumnByteLength(10); | 171 int encrypted_number_len = s.ColumnByteLength(10); |
172 if (encrypted_number_len) { | 172 if (encrypted_number_len) { |
173 encrypted_number->resize(encrypted_number_len); | 173 encrypted_number->resize(encrypted_number_len); |
174 memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len); | 174 memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len); |
175 } | 175 } |
176 *date_modified = s.ColumnInt64(12); | 176 *date_modified = s.ColumnInt64(12); |
177 credit_card->set_guid(s.ColumnString(13)); | 177 credit_card->set_guid(s.ColumnString(13)); |
178 EXPECT_TRUE(guid::IsValidGUID(credit_card->guid())); | 178 EXPECT_TRUE(base::IsValidGUID(credit_card->guid())); |
179 } | 179 } |
180 | 180 |
181 void CreditCard32FromStatement(const sql::Statement& s, | 181 void CreditCard32FromStatement(const sql::Statement& s, |
182 CreditCard* credit_card, | 182 CreditCard* credit_card, |
183 string16* label, | 183 string16* label, |
184 std::string* encrypted_number, | 184 std::string* encrypted_number, |
185 int64* date_modified) { | 185 int64* date_modified) { |
186 DCHECK(credit_card); | 186 DCHECK(credit_card); |
187 DCHECK(label); | 187 DCHECK(label); |
188 DCHECK(encrypted_number); | 188 DCHECK(encrypted_number); |
189 DCHECK(date_modified); | 189 DCHECK(date_modified); |
190 credit_card->set_guid(s.ColumnString(0)); | 190 credit_card->set_guid(s.ColumnString(0)); |
191 EXPECT_TRUE(guid::IsValidGUID(credit_card->guid())); | 191 EXPECT_TRUE(base::IsValidGUID(credit_card->guid())); |
192 *label = s.ColumnString16(1); | 192 *label = s.ColumnString16(1); |
193 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), s.ColumnString16(2)); | 193 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), s.ColumnString16(2)); |
194 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), | 194 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), |
195 s.ColumnString16(3)); | 195 s.ColumnString16(3)); |
196 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 196 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
197 s.ColumnString16(4)); | 197 s.ColumnString16(4)); |
198 int encrypted_number_len = s.ColumnByteLength(5); | 198 int encrypted_number_len = s.ColumnByteLength(5); |
199 if (encrypted_number_len) { | 199 if (encrypted_number_len) { |
200 encrypted_number->resize(encrypted_number_len); | 200 encrypted_number->resize(encrypted_number_len); |
201 memcpy(&(*encrypted_number)[0], s.ColumnBlob(5), encrypted_number_len); | 201 memcpy(&(*encrypted_number)[0], s.ColumnBlob(5), encrypted_number_len); |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 EXPECT_FALSE(s_home.Step()); | 1433 EXPECT_FALSE(s_home.Step()); |
1434 delete db_profile; | 1434 delete db_profile; |
1435 | 1435 |
1436 // Add a 'Billing' profile. | 1436 // Add a 'Billing' profile. |
1437 AutoFillProfile billing_profile = home_profile; | 1437 AutoFillProfile billing_profile = home_profile; |
1438 billing_profile.set_label(ASCIIToUTF16("Billing")); | 1438 billing_profile.set_label(ASCIIToUTF16("Billing")); |
1439 billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), | 1439 billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), |
1440 ASCIIToUTF16("5678 Bottom Street")); | 1440 ASCIIToUTF16("5678 Bottom Street")); |
1441 billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), | 1441 billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), |
1442 ASCIIToUTF16("suite 3")); | 1442 ASCIIToUTF16("suite 3")); |
1443 billing_profile.set_guid(guid::GenerateGUID()); | 1443 billing_profile.set_guid(base::GenerateGUID()); |
1444 | 1444 |
1445 pre_creation_time = Time::Now(); | 1445 pre_creation_time = Time::Now(); |
1446 EXPECT_TRUE(db.AddAutoFillProfile(billing_profile)); | 1446 EXPECT_TRUE(db.AddAutoFillProfile(billing_profile)); |
1447 post_creation_time = Time::Now(); | 1447 post_creation_time = Time::Now(); |
1448 | 1448 |
1449 // Get the 'Billing' profile. | 1449 // Get the 'Billing' profile. |
1450 ASSERT_TRUE(db.GetAutoFillProfileForLabel(ASCIIToUTF16("Billing"), | 1450 ASSERT_TRUE(db.GetAutoFillProfileForLabel(ASCIIToUTF16("Billing"), |
1451 &db_profile)); | 1451 &db_profile)); |
1452 EXPECT_EQ(billing_profile, *db_profile); | 1452 EXPECT_EQ(billing_profile, *db_profile); |
1453 sql::Statement s_billing(db.db_.GetUniqueStatement( | 1453 sql::Statement s_billing(db.db_.GetUniqueStatement( |
(...skipping 29 matching lines...) Expand all Loading... |
1483 EXPECT_FALSE(db.GetAutoFillProfileForLabel(ASCIIToUTF16("Billing"), | 1483 EXPECT_FALSE(db.GetAutoFillProfileForLabel(ASCIIToUTF16("Billing"), |
1484 &db_profile)); | 1484 &db_profile)); |
1485 | 1485 |
1486 // Add a 'GUID' profile. | 1486 // Add a 'GUID' profile. |
1487 AutoFillProfile guid_profile = home_profile; | 1487 AutoFillProfile guid_profile = home_profile; |
1488 guid_profile.set_label(ASCIIToUTF16("GUID")); | 1488 guid_profile.set_label(ASCIIToUTF16("GUID")); |
1489 guid_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), | 1489 guid_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), |
1490 ASCIIToUTF16("5678 Top Street")); | 1490 ASCIIToUTF16("5678 Top Street")); |
1491 guid_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), | 1491 guid_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), |
1492 ASCIIToUTF16("suite 4")); | 1492 ASCIIToUTF16("suite 4")); |
1493 guid_profile.set_guid(guid::GenerateGUID()); | 1493 guid_profile.set_guid(base::GenerateGUID()); |
1494 | 1494 |
1495 EXPECT_TRUE(db.AddAutoFillProfile(guid_profile)); | 1495 EXPECT_TRUE(db.AddAutoFillProfile(guid_profile)); |
1496 ASSERT_TRUE(db.GetAutoFillProfileForGUID(guid_profile.guid(), | 1496 ASSERT_TRUE(db.GetAutoFillProfileForGUID(guid_profile.guid(), |
1497 &db_profile)); | 1497 &db_profile)); |
1498 EXPECT_EQ(guid_profile, *db_profile); | 1498 EXPECT_EQ(guid_profile, *db_profile); |
1499 delete db_profile; | 1499 delete db_profile; |
1500 | 1500 |
1501 // Update the 'GUID' profile. | 1501 // Update the 'GUID' profile. |
1502 guid_profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Jimmy")); | 1502 guid_profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Jimmy")); |
1503 EXPECT_TRUE(db.UpdateAutoFillProfile(guid_profile)); | 1503 EXPECT_TRUE(db.UpdateAutoFillProfile(guid_profile)); |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2685 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid")); | 2685 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid")); |
2686 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "guid")); | 2686 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "guid")); |
2687 | 2687 |
2688 // Check that guids are non-null, non-empty, conforms to guid format, and | 2688 // Check that guids are non-null, non-empty, conforms to guid format, and |
2689 // are different. | 2689 // are different. |
2690 sql::Statement s( | 2690 sql::Statement s( |
2691 connection.GetUniqueStatement("SELECT guid FROM autofill_profiles")); | 2691 connection.GetUniqueStatement("SELECT guid FROM autofill_profiles")); |
2692 | 2692 |
2693 ASSERT_TRUE(s.Step()); | 2693 ASSERT_TRUE(s.Step()); |
2694 std::string guid1 = s.ColumnString(0); | 2694 std::string guid1 = s.ColumnString(0); |
2695 EXPECT_TRUE(guid::IsValidGUID(guid1)); | 2695 EXPECT_TRUE(base::IsValidGUID(guid1)); |
2696 | 2696 |
2697 ASSERT_TRUE(s.Step()); | 2697 ASSERT_TRUE(s.Step()); |
2698 std::string guid2 = s.ColumnString(0); | 2698 std::string guid2 = s.ColumnString(0); |
2699 EXPECT_TRUE(guid::IsValidGUID(guid2)); | 2699 EXPECT_TRUE(base::IsValidGUID(guid2)); |
2700 | 2700 |
2701 EXPECT_NE(guid1, guid2); | 2701 EXPECT_NE(guid1, guid2); |
2702 } | 2702 } |
2703 } | 2703 } |
2704 | 2704 |
2705 // Removes unique IDs and make GUIDs the primary key. Also removes unused | 2705 // Removes unique IDs and make GUIDs the primary key. Also removes unused |
2706 // columns. | 2706 // columns. |
2707 TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) { | 2707 TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) { |
2708 // Initialize the database. | 2708 // Initialize the database. |
2709 ASSERT_NO_FATAL_FAILURE( | 2709 ASSERT_NO_FATAL_FAILURE( |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2833 &credit_card_a, | 2833 &credit_card_a, |
2834 &cc_label_a, | 2834 &cc_label_a, |
2835 &cc_number_encrypted_a, | 2835 &cc_number_encrypted_a, |
2836 &cc_date_modified_a)); | 2836 &cc_date_modified_a)); |
2837 EXPECT_EQ(credit_card, credit_card_a); | 2837 EXPECT_EQ(credit_card, credit_card_a); |
2838 EXPECT_EQ(cc_label, cc_label_a); | 2838 EXPECT_EQ(cc_label, cc_label_a); |
2839 EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a); | 2839 EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a); |
2840 EXPECT_EQ(cc_date_modified, cc_date_modified_a); | 2840 EXPECT_EQ(cc_date_modified, cc_date_modified_a); |
2841 } | 2841 } |
2842 } | 2842 } |
OLD | NEW |