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

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: Initial upload. 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
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 168 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 802 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

Powered by Google App Engine
This is Rietveld 408576698