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

Side by Side Diff: chrome/browser/webdata/web_database_migration_unittest.cc

Issue 7232023: Added last_modified field to TemplateURL and database. Updated unit tests, including refactoring ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/webdata/web_database.cc ('k') | chrome/test/data/web_database/version_37.sql » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "app/sql/statement.h" 7 #include "app/sql/statement.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 23 matching lines...) Expand all
34 int* unique_id, 34 int* unique_id,
35 int64* date_modified) { 35 int64* date_modified) {
36 DCHECK(profile); 36 DCHECK(profile);
37 DCHECK(label); 37 DCHECK(label);
38 DCHECK(unique_id); 38 DCHECK(unique_id);
39 DCHECK(date_modified); 39 DCHECK(date_modified);
40 *label = s.ColumnString16(0); 40 *label = s.ColumnString16(0);
41 *unique_id = s.ColumnInt(1); 41 *unique_id = s.ColumnInt(1);
42 profile->SetInfo(NAME_FIRST, s.ColumnString16(2)); 42 profile->SetInfo(NAME_FIRST, s.ColumnString16(2));
43 profile->SetInfo(NAME_MIDDLE, s.ColumnString16(3)); 43 profile->SetInfo(NAME_MIDDLE, s.ColumnString16(3));
44 profile->SetInfo(NAME_LAST,s.ColumnString16(4)); 44 profile->SetInfo(NAME_LAST, s.ColumnString16(4));
45 profile->SetInfo(EMAIL_ADDRESS, s.ColumnString16(5)); 45 profile->SetInfo(EMAIL_ADDRESS, s.ColumnString16(5));
46 profile->SetInfo(COMPANY_NAME, s.ColumnString16(6)); 46 profile->SetInfo(COMPANY_NAME, s.ColumnString16(6));
47 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(7)); 47 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(7));
48 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(8)); 48 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(8));
49 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(9)); 49 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(9));
50 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(10)); 50 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(10));
51 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(11)); 51 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(11));
52 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(12)); 52 profile->SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(12));
53 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(13)); 53 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(13));
54 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, s.ColumnString16(14)); 54 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, s.ColumnString16(14));
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 // Assertion testing for migrating from version 27 and 28. 180 // Assertion testing for migrating from version 27 and 28.
181 void MigrateVersion28Assertions(); 181 void MigrateVersion28Assertions();
182 182
183 private: 183 private:
184 ScopedTempDir temp_dir_; 184 ScopedTempDir temp_dir_;
185 185
186 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); 186 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
187 }; 187 };
188 188
189 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 37; 189 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 38;
190 190
191 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { 191 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) {
192 std::string contents; 192 std::string contents;
193 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); 193 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents));
194 194
195 sql::Connection connection; 195 sql::Connection connection;
196 ASSERT_TRUE(connection.Open(GetDatabasePath())); 196 ASSERT_TRUE(connection.Open(GetDatabasePath()));
197 ASSERT_TRUE(connection.Execute(contents.data())); 197 ASSERT_TRUE(connection.Execute(contents.data()));
198 } 198 }
199 199
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 447
448 // Verify post-conditions. These are expectations for current version of the 448 // Verify post-conditions. These are expectations for current version of the
449 // database. 449 // database.
450 { 450 {
451 sql::Connection connection; 451 sql::Connection connection;
452 ASSERT_TRUE(connection.Open(GetDatabasePath())); 452 ASSERT_TRUE(connection.Open(GetDatabasePath()));
453 453
454 // Check version. 454 // Check version.
455 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 455 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
456 456
457 // |keywords| |logo_id| column should have been added. 457 // |keywords| |created_by_policy| column should have been added.
458 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); 458 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
459 EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy")); 459 EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy"));
460 } 460 }
461 } 461 }
462 462
463 // Tests that the credit_cards.billing_address column is changed from a string 463 // Tests that the credit_cards.billing_address column is changed from a string
464 // to an int whilst preserving the associated billing address. This version of 464 // to an int whilst preserving the associated billing address. This version of
465 // the test makes sure a stored label is converted to an ID. 465 // the test makes sure a stored label is converted to an ID.
466 TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) { 466 TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) {
467 // This schema is taken from a build prior to the change of column type for 467 // This schema is taken from a build prior to the change of column type for
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 580
581 // Verify post-conditions. These are expectations for current version of the 581 // Verify post-conditions. These are expectations for current version of the
582 // database. 582 // database.
583 { 583 {
584 sql::Connection connection; 584 sql::Connection connection;
585 ASSERT_TRUE(connection.Open(GetDatabasePath())); 585 ASSERT_TRUE(connection.Open(GetDatabasePath()));
586 586
587 // Check version. 587 // Check version.
588 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 588 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
589 589
590 // |keywords| |logo_id| column should have been added. 590 // |keywords| |created_by_policy| column should have been added.
591 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); 591 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
592 EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy")); 592 EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy"));
593 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address")); 593 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address"));
594 594
595 // Verify the credit card data is converted. 595 // Verify the credit card data is converted.
596 sql::Statement s(connection.GetUniqueStatement( 596 sql::Statement s(connection.GetUniqueStatement(
597 "SELECT guid, name_on_card, expiration_month, expiration_year, " 597 "SELECT guid, name_on_card, expiration_month, expiration_year, "
598 "card_number_encrypted, date_modified " 598 "card_number_encrypted, date_modified "
599 "FROM credit_cards")); 599 "FROM credit_cards"));
600 ASSERT_TRUE(s.Step()); 600 ASSERT_TRUE(s.Step());
601 EXPECT_EQ("Jack", s.ColumnString(1)); 601 EXPECT_EQ("Jack", s.ColumnString(1));
602 EXPECT_EQ(2, s.ColumnInt(2)); 602 EXPECT_EQ(2, s.ColumnInt(2));
603 EXPECT_EQ(2012, s.ColumnInt(3)); 603 EXPECT_EQ(2012, s.ColumnInt(3));
604 // Column 5 is encrypted credit card number blob. 604 // Column 5 is encrypted credit card number blo b.
605 // Column 6 is date_modified. 605 // Column 6 is date_modified.
606 } 606 }
607 } 607 }
608 608
609 // Tests migration from 27->current. This test is now the same as 28->current 609 // Tests migration from 27->current. This test is now the same as 28->current
610 // as the column added in 28 was nuked in 29. 610 // as the column added in 28 was nuked in 29.
611 TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) { 611 TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) {
612 // Initialize the database. 612 // Initialize the database.
613 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_27.sql"))); 613 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_27.sql")));
614 614
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 1162
1163 // John Doe phone. 1163 // John Doe phone.
1164 ASSERT_TRUE(s4.Step()); 1164 ASSERT_TRUE(s4.Step());
1165 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s4.ColumnString(0)); 1165 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s4.ColumnString(0));
1166 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone. 1166 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone.
1167 EXPECT_EQ(ASCIIToUTF16("4151112222"), s4.ColumnString16(2)); 1167 EXPECT_EQ(ASCIIToUTF16("4151112222"), s4.ColumnString16(2));
1168 1168
1169 // John Doe fax. 1169 // John Doe fax.
1170 ASSERT_TRUE(s4.Step()); 1170 ASSERT_TRUE(s4.Step());
1171 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s4.ColumnString(0)); 1171 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s4.ColumnString(0));
1172 EXPECT_EQ(1, s4.ColumnInt(1)); // 1 means phone. 1172 EXPECT_EQ(1, s4.ColumnInt(1)); // 1 means phone.
1173 EXPECT_EQ(ASCIIToUTF16("4153334444"), s4.ColumnString16(2)); 1173 EXPECT_EQ(ASCIIToUTF16("4153334444"), s4.ColumnString16(2));
1174 1174
1175 // John P. Doe phone. 1175 // John P. Doe phone.
1176 // Gets culled during migration from 35 to 37 due to merging of John Doe and 1176 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1177 // John P. Doe addresses. 1177 // John P. Doe addresses.
1178 1178
1179 // John P. Doe fax. 1179 // John P. Doe fax.
1180 // Gets culled during migration from 35 to 37 due to merging of John Doe and 1180 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1181 // John P. Doe addresses. 1181 // John P. Doe addresses.
1182 1182
1183 // 2 Main Street phone. 1183 // 2 Main Street phone.
1184 ASSERT_TRUE(s4.Step()); 1184 ASSERT_TRUE(s4.Step());
1185 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s4.ColumnString(0)); 1185 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s4.ColumnString(0));
1186 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone. 1186 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone.
1187 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2)); 1187 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2));
1188 1188
1189 // 2 Main Street fax. 1189 // 2 Main Street fax.
1190 ASSERT_TRUE(s4.Step()); 1190 ASSERT_TRUE(s4.Step());
1191 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s4.ColumnString(0)); 1191 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s4.ColumnString(0));
1192 EXPECT_EQ(1, s4.ColumnInt(1)); // 1 means fax. 1192 EXPECT_EQ(1, s4.ColumnInt(1)); // 1 means fax.
1193 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2)); 1193 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2));
1194 1194
1195 // 2 Main St phone. 1195 // 2 Main St phone.
1196 ASSERT_TRUE(s4.Step()); 1196 ASSERT_TRUE(s4.Step());
1197 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s4.ColumnString(0)); 1197 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s4.ColumnString(0));
1198 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone. 1198 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone.
1199 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2)); 1199 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2));
1200 1200
1201 // 2 Main St fax. 1201 // 2 Main St fax.
1202 ASSERT_TRUE(s4.Step()); 1202 ASSERT_TRUE(s4.Step());
1203 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s4.ColumnString(0)); 1203 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s4.ColumnString(0));
1204 EXPECT_EQ(1, s4.ColumnInt(1)); // 1 means fax. 1204 EXPECT_EQ(1, s4.ColumnInt(1)); // 1 means fax.
1205 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2)); 1205 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2));
1206 1206
1207 // Note no phone or fax for Alfred E Newman. 1207 // Note no phone or fax for Alfred E Newman.
1208 1208
1209 // 3 Main St phone. 1209 // 3 Main St phone.
1210 ASSERT_TRUE(s4.Step()); 1210 ASSERT_TRUE(s4.Step());
1211 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s4.ColumnString(0)); 1211 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s4.ColumnString(0));
1212 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone. 1212 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone.
1213 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2)); 1213 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2));
1214 1214
1215 // 2 Main St fax. 1215 // 2 Main St fax.
1216 ASSERT_TRUE(s4.Step()); 1216 ASSERT_TRUE(s4.Step());
1217 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s4.ColumnString(0)); 1217 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s4.ColumnString(0));
1218 EXPECT_EQ(1, s4.ColumnInt(1)); // 1 means fax. 1218 EXPECT_EQ(1, s4.ColumnInt(1)); // 1 means fax.
1219 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2)); 1219 EXPECT_EQ(ASCIIToUTF16(""), s4.ColumnString16(2));
1220 1220
1221 // Should be all. 1221 // Should be all.
1222 EXPECT_FALSE(s4.Step()); 1222 EXPECT_FALSE(s4.Step());
1223 } 1223 }
1224 } 1224 }
1225 1225
1226 // Adds a column for the autofill profile's country code. 1226 // Adds a column for the autofill profile's country code.
1227 TEST_F(WebDatabaseMigrationTest, MigrateVersion33ToCurrent) { 1227 TEST_F(WebDatabaseMigrationTest, MigrateVersion33ToCurrent) {
1228 // Initialize the database. 1228 // Initialize the database.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 ASSERT_TRUE(s2.Step()); 1417 ASSERT_TRUE(s2.Step());
1418 EXPECT_EQ("00000000-0000-0000-0000-000000000005", s2.ColumnString(0)); 1418 EXPECT_EQ("00000000-0000-0000-0000-000000000005", s2.ColumnString(0));
1419 1419
1420 ASSERT_TRUE(s2.Step()); 1420 ASSERT_TRUE(s2.Step());
1421 EXPECT_EQ("00000000-0000-0000-0000-000000000006", s2.ColumnString(0)); 1421 EXPECT_EQ("00000000-0000-0000-0000-000000000006", s2.ColumnString(0));
1422 1422
1423 // That should be it. 1423 // That should be it.
1424 ASSERT_FALSE(s2.Step()); 1424 ASSERT_FALSE(s2.Step());
1425 } 1425 }
1426 } 1426 }
1427
1428 // Tests that the |keywords| |last_modified| column gets added to the schema for
1429 // a version 37 database.
1430 TEST_F(WebDatabaseMigrationTest, MigrateVersion37ToCurrent) {
1431 // This schema is taken from a build prior to the addition of the |keywords|
1432 // |last_modified| column.
1433 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_37.sql")));
1434
1435 // Verify pre-conditions. These are expectations for version 37 of the
1436 // database.
1437 {
1438 sql::Connection connection;
1439 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1440
1441 // Columns existing and not existing before current version.
1442 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id"));
1443 ASSERT_FALSE(connection.DoesColumnExist("keywords", "last_modified"));
1444 }
1445
1446 // Load the database via the WebDatabase class and migrate the database to
1447 // the current version.
1448 {
1449 WebDatabase db;
1450 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath()));
1451 }
1452
1453 // Verify post-conditions. These are expectations for current version of the
1454 // database.
1455 {
1456 sql::Connection connection;
1457 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1458
1459 // Check version.
1460 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1461
1462 // |keywords| |last_modified| column should have been added.
1463 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
1464 EXPECT_TRUE(connection.DoesColumnExist("keywords", "last_modified"));
1465 }
1466 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_database.cc ('k') | chrome/test/data/web_database/version_37.sql » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698