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/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); | 118 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); |
119 credit_card->SetRawInfo(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 void CheckHasBackupData(sql::MetaTable* meta_table) { |
| 129 std::string value; |
| 130 EXPECT_TRUE(meta_table->GetValue( |
| 131 "Default Search Provider ID Backup", &value)); |
| 132 EXPECT_TRUE(meta_table->GetValue( |
| 133 "Default Search Provider ID Backup Signature", &value)); |
| 134 } |
| 135 |
| 136 void CheckNoBackupData(const sql::Connection& connection, |
| 137 sql::MetaTable* meta_table) { |
| 138 std::string value; |
| 139 EXPECT_FALSE(meta_table->GetValue( |
| 140 "Default Search Provider ID Backup", &value)); |
| 141 EXPECT_FALSE(meta_table->GetValue( |
| 142 "Default Search Provider ID Backup Signature", &value)); |
| 143 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); |
| 144 } |
| 145 |
128 } // anonymous namespace | 146 } // anonymous namespace |
129 | 147 |
130 // The WebDatabaseMigrationTest encapsulates testing of database migrations. | 148 // The WebDatabaseMigrationTest encapsulates testing of database migrations. |
131 // Specifically, these tests are intended to exercise any schema changes in | 149 // Specifically, these tests are intended to exercise any schema changes in |
132 // the WebDatabase and data migrations that occur in | 150 // the WebDatabase and data migrations that occur in |
133 // |WebDatabase::MigrateOldVersionsAsNeeded()|. | 151 // |WebDatabase::MigrateOldVersionsAsNeeded()|. |
134 class WebDatabaseMigrationTest : public testing::Test { | 152 class WebDatabaseMigrationTest : public testing::Test { |
135 public: | 153 public: |
136 // In order to access the application locale -- which the tested functions do | 154 // In order to access the application locale -- which the tested functions do |
137 // internally -- this test must run on the UI thread. | 155 // internally -- this test must run on the UI thread. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void LoadDatabase(const FilePath::StringType& file); | 206 void LoadDatabase(const FilePath::StringType& file); |
189 | 207 |
190 private: | 208 private: |
191 MessageLoopForUI message_loop_for_ui_; | 209 MessageLoopForUI message_loop_for_ui_; |
192 content::TestBrowserThread ui_thread_; | 210 content::TestBrowserThread ui_thread_; |
193 base::ScopedTempDir temp_dir_; | 211 base::ScopedTempDir temp_dir_; |
194 | 212 |
195 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 213 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
196 }; | 214 }; |
197 | 215 |
198 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 47; | 216 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 48; |
199 | 217 |
200 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { | 218 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { |
201 std::string contents; | 219 std::string contents; |
202 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); | 220 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); |
203 | 221 |
204 sql::Connection connection; | 222 sql::Connection connection; |
205 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 223 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
206 ASSERT_TRUE(connection.Execute(contents.data())); | 224 ASSERT_TRUE(connection.Execute(contents.data())); |
207 } | 225 } |
208 | 226 |
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 | 1446 |
1429 // Check version. | 1447 // Check version. |
1430 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1448 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
1431 | 1449 |
1432 // |keywords| |sync_guid| column should have been added. | 1450 // |keywords| |sync_guid| column should have been added. |
1433 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); | 1451 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); |
1434 EXPECT_TRUE(connection.DoesColumnExist("keywords", "sync_guid")); | 1452 EXPECT_TRUE(connection.DoesColumnExist("keywords", "sync_guid")); |
1435 } | 1453 } |
1436 } | 1454 } |
1437 | 1455 |
1438 // Tests that the backup field for the default search provider gets added to | 1456 // Tests that no backup data is added to a version 39 database. |
1439 // the meta table of a version 39 database. | |
1440 TEST_F(WebDatabaseMigrationTest, MigrateVersion39ToCurrent) { | 1457 TEST_F(WebDatabaseMigrationTest, MigrateVersion39ToCurrent) { |
1441 // This schema is taken from a build prior to the addition of the default | 1458 // This schema is taken from a build prior to the addition of the default |
1442 // search provider backup field to the meta table. | 1459 // search provider backup field to the meta table. |
1443 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_39.sql"))); | 1460 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_39.sql"))); |
1444 | 1461 |
1445 // Verify pre-conditions. These are expectations for version 39 of the | 1462 // Verify pre-conditions. These are expectations for version 39 of the |
1446 // database. | 1463 // database. |
1447 { | 1464 { |
1448 sql::Connection connection; | 1465 sql::Connection connection; |
1449 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1466 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1450 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1467 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1451 | 1468 |
1452 sql::MetaTable meta_table; | 1469 sql::MetaTable meta_table; |
1453 ASSERT_TRUE(meta_table.Init(&connection, 39, 39)); | 1470 ASSERT_TRUE(meta_table.Init(&connection, 39, 39)); |
1454 | 1471 |
1455 int64 default_search_provider_id = 0; | 1472 int64 default_search_provider_id = 0; |
1456 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1473 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1457 &default_search_provider_id)); | 1474 &default_search_provider_id)); |
1458 | 1475 |
1459 int64 default_search_provider_id_backup = 0; | 1476 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
1460 EXPECT_FALSE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1461 &default_search_provider_id_backup)); | |
1462 | |
1463 std::string default_search_provider_id_backup_signature; | |
1464 EXPECT_FALSE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1465 &default_search_provider_id_backup_signature)); | |
1466 } | 1477 } |
1467 | 1478 |
1468 // Load the database via the WebDatabase class and migrate the database to | 1479 // Load the database via the WebDatabase class and migrate the database to |
1469 // the current version. | |
1470 { | |
1471 WebDatabase db; | |
1472 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | |
1473 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
1474 } | |
1475 | |
1476 // Verify post-conditions. These are expectations for current version of the | |
1477 // database. | |
1478 { | |
1479 sql::Connection connection; | |
1480 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
1481 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
1482 | |
1483 // Check version. | |
1484 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
1485 | |
1486 sql::MetaTable meta_table; | |
1487 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, | |
1488 kCurrentTestedVersionNumber)); | |
1489 | |
1490 int64 default_search_provider_id = 0; | |
1491 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | |
1492 &default_search_provider_id)); | |
1493 | |
1494 int64 default_search_provider_id_backup = 0; | |
1495 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1496 &default_search_provider_id_backup)); | |
1497 EXPECT_EQ(default_search_provider_id, default_search_provider_id_backup); | |
1498 | |
1499 std::string default_search_provider_id_backup_signature; | |
1500 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1501 &default_search_provider_id_backup_signature)); | |
1502 } | |
1503 } | |
1504 | |
1505 #if !defined(GOOGLE_CHROME_BUILD) | |
1506 // Test that a valid backup is not overwritten during migration from version 39. | |
1507 // This is enabled on Chromium only because a valid signature is required for | |
1508 // this test, which makes it key-dependent. | |
1509 TEST_F(WebDatabaseMigrationTest, MigrateVersion39WithBackupToCurrent) { | |
1510 // This schema is taken from a build prior to the addition of the default | |
1511 // search provider backup field to the meta table. | |
1512 ASSERT_NO_FATAL_FAILURE( | |
1513 LoadDatabase(FILE_PATH_LITERAL("version_39_with_backup.sql"))); | |
1514 | |
1515 // Verify pre-conditions. These are expectations for version 39 of the | |
1516 // database. | |
1517 { | |
1518 sql::Connection connection; | |
1519 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
1520 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
1521 | |
1522 sql::MetaTable meta_table; | |
1523 ASSERT_TRUE(meta_table.Init(&connection, 39, 39)); | |
1524 | |
1525 int64 default_search_provider_id = 0; | |
1526 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | |
1527 &default_search_provider_id)); | |
1528 | |
1529 int64 default_search_provider_id_backup = 0; | |
1530 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1531 &default_search_provider_id_backup)); | |
1532 EXPECT_NE(default_search_provider_id, default_search_provider_id_backup); | |
1533 | |
1534 std::string default_search_provider_id_backup_signature; | |
1535 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1536 &default_search_provider_id_backup_signature)); | |
1537 } | |
1538 | |
1539 // Load the database via the WebDatabase class and migrate the database to | |
1540 // the current version. | 1480 // the current version. |
1541 { | 1481 { |
1542 WebDatabase db; | 1482 WebDatabase db; |
1543 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 1483 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
1544 // A change to the default search provider must be detected. | |
1545 ASSERT_TRUE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
1546 } | 1484 } |
1547 | 1485 |
1548 // Verify post-conditions. These are expectations for current version of the | 1486 // Verify post-conditions. These are expectations for current version of the |
1549 // database. | 1487 // database. |
1550 { | 1488 { |
1551 sql::Connection connection; | 1489 sql::Connection connection; |
1552 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1490 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1553 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1491 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1554 | 1492 |
1555 // Check version. | 1493 // Check version. |
1556 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1494 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
1557 | 1495 |
1558 sql::MetaTable meta_table; | 1496 sql::MetaTable meta_table; |
1559 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, | 1497 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, |
1560 kCurrentTestedVersionNumber)); | 1498 kCurrentTestedVersionNumber)); |
1561 | 1499 |
1562 int64 default_search_provider_id = 0; | 1500 int64 default_search_provider_id = 0; |
1563 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1501 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1564 &default_search_provider_id)); | 1502 &default_search_provider_id)); |
| 1503 EXPECT_NE(0, default_search_provider_id); |
1565 | 1504 |
1566 int64 default_search_provider_id_backup = 0; | 1505 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
1567 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1568 &default_search_provider_id_backup)); | |
1569 EXPECT_NE(default_search_provider_id, default_search_provider_id_backup); | |
1570 | |
1571 std::string default_search_provider_id_backup_signature; | |
1572 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1573 &default_search_provider_id_backup_signature)); | |
1574 } | 1506 } |
1575 } | 1507 } |
1576 #endif // !defined(GOOGLE_CHROME_BUILD) | |
1577 | 1508 |
1578 // Tests that the backup field for the default search provider is rewritten | 1509 // Tests that the backup data is removed from the database. |
1579 // despite any value in the old version. | |
1580 TEST_F(WebDatabaseMigrationTest, MigrateVersion40ToCurrent) { | 1510 TEST_F(WebDatabaseMigrationTest, MigrateVersion40ToCurrent) { |
1581 // This schema is taken from a build after the addition of the default | |
1582 // search provider backup field to the meta table. Due to crbug.com/101815 | |
1583 // the signature was empty in all build between revisions 106214 and 108111. | |
1584 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_40.sql"))); | 1511 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_40.sql"))); |
1585 | 1512 |
1586 // Verify pre-conditions. These are expectations for version 40 of the | 1513 // Verify pre-conditions. These are expectations for version 40 of the |
1587 // database. | 1514 // database. |
1588 { | 1515 { |
1589 sql::Connection connection; | 1516 sql::Connection connection; |
1590 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1517 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1591 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1518 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1592 | 1519 |
1593 sql::MetaTable meta_table; | 1520 sql::MetaTable meta_table; |
1594 ASSERT_TRUE(meta_table.Init(&connection, 40, 40)); | 1521 ASSERT_TRUE(meta_table.Init(&connection, 40, 40)); |
1595 | 1522 |
1596 int64 default_search_provider_id = 0; | 1523 int64 default_search_provider_id = 0; |
1597 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1524 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1598 &default_search_provider_id)); | 1525 &default_search_provider_id)); |
1599 | 1526 |
1600 int64 default_search_provider_id_backup = 0; | 1527 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table)); |
1601 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1602 &default_search_provider_id_backup)); | |
1603 | |
1604 std::string default_search_provider_id_backup_signature; | |
1605 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1606 &default_search_provider_id_backup_signature)); | |
1607 EXPECT_TRUE(default_search_provider_id_backup_signature.empty()); | |
1608 } | 1528 } |
1609 | 1529 |
1610 // Load the database via the WebDatabase class and migrate the database to | 1530 // Load the database via the WebDatabase class and migrate the database to |
1611 // the current version. | 1531 // the current version. |
1612 { | 1532 { |
1613 WebDatabase db; | 1533 WebDatabase db; |
1614 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 1534 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
1615 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
1616 } | 1535 } |
1617 | 1536 |
1618 // Verify post-conditions. These are expectations for current version of the | 1537 // Verify post-conditions. These are expectations for current version of the |
1619 // database. | 1538 // database. |
1620 { | 1539 { |
1621 sql::Connection connection; | 1540 sql::Connection connection; |
1622 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1541 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1623 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1542 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1624 | 1543 |
1625 // Check version. | 1544 // Check version. |
1626 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1545 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
1627 | 1546 |
1628 sql::MetaTable meta_table; | 1547 sql::MetaTable meta_table; |
1629 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, | 1548 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, |
1630 kCurrentTestedVersionNumber)); | 1549 kCurrentTestedVersionNumber)); |
1631 | 1550 |
1632 int64 default_search_provider_id = 0; | 1551 int64 default_search_provider_id = 0; |
1633 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1552 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1634 &default_search_provider_id)); | 1553 &default_search_provider_id)); |
1635 EXPECT_NE(0, default_search_provider_id); | 1554 EXPECT_NE(0, default_search_provider_id); |
1636 | 1555 |
1637 int64 default_search_provider_id_backup = 0; | 1556 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
1638 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1639 &default_search_provider_id_backup)); | |
1640 EXPECT_EQ(default_search_provider_id, default_search_provider_id_backup); | |
1641 | |
1642 std::string default_search_provider_id_backup_signature; | |
1643 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1644 &default_search_provider_id_backup_signature)); | |
1645 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); | |
1646 } | 1557 } |
1647 } | 1558 } |
1648 | 1559 |
1649 // Used to test that the default search provider was backed up and signed, | 1560 // Tests that the backup data is removed from the database. |
1650 // before the backup method was changed in version 43. | |
1651 TEST_F(WebDatabaseMigrationTest, MigrateVersion41ToCurrent) { | 1561 TEST_F(WebDatabaseMigrationTest, MigrateVersion41ToCurrent) { |
1652 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_41.sql"))); | 1562 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_41.sql"))); |
1653 | 1563 |
1654 // Verify pre-conditions. These are expectations for version 41 of the | 1564 // Verify pre-conditions. These are expectations for version 41 of the |
1655 // database. | 1565 // database. |
1656 { | 1566 { |
1657 sql::Connection connection; | 1567 sql::Connection connection; |
1658 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1568 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1659 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1569 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1660 | 1570 |
1661 sql::MetaTable meta_table; | 1571 sql::MetaTable meta_table; |
1662 ASSERT_TRUE(meta_table.Init(&connection, 41, 41)); | 1572 ASSERT_TRUE(meta_table.Init(&connection, 41, 41)); |
1663 | 1573 |
1664 int64 default_search_provider_id = 0; | 1574 int64 default_search_provider_id = 0; |
1665 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1575 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1666 &default_search_provider_id)); | 1576 &default_search_provider_id)); |
1667 | 1577 |
1668 int64 default_search_provider_id_backup = 0; | 1578 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table)); |
1669 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1670 &default_search_provider_id_backup)); | |
1671 | |
1672 std::string default_search_provider_id_backup_signature; | |
1673 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1674 &default_search_provider_id_backup_signature)); | |
1675 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); | |
1676 } | 1579 } |
1677 | 1580 |
1678 // Load the database via the WebDatabase class and migrate the database to | 1581 // Load the database via the WebDatabase class and migrate the database to |
1679 // the current version. | 1582 // the current version. |
1680 { | 1583 { |
1681 WebDatabase db; | 1584 WebDatabase db; |
1682 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 1585 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
1683 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
1684 } | 1586 } |
1685 | 1587 |
1686 // Verify post-conditions. These are expectations for current version of the | 1588 // Verify post-conditions. These are expectations for current version of the |
1687 // database. | 1589 // database. |
1688 { | 1590 { |
1689 sql::Connection connection; | 1591 sql::Connection connection; |
1690 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1592 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1691 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1593 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1692 | 1594 |
1693 // Check version. | 1595 // Check version. |
1694 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1596 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
1695 | 1597 |
1696 sql::MetaTable meta_table; | 1598 sql::MetaTable meta_table; |
1697 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, | 1599 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, |
1698 kCurrentTestedVersionNumber)); | 1600 kCurrentTestedVersionNumber)); |
1699 | 1601 |
1700 int64 default_search_provider_id = 0; | 1602 int64 default_search_provider_id = 0; |
1701 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1603 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1702 &default_search_provider_id)); | 1604 &default_search_provider_id)); |
1703 EXPECT_NE(0, default_search_provider_id); | 1605 EXPECT_NE(0, default_search_provider_id); |
1704 | 1606 |
1705 int64 default_search_provider_id_backup = 0; | 1607 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
1706 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1707 &default_search_provider_id_backup)); | |
1708 EXPECT_EQ(default_search_provider_id, default_search_provider_id_backup); | |
1709 | |
1710 std::string default_search_provider_id_backup_signature; | |
1711 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1712 &default_search_provider_id_backup_signature)); | |
1713 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); | |
1714 } | 1608 } |
1715 } | 1609 } |
1716 | 1610 |
1717 // Tests that all keywords are backed up and signed. | 1611 // Tests that the backup data is removed from the database. |
1718 TEST_F(WebDatabaseMigrationTest, MigrateVersion42ToCurrent) { | 1612 TEST_F(WebDatabaseMigrationTest, MigrateVersion42ToCurrent) { |
1719 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_42.sql"))); | 1613 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_42.sql"))); |
1720 | 1614 |
1721 // Verify pre-conditions. These are expectations for version 42 of the | 1615 // Verify pre-conditions. These are expectations for version 42 of the |
1722 // database. | 1616 // database. |
1723 { | 1617 { |
1724 sql::Connection connection; | 1618 sql::Connection connection; |
1725 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1619 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1726 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1620 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1727 | 1621 |
1728 sql::MetaTable meta_table; | 1622 sql::MetaTable meta_table; |
1729 ASSERT_TRUE(meta_table.Init(&connection, 42, 42)); | 1623 ASSERT_TRUE(meta_table.Init(&connection, 42, 42)); |
1730 | 1624 |
1731 int64 default_search_provider_id = 0; | 1625 int64 default_search_provider_id = 0; |
1732 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1626 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1733 &default_search_provider_id)); | 1627 &default_search_provider_id)); |
1734 | 1628 |
1735 int64 default_search_provider_id_backup = 0; | 1629 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table)); |
1736 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1737 &default_search_provider_id_backup)); | |
1738 | |
1739 std::string default_search_provider_id_backup_signature; | |
1740 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1741 &default_search_provider_id_backup_signature)); | |
1742 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); | |
1743 | 1630 |
1744 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); | 1631 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); |
1745 } | 1632 } |
1746 | 1633 |
1747 // Load the database via the WebDatabase class and migrate the database to | 1634 // Load the database via the WebDatabase class and migrate the database to |
1748 // the current version. | 1635 // the current version. |
1749 { | 1636 { |
1750 WebDatabase db; | 1637 WebDatabase db; |
1751 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 1638 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
1752 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
1753 } | 1639 } |
1754 | 1640 |
1755 // Verify post-conditions. These are expectations for current version of the | 1641 // Verify post-conditions. These are expectations for current version of the |
1756 // database. | 1642 // database. |
1757 { | 1643 { |
1758 sql::Connection connection; | 1644 sql::Connection connection; |
1759 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1645 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1760 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1646 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1761 | 1647 |
1762 // Check version. | 1648 // Check version. |
1763 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1649 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
1764 | 1650 |
1765 sql::MetaTable meta_table; | 1651 sql::MetaTable meta_table; |
1766 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, | 1652 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, |
1767 kCurrentTestedVersionNumber)); | 1653 kCurrentTestedVersionNumber)); |
1768 | 1654 |
1769 int64 default_search_provider_id = 0; | 1655 int64 default_search_provider_id = 0; |
1770 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1656 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1771 &default_search_provider_id)); | 1657 &default_search_provider_id)); |
1772 EXPECT_NE(0, default_search_provider_id); | 1658 EXPECT_NE(0, default_search_provider_id); |
1773 | 1659 |
1774 int64 default_search_provider_id_backup = 0; | 1660 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
1775 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1776 &default_search_provider_id_backup)); | |
1777 EXPECT_EQ(default_search_provider_id, default_search_provider_id_backup); | |
1778 | |
1779 std::string default_search_provider_id_backup_signature; | |
1780 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1781 &default_search_provider_id_backup_signature)); | |
1782 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); | |
1783 | |
1784 EXPECT_TRUE(connection.DoesTableExist("keywords_backup")); | |
1785 std::string query("SELECT " + KeywordTable::GetKeywordColumns() + | |
1786 " FROM keywords_backup"); | |
1787 sql::Statement s(connection.GetUniqueStatement(query.c_str())); | |
1788 ASSERT_TRUE(s.Step()); | |
1789 EXPECT_EQ(2, s.ColumnInt(0)); | |
1790 EXPECT_EQ("Google", s.ColumnString(1)); | |
1791 EXPECT_EQ("google.com", s.ColumnString(2)); | |
1792 EXPECT_EQ("http://www.google.com/favicon.ico", s.ColumnString(3)); | |
1793 EXPECT_EQ("{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}" | |
1794 "{google:originalQueryForSuggestion}sourceid=chrome&" | |
1795 "ie={inputEncoding}&q={searchTerms}", | |
1796 s.ColumnString(4)); | |
1797 EXPECT_TRUE(s.ColumnBool(5)); | |
1798 EXPECT_EQ(std::string(), s.ColumnString(6)); | |
1799 EXPECT_EQ(0, s.ColumnInt(7)); | |
1800 EXPECT_EQ(0, s.ColumnInt(8)); | |
1801 EXPECT_EQ("UTF-8", s.ColumnString(9)); | |
1802 EXPECT_TRUE(s.ColumnBool(10)); | |
1803 EXPECT_EQ("{google:baseSuggestURL}search?client=chrome&hl={language}&" | |
1804 "q={searchTerms}", s.ColumnString(11)); | |
1805 EXPECT_EQ(1, s.ColumnInt(12)); | |
1806 //EXPECT_EQ(false, s.ColumnBool(13)); | |
1807 EXPECT_EQ("{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&" | |
1808 "ie={inputEncoding}&ion=1{searchTerms}&nord=1", | |
1809 s.ColumnString(14)); | |
1810 EXPECT_EQ(0, s.ColumnInt(15)); | |
1811 EXPECT_EQ("{1234-5678-90AB-CDEF}", s.ColumnString(16)); | |
1812 | |
1813 EXPECT_FALSE(s.Step()); | |
1814 } | 1661 } |
1815 } | 1662 } |
1816 | 1663 |
1817 // Tests that the default search provider is backed up and signed. | 1664 // Tests that the backup data is removed from the database. |
1818 TEST_F(WebDatabaseMigrationTest, MigrateVersion43ToCurrent) { | 1665 TEST_F(WebDatabaseMigrationTest, MigrateVersion43ToCurrent) { |
1819 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_43.sql"))); | 1666 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_43.sql"))); |
1820 | 1667 |
1821 int64 previous_default_search_provider_id; | 1668 int64 previous_default_search_provider_id; |
1822 | 1669 |
1823 // Verify pre-conditions. These are expectations for version 43 of the | 1670 // Verify pre-conditions. These are expectations for version 43 of the |
1824 // database. | 1671 // database. |
1825 { | 1672 { |
1826 sql::Connection connection; | 1673 sql::Connection connection; |
1827 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1674 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1828 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1675 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1829 | 1676 |
1830 sql::MetaTable meta_table; | 1677 sql::MetaTable meta_table; |
1831 ASSERT_TRUE(meta_table.Init(&connection, 43, 43)); | 1678 ASSERT_TRUE(meta_table.Init(&connection, 43, 43)); |
1832 | 1679 |
1833 int64 default_search_provider_id = 0; | 1680 int64 default_search_provider_id = 0; |
1834 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1681 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1835 &default_search_provider_id)); | 1682 &default_search_provider_id)); |
1836 EXPECT_NE(default_search_provider_id, 0); | 1683 EXPECT_NE(default_search_provider_id, 0); |
1837 previous_default_search_provider_id = default_search_provider_id; | 1684 previous_default_search_provider_id = default_search_provider_id; |
1838 | 1685 |
1839 int64 default_search_provider_id_backup = 0; | 1686 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table)); |
1840 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | 1687 EXPECT_TRUE(connection.DoesTableExist("keywords_backup")); |
1841 &default_search_provider_id_backup)); | |
1842 EXPECT_NE(default_search_provider_id_backup, 0); | |
1843 | |
1844 // Backup ID is invalid, signature is invalid as well. | |
1845 EXPECT_NE(default_search_provider_id, default_search_provider_id_backup); | |
1846 | |
1847 std::string default_search_provider_id_backup_signature; | |
1848 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1849 &default_search_provider_id_backup_signature)); | |
1850 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); | |
1851 } | 1688 } |
1852 | 1689 |
1853 // Load the database via the WebDatabase class and migrate the database to | 1690 // Load the database via the WebDatabase class and migrate the database to |
1854 // the current version. | 1691 // the current version. |
1855 { | 1692 { |
1856 WebDatabase db; | 1693 WebDatabase db; |
1857 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 1694 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
1858 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
1859 } | 1695 } |
1860 | 1696 |
1861 // Verify post-conditions. These are expectations for current version of the | 1697 // Verify post-conditions. These are expectations for current version of the |
1862 // database. | 1698 // database. |
1863 { | 1699 { |
1864 sql::Connection connection; | 1700 sql::Connection connection; |
1865 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1701 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1866 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1702 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1867 | 1703 |
1868 // Check version. | 1704 // Check version. |
1869 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1705 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
1870 | 1706 |
1871 sql::MetaTable meta_table; | 1707 sql::MetaTable meta_table; |
1872 ASSERT_TRUE(meta_table.Init( | 1708 ASSERT_TRUE(meta_table.Init( |
1873 &connection, | 1709 &connection, |
1874 kCurrentTestedVersionNumber, | 1710 kCurrentTestedVersionNumber, |
1875 kCurrentTestedVersionNumber)); | 1711 kCurrentTestedVersionNumber)); |
1876 | 1712 |
1877 int64 default_search_provider_id = 0; | 1713 int64 default_search_provider_id = 0; |
1878 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 1714 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
1879 &default_search_provider_id)); | 1715 &default_search_provider_id)); |
1880 // Default search provider ID should not change. | 1716 // Default search provider ID should not change. |
1881 EXPECT_EQ(previous_default_search_provider_id, default_search_provider_id); | 1717 EXPECT_EQ(previous_default_search_provider_id, default_search_provider_id); |
1882 | 1718 |
1883 int64 default_search_provider_id_backup = 0; | 1719 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
1884 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | |
1885 &default_search_provider_id_backup)); | |
1886 // Backup ID must be updated to match the old default search provider ID. | |
1887 EXPECT_EQ(default_search_provider_id, default_search_provider_id_backup); | |
1888 | |
1889 std::string default_search_provider_id_backup_signature; | |
1890 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | |
1891 &default_search_provider_id_backup_signature)); | |
1892 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); | |
1893 } | 1720 } |
1894 } | 1721 } |
1895 | 1722 |
1896 #if !defined(GOOGLE_CHROME_BUILD) | |
1897 // Tests that the |autogenerate_keyword| and |logo_id| columns get removed from | 1723 // Tests that the |autogenerate_keyword| and |logo_id| columns get removed from |
1898 // the keyword table schema for a version 45 database. | 1724 // the keyword table schema for a version 45 database. |
1899 // | |
1900 // This is enabled on Chromium only because a valid signature is required for | |
1901 // this test, which makes it key-dependent. | |
1902 TEST_F(WebDatabaseMigrationTest, MigrateVersion44ToCurrent) { | 1725 TEST_F(WebDatabaseMigrationTest, MigrateVersion44ToCurrent) { |
1903 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_44.sql"))); | 1726 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_44.sql"))); |
1904 | 1727 |
1905 // Verify pre-conditions. These are expectations for version 44 of the | 1728 // Verify pre-conditions. These are expectations for version 44 of the |
1906 // database. | 1729 // database. |
1907 { | 1730 { |
1908 sql::Connection connection; | 1731 sql::Connection connection; |
1909 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1732 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1910 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1733 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1911 | 1734 |
1912 sql::MetaTable meta_table; | 1735 sql::MetaTable meta_table; |
1913 ASSERT_TRUE(meta_table.Init(&connection, 44, 44)); | 1736 ASSERT_TRUE(meta_table.Init(&connection, 44, 44)); |
1914 | 1737 |
1915 ASSERT_TRUE(connection.DoesColumnExist("keywords", "autogenerate_keyword")); | 1738 ASSERT_TRUE(connection.DoesColumnExist("keywords", "autogenerate_keyword")); |
1916 ASSERT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); | 1739 ASSERT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); |
1917 } | 1740 } |
1918 | 1741 |
1919 // Load the database via the WebDatabase class and migrate the database to | 1742 // Load the database via the WebDatabase class and migrate the database to |
1920 // the current version. | 1743 // the current version. |
1921 { | 1744 { |
1922 WebDatabase db; | 1745 WebDatabase db; |
1923 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 1746 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
1924 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
1925 | |
1926 // The backup table should match the keyword table. | |
1927 std::string keywords_contents; | |
1928 EXPECT_TRUE(db.GetKeywordTable()->GetTableContents("keywords", | |
1929 kCurrentTestedVersionNumber, &keywords_contents)); | |
1930 std::string keywords_backup_contents; | |
1931 EXPECT_TRUE(db.GetKeywordTable()->GetTableContents("keywords_backup", | |
1932 kCurrentTestedVersionNumber, &keywords_backup_contents)); | |
1933 EXPECT_EQ(keywords_contents, keywords_backup_contents); | |
1934 } | 1747 } |
1935 | 1748 |
1936 // Verify post-conditions. These are expectations for current version of the | 1749 // Verify post-conditions. These are expectations for current version of the |
1937 // database. | |
1938 { | |
1939 sql::Connection connection; | |
1940 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
1941 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
1942 | |
1943 // Check version. | |
1944 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
1945 | |
1946 sql::MetaTable meta_table; | |
1947 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, | |
1948 kCurrentTestedVersionNumber)); | |
1949 | |
1950 // We should have removed this obsolete key. | |
1951 std::string default_search_provider_backup; | |
1952 EXPECT_FALSE(meta_table.GetValue("Default Search Provider Backup", | |
1953 &default_search_provider_backup)); | |
1954 | |
1955 // Two columns should have been removed. | |
1956 EXPECT_FALSE(connection.DoesColumnExist("keywords", | |
1957 "autogenerate_keyword")); | |
1958 EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); | |
1959 } | |
1960 } | |
1961 #endif // !defined(GOOGLE_CHROME_BUILD) | |
1962 | |
1963 // Like MigrateVersion44ToCurrent above, but with a corrupt backup signature. | |
1964 // This should result in us dropping the backup table but successfully migrating | |
1965 // otherwise. | |
1966 // | |
1967 // Because this test doesn't rely on a valid signature, we can run it on | |
1968 // official builds as well. | |
1969 TEST_F(WebDatabaseMigrationTest, MigrateVersion44CorruptBackupToCurrent) { | |
1970 ASSERT_NO_FATAL_FAILURE( | |
1971 LoadDatabase(FILE_PATH_LITERAL("version_44_backup_corrupt.sql"))); | |
1972 | |
1973 // Verify pre-conditions. These are expectations for version 44 of the | |
1974 // database. | |
1975 { | |
1976 sql::Connection connection; | |
1977 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
1978 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
1979 | |
1980 sql::MetaTable meta_table; | |
1981 ASSERT_TRUE(meta_table.Init(&connection, 44, 44)); | |
1982 | |
1983 ASSERT_TRUE(connection.DoesColumnExist("keywords", "autogenerate_keyword")); | |
1984 ASSERT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); | |
1985 } | |
1986 | |
1987 // Load the database via the WebDatabase class and migrate the database to | |
1988 // the current version. | |
1989 { | |
1990 WebDatabase db; | |
1991 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | |
1992 // We should detect a "search provider change" as a side effect of dropping | |
1993 // the backup table. | |
1994 ASSERT_TRUE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
1995 } | |
1996 | |
1997 // Verify post-conditions. These are expectations for current version of the | |
1998 // database. | 1750 // database. |
1999 { | 1751 { |
2000 sql::Connection connection; | 1752 sql::Connection connection; |
2001 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1753 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
2002 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1754 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
2003 | 1755 |
2004 // Check version. | 1756 // Check version. |
2005 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1757 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
2006 | 1758 |
2007 sql::MetaTable meta_table; | 1759 sql::MetaTable meta_table; |
2008 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, | 1760 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, |
2009 kCurrentTestedVersionNumber)); | 1761 kCurrentTestedVersionNumber)); |
2010 | 1762 |
2011 // We should have removed this obsolete key. | 1763 // We should have removed this obsolete key. |
2012 std::string default_search_provider_backup; | 1764 std::string default_search_provider_backup; |
2013 EXPECT_FALSE(meta_table.GetValue("Default Search Provider Backup", | 1765 EXPECT_FALSE(meta_table.GetValue("Default Search Provider Backup", |
2014 &default_search_provider_backup)); | 1766 &default_search_provider_backup)); |
2015 | 1767 |
2016 // Two columns should have been removed. | 1768 // Two columns should have been removed. |
2017 EXPECT_FALSE(connection.DoesColumnExist("keywords", | 1769 EXPECT_FALSE(connection.DoesColumnExist("keywords", |
2018 "autogenerate_keyword")); | 1770 "autogenerate_keyword")); |
2019 EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); | 1771 EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); |
2020 | 1772 |
2021 // The backup table should be gone. | 1773 // Backup data should have been removed. |
2022 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); | 1774 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
2023 } | 1775 } |
2024 } | 1776 } |
2025 | 1777 |
2026 // Tests that the web_intents and web_intents_defaults tables are | 1778 // Tests that the web_intents and web_intents_defaults tables are |
2027 // modified to include "scheme" columns. | 1779 // modified to include "scheme" columns. |
2028 TEST_F(WebDatabaseMigrationTest, MigrateVersion45ToCurrent) { | 1780 TEST_F(WebDatabaseMigrationTest, MigrateVersion45ToCurrent) { |
2029 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_45.sql"))); | 1781 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_45.sql"))); |
2030 | 1782 |
2031 // Verify pre-conditions. These are expectations for version 45 of the | 1783 // Verify pre-conditions. These are expectations for version 45 of the |
2032 // database. | 1784 // database. |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2202 sql::Connection connection; | 1954 sql::Connection connection; |
2203 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1955 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
2204 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1956 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
2205 | 1957 |
2206 // Check version. | 1958 // Check version. |
2207 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1959 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
2208 EXPECT_LE(45, VersionFromConnection(&connection)); | 1960 EXPECT_LE(45, VersionFromConnection(&connection)); |
2209 } | 1961 } |
2210 } | 1962 } |
2211 | 1963 |
2212 #if !defined(GOOGLE_CHROME_BUILD) | |
2213 // Tests that the |alternate_urls| column is added to the keyword table schema | 1964 // Tests that the |alternate_urls| column is added to the keyword table schema |
2214 // for a version 47 database. | 1965 // for a version 47 database. |
2215 // | |
2216 // This is enabled on Chromium only because a valid signature is required for | |
2217 // this test, which makes it key-dependent. | |
2218 TEST_F(WebDatabaseMigrationTest, MigrateVersion46ToCurrent) { | 1966 TEST_F(WebDatabaseMigrationTest, MigrateVersion46ToCurrent) { |
2219 ASSERT_NO_FATAL_FAILURE( | 1967 ASSERT_NO_FATAL_FAILURE( |
2220 LoadDatabase(FILE_PATH_LITERAL("version_46.sql"))); | 1968 LoadDatabase(FILE_PATH_LITERAL("version_46.sql"))); |
2221 | 1969 |
2222 // Verify pre-conditions. These are expectations for version 46 of the | 1970 // Verify pre-conditions. These are expectations for version 46 of the |
2223 // database. | 1971 // database. |
2224 { | 1972 { |
2225 sql::Connection connection; | 1973 sql::Connection connection; |
2226 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1974 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
2227 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1975 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
2228 | 1976 |
2229 sql::MetaTable meta_table; | 1977 sql::MetaTable meta_table; |
2230 ASSERT_TRUE(meta_table.Init(&connection, 46, 46)); | 1978 ASSERT_TRUE(meta_table.Init(&connection, 46, 46)); |
2231 | 1979 |
2232 ASSERT_FALSE(connection.DoesColumnExist("keywords", "alternate_urls")); | 1980 ASSERT_FALSE(connection.DoesColumnExist("keywords", "alternate_urls")); |
2233 ASSERT_FALSE(connection.DoesColumnExist("keywords_backup", | 1981 ASSERT_FALSE(connection.DoesColumnExist("keywords_backup", |
2234 "alternate_urls")); | 1982 "alternate_urls")); |
2235 } | 1983 } |
2236 | 1984 |
2237 // Load the database via the WebDatabase class and migrate the database to | 1985 // Load the database via the WebDatabase class and migrate the database to |
2238 // the current version. | 1986 // the current version. |
2239 { | 1987 { |
2240 WebDatabase db; | 1988 WebDatabase db; |
2241 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 1989 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
2242 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
2243 } | 1990 } |
2244 | 1991 |
2245 // Verify post-conditions. These are expectations for current version of the | 1992 // Verify post-conditions. These are expectations for current version of the |
2246 // database. | 1993 // database. |
2247 { | 1994 { |
2248 sql::Connection connection; | 1995 sql::Connection connection; |
2249 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1996 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
2250 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1997 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
2251 | 1998 |
2252 // Check version. | 1999 // Check version. |
2253 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 2000 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
2254 | 2001 |
2255 // A new column should have been created. | 2002 // A new column should have been created. |
2256 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls")); | 2003 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls")); |
2257 ASSERT_TRUE(connection.DoesColumnExist("keywords_backup", | |
2258 "alternate_urls")); | |
2259 } | 2004 } |
2260 } | 2005 } |
2261 #endif // !defined(GOOGLE_CHROME_BUILD) | |
2262 | 2006 |
2263 // Like MigrateVersion46ToCurrent above, but with a corrupt backup signature. | 2007 // Tests that the backup data is removed from the database. |
2264 // This should result in us dropping the backup table but successfully migrating | 2008 TEST_F(WebDatabaseMigrationTest, MigrateVersion47ToCurrent) { |
2265 // otherwise. | 2009 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_47.sql"))); |
2266 // | |
2267 // Because this test doesn't rely on a valid signature, we can run it on | |
2268 // official builds as well. | |
2269 TEST_F(WebDatabaseMigrationTest, MigrateVersion46CorruptBackupToCurrent) { | |
2270 ASSERT_NO_FATAL_FAILURE( | |
2271 LoadDatabase(FILE_PATH_LITERAL("version_46_backup_corrupt.sql"))); | |
2272 | 2010 |
2273 // Verify pre-conditions. These are expectations for version 46 of the | 2011 // Verify pre-conditions. These are expectations for version 47 of the |
2274 // database. | 2012 // database. |
2275 { | 2013 { |
2276 sql::Connection connection; | 2014 sql::Connection connection; |
2277 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2015 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
2278 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 2016 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
2279 | 2017 |
2280 sql::MetaTable meta_table; | 2018 sql::MetaTable meta_table; |
2281 ASSERT_TRUE(meta_table.Init(&connection, 46, 46)); | 2019 ASSERT_TRUE(meta_table.Init(&connection, 47, 47)); |
2282 | 2020 |
2283 ASSERT_FALSE(connection.DoesColumnExist("keywords", "alternate_urls")); | 2021 int64 default_search_provider_id = 0; |
2284 ASSERT_FALSE(connection.DoesColumnExist("keywords_backup", | 2022 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
2285 "alternate_urls")); | 2023 &default_search_provider_id)); |
| 2024 EXPECT_NE(0, default_search_provider_id); |
| 2025 |
| 2026 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table)); |
| 2027 EXPECT_TRUE(connection.DoesTableExist("keywords_backup")); |
2286 } | 2028 } |
2287 | 2029 |
2288 // Load the database via the WebDatabase class and migrate the database to | 2030 // Load the database via the WebDatabase class and migrate the database to |
2289 // the current version. | 2031 // the current version. |
2290 { | 2032 { |
2291 WebDatabase db; | 2033 WebDatabase db; |
2292 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 2034 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
2293 // We should detect a "search provider change" as a side effect of dropping | |
2294 // the backup table. | |
2295 ASSERT_TRUE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
2296 } | 2035 } |
2297 | 2036 |
2298 // Verify post-conditions. These are expectations for current version of the | 2037 // Verify post-conditions. These are expectations for current version of the |
2299 // database. | 2038 // database. |
2300 { | 2039 { |
2301 sql::Connection connection; | 2040 sql::Connection connection; |
2302 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2041 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
2303 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 2042 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
2304 | 2043 |
2305 // Check version. | 2044 // Check version. |
2306 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 2045 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
2307 | 2046 |
2308 // A new column should have been created. | 2047 sql::MetaTable meta_table; |
2309 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls")); | 2048 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber, |
| 2049 kCurrentTestedVersionNumber)); |
2310 | 2050 |
2311 // The backup table should be gone. | 2051 int64 default_search_provider_id = 0; |
2312 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); | 2052 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
| 2053 &default_search_provider_id)); |
| 2054 EXPECT_NE(0, default_search_provider_id); |
| 2055 |
| 2056 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
2313 } | 2057 } |
2314 } | 2058 } |
OLD | NEW |