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

Side by Side Diff: sync/syncable/directory_backing_store_unittest.cc

Issue 10989063: Changed DB to store node positions as Ordinals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added SetUpVersion81Database() fn. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 {
akalin 2012/10/08 21:09:46 newline after namespace {
1830 const int V80_ROW_COUNT = 13;
1831 const int64 V80_POSITIONS[V80_ROW_COUNT] = {
1832 0,
1833 -2097152,
1834 -3145728,
1835 1048576,
1836 -4194304,
1837 1048576,
1838 1048576,
1839 1048576,
1840 2097152,
1841 -1048576,
1842 0,
1843 -917504,
1844 1048576 };
akalin 2012/10/08 21:09:46 newline before }
1845
1846 const std::string V81_Ordinal(int n) {
akalin 2012/10/08 21:09:46 no need for const in return value
1847 return Int64ToNodeOrdinal(V80_POSITIONS[n]).ToInternalValue();
1848 }
1849
1850 } //namespace
1851
1852 // Unlike the earlier versions, the rows for version 81 are generated
1853 // programmatically to accurately handle unprintable characters for the
1854 // server_ordinal_in_parent field.
1855 void MigrationTest::SetUpVersion81Database(sql::Connection* connection) {
1856 ASSERT_TRUE(connection->is_open());
1857 ASSERT_TRUE(connection->BeginTransaction());
1858 ASSERT_TRUE(connection->Execute(
1859 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1860 "INSERT INTO 'share_version' VALUES('nick@chromium.org',81);"
1861 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1862 "itial_sync_ended BOOLEAN default 0);"
1863 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1864 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1865 "_version bigint default -1,server_version bigint default 0, "
1866 "local_external_id bigint default 0"
1867 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1868 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1869 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1870 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
1871 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
1872 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
1873 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
1874 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
1875 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
1876 ", server_ordinal_in_parent blob);"
1877 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1878 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1879 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
1880 "blob);"
1881 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1882 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
1883 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
1884
1885 std::string insert_stmts[V80_ROW_COUNT] = {
akalin 2012/10/08 21:09:46 can this be "const char* insert_stmts[...]" inste
1886 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
1887 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?);",
1888 "INSERT INTO 'metas' VALUES(2,669,669,4,"
1889 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
1890 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
1891 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
1892 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
1893 "14447414447414447',NULL,?);",
1894 "INSERT INTO 'metas' VALUES(4,681,681,3,"
1895 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
1896 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
1897 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
1898 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
1899 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
1900 "E2F77656C636F6D652E68746D6C1200',NULL,?);",
1901 "INSERT INTO 'metas' VALUES(5,677,677,7,"
1902 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
1903 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
1904 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
1905 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
1906 "ULL,?);",
1907 "INSERT INTO 'metas' VALUES(6,694,694,6,"
1908 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
1909 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
1910 ",NULL,?);",
1911 "INSERT INTO 'metas' VALUES(7,663,663,0,"
1912 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
1913 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?);",
1914 "INSERT INTO 'metas' VALUES(8,664,664,0,"
1915 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
1916 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
1917 "00',X'C2881000',NULL,?);",
1918 "INSERT INTO 'metas' VALUES(9,665,665,1,"
1919 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
1920 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
1921 "000',X'C2881000',NULL,?);",
1922 "INSERT INTO 'metas' VALUES(10,666,666,2,"
1923 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
1924 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
1925 "LL,X'C2881000',X'C2881000',NULL,?);",
1926 "INSERT INTO 'metas' VALUES(11,683,683,8,"
1927 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
1928 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
1929 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
1930 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
1931 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?);",
1932 "INSERT INTO 'metas' VALUES(12,685,685,9,"
1933 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
1934 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
1935 "2881000',X'C2881000',NULL,?);",
1936 "INSERT INTO 'metas' VALUES(13,687,687,10,"
1937 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
1938 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
1939 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
1940 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
1941 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
1942 "E6963616E6E2E636F6D2F120744414146415346',NULL,?);",
1943 "INSERT INTO 'metas' VALUES(14,692,692,11,"
1944 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
1945 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
1946 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
1947 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
1948 "81205504E473259',NULL,?);" };
1949
1950 for (int i = 0; i < V80_ROW_COUNT; i++) {
1951 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i].c_str()));
1952 std::string ord = V81_Ordinal(i);
1953 s.BindBlob(0, ord.data(), ord.length());
1954 ASSERT_TRUE(s.Run());
1955 s.Reset(true);
1956 }
1957 ASSERT_TRUE(connection->CommitTransaction());
1958 }
1959
1728 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { 1960 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) {
1729 sql::Connection connection; 1961 sql::Connection connection;
1730 ASSERT_TRUE(connection.OpenInMemory()); 1962 ASSERT_TRUE(connection.OpenInMemory());
1731 1963
1732 SetUpVersion67Database(&connection); 1964 SetUpVersion67Database(&connection);
1733 1965
1734 // Columns existing before version 67. 1966 // Columns existing before version 67.
1735 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); 1967 ASSERT_TRUE(connection.DoesColumnExist("metas", "name"));
1736 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); 1968 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name"));
1737 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); 1969 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name"));
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 ASSERT_FALSE(dbs->needs_column_refresh_); 2275 ASSERT_FALSE(dbs->needs_column_refresh_);
2044 ASSERT_TRUE(dbs->MigrateVersion78To79()); 2276 ASSERT_TRUE(dbs->MigrateVersion78To79());
2045 ASSERT_EQ(79, dbs->GetVersion()); 2277 ASSERT_EQ(79, dbs->GetVersion());
2046 ASSERT_FALSE(dbs->needs_column_refresh_); 2278 ASSERT_FALSE(dbs->needs_column_refresh_);
2047 2279
2048 // Ensure the next_id has been incremented. 2280 // Ensure the next_id has been incremented.
2049 MetahandlesIndex entry_bucket; 2281 MetahandlesIndex entry_bucket;
2050 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); 2282 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket);
2051 Directory::KernelLoadInfo load_info; 2283 Directory::KernelLoadInfo load_info;
2052 2284
2285 s.Clear();
2053 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); 2286 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info));
2054 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536); 2287 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536);
2055 } 2288 }
2056 2289
2057 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) { 2290 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) {
2058 sql::Connection connection; 2291 sql::Connection connection;
2059 ASSERT_TRUE(connection.OpenInMemory()); 2292 ASSERT_TRUE(connection.OpenInMemory());
2060 SetUpVersion79Database(&connection); 2293 SetUpVersion79Database(&connection);
2061 2294
2062 scoped_ptr<TestDirectoryBackingStore> dbs( 2295 scoped_ptr<TestDirectoryBackingStore> dbs(
2063 new TestDirectoryBackingStore(GetUsername(), &connection)); 2296 new TestDirectoryBackingStore(GetUsername(), &connection));
2064 ASSERT_FALSE(dbs->needs_column_refresh_); 2297 ASSERT_FALSE(dbs->needs_column_refresh_);
2065 ASSERT_TRUE(dbs->MigrateVersion79To80()); 2298 ASSERT_TRUE(dbs->MigrateVersion79To80());
2066 ASSERT_EQ(80, dbs->GetVersion()); 2299 ASSERT_EQ(80, dbs->GetVersion());
2067 ASSERT_FALSE(dbs->needs_column_refresh_); 2300 ASSERT_FALSE(dbs->needs_column_refresh_);
2068 2301
2069 // Ensure the bag_of_chips has been set. 2302 // Ensure the bag_of_chips has been set.
2070 MetahandlesIndex entry_bucket; 2303 MetahandlesIndex entry_bucket;
2071 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); 2304 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket);
2072 Directory::KernelLoadInfo load_info; 2305 Directory::KernelLoadInfo load_info;
2073 2306
2074 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); 2307 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info));
2075 // Check that the initial value is the serialization of an empty ChipBag. 2308 // Check that the initial value is the serialization of an empty ChipBag.
2076 sync_pb::ChipBag chip_bag; 2309 sync_pb::ChipBag chip_bag;
2077 std::string serialized_chip_bag; 2310 std::string serialized_chip_bag;
2078 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); 2311 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag));
2079 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); 2312 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips);
2080 } 2313 }
2081 2314
2315 TEST_F(DirectoryBackingStoreTest, MigrateVersion80To81) {
2316 sql::Connection connection;
2317 ASSERT_TRUE(connection.OpenInMemory());
2318 SetUpVersion80Database(&connection);
2319
2320 sql::Statement s(connection.GetUniqueStatement(
2321 "SELECT metahandle, server_position_in_parent "
2322 "FROM metas WHERE unique_server_tag = 'google_chrome'"));
2323 ASSERT_TRUE(s.Step());
2324 ASSERT_EQ(sql::COLUMN_TYPE_INTEGER, s.ColumnType(1));
2325
2326 scoped_ptr<TestDirectoryBackingStore> dbs(
2327 new TestDirectoryBackingStore(GetUsername(), &connection));
2328 ASSERT_TRUE(dbs->MigrateVersion80To81());
2329 ASSERT_EQ(81, dbs->GetVersion());
2330
2331 // Test that ordinal values are preserved correctly.
2332 sql::Statement new_s(connection.GetUniqueStatement(
2333 "SELECT metahandle, server_ordinal_in_parent "
2334 "FROM metas WHERE unique_server_tag = 'google_chrome'"));
2335 ASSERT_TRUE(new_s.Step());
2336 ASSERT_EQ(sql::COLUMN_TYPE_BLOB, new_s.ColumnType(1));
2337
2338 std::string expected_ordinal = Int64ToNodeOrdinal(1048576).ToInternalValue();
2339 std::string actual_ordinal;
2340 new_s.ColumnBlobAsString(1, &actual_ordinal);
2341 ASSERT_EQ(expected_ordinal, actual_ordinal);
2342 }
2343
2344 TEST_F(DirectoryBackingStoreTest, InvalidOrdinalTriggersRedownload) {
rlarocque 2012/10/08 20:48:38 I wouldn't call this "TriggersRedownload". That h
2345 sql::Connection connection;
2346 ASSERT_TRUE(connection.OpenInMemory());
2347 SetUpVersion81Database(&connection);
2348
2349 scoped_ptr<TestDirectoryBackingStore> dbs(
2350 new TestDirectoryBackingStore(GetUsername(), &connection));
2351 ASSERT_EQ(81, dbs->GetVersion());
2352
2353 // Insert row with bad ordinal.
2354 const int64 now = TimeToProtoTime(base::Time::Now());
2355 sql::Statement s(connection.GetUniqueStatement(
2356 "INSERT INTO metas "
2357 "( id, metahandle, is_dir, ctime, mtime, server_ordinal_in_parent) "
2358 "VALUES( \"c-invalid\", 9999, 1, ?, ?, \" \")"));
2359 s.BindInt64(0, now);
2360 s.BindInt64(1, now);
2361 ASSERT_TRUE(s.Run());
2362
2363 // Trying to unpack this entry should signal that the DB is corrupted.
2364 MetahandlesIndex entry_bucket;
2365 Directory::KernelLoadInfo kernel_load_info;
2366 ASSERT_EQ(FAILED_DATABASE_CORRUPT,
2367 dbs->Load(&entry_bucket, &kernel_load_info));
2368 }
2369
2082 TEST_P(MigrationTest, ToCurrentVersion) { 2370 TEST_P(MigrationTest, ToCurrentVersion) {
2083 sql::Connection connection; 2371 sql::Connection connection;
2084 ASSERT_TRUE(connection.OpenInMemory()); 2372 ASSERT_TRUE(connection.OpenInMemory());
2085 switch (GetParam()) { 2373 switch (GetParam()) {
2086 case 67: 2374 case 67:
2087 SetUpVersion67Database(&connection); 2375 SetUpVersion67Database(&connection);
2088 break; 2376 break;
2089 case 68: 2377 case 68:
2090 SetUpVersion68Database(&connection); 2378 SetUpVersion68Database(&connection);
2091 break; 2379 break;
(...skipping 23 matching lines...) Expand all
2115 break; 2403 break;
2116 case 77: 2404 case 77:
2117 SetUpVersion77Database(&connection); 2405 SetUpVersion77Database(&connection);
2118 break; 2406 break;
2119 case 78: 2407 case 78:
2120 SetUpVersion78Database(&connection); 2408 SetUpVersion78Database(&connection);
2121 break; 2409 break;
2122 case 79: 2410 case 79:
2123 SetUpVersion79Database(&connection); 2411 SetUpVersion79Database(&connection);
2124 break; 2412 break;
2413 case 80:
2414 SetUpVersion80Database(&connection);
2415 break;
2125 default: 2416 default:
2126 // If you see this error, it may mean that you've increased the 2417 // 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 2418 // database version number but you haven't finished adding unit tests
2128 // for the database migration code. You need to need to supply a 2419 // for the database migration code. You need to need to supply a
2129 // SetUpVersionXXDatabase function with a dump of the test database 2420 // SetUpVersionXXDatabase function with a dump of the test database
2130 // at the old schema. Here's one way to do that: 2421 // 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). 2422 // 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. 2423 // 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), 2424 // 3. Allow this test to run to completion (step out of the call),
2134 // without allowing ~MigrationTest to execute. 2425 // without allowing ~MigrationTest to execute.
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2452 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); 2743 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID();
2453 EXPECT_EQ(24U, guid1.size()); 2744 EXPECT_EQ(24U, guid1.size());
2454 EXPECT_EQ(24U, guid2.size()); 2745 EXPECT_EQ(24U, guid2.size());
2455 // In theory this test can fail, but it won't before the universe 2746 // In theory this test can fail, but it won't before the universe
2456 // dies of heat death. 2747 // dies of heat death.
2457 EXPECT_NE(guid1, guid2); 2748 EXPECT_NE(guid1, guid2);
2458 } 2749 }
2459 2750
2460 } // namespace syncable 2751 } // namespace syncable
2461 } // namespace syncer 2752 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698