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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "sql/connection.h" | 15 #include "sql/connection.h" |
16 #include "sql/statement.h" | 16 #include "sql/statement.h" |
| 17 #include "sync/internal_api/public/base/node_ordinal.h" |
17 #include "sync/protocol/bookmark_specifics.pb.h" | 18 #include "sync/protocol/bookmark_specifics.pb.h" |
18 #include "sync/protocol/sync.pb.h" | 19 #include "sync/protocol/sync.pb.h" |
19 #include "sync/syncable/directory_backing_store.h" | 20 #include "sync/syncable/directory_backing_store.h" |
20 #include "sync/syncable/on_disk_directory_backing_store.h" | 21 #include "sync/syncable/on_disk_directory_backing_store.h" |
21 #include "sync/syncable/syncable-inl.h" | 22 #include "sync/syncable/syncable-inl.h" |
22 #include "sync/test/test_directory_backing_store.h" | 23 #include "sync/test/test_directory_backing_store.h" |
23 #include "sync/util/time.h" | 24 #include "sync/util/time.h" |
24 #include "testing/gtest/include/gtest/gtest-param-test.h" | 25 #include "testing/gtest/include/gtest/gtest-param-test.h" |
25 | 26 |
26 namespace syncer { | 27 namespace syncer { |
(...skipping 29 matching lines...) Expand all Loading... |
56 void SetUpVersion70Database(sql::Connection* connection); | 57 void SetUpVersion70Database(sql::Connection* connection); |
57 void SetUpVersion71Database(sql::Connection* connection); | 58 void SetUpVersion71Database(sql::Connection* connection); |
58 void SetUpVersion72Database(sql::Connection* connection); | 59 void SetUpVersion72Database(sql::Connection* connection); |
59 void SetUpVersion73Database(sql::Connection* connection); | 60 void SetUpVersion73Database(sql::Connection* connection); |
60 void SetUpVersion74Database(sql::Connection* connection); | 61 void SetUpVersion74Database(sql::Connection* connection); |
61 void SetUpVersion75Database(sql::Connection* connection); | 62 void SetUpVersion75Database(sql::Connection* connection); |
62 void SetUpVersion76Database(sql::Connection* connection); | 63 void SetUpVersion76Database(sql::Connection* connection); |
63 void SetUpVersion77Database(sql::Connection* connection); | 64 void SetUpVersion77Database(sql::Connection* connection); |
64 void SetUpVersion78Database(sql::Connection* connection); | 65 void SetUpVersion78Database(sql::Connection* connection); |
65 void SetUpVersion79Database(sql::Connection* connection); | 66 void SetUpVersion79Database(sql::Connection* connection); |
| 67 void SetUpVersion80Database(sql::Connection* connection); |
| 68 void SetUpVersion81Database(sql::Connection* connection); |
66 | 69 |
67 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { | 70 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { |
68 SetUpVersion77Database(connection); // Prepopulates data. | 71 SetUpVersion77Database(connection); // Prepopulates data. |
69 scoped_ptr<TestDirectoryBackingStore> dbs( | 72 scoped_ptr<TestDirectoryBackingStore> dbs( |
70 new TestDirectoryBackingStore(GetUsername(), connection)); | 73 new TestDirectoryBackingStore(GetUsername(), connection)); |
71 | 74 |
72 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); | 75 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); |
73 ASSERT_FALSE(dbs->needs_column_refresh_); | 76 ASSERT_FALSE(dbs->needs_column_refresh_); |
74 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); | 77 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); |
75 } | 78 } |
(...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 "9010788312004066376x-6609234393368420856x',NULL);" | 1631 "9010788312004066376x-6609234393368420856x',NULL);" |
1629 )); | 1632 )); |
1630 ASSERT_TRUE(connection->CommitTransaction()); | 1633 ASSERT_TRUE(connection->CommitTransaction()); |
1631 } | 1634 } |
1632 | 1635 |
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',79);" |
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" |
1643 "_version bigint default -1,server_version bigint default 0,server_po" | 1646 "_version bigint default -1,server_version bigint default 0,server_po" |
1644 "sition_in_parent bigint default 0,local_external_id bigint default 0" | 1647 "sition_in_parent bigint default 0,local_external_id bigint default 0" |
1645 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d" | 1648 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d" |
1646 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p" | 1649 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p" |
1647 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa" | 1650 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa" |
1648 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul" | 1651 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul" |
(...skipping 69 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);" |
| 1781 "INSERT INTO 'metas' VALUES(8,664,664,1048576,0," |
| 1782 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1" |
| 1783 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810" |
| 1784 "00',X'C2881000',NULL);" |
| 1785 "INSERT INTO 'metas' VALUES(9,665,665,1048576,1," |
| 1786 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0" |
| 1787 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881" |
| 1788 "000',X'C2881000',NULL);" |
| 1789 "INSERT INTO 'metas' VALUES(10,666,666,2097152,2," |
| 1790 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r'," |
| 1791 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU" |
| 1792 "LL,X'C2881000',X'C2881000',NULL);" |
| 1793 "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8," |
| 1794 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'" |
| 1795 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj" |
| 1796 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756" |
| 1797 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636" |
| 1798 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);" |
| 1799 "INSERT INTO 'metas' VALUES(12,685,685,0,9," |
| 1800 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_" |
| 1801 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C" |
| 1802 "2881000',X'C2881000',NULL);" |
| 1803 "INSERT INTO 'metas' VALUES(13,687,687,-917504,10," |
| 1804 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_" |
| 1805 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names " |
| 1806 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu" |
| 1807 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636" |
| 1808 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772" |
| 1809 "E6963616E6E2E636F6D2F120744414146415346',NULL);" |
| 1810 "INSERT INTO 'metas' VALUES(14,692,692,1048576,11," |
| 1811 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'" |
| 1812 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc" |
| 1813 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726" |
| 1814 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7" |
| 1815 "81205504E473259',NULL);" |
| 1816 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" |
| 1817 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" |
| 1818 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips " |
| 1819 "blob);" |
| 1820 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," |
| 1821 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," |
| 1822 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);" |
| 1823 )); |
| 1824 ASSERT_TRUE(connection->CommitTransaction()); |
| 1825 } |
| 1826 |
| 1827 |
| 1828 // Helper definitions to create the version 81 DB tables. |
| 1829 namespace { |
| 1830 |
| 1831 const int V80_ROW_COUNT = 13; |
| 1832 const int64 V80_POSITIONS[V80_ROW_COUNT] = { |
| 1833 0, |
| 1834 -2097152, |
| 1835 -3145728, |
| 1836 1048576, |
| 1837 -4194304, |
| 1838 1048576, |
| 1839 1048576, |
| 1840 1048576, |
| 1841 2097152, |
| 1842 -1048576, |
| 1843 0, |
| 1844 -917504, |
| 1845 1048576 |
| 1846 }; |
| 1847 |
| 1848 std::string V81_Ordinal(int n) { |
| 1849 return Int64ToNodeOrdinal(V80_POSITIONS[n]).ToInternalValue(); |
| 1850 } |
| 1851 |
| 1852 } //namespace |
| 1853 |
| 1854 // Unlike the earlier versions, the rows for version 81 are generated |
| 1855 // programmatically to accurately handle unprintable characters for the |
| 1856 // server_ordinal_in_parent field. |
| 1857 void MigrationTest::SetUpVersion81Database(sql::Connection* connection) { |
| 1858 ASSERT_TRUE(connection->is_open()); |
| 1859 ASSERT_TRUE(connection->BeginTransaction()); |
| 1860 ASSERT_TRUE(connection->Execute( |
| 1861 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" |
| 1862 "INSERT INTO 'share_version' VALUES('nick@chromium.org',81);" |
| 1863 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in" |
| 1864 "itial_sync_ended BOOLEAN default 0);" |
| 1865 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);" |
| 1866 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base" |
| 1867 "_version bigint default -1,server_version bigint default 0, " |
| 1868 "local_external_id bigint default 0" |
| 1869 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d" |
| 1870 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p" |
| 1871 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa" |
| 1872 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul" |
| 1873 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is" |
| 1874 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0," |
| 1875 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu" |
| 1876 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc" |
| 1877 "har,specifics blob,server_specifics blob, base_server_specifics BLOB" |
| 1878 ", server_ordinal_in_parent blob);" |
| 1879 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" |
| 1880 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" |
| 1881 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips " |
| 1882 "blob);" |
| 1883 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," |
| 1884 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," |
| 1885 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);")); |
| 1886 |
| 1887 const char* insert_stmts[V80_ROW_COUNT] = { |
| 1888 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','" |
| 1889 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?);", |
| 1890 "INSERT INTO 'metas' VALUES(2,669,669,4," |
| 1891 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_" |
| 1892 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1" |
| 1893 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X" |
| 1894 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534" |
| 1895 "14447414447414447',NULL,?);", |
| 1896 "INSERT INTO 'metas' VALUES(4,681,681,3," |
| 1897 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_" |
| 1898 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL" |
| 1899 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6" |
| 1900 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687" |
| 1901 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656" |
| 1902 "E2F77656C636F6D652E68746D6C1200',NULL,?);", |
| 1903 "INSERT INTO 'metas' VALUES(5,677,677,7," |
| 1904 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_" |
| 1905 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2" |
| 1906 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1" |
| 1907 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N" |
| 1908 "ULL,?);", |
| 1909 "INSERT INTO 'metas' VALUES(6,694,694,6," |
| 1910 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1" |
| 1911 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'" |
| 1912 ",NULL,?);", |
| 1913 "INSERT INTO 'metas' VALUES(7,663,663,0," |
| 1914 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog" |
| 1915 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?);", |
| 1916 "INSERT INTO 'metas' VALUES(8,664,664,0," |
| 1917 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1" |
| 1918 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810" |
| 1919 "00',X'C2881000',NULL,?);", |
| 1920 "INSERT INTO 'metas' VALUES(9,665,665,1," |
| 1921 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0" |
| 1922 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881" |
| 1923 "000',X'C2881000',NULL,?);", |
| 1924 "INSERT INTO 'metas' VALUES(10,666,666,2," |
| 1925 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r'," |
| 1926 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU" |
| 1927 "LL,X'C2881000',X'C2881000',NULL,?);", |
| 1928 "INSERT INTO 'metas' VALUES(11,683,683,8," |
| 1929 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'" |
| 1930 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj" |
| 1931 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756" |
| 1932 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636" |
| 1933 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?);", |
| 1934 "INSERT INTO 'metas' VALUES(12,685,685,9," |
| 1935 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_" |
| 1936 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C" |
| 1937 "2881000',X'C2881000',NULL,?);", |
| 1938 "INSERT INTO 'metas' VALUES(13,687,687,10," |
| 1939 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_" |
| 1940 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names " |
| 1941 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu" |
| 1942 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636" |
| 1943 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772" |
| 1944 "E6963616E6E2E636F6D2F120744414146415346',NULL,?);", |
| 1945 "INSERT INTO 'metas' VALUES(14,692,692,11," |
| 1946 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'" |
| 1947 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc" |
| 1948 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726" |
| 1949 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7" |
| 1950 "81205504E473259',NULL,?);" }; |
| 1951 |
| 1952 for (int i = 0; i < V80_ROW_COUNT; i++) { |
| 1953 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i])); |
| 1954 std::string ord = V81_Ordinal(i); |
| 1955 s.BindBlob(0, ord.data(), ord.length()); |
| 1956 ASSERT_TRUE(s.Run()); |
| 1957 s.Reset(true); |
| 1958 } |
| 1959 ASSERT_TRUE(connection->CommitTransaction()); |
| 1960 } |
| 1961 |
1728 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { | 1962 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { |
1729 sql::Connection connection; | 1963 sql::Connection connection; |
1730 ASSERT_TRUE(connection.OpenInMemory()); | 1964 ASSERT_TRUE(connection.OpenInMemory()); |
1731 | 1965 |
1732 SetUpVersion67Database(&connection); | 1966 SetUpVersion67Database(&connection); |
1733 | 1967 |
1734 // Columns existing before version 67. | 1968 // Columns existing before version 67. |
1735 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); | 1969 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); |
1736 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); | 1970 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); |
1737 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); | 1971 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 ASSERT_FALSE(dbs->needs_column_refresh_); | 2277 ASSERT_FALSE(dbs->needs_column_refresh_); |
2044 ASSERT_TRUE(dbs->MigrateVersion78To79()); | 2278 ASSERT_TRUE(dbs->MigrateVersion78To79()); |
2045 ASSERT_EQ(79, dbs->GetVersion()); | 2279 ASSERT_EQ(79, dbs->GetVersion()); |
2046 ASSERT_FALSE(dbs->needs_column_refresh_); | 2280 ASSERT_FALSE(dbs->needs_column_refresh_); |
2047 | 2281 |
2048 // Ensure the next_id has been incremented. | 2282 // Ensure the next_id has been incremented. |
2049 MetahandlesIndex entry_bucket; | 2283 MetahandlesIndex entry_bucket; |
2050 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); | 2284 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); |
2051 Directory::KernelLoadInfo load_info; | 2285 Directory::KernelLoadInfo load_info; |
2052 | 2286 |
| 2287 s.Clear(); |
2053 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); | 2288 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); |
2054 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536); | 2289 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536); |
2055 } | 2290 } |
2056 | 2291 |
2057 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) { | 2292 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) { |
2058 sql::Connection connection; | 2293 sql::Connection connection; |
2059 ASSERT_TRUE(connection.OpenInMemory()); | 2294 ASSERT_TRUE(connection.OpenInMemory()); |
2060 SetUpVersion79Database(&connection); | 2295 SetUpVersion79Database(&connection); |
2061 | 2296 |
2062 scoped_ptr<TestDirectoryBackingStore> dbs( | 2297 scoped_ptr<TestDirectoryBackingStore> dbs( |
2063 new TestDirectoryBackingStore(GetUsername(), &connection)); | 2298 new TestDirectoryBackingStore(GetUsername(), &connection)); |
2064 ASSERT_FALSE(dbs->needs_column_refresh_); | 2299 ASSERT_FALSE(dbs->needs_column_refresh_); |
2065 ASSERT_TRUE(dbs->MigrateVersion79To80()); | 2300 ASSERT_TRUE(dbs->MigrateVersion79To80()); |
2066 ASSERT_EQ(80, dbs->GetVersion()); | 2301 ASSERT_EQ(80, dbs->GetVersion()); |
2067 ASSERT_FALSE(dbs->needs_column_refresh_); | 2302 ASSERT_FALSE(dbs->needs_column_refresh_); |
2068 | 2303 |
2069 // Ensure the bag_of_chips has been set. | 2304 // Ensure the bag_of_chips has been set. |
2070 MetahandlesIndex entry_bucket; | 2305 MetahandlesIndex entry_bucket; |
2071 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); | 2306 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); |
2072 Directory::KernelLoadInfo load_info; | 2307 Directory::KernelLoadInfo load_info; |
2073 | 2308 |
2074 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); | 2309 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); |
2075 // Check that the initial value is the serialization of an empty ChipBag. | 2310 // Check that the initial value is the serialization of an empty ChipBag. |
2076 sync_pb::ChipBag chip_bag; | 2311 sync_pb::ChipBag chip_bag; |
2077 std::string serialized_chip_bag; | 2312 std::string serialized_chip_bag; |
2078 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); | 2313 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); |
2079 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); | 2314 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); |
2080 } | 2315 } |
2081 | 2316 |
| 2317 TEST_F(DirectoryBackingStoreTest, MigrateVersion80To81) { |
| 2318 sql::Connection connection; |
| 2319 ASSERT_TRUE(connection.OpenInMemory()); |
| 2320 SetUpVersion80Database(&connection); |
| 2321 |
| 2322 sql::Statement s(connection.GetUniqueStatement( |
| 2323 "SELECT metahandle, server_position_in_parent " |
| 2324 "FROM metas WHERE unique_server_tag = 'google_chrome'")); |
| 2325 ASSERT_TRUE(s.Step()); |
| 2326 ASSERT_EQ(sql::COLUMN_TYPE_INTEGER, s.ColumnType(1)); |
| 2327 |
| 2328 scoped_ptr<TestDirectoryBackingStore> dbs( |
| 2329 new TestDirectoryBackingStore(GetUsername(), &connection)); |
| 2330 ASSERT_TRUE(dbs->MigrateVersion80To81()); |
| 2331 ASSERT_EQ(81, dbs->GetVersion()); |
| 2332 |
| 2333 // Test that ordinal values are preserved correctly. |
| 2334 sql::Statement new_s(connection.GetUniqueStatement( |
| 2335 "SELECT metahandle, server_ordinal_in_parent " |
| 2336 "FROM metas WHERE unique_server_tag = 'google_chrome'")); |
| 2337 ASSERT_TRUE(new_s.Step()); |
| 2338 ASSERT_EQ(sql::COLUMN_TYPE_BLOB, new_s.ColumnType(1)); |
| 2339 |
| 2340 std::string expected_ordinal = Int64ToNodeOrdinal(1048576).ToInternalValue(); |
| 2341 std::string actual_ordinal; |
| 2342 new_s.ColumnBlobAsString(1, &actual_ordinal); |
| 2343 ASSERT_EQ(expected_ordinal, actual_ordinal); |
| 2344 } |
| 2345 |
| 2346 TEST_F(DirectoryBackingStoreTest, DetectInvalidOrdinal) { |
| 2347 sql::Connection connection; |
| 2348 ASSERT_TRUE(connection.OpenInMemory()); |
| 2349 SetUpVersion81Database(&connection); |
| 2350 |
| 2351 scoped_ptr<TestDirectoryBackingStore> dbs( |
| 2352 new TestDirectoryBackingStore(GetUsername(), &connection)); |
| 2353 ASSERT_EQ(81, dbs->GetVersion()); |
| 2354 |
| 2355 // Insert row with bad ordinal. |
| 2356 const int64 now = TimeToProtoTime(base::Time::Now()); |
| 2357 sql::Statement s(connection.GetUniqueStatement( |
| 2358 "INSERT INTO metas " |
| 2359 "( id, metahandle, is_dir, ctime, mtime, server_ordinal_in_parent) " |
| 2360 "VALUES( \"c-invalid\", 9999, 1, ?, ?, \" \")")); |
| 2361 s.BindInt64(0, now); |
| 2362 s.BindInt64(1, now); |
| 2363 ASSERT_TRUE(s.Run()); |
| 2364 |
| 2365 // Trying to unpack this entry should signal that the DB is corrupted. |
| 2366 MetahandlesIndex entry_bucket; |
| 2367 Directory::KernelLoadInfo kernel_load_info; |
| 2368 ASSERT_EQ(FAILED_DATABASE_CORRUPT, |
| 2369 dbs->Load(&entry_bucket, &kernel_load_info)); |
| 2370 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); |
| 2371 |
| 2372 } |
| 2373 |
2082 TEST_P(MigrationTest, ToCurrentVersion) { | 2374 TEST_P(MigrationTest, ToCurrentVersion) { |
2083 sql::Connection connection; | 2375 sql::Connection connection; |
2084 ASSERT_TRUE(connection.OpenInMemory()); | 2376 ASSERT_TRUE(connection.OpenInMemory()); |
2085 switch (GetParam()) { | 2377 switch (GetParam()) { |
2086 case 67: | 2378 case 67: |
2087 SetUpVersion67Database(&connection); | 2379 SetUpVersion67Database(&connection); |
2088 break; | 2380 break; |
2089 case 68: | 2381 case 68: |
2090 SetUpVersion68Database(&connection); | 2382 SetUpVersion68Database(&connection); |
2091 break; | 2383 break; |
(...skipping 23 matching lines...) Expand all Loading... |
2115 break; | 2407 break; |
2116 case 77: | 2408 case 77: |
2117 SetUpVersion77Database(&connection); | 2409 SetUpVersion77Database(&connection); |
2118 break; | 2410 break; |
2119 case 78: | 2411 case 78: |
2120 SetUpVersion78Database(&connection); | 2412 SetUpVersion78Database(&connection); |
2121 break; | 2413 break; |
2122 case 79: | 2414 case 79: |
2123 SetUpVersion79Database(&connection); | 2415 SetUpVersion79Database(&connection); |
2124 break; | 2416 break; |
| 2417 case 80: |
| 2418 SetUpVersion80Database(&connection); |
| 2419 break; |
2125 default: | 2420 default: |
2126 // If you see this error, it may mean that you've increased the | 2421 // If you see this error, it may mean that you've increased the |
2127 // database version number but you haven't finished adding unit tests | 2422 // database version number but you haven't finished adding unit tests |
2128 // for the database migration code. You need to need to supply a | 2423 // for the database migration code. You need to need to supply a |
2129 // SetUpVersionXXDatabase function with a dump of the test database | 2424 // SetUpVersionXXDatabase function with a dump of the test database |
2130 // at the old schema. Here's one way to do that: | 2425 // at the old schema. Here's one way to do that: |
2131 // 1. Start on a clean tree (with none of your pending schema changes). | 2426 // 1. Start on a clean tree (with none of your pending schema changes). |
2132 // 2. Set a breakpoint in this function and run the unit test. | 2427 // 2. Set a breakpoint in this function and run the unit test. |
2133 // 3. Allow this test to run to completion (step out of the call), | 2428 // 3. Allow this test to run to completion (step out of the call), |
2134 // without allowing ~MigrationTest to execute. | 2429 // without allowing ~MigrationTest to execute. |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2452 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); | 2747 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); |
2453 EXPECT_EQ(24U, guid1.size()); | 2748 EXPECT_EQ(24U, guid1.size()); |
2454 EXPECT_EQ(24U, guid2.size()); | 2749 EXPECT_EQ(24U, guid2.size()); |
2455 // In theory this test can fail, but it won't before the universe | 2750 // In theory this test can fail, but it won't before the universe |
2456 // dies of heat death. | 2751 // dies of heat death. |
2457 EXPECT_NE(guid1, guid2); | 2752 EXPECT_NE(guid1, guid2); |
2458 } | 2753 } |
2459 | 2754 |
2460 } // namespace syncable | 2755 } // namespace syncable |
2461 } // namespace syncer | 2756 } // namespace syncer |
OLD | NEW |