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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 void SetUpVersion70Database(sql::Connection* connection); | 56 void SetUpVersion70Database(sql::Connection* connection); |
57 void SetUpVersion71Database(sql::Connection* connection); | 57 void SetUpVersion71Database(sql::Connection* connection); |
58 void SetUpVersion72Database(sql::Connection* connection); | 58 void SetUpVersion72Database(sql::Connection* connection); |
59 void SetUpVersion73Database(sql::Connection* connection); | 59 void SetUpVersion73Database(sql::Connection* connection); |
60 void SetUpVersion74Database(sql::Connection* connection); | 60 void SetUpVersion74Database(sql::Connection* connection); |
61 void SetUpVersion75Database(sql::Connection* connection); | 61 void SetUpVersion75Database(sql::Connection* connection); |
62 void SetUpVersion76Database(sql::Connection* connection); | 62 void SetUpVersion76Database(sql::Connection* connection); |
63 void SetUpVersion77Database(sql::Connection* connection); | 63 void SetUpVersion77Database(sql::Connection* connection); |
64 void SetUpVersion78Database(sql::Connection* connection); | 64 void SetUpVersion78Database(sql::Connection* connection); |
65 void SetUpVersion79Database(sql::Connection* connection); | 65 void SetUpVersion79Database(sql::Connection* connection); |
66 void SetUpVersion80Database(sql::Connection* connection); | |
66 | 67 |
67 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { | 68 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { |
68 SetUpVersion77Database(connection); // Prepopulates data. | 69 SetUpVersion77Database(connection); // Prepopulates data. |
69 scoped_ptr<TestDirectoryBackingStore> dbs( | 70 scoped_ptr<TestDirectoryBackingStore> dbs( |
70 new TestDirectoryBackingStore(GetUsername(), connection)); | 71 new TestDirectoryBackingStore(GetUsername(), connection)); |
71 | 72 |
72 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); | 73 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); |
73 ASSERT_FALSE(dbs->needs_column_refresh_); | 74 ASSERT_FALSE(dbs->needs_column_refresh_); |
74 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); | 75 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); |
75 } | 76 } |
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1623 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" | 1624 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" |
1624 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" | 1625 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" |
1625 "ult -2, cache_guid TEXT , notification_state BLOB);" | 1626 "ult -2, cache_guid TEXT , notification_state BLOB);" |
1626 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," | 1627 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," |
1627 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'" | 1628 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'" |
1628 "9010788312004066376x-6609234393368420856x',NULL);" | 1629 "9010788312004066376x-6609234393368420856x',NULL);" |
1629 )); | 1630 )); |
1630 ASSERT_TRUE(connection->CommitTransaction()); | 1631 ASSERT_TRUE(connection->CommitTransaction()); |
1631 } | 1632 } |
1632 | 1633 |
1634 //Todo(vishwath): Noticed that the share_version is retained as 78 below. | |
1635 // Is that intentional or should it be fixed? | |
rlarocque
2012/09/28 01:43:40
I'd fix it.
| |
1633 void MigrationTest::SetUpVersion79Database(sql::Connection* connection) { | 1636 void MigrationTest::SetUpVersion79Database(sql::Connection* connection) { |
1634 ASSERT_TRUE(connection->is_open()); | 1637 ASSERT_TRUE(connection->is_open()); |
1635 ASSERT_TRUE(connection->BeginTransaction()); | 1638 ASSERT_TRUE(connection->BeginTransaction()); |
1636 ASSERT_TRUE(connection->Execute( | 1639 ASSERT_TRUE(connection->Execute( |
1637 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" | 1640 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" |
1638 "INSERT INTO 'share_version' VALUES('nick@chromium.org',78);" | 1641 "INSERT INTO 'share_version' VALUES('nick@chromium.org',78);" |
1639 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in" | 1642 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in" |
1640 "itial_sync_ended BOOLEAN default 0);" | 1643 "itial_sync_ended BOOLEAN default 0);" |
1641 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);" | 1644 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);" |
1642 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base" | 1645 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1718 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" | 1721 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" |
1719 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" | 1722 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" |
1720 "ult -2, cache_guid TEXT , notification_state BLOB);" | 1723 "ult -2, cache_guid TEXT , notification_state BLOB);" |
1721 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," | 1724 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," |
1722 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," | 1725 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," |
1723 "-131078,'9010788312004066376x-6609234393368420856x',NULL);" | 1726 "-131078,'9010788312004066376x-6609234393368420856x',NULL);" |
1724 )); | 1727 )); |
1725 ASSERT_TRUE(connection->CommitTransaction()); | 1728 ASSERT_TRUE(connection->CommitTransaction()); |
1726 } | 1729 } |
1727 | 1730 |
1731 void MigrationTest::SetUpVersion80Database(sql::Connection* connection) { | |
1732 ASSERT_TRUE(connection->is_open()); | |
1733 ASSERT_TRUE(connection->BeginTransaction()); | |
1734 ASSERT_TRUE(connection->Execute( | |
1735 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" | |
1736 "INSERT INTO 'share_version' VALUES('nick@chromium.org',80);" | |
1737 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in" | |
1738 "itial_sync_ended BOOLEAN default 0);" | |
1739 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);" | |
1740 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base" | |
1741 "_version bigint default -1,server_version bigint default 0,server_po" | |
1742 "sition_in_parent bigint default 0,local_external_id bigint default 0" | |
1743 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d" | |
1744 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p" | |
1745 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa" | |
1746 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul" | |
1747 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is" | |
1748 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0," | |
1749 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu" | |
1750 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc" | |
1751 "har,specifics blob,server_specifics blob, base_server_specifics BLOB" | |
1752 ");" | |
1753 "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','" | |
1754 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);" | |
1755 "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4," | |
1756 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_" | |
1757 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1" | |
1758 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X" | |
1759 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534" | |
1760 "14447414447414447',NULL);" | |
1761 "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3," | |
1762 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_" | |
1763 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL" | |
1764 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6" | |
1765 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687" | |
1766 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656" | |
1767 "E2F77656C636F6D652E68746D6C1200',NULL);" | |
1768 "INSERT INTO 'metas' VALUES(5,677,677,1048576,7," | |
1769 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_" | |
1770 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2" | |
1771 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1" | |
1772 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N" | |
1773 "ULL);" | |
1774 "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6," | |
1775 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1" | |
1776 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'" | |
1777 ",NULL);" | |
1778 "INSERT INTO 'metas' VALUES(7,663,663,1048576,0," | |
1779 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog" | |
1780 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL, NULL" | |
1781 ");" | |
1782 "INSERT INTO 'metas' VALUES(8,664,664,1048576,0," | |
1783 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1" | |
1784 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810" | |
1785 "00',X'C2881000',NULL);" | |
1786 "INSERT INTO 'metas' VALUES(9,665,665,1048576,1," | |
1787 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0" | |
1788 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881" | |
1789 "000',X'C2881000',NULL);" | |
1790 "INSERT INTO 'metas' VALUES(10,666,666,2097152,2," | |
1791 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r'," | |
1792 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU" | |
1793 "LL,X'C2881000',X'C2881000',NULL);" | |
1794 "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8," | |
1795 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'" | |
1796 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj" | |
1797 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756" | |
1798 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636" | |
1799 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);" | |
1800 "INSERT INTO 'metas' VALUES(12,685,685,0,9," | |
1801 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_" | |
1802 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C" | |
1803 "2881000',X'C2881000',NULL);" | |
1804 "INSERT INTO 'metas' VALUES(13,687,687,-917504,10," | |
1805 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_" | |
1806 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names " | |
1807 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu" | |
1808 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636" | |
1809 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772" | |
1810 "E6963616E6E2E636F6D2F120744414146415346',NULL);" | |
1811 "INSERT INTO 'metas' VALUES(14,692,692,1048576,11," | |
1812 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'" | |
1813 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc" | |
1814 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726" | |
1815 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7" | |
1816 "81205504E473259',NULL);" | |
1817 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" | |
1818 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" | |
1819 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips " | |
1820 "blob);" | |
1821 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," | |
1822 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," | |
1823 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);" | |
1824 )); | |
1825 ASSERT_TRUE(connection->CommitTransaction()); | |
1826 } | |
1827 | |
1828 | |
1728 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { | 1829 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { |
1729 sql::Connection connection; | 1830 sql::Connection connection; |
1730 ASSERT_TRUE(connection.OpenInMemory()); | 1831 ASSERT_TRUE(connection.OpenInMemory()); |
1731 | 1832 |
1732 SetUpVersion67Database(&connection); | 1833 SetUpVersion67Database(&connection); |
1733 | 1834 |
1734 // Columns existing before version 67. | 1835 // Columns existing before version 67. |
1735 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); | 1836 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); |
1736 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); | 1837 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); |
1737 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); | 1838 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2072 Directory::KernelLoadInfo load_info; | 2173 Directory::KernelLoadInfo load_info; |
2073 | 2174 |
2074 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); | 2175 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); |
2075 // Check that the initial value is the serialization of an empty ChipBag. | 2176 // Check that the initial value is the serialization of an empty ChipBag. |
2076 sync_pb::ChipBag chip_bag; | 2177 sync_pb::ChipBag chip_bag; |
2077 std::string serialized_chip_bag; | 2178 std::string serialized_chip_bag; |
2078 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); | 2179 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); |
2079 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); | 2180 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); |
2080 } | 2181 } |
2081 | 2182 |
2183 TEST_F(DirectoryBackingStoreTest, MigrateVersion80To81) { | |
2184 sql::Connection connection; | |
2185 ASSERT_TRUE(connection.OpenInMemory()); | |
2186 SetupVersion80Database(&connection); | |
2187 | |
2188 sql::Statement s(connection.GetUniqueStatement( | |
2189 "SELECT id FROM metas WHERE unique_server_tag = 'google_chrome'")); | |
2190 ASSERT_TRUE(s.Step()); | |
2191 ASSERT_EQ(s.ColumnType(3), COLUMN_TYPE_INTEGER); | |
2192 | |
2193 scoped_ptr<TestDirectoryBackingStore> dbs( | |
2194 new TestDirectoryBackingStore(GetUsername(), &connection)); | |
2195 ASSERT_TRUE(dbs->MigrateVersion80To81()); | |
2196 | |
2197 sql::Statement s(connection.GetUniqueStatement( | |
2198 "SELECT id FROM metas WHERE unique_server_tag = 'google_chrome'")); | |
2199 ASSERT_TRUE(s.Step()); | |
2200 ASSERT_EQ(s.ColumnType(3), COLUMN_TYPE_TEXT); | |
2201 ASSERT_EQ("1048576", s.ColumnString); | |
rlarocque
2012/09/28 01:43:40
I don't think this is right.
Wouldn't the int64 v
| |
2202 } | |
2203 | |
rlarocque
2012/09/28 01:43:40
Given the likelihood of a regression, I think you
| |
2082 TEST_P(MigrationTest, ToCurrentVersion) { | 2204 TEST_P(MigrationTest, ToCurrentVersion) { |
2083 sql::Connection connection; | 2205 sql::Connection connection; |
2084 ASSERT_TRUE(connection.OpenInMemory()); | 2206 ASSERT_TRUE(connection.OpenInMemory()); |
2085 switch (GetParam()) { | 2207 switch (GetParam()) { |
2086 case 67: | 2208 case 67: |
2087 SetUpVersion67Database(&connection); | 2209 SetUpVersion67Database(&connection); |
2088 break; | 2210 break; |
2089 case 68: | 2211 case 68: |
2090 SetUpVersion68Database(&connection); | 2212 SetUpVersion68Database(&connection); |
2091 break; | 2213 break; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2452 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); | 2574 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); |
2453 EXPECT_EQ(24U, guid1.size()); | 2575 EXPECT_EQ(24U, guid1.size()); |
2454 EXPECT_EQ(24U, guid2.size()); | 2576 EXPECT_EQ(24U, guid2.size()); |
2455 // In theory this test can fail, but it won't before the universe | 2577 // In theory this test can fail, but it won't before the universe |
2456 // dies of heat death. | 2578 // dies of heat death. |
2457 EXPECT_NE(guid1, guid2); | 2579 EXPECT_NE(guid1, guid2); |
2458 } | 2580 } |
2459 | 2581 |
2460 } // namespace syncable | 2582 } // namespace syncable |
2461 } // namespace syncer | 2583 } // namespace syncer |
OLD | NEW |