OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <list> | 5 #include <list> |
6 #include <map> | 6 #include <map> |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "app/sql/statement.h" |
12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/scoped_temp_dir.h" |
14 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" |
15 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
16 #include "base/string16.h" | 18 #include "base/string16.h" |
17 #include "base/time.h" | 19 #include "base/time.h" |
18 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
19 #include "base/values.h" | 21 #include "base/values.h" |
20 #include "chrome/browser/autofill/autofill_profile.h" | 22 #include "chrome/browser/autofill/autofill_profile.h" |
21 #include "chrome/browser/autofill/autofill_type.h" | 23 #include "chrome/browser/autofill/autofill_type.h" |
22 #include "chrome/browser/autofill/credit_card.h" | 24 #include "chrome/browser/autofill/credit_card.h" |
23 #include "chrome/browser/search_engines/template_url.h" | 25 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 84 |
83 std::set<base::Time>::iterator it; | 85 std::set<base::Time>::iterator it; |
84 for (it = timestamps1.begin(); it != timestamps1.end(); it++) { | 86 for (it = timestamps1.begin(); it != timestamps1.end(); it++) { |
85 timestamps2.erase(*it); | 87 timestamps2.erase(*it); |
86 } | 88 } |
87 | 89 |
88 return timestamps2.size() != 0U; | 90 return timestamps2.size() != 0U; |
89 } | 91 } |
90 | 92 |
91 class WebDatabaseTest : public testing::Test { | 93 class WebDatabaseTest : public testing::Test { |
| 94 public: |
| 95 WebDatabaseTest() {} |
| 96 virtual ~WebDatabaseTest() {} |
| 97 |
92 protected: | 98 protected: |
93 typedef std::vector<AutofillChange> AutofillChangeList; | 99 typedef std::vector<AutofillChange> AutofillChangeList; |
94 typedef std::set<AutofillEntry, | 100 typedef std::set<AutofillEntry, |
95 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet; | 101 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet; |
96 typedef std::set<AutofillEntry, bool (*)(const AutofillEntry&, | 102 typedef std::set<AutofillEntry, bool (*)(const AutofillEntry&, |
97 const AutofillEntry&)>::iterator AutofillEntrySetIterator; | 103 const AutofillEntry&)>::iterator AutofillEntrySetIterator; |
98 virtual void SetUp() { | 104 virtual void SetUp() { |
99 #if defined(OS_MACOSX) | 105 #if defined(OS_MACOSX) |
100 Encryptor::UseMockKeychain(true); | 106 Encryptor::UseMockKeychain(true); |
101 #endif | 107 #endif |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 std::vector<base::Time> timestamps; | 172 std::vector<base::Time> timestamps; |
167 if (timestamp0 >= 0) | 173 if (timestamp0 >= 0) |
168 timestamps.push_back(Time::FromTimeT(timestamp0)); | 174 timestamps.push_back(Time::FromTimeT(timestamp0)); |
169 if (timestamp1 >= 0) | 175 if (timestamp1 >= 0) |
170 timestamps.push_back(Time::FromTimeT(timestamp1)); | 176 timestamps.push_back(Time::FromTimeT(timestamp1)); |
171 return AutofillEntry( | 177 return AutofillEntry( |
172 AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), timestamps); | 178 AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), timestamps); |
173 } | 179 } |
174 | 180 |
175 FilePath file_; | 181 FilePath file_; |
| 182 |
| 183 private: |
| 184 DISALLOW_COPY_AND_ASSIGN(WebDatabaseTest); |
176 }; | 185 }; |
177 | 186 |
178 TEST_F(WebDatabaseTest, Keywords) { | 187 TEST_F(WebDatabaseTest, Keywords) { |
179 WebDatabase db; | 188 WebDatabase db; |
180 | 189 |
181 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 190 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
182 | 191 |
183 TemplateURL template_url; | 192 TemplateURL template_url; |
184 template_url.set_short_name(L"short_name"); | 193 template_url.set_short_name(L"short_name"); |
185 template_url.set_keyword(L"keyword"); | 194 template_url.set_keyword(L"keyword"); |
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 | 1509 |
1501 // make sure the lists of entries match | 1510 // make sure the lists of entries match |
1502 ASSERT_EQ(expected_entries.size(), entry_set.size()); | 1511 ASSERT_EQ(expected_entries.size(), entry_set.size()); |
1503 AutofillEntrySetIterator it; | 1512 AutofillEntrySetIterator it; |
1504 for (it = entry_set.begin(); it != entry_set.end(); it++) { | 1513 for (it = entry_set.begin(); it != entry_set.end(); it++) { |
1505 expected_entries.erase(*it); | 1514 expected_entries.erase(*it); |
1506 } | 1515 } |
1507 | 1516 |
1508 EXPECT_EQ(0U, expected_entries.size()); | 1517 EXPECT_EQ(0U, expected_entries.size()); |
1509 } | 1518 } |
| 1519 |
| 1520 // The WebDatabaseMigrationTest encapsulates testing of database migrations. |
| 1521 // Specifically, these tests are intended to exercise any schema changes in |
| 1522 // the WebDatabase and data migrations that occur in |
| 1523 // |WebDatabase::MigrateOldVersionsAsNeeded()|. |
| 1524 class WebDatabaseMigrationTest : public testing::Test { |
| 1525 public: |
| 1526 WebDatabaseMigrationTest() {} |
| 1527 virtual ~WebDatabaseMigrationTest() {} |
| 1528 |
| 1529 virtual void SetUp() { |
| 1530 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 1531 } |
| 1532 |
| 1533 protected: |
| 1534 // Current tested version number. When adding a migration in |
| 1535 // |WebDatabase::MigrateOldVersionsAsNeeded()| and changing the version number |
| 1536 // |kCurrentVersionNumber| this value should change to reflect the new version |
| 1537 // number and a new migration test added below. |
| 1538 static const int kCurrentTestedVersionNumber; |
| 1539 |
| 1540 FilePath GetDatabasePath() { |
| 1541 const FilePath::CharType kWebDatabaseFilename[] = |
| 1542 FILE_PATH_LITERAL("TestWebDatabase.sqlite3"); |
| 1543 return temp_dir_.path().Append(FilePath(kWebDatabaseFilename)); |
| 1544 } |
| 1545 |
| 1546 static int VersionFromConnection(sql::Connection* connection) { |
| 1547 // Get version. |
| 1548 sql::Statement s(connection->GetUniqueStatement( |
| 1549 "SELECT value FROM meta WHERE key='version'")); |
| 1550 if (!s.Step()) |
| 1551 return 0; |
| 1552 return s.ColumnInt(0); |
| 1553 } |
| 1554 |
| 1555 // The tables in these "Setup" routines were generated by launching the |
| 1556 // Chromium application prior to schema change, then using the sqlite |
| 1557 // command-line application to dump the contents of the "Web Data" database. |
| 1558 // Like this: |
| 1559 // > .output foo_dump.sql |
| 1560 // > .dump |
| 1561 void SetUpVersion22Database(); |
| 1562 void SetUpVersion22CorruptDatabase(); |
| 1563 void SetUpVersion24Database(); |
| 1564 |
| 1565 private: |
| 1566 ScopedTempDir temp_dir_; |
| 1567 |
| 1568 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
| 1569 }; |
| 1570 |
| 1571 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 25; |
| 1572 |
| 1573 // This schema is taken from a build prior to the addition of the |credit_card| |
| 1574 // table. Version 22 of the schema. Contrast this with the corrupt version |
| 1575 // below. |
| 1576 void WebDatabaseMigrationTest::SetUpVersion22Database() { |
| 1577 sql::Connection connection; |
| 1578 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1579 ASSERT_TRUE(connection.BeginTransaction()); |
| 1580 ASSERT_TRUE(connection.Execute( |
| 1581 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," |
| 1582 "value LONGVARCHAR);" |
| 1583 "INSERT INTO \"meta\" VALUES('version','22');" |
| 1584 "INSERT INTO \"meta\" VALUES('last_compatible_version','21');" |
| 1585 "INSERT INTO \"meta\" VALUES('Builtin Keyword Version','27');" |
| 1586 "INSERT INTO \"meta\" VALUES('Default Search Provider ID','7');" |
| 1587 "CREATE TABLE keywords (id INTEGER PRIMARY KEY,short_name VARCHAR NOT NULL," |
| 1588 "keyword VARCHAR NOT NULL,favicon_url VARCHAR NOT NULL," |
| 1589 "url VARCHAR NOT NULL,show_in_default_list INTEGER," |
| 1590 "safe_for_autoreplace INTEGER,originating_url VARCHAR," |
| 1591 "date_created INTEGER DEFAULT 0,usage_count INTEGER DEFAULT 0," |
| 1592 "input_encodings VARCHAR,suggest_url VARCHAR," |
| 1593 "prepopulate_id INTEGER DEFAULT 0," |
| 1594 "autogenerate_keyword INTEGER DEFAULT 0);" |
| 1595 "INSERT INTO \"keywords\" VALUES(2,'Google','google.com'," |
| 1596 "'http://www.google.com/favicon.ico'," |
| 1597 "'{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}" |
| 1598 "{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}" |
| 1599 "&q={searchTerms}',1,1,'',0,0,'UTF-8','{google:baseSuggestURL}search?" |
| 1600 "client=chrome&hl={language}&q={searchTerms}',1,1);" |
| 1601 "INSERT INTO \"keywords\" VALUES(3,'Yahoo!','yahoo.com'," |
| 1602 "'http://search.yahoo.com/favicon.ico','http://search.yahoo.com/search?" |
| 1603 "ei={inputEncoding}&fr=crmas&p={searchTerms}',1,1,'',0,0,'UTF-8'," |
| 1604 "'http://ff.search.yahoo.com/gossip?output=fxjson&" |
| 1605 "command={searchTerms}',2,0);" |
| 1606 "INSERT INTO \"keywords\" VALUES(4,'Bing','bing.com'," |
| 1607 "'http://www.bing.com/s/wlflag.ico','http://www.bing.com/search?" |
| 1608 "setmkt=en-US&q={searchTerms}',1,1,'',0,0,'UTF-8'," |
| 1609 "'http://api.bing.com/osjson.aspx?query={searchTerms}&" |
| 1610 "language={language}',3,0);" |
| 1611 "INSERT INTO \"keywords\" VALUES(5,'Wikipedia (en)','en.wikipedia.org',''," |
| 1612 "'http://en.wikipedia.org/w/index.php?title=Special:Search&" |
| 1613 "search={searchTerms}',1,0,'',1283287335,0,'','',0,0);" |
| 1614 "INSERT INTO \"keywords\" VALUES(6,'NYTimes','query.nytimes.com',''," |
| 1615 "'http://query.nytimes.com/gst/handler.html?query={searchTerms}&" |
| 1616 "opensearch=1',1,0,'',1283287335,0,'','',0,0);" |
| 1617 "INSERT INTO \"keywords\" VALUES(7,'eBay','rover.ebay.com',''," |
| 1618 "'http://rover.ebay.com/rover/1/711-43047-14818-1/4?" |
| 1619 "satitle={searchTerms}',1,0,'',1283287335,0,'','',0,0);" |
| 1620 "INSERT INTO \"keywords\" VALUES(8,'ff','ff','','http://ff{searchTerms}'," |
| 1621 "0,0,'',1283287356,0,'','',0,0);" |
| 1622 "CREATE TABLE logins (origin_url VARCHAR NOT NULL, action_url VARCHAR, " |
| 1623 "username_element VARCHAR, username_value VARCHAR, " |
| 1624 "password_element VARCHAR, password_value BLOB, submit_element VARCHAR," |
| 1625 "signon_realm VARCHAR NOT NULL,ssl_valid INTEGER NOT NULL," |
| 1626 "preferred INTEGER NOT NULL,date_created INTEGER NOT NULL," |
| 1627 "blacklisted_by_user INTEGER NOT NULL,scheme INTEGER NOT NULL," |
| 1628 "UNIQUE (origin_url, username_element, username_value, " |
| 1629 "password_element, submit_element, signon_realm));" |
| 1630 "CREATE TABLE ie7_logins (url_hash VARCHAR NOT NULL, password_value BLOB, " |
| 1631 "date_created INTEGER NOT NULL,UNIQUE (url_hash));" |
| 1632 "CREATE TABLE web_app_icons (url LONGVARCHAR,width int,height int," |
| 1633 "image BLOB, UNIQUE (url, width, height));" |
| 1634 "CREATE TABLE web_apps (url LONGVARCHAR UNIQUE," |
| 1635 "has_all_images INTEGER NOT NULL);" |
| 1636 "CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR, " |
| 1637 "pair_id INTEGER PRIMARY KEY, count INTEGER DEFAULT 1);" |
| 1638 "CREATE TABLE autofill_dates ( pair_id INTEGER DEFAULT 0," |
| 1639 "date_created INTEGER DEFAULT 0);" |
| 1640 "CREATE INDEX logins_signon ON logins (signon_realm);" |
| 1641 "CREATE INDEX ie7_logins_hash ON ie7_logins (url_hash);" |
| 1642 "CREATE INDEX web_apps_url_index ON web_apps (url);" |
| 1643 "CREATE INDEX autofill_name ON autofill (name);" |
| 1644 "CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);" |
| 1645 "CREATE INDEX autofill_dates_pair_id ON autofill_dates (pair_id);")); |
| 1646 ASSERT_TRUE(connection.CommitTransaction()); |
| 1647 } |
| 1648 |
| 1649 // This schema is taken from a build after the addition of the |credit_card| |
| 1650 // table. Due to a bug in the migration logic the version is set incorrectly to |
| 1651 // 22 (it should have been updated to 23 at least). |
| 1652 void WebDatabaseMigrationTest::SetUpVersion22CorruptDatabase() { |
| 1653 sql::Connection connection; |
| 1654 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1655 ASSERT_TRUE(connection.BeginTransaction()); |
| 1656 ASSERT_TRUE(connection.Execute( |
| 1657 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," |
| 1658 "value LONGVARCHAR);" |
| 1659 "INSERT INTO \"meta\" VALUES('version','22');" |
| 1660 "INSERT INTO \"meta\" VALUES('last_compatible_version','21');" |
| 1661 "INSERT INTO \"meta\" VALUES('Default Search Provider ID','2');" |
| 1662 "INSERT INTO \"meta\" VALUES('Builtin Keyword Version','29');" |
| 1663 "CREATE TABLE keywords (id INTEGER PRIMARY KEY," |
| 1664 "short_name VARCHAR NOT NULL,keyword VARCHAR NOT NULL," |
| 1665 "favicon_url VARCHAR NOT NULL,url VARCHAR NOT NULL," |
| 1666 "show_in_default_list INTEGER,safe_for_autoreplace INTEGER," |
| 1667 "originating_url VARCHAR,date_created INTEGER DEFAULT 0," |
| 1668 "usage_count INTEGER DEFAULT 0,input_encodings VARCHAR," |
| 1669 "suggest_url VARCHAR,prepopulate_id INTEGER DEFAULT 0," |
| 1670 "autogenerate_keyword INTEGER DEFAULT 0);" |
| 1671 "INSERT INTO \"keywords\" VALUES(2,'Google','google.com'," |
| 1672 "'http://www.google.com/favicon.ico','{google:baseURL}search?" |
| 1673 "{google:RLZ}{google:acceptedSuggestion}" |
| 1674 "{google:originalQueryForSuggestion}sourceid=chrome&" |
| 1675 "ie={inputEncoding}&q={searchTerms}',1,1,'',0,0,'UTF-8'," |
| 1676 "'{google:baseSuggestURL}search?client=chrome&hl={language}&" |
| 1677 "q={searchTerms}',1,1);" |
| 1678 "INSERT INTO \"keywords\" VALUES(3,'Yahoo!','yahoo.com'," |
| 1679 "'http://search.yahoo.com/favicon.ico'," |
| 1680 "'http://search.yahoo.com/search?ei={inputEncoding}&fr=crmas&" |
| 1681 "p={searchTerms}',1,1,'',0,0,'UTF-8'," |
| 1682 "'http://ff.search.yahoo.com/gossip?output=fxjson&" |
| 1683 "command={searchTerms}',2,0);" |
| 1684 "INSERT INTO \"keywords\" VALUES(4,'Bing','bing.com'," |
| 1685 "'http://www.bing.com/s/wlflag.ico','http://www.bing.com/search?" |
| 1686 "setmkt=en-US&q={searchTerms}',1,1,'',0,0,'UTF-8'," |
| 1687 "'http://api.bing.com/osjson.aspx?query={searchTerms}&" |
| 1688 "language={language}',3,0);" |
| 1689 "INSERT INTO \"keywords\" VALUES(5,'Wikipedia (en)','en.wikipedia.org'," |
| 1690 "'','http://en.wikipedia.org/w/index.php?title=Special:Search&" |
| 1691 "search={searchTerms}',1,0,'',1283287335,0,'','',0,0);" |
| 1692 "INSERT INTO \"keywords\" VALUES(6,'NYTimes','query.nytimes.com',''," |
| 1693 "'http://query.nytimes.com/gst/handler.html?query={searchTerms}&" |
| 1694 "opensearch=1',1,0,'',1283287335,0,'','',0,0);" |
| 1695 "INSERT INTO \"keywords\" VALUES(7,'eBay','rover.ebay.com',''," |
| 1696 "'http://rover.ebay.com/rover/1/711-43047-14818-1/4?" |
| 1697 "satitle={searchTerms}',1,0,'',1283287335,0,'','',0,0);" |
| 1698 "INSERT INTO \"keywords\" VALUES(8,'ff','ff','','http://ff{searchTerms}'" |
| 1699 ",0,0,'',1283287356,0,'','',0,0);" |
| 1700 "CREATE TABLE logins (origin_url VARCHAR NOT NULL, action_url VARCHAR, " |
| 1701 "username_element VARCHAR, username_value VARCHAR, " |
| 1702 "password_element VARCHAR, password_value BLOB, " |
| 1703 "submit_element VARCHAR, signon_realm VARCHAR NOT NULL," |
| 1704 "ssl_valid INTEGER NOT NULL,preferred INTEGER NOT NULL," |
| 1705 "date_created INTEGER NOT NULL,blacklisted_by_user INTEGER NOT NULL," |
| 1706 "scheme INTEGER NOT NULL,UNIQUE (origin_url, username_element, " |
| 1707 "username_value, password_element, submit_element, signon_realm));" |
| 1708 "CREATE TABLE ie7_logins (url_hash VARCHAR NOT NULL, password_value BLOB," |
| 1709 "date_created INTEGER NOT NULL,UNIQUE (url_hash));" |
| 1710 "CREATE TABLE web_app_icons (url LONGVARCHAR,width int,height int," |
| 1711 "image BLOB, UNIQUE (url, width, height));" |
| 1712 "CREATE TABLE web_apps (url LONGVARCHAR UNIQUE," |
| 1713 "has_all_images INTEGER NOT NULL);" |
| 1714 "CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR," |
| 1715 "pair_id INTEGER PRIMARY KEY, count INTEGER DEFAULT 1);" |
| 1716 "CREATE TABLE autofill_dates ( pair_id INTEGER DEFAULT 0," |
| 1717 "date_created INTEGER DEFAULT 0);" |
| 1718 "CREATE TABLE autofill_profiles ( label VARCHAR, " |
| 1719 "unique_id INTEGER PRIMARY KEY, first_name VARCHAR, " |
| 1720 "middle_name VARCHAR, last_name VARCHAR, email VARCHAR, " |
| 1721 "company_name VARCHAR, address_line_1 VARCHAR, " |
| 1722 "address_line_2 VARCHAR, city VARCHAR, state VARCHAR, " |
| 1723 "zipcode VARCHAR, country VARCHAR, phone VARCHAR, fax VARCHAR);" |
| 1724 "CREATE TABLE credit_cards ( label VARCHAR, " |
| 1725 "unique_id INTEGER PRIMARY KEY, name_on_card VARCHAR, type VARCHAR," |
| 1726 "card_number VARCHAR, expiration_month INTEGER, " |
| 1727 "expiration_year INTEGER, verification_code VARCHAR, " |
| 1728 "billing_address VARCHAR, shipping_address VARCHAR, " |
| 1729 "card_number_encrypted BLOB, verification_code_encrypted BLOB);" |
| 1730 "CREATE INDEX logins_signon ON logins (signon_realm);" |
| 1731 "CREATE INDEX ie7_logins_hash ON ie7_logins (url_hash);" |
| 1732 "CREATE INDEX web_apps_url_index ON web_apps (url);" |
| 1733 "CREATE INDEX autofill_name ON autofill (name);" |
| 1734 "CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);" |
| 1735 "CREATE INDEX autofill_dates_pair_id ON autofill_dates (pair_id);" |
| 1736 "CREATE INDEX autofill_profiles_label_index ON autofill_profiles (label);" |
| 1737 "CREATE INDEX credit_cards_label_index ON credit_cards (label);")); |
| 1738 ASSERT_TRUE(connection.CommitTransaction()); |
| 1739 } |
| 1740 |
| 1741 // This schema is taken from a build prior to the addition of the |keywords| |
| 1742 // |logo_id| column. |
| 1743 void WebDatabaseMigrationTest::SetUpVersion24Database() { |
| 1744 sql::Connection connection; |
| 1745 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1746 ASSERT_TRUE(connection.BeginTransaction()); |
| 1747 ASSERT_TRUE(connection.Execute( |
| 1748 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," |
| 1749 "value LONGVARCHAR);" |
| 1750 "INSERT INTO \"meta\" VALUES('version','24');" |
| 1751 "INSERT INTO \"meta\" VALUES('last_compatible_version','24');" |
| 1752 "CREATE TABLE keywords (id INTEGER PRIMARY KEY,short_name VARCHAR NOT NULL," |
| 1753 "keyword VARCHAR NOT NULL,favicon_url VARCHAR NOT NULL," |
| 1754 "url VARCHAR NOT NULL,show_in_default_list INTEGER," |
| 1755 "safe_for_autoreplace INTEGER,originating_url VARCHAR," |
| 1756 "date_created INTEGER DEFAULT 0,usage_count INTEGER DEFAULT 0," |
| 1757 "input_encodings VARCHAR,suggest_url VARCHAR," |
| 1758 "prepopulate_id INTEGER DEFAULT 0," |
| 1759 "autogenerate_keyword INTEGER DEFAULT 0);" |
| 1760 "CREATE TABLE logins (origin_url VARCHAR NOT NULL, action_url VARCHAR," |
| 1761 "username_element VARCHAR, username_value VARCHAR," |
| 1762 "password_element VARCHAR, password_value BLOB, submit_element VARCHAR," |
| 1763 "signon_realm VARCHAR NOT NULL," |
| 1764 "ssl_valid INTEGER NOT NULL,preferred INTEGER NOT NULL," |
| 1765 "date_created INTEGER NOT NULL,blacklisted_by_user INTEGER NOT NULL," |
| 1766 "scheme INTEGER NOT NULL,UNIQUE (origin_url, username_element," |
| 1767 "username_value, password_element, submit_element, signon_realm));" |
| 1768 "CREATE TABLE web_app_icons (url LONGVARCHAR,width int,height int," |
| 1769 "image BLOB, UNIQUE (url, width, height));" |
| 1770 "CREATE TABLE web_apps (url LONGVARCHAR UNIQUE," |
| 1771 "has_all_images INTEGER NOT NULL);" |
| 1772 "CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR," |
| 1773 "pair_id INTEGER PRIMARY KEY, count INTEGER DEFAULT 1);" |
| 1774 "CREATE TABLE autofill_dates ( pair_id INTEGER DEFAULT 0," |
| 1775 "date_created INTEGER DEFAULT 0);" |
| 1776 "CREATE TABLE autofill_profiles ( label VARCHAR," |
| 1777 "unique_id INTEGER PRIMARY KEY, first_name VARCHAR," |
| 1778 "middle_name VARCHAR, last_name VARCHAR, email VARCHAR," |
| 1779 "company_name VARCHAR, address_line_1 VARCHAR, address_line_2 VARCHAR," |
| 1780 "city VARCHAR, state VARCHAR, zipcode VARCHAR, country VARCHAR," |
| 1781 "phone VARCHAR, fax VARCHAR);" |
| 1782 "CREATE TABLE credit_cards ( label VARCHAR, unique_id INTEGER PRIMARY KEY," |
| 1783 "name_on_card VARCHAR, type VARCHAR, card_number VARCHAR," |
| 1784 "expiration_month INTEGER, expiration_year INTEGER," |
| 1785 "verification_code VARCHAR, billing_address VARCHAR," |
| 1786 "shipping_address VARCHAR, card_number_encrypted BLOB," |
| 1787 "verification_code_encrypted BLOB);" |
| 1788 "CREATE TABLE token_service (service VARCHAR PRIMARY KEY NOT NULL," |
| 1789 "encrypted_token BLOB);" |
| 1790 "CREATE INDEX logins_signon ON logins (signon_realm);" |
| 1791 "CREATE INDEX web_apps_url_index ON web_apps (url);" |
| 1792 "CREATE INDEX autofill_name ON autofill (name);" |
| 1793 "CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);" |
| 1794 "CREATE INDEX autofill_dates_pair_id ON autofill_dates (pair_id);" |
| 1795 "CREATE INDEX autofill_profiles_label_index ON autofill_profiles (label);" |
| 1796 "CREATE INDEX credit_cards_label_index ON credit_cards (label);")); |
| 1797 ASSERT_TRUE(connection.CommitTransaction()); |
| 1798 } |
| 1799 |
| 1800 // Tests that the all migrations from an empty database succeed. |
| 1801 TEST_F(WebDatabaseMigrationTest, MigrateEmptyToCurrent) { |
| 1802 // Load the database via the WebDatabase class and migrate the database to |
| 1803 // the current version. |
| 1804 { |
| 1805 WebDatabase db; |
| 1806 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
| 1807 } |
| 1808 |
| 1809 // Verify post-conditions. These are expectations for current version of the |
| 1810 // database. |
| 1811 { |
| 1812 sql::Connection connection; |
| 1813 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1814 |
| 1815 // Check version. |
| 1816 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 1817 |
| 1818 // Check that expected tables are present. |
| 1819 EXPECT_TRUE(connection.DoesTableExist("meta")); |
| 1820 EXPECT_TRUE(connection.DoesTableExist("keywords")); |
| 1821 EXPECT_TRUE(connection.DoesTableExist("logins")); |
| 1822 EXPECT_TRUE(connection.DoesTableExist("web_app_icons")); |
| 1823 EXPECT_TRUE(connection.DoesTableExist("web_apps")); |
| 1824 EXPECT_TRUE(connection.DoesTableExist("autofill")); |
| 1825 EXPECT_TRUE(connection.DoesTableExist("autofill_dates")); |
| 1826 EXPECT_TRUE(connection.DoesTableExist("autofill_profiles")); |
| 1827 EXPECT_TRUE(connection.DoesTableExist("credit_cards")); |
| 1828 EXPECT_TRUE(connection.DoesTableExist("token_service")); |
| 1829 } |
| 1830 } |
| 1831 |
| 1832 // Tests that the |credit_card| table gets added to the schema for a version 22 |
| 1833 // database. |
| 1834 TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) { |
| 1835 // Initialize the database. |
| 1836 SetUpVersion22Database(); |
| 1837 |
| 1838 // Verify pre-conditions. |
| 1839 { |
| 1840 sql::Connection connection; |
| 1841 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1842 |
| 1843 // No |credit_card| table prior to version 23. |
| 1844 ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id")); |
| 1845 ASSERT_FALSE( |
| 1846 connection.DoesColumnExist("credit_cards", "card_number_encrypted")); |
| 1847 } |
| 1848 |
| 1849 // Load the database via the WebDatabase class and migrate the database to |
| 1850 // the current version. |
| 1851 { |
| 1852 WebDatabase db; |
| 1853 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
| 1854 } |
| 1855 |
| 1856 // Verify post-conditions. These are expectations for current version of the |
| 1857 // database. |
| 1858 { |
| 1859 sql::Connection connection; |
| 1860 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1861 |
| 1862 // Check version. |
| 1863 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 1864 |
| 1865 // |credit_card| table now exists. |
| 1866 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id")); |
| 1867 EXPECT_TRUE( |
| 1868 connection.DoesColumnExist("credit_cards", "card_number_encrypted")); |
| 1869 } |
| 1870 } |
| 1871 |
| 1872 // Tests that the |credit_card| table gets added to the schema for a corrupt |
| 1873 // version 22 database. The corruption is that the |credit_cards| table exists |
| 1874 // but the schema version number was not set correctly to 23 or later. This |
| 1875 // test exercises code introduced to fix bug http://crbug.com/50699 that |
| 1876 // resulted from the corruption. |
| 1877 TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) { |
| 1878 // Initialize the database. |
| 1879 SetUpVersion22CorruptDatabase(); |
| 1880 |
| 1881 // Verify pre-conditions. These are expectations for corrupt version 22 of |
| 1882 // the database. |
| 1883 { |
| 1884 sql::Connection connection; |
| 1885 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1886 |
| 1887 // Columns existing and not existing before current version. |
| 1888 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id")); |
| 1889 ASSERT_TRUE( |
| 1890 connection.DoesColumnExist("credit_cards", "card_number_encrypted")); |
| 1891 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id")); |
| 1892 ASSERT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); |
| 1893 } |
| 1894 |
| 1895 // Load the database via the WebDatabase class and migrate the database to |
| 1896 // the current version. |
| 1897 { |
| 1898 WebDatabase db; |
| 1899 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
| 1900 } |
| 1901 |
| 1902 // Verify post-conditions. These are expectations for current version of the |
| 1903 // database. |
| 1904 { |
| 1905 sql::Connection connection; |
| 1906 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1907 |
| 1908 // Check version. |
| 1909 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 1910 |
| 1911 |
| 1912 // Columns existing and not existing before version 25. |
| 1913 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id")); |
| 1914 EXPECT_TRUE( |
| 1915 connection.DoesColumnExist("credit_cards", "card_number_encrypted")); |
| 1916 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); |
| 1917 EXPECT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); |
| 1918 } |
| 1919 } |
| 1920 |
| 1921 // Tests that the |keywords| |logo_id| column gets added to the schema for a |
| 1922 // version 24 database. |
| 1923 TEST_F(WebDatabaseMigrationTest, MigrateVersion24ToCurrent) { |
| 1924 // Initialize the database. |
| 1925 SetUpVersion24Database(); |
| 1926 |
| 1927 // Verify pre-conditions. These are expectations for version 24 of the |
| 1928 // database. |
| 1929 { |
| 1930 sql::Connection connection; |
| 1931 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1932 |
| 1933 // Columns existing and not existing before current version. |
| 1934 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id")); |
| 1935 ASSERT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); |
| 1936 } |
| 1937 |
| 1938 // Load the database via the WebDatabase class and migrate the database to |
| 1939 // the current version. |
| 1940 { |
| 1941 WebDatabase db; |
| 1942 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
| 1943 } |
| 1944 |
| 1945 // Verify post-conditions. These are expectations for current version of the |
| 1946 // database. |
| 1947 { |
| 1948 sql::Connection connection; |
| 1949 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1950 |
| 1951 // Check version. |
| 1952 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 1953 |
| 1954 // |keywords| |logo_id| column should have been added. |
| 1955 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); |
| 1956 EXPECT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); |
| 1957 } |
| 1958 } |
OLD | NEW |