Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 void SetUpVersion69Database(sql::Connection* connection); | 55 void SetUpVersion69Database(sql::Connection* connection); |
| 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 | 66 |
| 66 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { | 67 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { |
| 67 SetUpVersion77Database(connection); // Prepopulates data. | 68 SetUpVersion77Database(connection); // Prepopulates data. |
| 68 scoped_ptr<TestDirectoryBackingStore> dbs( | 69 scoped_ptr<TestDirectoryBackingStore> dbs( |
| 69 new TestDirectoryBackingStore(GetUsername(), connection)); | 70 new TestDirectoryBackingStore(GetUsername(), connection)); |
| 70 | 71 |
| 71 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); | 72 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); |
| 72 ASSERT_FALSE(dbs->needs_column_refresh_); | 73 ASSERT_FALSE(dbs->needs_column_refresh_); |
| 73 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); | 74 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); |
| 74 } | 75 } |
| (...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1622 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" | 1623 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" |
| 1623 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" | 1624 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" |
| 1624 "ult -2, cache_guid TEXT , notification_state BLOB);" | 1625 "ult -2, cache_guid TEXT , notification_state BLOB);" |
| 1625 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," | 1626 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," |
| 1626 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'" | 1627 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'" |
| 1627 "9010788312004066376x-6609234393368420856x',NULL);" | 1628 "9010788312004066376x-6609234393368420856x',NULL);" |
| 1628 )); | 1629 )); |
| 1629 ASSERT_TRUE(connection->CommitTransaction()); | 1630 ASSERT_TRUE(connection->CommitTransaction()); |
| 1630 } | 1631 } |
| 1631 | 1632 |
| 1633 void MigrationTest::SetUpVersion79Database(sql::Connection* connection) { | |
| 1634 ASSERT_TRUE(connection->is_open()); | |
| 1635 ASSERT_TRUE(connection->BeginTransaction()); | |
| 1636 ASSERT_TRUE(connection->Execute( | |
| 1637 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" | |
| 1638 "INSERT INTO 'share_version' VALUES('nick@chromium.org',78);" | |
| 1639 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in" | |
| 1640 "itial_sync_ended BOOLEAN default 0);" | |
| 1641 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);" | |
| 1642 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base" | |
| 1643 "_version bigint default -1,server_version bigint default 0,server_po" | |
| 1644 "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" | |
| 1646 "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" | |
| 1648 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul" | |
| 1649 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is" | |
| 1650 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0," | |
| 1651 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu" | |
| 1652 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc" | |
| 1653 "har,specifics blob,server_specifics blob, base_server_specifics BLOB" | |
| 1654 ");" | |
| 1655 "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','" | |
| 1656 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);" | |
| 1657 "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4," | |
| 1658 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_" | |
| 1659 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1" | |
| 1660 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X" | |
| 1661 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534" | |
| 1662 "14447414447414447',NULL);" | |
| 1663 "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3," | |
| 1664 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_" | |
| 1665 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL" | |
| 1666 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6" | |
| 1667 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687" | |
| 1668 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656" | |
| 1669 "E2F77656C636F6D652E68746D6C1200',NULL);" | |
| 1670 "INSERT INTO 'metas' VALUES(5,677,677,1048576,7," | |
| 1671 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_" | |
| 1672 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2" | |
| 1673 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1" | |
| 1674 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N" | |
| 1675 "ULL);" | |
| 1676 "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6," | |
| 1677 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1" | |
| 1678 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'" | |
| 1679 ",NULL);" | |
| 1680 "INSERT INTO 'metas' VALUES(7,663,663,1048576,0," | |
| 1681 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog" | |
| 1682 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL);" | |
| 1683 "INSERT INTO 'metas' VALUES(8,664,664,1048576,0," | |
| 1684 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1" | |
| 1685 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810" | |
| 1686 "00',X'C2881000',NULL);" | |
| 1687 "INSERT INTO 'metas' VALUES(9,665,665,1048576,1," | |
| 1688 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0" | |
| 1689 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881" | |
| 1690 "000',X'C2881000',NULL);" | |
| 1691 "INSERT INTO 'metas' VALUES(10,666,666,2097152,2," | |
| 1692 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r'," | |
| 1693 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU" | |
| 1694 "LL,X'C2881000',X'C2881000',NULL);" | |
| 1695 "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8," | |
| 1696 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'" | |
| 1697 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj" | |
| 1698 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756" | |
| 1699 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636" | |
| 1700 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);" | |
| 1701 "INSERT INTO 'metas' VALUES(12,685,685,0,9," | |
| 1702 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_" | |
| 1703 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C" | |
| 1704 "2881000',X'C2881000',NULL);" | |
| 1705 "INSERT INTO 'metas' VALUES(13,687,687,-917504,10," | |
| 1706 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_" | |
| 1707 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names " | |
| 1708 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu" | |
| 1709 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636" | |
| 1710 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772" | |
| 1711 "E6963616E6E2E636F6D2F120744414146415346',NULL);" | |
| 1712 "INSERT INTO 'metas' VALUES(14,692,692,1048576,11," | |
| 1713 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'" | |
| 1714 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc" | |
| 1715 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726" | |
| 1716 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7" | |
| 1717 "81205504E473259',NULL);" | |
| 1718 "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" | |
| 1720 "ult -2, cache_guid TEXT , notification_state BLOB);" | |
| 1721 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," | |
| 1722 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," | |
| 1723 "-131078,'9010788312004066376x-6609234393368420856x',NULL);" | |
| 1724 )); | |
| 1725 ASSERT_TRUE(connection->CommitTransaction()); | |
| 1726 } | |
| 1727 | |
| 1632 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { | 1728 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { |
| 1633 sql::Connection connection; | 1729 sql::Connection connection; |
| 1634 ASSERT_TRUE(connection.OpenInMemory()); | 1730 ASSERT_TRUE(connection.OpenInMemory()); |
| 1635 | 1731 |
| 1636 SetUpVersion67Database(&connection); | 1732 SetUpVersion67Database(&connection); |
| 1637 | 1733 |
| 1638 // Columns existing before version 67. | 1734 // Columns existing before version 67. |
| 1639 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); | 1735 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); |
| 1640 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); | 1736 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); |
| 1641 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); | 1737 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1951 | 2047 |
| 1952 // Ensure the next_id has been incremented. | 2048 // Ensure the next_id has been incremented. |
| 1953 MetahandlesIndex entry_bucket; | 2049 MetahandlesIndex entry_bucket; |
| 1954 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); | 2050 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); |
| 1955 Directory::KernelLoadInfo load_info; | 2051 Directory::KernelLoadInfo load_info; |
| 1956 | 2052 |
| 1957 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); | 2053 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); |
| 1958 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536); | 2054 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536); |
| 1959 } | 2055 } |
| 1960 | 2056 |
| 2057 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) { | |
| 2058 sql::Connection connection; | |
| 2059 ASSERT_TRUE(connection.OpenInMemory()); | |
| 2060 SetUpVersion79Database(&connection); | |
| 2061 | |
| 2062 scoped_ptr<TestDirectoryBackingStore> dbs( | |
| 2063 new TestDirectoryBackingStore(GetUsername(), &connection)); | |
| 2064 ASSERT_FALSE(dbs->needs_column_refresh_); | |
| 2065 ASSERT_TRUE(dbs->MigrateVersion79To80()); | |
| 2066 ASSERT_EQ(80, dbs->GetVersion()); | |
| 2067 ASSERT_FALSE(dbs->needs_column_refresh_); | |
| 2068 | |
| 2069 // Ensure the bag_of_chips has been set. | |
| 2070 MetahandlesIndex entry_bucket; | |
| 2071 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); | |
| 2072 Directory::KernelLoadInfo load_info; | |
| 2073 | |
| 2074 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); | |
| 2075 // Check that the initial value is the serialization of an empty ChigBag. | |
|
tim (not reviewing)
2012/09/11 17:57:20
nit ChipBag
qsr (NOT THE RIGHT qsr)
2012/09/11 18:48:49
Done.
| |
| 2076 sync_pb::ChipBag chip_bag; | |
| 2077 std::string serialized_chip_bag; | |
| 2078 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); | |
|
tim (not reviewing)
2012/09/11 17:57:20
maybe also ASSERT_TRUE(!serialized_chip_bag.empty(
qsr (NOT THE RIGHT qsr)
2012/09/11 18:48:49
That would be wrong, as the default value is an em
| |
| 2079 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); | |
| 2080 } | |
| 2081 | |
| 1961 TEST_P(MigrationTest, ToCurrentVersion) { | 2082 TEST_P(MigrationTest, ToCurrentVersion) { |
| 1962 sql::Connection connection; | 2083 sql::Connection connection; |
| 1963 ASSERT_TRUE(connection.OpenInMemory()); | 2084 ASSERT_TRUE(connection.OpenInMemory()); |
| 1964 switch (GetParam()) { | 2085 switch (GetParam()) { |
| 1965 case 67: | 2086 case 67: |
| 1966 SetUpVersion67Database(&connection); | 2087 SetUpVersion67Database(&connection); |
| 1967 break; | 2088 break; |
| 1968 case 68: | 2089 case 68: |
| 1969 SetUpVersion68Database(&connection); | 2090 SetUpVersion68Database(&connection); |
| 1970 break; | 2091 break; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1991 break; | 2112 break; |
| 1992 case 76: | 2113 case 76: |
| 1993 SetUpVersion76Database(&connection); | 2114 SetUpVersion76Database(&connection); |
| 1994 break; | 2115 break; |
| 1995 case 77: | 2116 case 77: |
| 1996 SetUpVersion77Database(&connection); | 2117 SetUpVersion77Database(&connection); |
| 1997 break; | 2118 break; |
| 1998 case 78: | 2119 case 78: |
| 1999 SetUpVersion78Database(&connection); | 2120 SetUpVersion78Database(&connection); |
| 2000 break; | 2121 break; |
| 2122 case 79: | |
| 2123 SetUpVersion79Database(&connection); | |
| 2124 break; | |
| 2001 default: | 2125 default: |
| 2002 // If you see this error, it may mean that you've increased the | 2126 // If you see this error, it may mean that you've increased the |
| 2003 // database version number but you haven't finished adding unit tests | 2127 // database version number but you haven't finished adding unit tests |
| 2004 // for the database migration code. You need to need to supply a | 2128 // for the database migration code. You need to need to supply a |
| 2005 // SetUpVersionXXDatabase function with a dump of the test database | 2129 // SetUpVersionXXDatabase function with a dump of the test database |
| 2006 // at the old schema. Here's one way to do that: | 2130 // at the old schema. Here's one way to do that: |
| 2007 // 1. Start on a clean tree (with none of your pending schema changes). | 2131 // 1. Start on a clean tree (with none of your pending schema changes). |
| 2008 // 2. Set a breakpoint in this function and run the unit test. | 2132 // 2. Set a breakpoint in this function and run the unit test. |
| 2009 // 3. Allow this test to run to completion (step out of the call), | 2133 // 3. Allow this test to run to completion (step out of the call), |
| 2010 // without allowing ~MigrationTest to execute. | 2134 // without allowing ~MigrationTest to execute. |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2328 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); | 2452 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); |
| 2329 EXPECT_EQ(24U, guid1.size()); | 2453 EXPECT_EQ(24U, guid1.size()); |
| 2330 EXPECT_EQ(24U, guid2.size()); | 2454 EXPECT_EQ(24U, guid2.size()); |
| 2331 // In theory this test can fail, but it won't before the universe | 2455 // In theory this test can fail, but it won't before the universe |
| 2332 // dies of heat death. | 2456 // dies of heat death. |
| 2333 EXPECT_NE(guid1, guid2); | 2457 EXPECT_NE(guid1, guid2); |
| 2334 } | 2458 } |
| 2335 | 2459 |
| 2336 } // namespace syncable | 2460 } // namespace syncable |
| 2337 } // namespace syncer | 2461 } // namespace syncer |
| OLD | NEW |