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/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "base/string16.h" | 12 #include "base/string16.h" |
12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
13 #include "base/time.h" | 14 #include "base/time.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/autofill/autofill_profile.h" | 17 #include "chrome/browser/autofill/autofill_profile.h" |
17 #include "chrome/browser/autofill/autofill_type.h" | 18 #include "chrome/browser/autofill/autofill_type.h" |
18 #include "chrome/browser/autofill/credit_card.h" | 19 #include "chrome/browser/autofill/credit_card.h" |
19 #include "chrome/browser/webdata/autofill_change.h" | 20 #include "chrome/browser/webdata/autofill_change.h" |
20 #include "chrome/browser/webdata/autofill_entry.h" | 21 #include "chrome/browser/webdata/autofill_entry.h" |
21 #include "chrome/browser/webdata/keyword_table.h" | 22 #include "chrome/browser/webdata/keyword_table.h" |
22 #include "chrome/browser/webdata/web_database.h" | 23 #include "chrome/browser/webdata/web_database.h" |
23 #include "chrome/browser/webdata/web_intents_table.h" | 24 #include "chrome/browser/webdata/web_intents_table.h" |
24 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/guid.h" | |
26 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
27 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
28 #include "sql/statement.h" | 28 #include "sql/statement.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 | 30 |
31 using base::Time; | 31 using base::Time; |
32 using content::BrowserThread; | 32 using content::BrowserThread; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
(...skipping 15 matching lines...) Expand all Loading... |
51 profile->SetInfo(COMPANY_NAME, s.ColumnString16(6)); | 51 profile->SetInfo(COMPANY_NAME, s.ColumnString16(6)); |
52 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(7)); | 52 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(7)); |
53 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(8)); | 53 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(8)); |
54 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(9)); | 54 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(9)); |
55 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(10)); | 55 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(10)); |
56 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(11)); | 56 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(11)); |
57 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(12)); | 57 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(12)); |
58 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(13)); | 58 profile->SetInfo(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(guid::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(guid::IsValidGUID(profile->guid())); | 70 EXPECT_TRUE(base::IsValidGUID(profile->guid())); |
71 profile->SetInfo(COMPANY_NAME, s.ColumnString16(1)); | 71 profile->SetInfo(COMPANY_NAME, s.ColumnString16(1)); |
72 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); | 72 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); |
73 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); | 73 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); |
74 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); | 74 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); |
75 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); | 75 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); |
76 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); | 76 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); |
77 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(7)); | 77 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(7)); |
78 *date_modified = s.ColumnInt64(8); | 78 *date_modified = s.ColumnInt64(8); |
79 } | 79 } |
80 | 80 |
(...skipping 14 matching lines...) Expand all Loading... |
95 credit_card->SetInfo(CREDIT_CARD_TYPE, s.ColumnString16(3)); | 95 credit_card->SetInfo(CREDIT_CARD_TYPE, s.ColumnString16(3)); |
96 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(5)); | 96 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(5)); |
97 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(6)); | 97 credit_card->SetInfo(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(guid::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(guid::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->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); |
118 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); | 118 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); |
119 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); | 119 credit_card->SetInfo(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 } |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid")); | 686 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid")); |
687 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "guid")); | 687 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "guid")); |
688 | 688 |
689 // Check that guids are non-null, non-empty, conforms to guid format, and | 689 // Check that guids are non-null, non-empty, conforms to guid format, and |
690 // are different. | 690 // are different. |
691 sql::Statement s( | 691 sql::Statement s( |
692 connection.GetUniqueStatement("SELECT guid FROM autofill_profiles")); | 692 connection.GetUniqueStatement("SELECT guid FROM autofill_profiles")); |
693 | 693 |
694 ASSERT_TRUE(s.Step()); | 694 ASSERT_TRUE(s.Step()); |
695 std::string guid1 = s.ColumnString(0); | 695 std::string guid1 = s.ColumnString(0); |
696 EXPECT_TRUE(guid::IsValidGUID(guid1)); | 696 EXPECT_TRUE(base::IsValidGUID(guid1)); |
697 | 697 |
698 ASSERT_TRUE(s.Step()); | 698 ASSERT_TRUE(s.Step()); |
699 std::string guid2 = s.ColumnString(0); | 699 std::string guid2 = s.ColumnString(0); |
700 EXPECT_TRUE(guid::IsValidGUID(guid2)); | 700 EXPECT_TRUE(base::IsValidGUID(guid2)); |
701 | 701 |
702 EXPECT_NE(guid1, guid2); | 702 EXPECT_NE(guid1, guid2); |
703 } | 703 } |
704 } | 704 } |
705 | 705 |
706 // Removes unique IDs and make GUIDs the primary key. Also removes unused | 706 // Removes unique IDs and make GUIDs the primary key. Also removes unused |
707 // columns. | 707 // columns. |
708 TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) { | 708 TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) { |
709 // Initialize the database. | 709 // Initialize the database. |
710 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_31.sql"))); | 710 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_31.sql"))); |
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2164 | 2164 |
2165 // We were able to create the new tables, but unable to copy any data | 2165 // We were able to create the new tables, but unable to copy any data |
2166 // Given the initial bad state of the tables. | 2166 // Given the initial bad state of the tables. |
2167 ASSERT_FALSE(s2.Step()); | 2167 ASSERT_FALSE(s2.Step()); |
2168 | 2168 |
2169 // Finally ensure the migration code cleaned up after itself. | 2169 // Finally ensure the migration code cleaned up after itself. |
2170 EXPECT_FALSE(connection.DoesTableExist("old_web_intents")); | 2170 EXPECT_FALSE(connection.DoesTableExist("old_web_intents")); |
2171 EXPECT_FALSE(connection.DoesTableExist("old_web_intents_defaults")); | 2171 EXPECT_FALSE(connection.DoesTableExist("old_web_intents_defaults")); |
2172 } | 2172 } |
2173 } | 2173 } |
OLD | NEW |