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 28 matching lines...) Expand all Loading... |
39 std::string GetUsername() { | 39 std::string GetUsername() { |
40 return "nick@chromium.org"; | 40 return "nick@chromium.org"; |
41 } | 41 } |
42 | 42 |
43 FilePath GetDatabasePath() { | 43 FilePath GetDatabasePath() { |
44 return temp_dir_.path().Append(Directory::kSyncDatabaseFilename); | 44 return temp_dir_.path().Append(Directory::kSyncDatabaseFilename); |
45 } | 45 } |
46 | 46 |
47 static bool LoadAndIgnoreReturnedData(DirectoryBackingStore *dbs) { | 47 static bool LoadAndIgnoreReturnedData(DirectoryBackingStore *dbs) { |
48 MetahandlesIndex metas; | 48 MetahandlesIndex metas; |
| 49 IdsIndex delete_journals; |
49 STLElementDeleter<MetahandlesIndex> index_deleter(&metas); | 50 STLElementDeleter<MetahandlesIndex> index_deleter(&metas); |
50 Directory::KernelLoadInfo kernel_load_info; | 51 Directory::KernelLoadInfo kernel_load_info; |
51 return dbs->Load(&metas, &kernel_load_info) == OPENED; | 52 return dbs->Load(&metas, &delete_journals, &kernel_load_info) == OPENED; |
52 } | 53 } |
53 | 54 |
54 void SetUpVersion67Database(sql::Connection* connection); | 55 void SetUpVersion67Database(sql::Connection* connection); |
55 void SetUpVersion68Database(sql::Connection* connection); | 56 void SetUpVersion68Database(sql::Connection* connection); |
56 void SetUpVersion69Database(sql::Connection* connection); | 57 void SetUpVersion69Database(sql::Connection* connection); |
57 void SetUpVersion70Database(sql::Connection* connection); | 58 void SetUpVersion70Database(sql::Connection* connection); |
58 void SetUpVersion71Database(sql::Connection* connection); | 59 void SetUpVersion71Database(sql::Connection* connection); |
59 void SetUpVersion72Database(sql::Connection* connection); | 60 void SetUpVersion72Database(sql::Connection* connection); |
60 void SetUpVersion73Database(sql::Connection* connection); | 61 void SetUpVersion73Database(sql::Connection* connection); |
61 void SetUpVersion74Database(sql::Connection* connection); | 62 void SetUpVersion74Database(sql::Connection* connection); |
62 void SetUpVersion75Database(sql::Connection* connection); | 63 void SetUpVersion75Database(sql::Connection* connection); |
63 void SetUpVersion76Database(sql::Connection* connection); | 64 void SetUpVersion76Database(sql::Connection* connection); |
64 void SetUpVersion77Database(sql::Connection* connection); | 65 void SetUpVersion77Database(sql::Connection* connection); |
65 void SetUpVersion78Database(sql::Connection* connection); | 66 void SetUpVersion78Database(sql::Connection* connection); |
66 void SetUpVersion79Database(sql::Connection* connection); | 67 void SetUpVersion79Database(sql::Connection* connection); |
67 void SetUpVersion80Database(sql::Connection* connection); | 68 void SetUpVersion80Database(sql::Connection* connection); |
68 void SetUpVersion81Database(sql::Connection* connection); | 69 void SetUpVersion81Database(sql::Connection* connection); |
69 void SetUpVersion82Database(sql::Connection* connection); | 70 void SetUpVersion82Database(sql::Connection* connection); |
| 71 void SetUpVersion83Database(sql::Connection* connection); |
70 | 72 |
71 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { | 73 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { |
72 SetUpVersion77Database(connection); // Prepopulates data. | 74 SetUpVersion77Database(connection); // Prepopulates data. |
73 scoped_ptr<TestDirectoryBackingStore> dbs( | 75 scoped_ptr<TestDirectoryBackingStore> dbs( |
74 new TestDirectoryBackingStore(GetUsername(), connection)); | 76 new TestDirectoryBackingStore(GetUsername(), connection)); |
75 | 77 |
76 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); | 78 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); |
77 ASSERT_FALSE(dbs->needs_column_refresh_); | 79 ASSERT_FALSE(dbs->needs_column_refresh_); |
78 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); | 80 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); |
79 } | 81 } |
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2061 for (int i = 0; i < V80_ROW_COUNT; i++) { | 2063 for (int i = 0; i < V80_ROW_COUNT; i++) { |
2062 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i])); | 2064 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i])); |
2063 std::string ord = V81_Ordinal(i); | 2065 std::string ord = V81_Ordinal(i); |
2064 s.BindBlob(0, ord.data(), ord.length()); | 2066 s.BindBlob(0, ord.data(), ord.length()); |
2065 ASSERT_TRUE(s.Run()); | 2067 ASSERT_TRUE(s.Run()); |
2066 s.Reset(true); | 2068 s.Reset(true); |
2067 } | 2069 } |
2068 ASSERT_TRUE(connection->CommitTransaction()); | 2070 ASSERT_TRUE(connection->CommitTransaction()); |
2069 } | 2071 } |
2070 | 2072 |
| 2073 void MigrationTest::SetUpVersion83Database(sql::Connection* connection) { |
| 2074 ASSERT_TRUE(connection->is_open()); |
| 2075 ASSERT_TRUE(connection->BeginTransaction()); |
| 2076 ASSERT_TRUE(connection->Execute( |
| 2077 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" |
| 2078 "INSERT INTO 'share_version' VALUES('nick@chromium.org',81);" |
| 2079 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in" |
| 2080 "itial_sync_ended BOOLEAN default 0, transaction_version BIGINT " |
| 2081 "default 0);" |
| 2082 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1, 1);" |
| 2083 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base" |
| 2084 "_version bigint default -1,server_version bigint default 0, " |
| 2085 "local_external_id bigint default 0" |
| 2086 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d" |
| 2087 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p" |
| 2088 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa" |
| 2089 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul" |
| 2090 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is" |
| 2091 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0," |
| 2092 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu" |
| 2093 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc" |
| 2094 "har,specifics blob,server_specifics blob, base_server_specifics BLOB" |
| 2095 ", server_ordinal_in_parent blob, transaction_verion bigint default 0" |
| 2096 ");" |
| 2097 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" |
| 2098 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" |
| 2099 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips " |
| 2100 "blob);" |
| 2101 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," |
| 2102 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," |
| 2103 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);")); |
| 2104 |
| 2105 const char* insert_stmts[V80_ROW_COUNT] = { |
| 2106 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','" |
| 2107 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?,0);", |
| 2108 "INSERT INTO 'metas' VALUES(2,669,669,4," |
| 2109 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_" |
| 2110 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1" |
| 2111 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X" |
| 2112 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534" |
| 2113 "14447414447414447',NULL,?,0);", |
| 2114 "INSERT INTO 'metas' VALUES(4,681,681,3," |
| 2115 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_" |
| 2116 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL" |
| 2117 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6" |
| 2118 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687" |
| 2119 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656" |
| 2120 "E2F77656C636F6D652E68746D6C1200',NULL,?,0);", |
| 2121 "INSERT INTO 'metas' VALUES(5,677,677,7," |
| 2122 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_" |
| 2123 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2" |
| 2124 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1" |
| 2125 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N" |
| 2126 "ULL,?,0);", |
| 2127 "INSERT INTO 'metas' VALUES(6,694,694,6," |
| 2128 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1" |
| 2129 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'" |
| 2130 ",NULL,?,0);", |
| 2131 "INSERT INTO 'metas' VALUES(7,663,663,0," |
| 2132 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog" |
| 2133 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?,0);" |
| 2134 "", |
| 2135 "INSERT INTO 'metas' VALUES(8,664,664,0," |
| 2136 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1" |
| 2137 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810" |
| 2138 "00',X'C2881000',NULL,?,0);", |
| 2139 "INSERT INTO 'metas' VALUES(9,665,665,1," |
| 2140 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0" |
| 2141 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881" |
| 2142 "000',X'C2881000',NULL,?,0);", |
| 2143 "INSERT INTO 'metas' VALUES(10,666,666,2," |
| 2144 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r'," |
| 2145 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU" |
| 2146 "LL,X'C2881000',X'C2881000',NULL,?,0);", |
| 2147 "INSERT INTO 'metas' VALUES(11,683,683,8," |
| 2148 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'" |
| 2149 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj" |
| 2150 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756" |
| 2151 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636" |
| 2152 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?,0);", |
| 2153 "INSERT INTO 'metas' VALUES(12,685,685,9," |
| 2154 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_" |
| 2155 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C" |
| 2156 "2881000',X'C2881000',NULL,?,0);", |
| 2157 "INSERT INTO 'metas' VALUES(13,687,687,10," |
| 2158 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_" |
| 2159 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names " |
| 2160 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu" |
| 2161 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636" |
| 2162 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772" |
| 2163 "E6963616E6E2E636F6D2F120744414146415346',NULL,?,0);", |
| 2164 "INSERT INTO 'metas' VALUES(14,692,692,11," |
| 2165 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'" |
| 2166 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc" |
| 2167 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726" |
| 2168 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7" |
| 2169 "81205504E473259',NULL,?,0);" }; |
| 2170 |
| 2171 for (int i = 0; i < V80_ROW_COUNT; i++) { |
| 2172 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i])); |
| 2173 std::string ord = V81_Ordinal(i); |
| 2174 s.BindBlob(0, ord.data(), ord.length()); |
| 2175 ASSERT_TRUE(s.Run()); |
| 2176 s.Reset(true); |
| 2177 } |
| 2178 ASSERT_TRUE(connection->CommitTransaction()); |
| 2179 } |
| 2180 |
2071 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { | 2181 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { |
2072 sql::Connection connection; | 2182 sql::Connection connection; |
2073 ASSERT_TRUE(connection.OpenInMemory()); | 2183 ASSERT_TRUE(connection.OpenInMemory()); |
2074 | 2184 |
2075 SetUpVersion67Database(&connection); | 2185 SetUpVersion67Database(&connection); |
2076 | 2186 |
2077 // Columns existing before version 67. | 2187 // Columns existing before version 67. |
2078 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); | 2188 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); |
2079 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); | 2189 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); |
2080 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); | 2190 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2383 | 2493 |
2384 scoped_ptr<TestDirectoryBackingStore> dbs( | 2494 scoped_ptr<TestDirectoryBackingStore> dbs( |
2385 new TestDirectoryBackingStore(GetUsername(), &connection)); | 2495 new TestDirectoryBackingStore(GetUsername(), &connection)); |
2386 ASSERT_FALSE(dbs->needs_column_refresh_); | 2496 ASSERT_FALSE(dbs->needs_column_refresh_); |
2387 ASSERT_TRUE(dbs->MigrateVersion78To79()); | 2497 ASSERT_TRUE(dbs->MigrateVersion78To79()); |
2388 ASSERT_EQ(79, dbs->GetVersion()); | 2498 ASSERT_EQ(79, dbs->GetVersion()); |
2389 ASSERT_FALSE(dbs->needs_column_refresh_); | 2499 ASSERT_FALSE(dbs->needs_column_refresh_); |
2390 | 2500 |
2391 // Ensure the next_id has been incremented. | 2501 // Ensure the next_id has been incremented. |
2392 MetahandlesIndex entry_bucket; | 2502 MetahandlesIndex entry_bucket; |
| 2503 IdsIndex delete_journals; |
2393 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); | 2504 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); |
2394 Directory::KernelLoadInfo load_info; | 2505 Directory::KernelLoadInfo load_info; |
2395 | 2506 |
2396 s.Clear(); | 2507 s.Clear(); |
2397 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); | 2508 ASSERT_TRUE(dbs->Load(&entry_bucket, &delete_journals, &load_info)); |
2398 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536); | 2509 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536); |
2399 } | 2510 } |
2400 | 2511 |
2401 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) { | 2512 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) { |
2402 sql::Connection connection; | 2513 sql::Connection connection; |
2403 ASSERT_TRUE(connection.OpenInMemory()); | 2514 ASSERT_TRUE(connection.OpenInMemory()); |
2404 SetUpVersion79Database(&connection); | 2515 SetUpVersion79Database(&connection); |
2405 | 2516 |
2406 scoped_ptr<TestDirectoryBackingStore> dbs( | 2517 scoped_ptr<TestDirectoryBackingStore> dbs( |
2407 new TestDirectoryBackingStore(GetUsername(), &connection)); | 2518 new TestDirectoryBackingStore(GetUsername(), &connection)); |
2408 ASSERT_FALSE(dbs->needs_column_refresh_); | 2519 ASSERT_FALSE(dbs->needs_column_refresh_); |
2409 ASSERT_TRUE(dbs->MigrateVersion79To80()); | 2520 ASSERT_TRUE(dbs->MigrateVersion79To80()); |
2410 ASSERT_EQ(80, dbs->GetVersion()); | 2521 ASSERT_EQ(80, dbs->GetVersion()); |
2411 ASSERT_FALSE(dbs->needs_column_refresh_); | 2522 ASSERT_FALSE(dbs->needs_column_refresh_); |
2412 | 2523 |
2413 // Ensure the bag_of_chips has been set. | 2524 // Ensure the bag_of_chips has been set. |
2414 MetahandlesIndex entry_bucket; | 2525 MetahandlesIndex entry_bucket; |
| 2526 IdsIndex delete_journals; |
2415 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); | 2527 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); |
2416 Directory::KernelLoadInfo load_info; | 2528 Directory::KernelLoadInfo load_info; |
2417 | 2529 |
2418 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); | 2530 ASSERT_TRUE(dbs->Load(&entry_bucket, &delete_journals, &load_info)); |
2419 // Check that the initial value is the serialization of an empty ChipBag. | 2531 // Check that the initial value is the serialization of an empty ChipBag. |
2420 sync_pb::ChipBag chip_bag; | 2532 sync_pb::ChipBag chip_bag; |
2421 std::string serialized_chip_bag; | 2533 std::string serialized_chip_bag; |
2422 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); | 2534 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); |
2423 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); | 2535 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); |
2424 } | 2536 } |
2425 | 2537 |
2426 TEST_F(DirectoryBackingStoreTest, MigrateVersion80To81) { | 2538 TEST_F(DirectoryBackingStoreTest, MigrateVersion80To81) { |
2427 sql::Connection connection; | 2539 sql::Connection connection; |
2428 ASSERT_TRUE(connection.OpenInMemory()); | 2540 ASSERT_TRUE(connection.OpenInMemory()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2466 sql::Statement s(connection.GetUniqueStatement( | 2578 sql::Statement s(connection.GetUniqueStatement( |
2467 "INSERT INTO metas " | 2579 "INSERT INTO metas " |
2468 "( id, metahandle, is_dir, ctime, mtime, server_ordinal_in_parent) " | 2580 "( id, metahandle, is_dir, ctime, mtime, server_ordinal_in_parent) " |
2469 "VALUES( \"c-invalid\", 9999, 1, ?, ?, \" \")")); | 2581 "VALUES( \"c-invalid\", 9999, 1, ?, ?, \" \")")); |
2470 s.BindInt64(0, now); | 2582 s.BindInt64(0, now); |
2471 s.BindInt64(1, now); | 2583 s.BindInt64(1, now); |
2472 ASSERT_TRUE(s.Run()); | 2584 ASSERT_TRUE(s.Run()); |
2473 | 2585 |
2474 // Trying to unpack this entry should signal that the DB is corrupted. | 2586 // Trying to unpack this entry should signal that the DB is corrupted. |
2475 MetahandlesIndex entry_bucket; | 2587 MetahandlesIndex entry_bucket; |
| 2588 IdsIndex delete_journals; |
2476 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); | 2589 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); |
2477 Directory::KernelLoadInfo kernel_load_info; | 2590 Directory::KernelLoadInfo kernel_load_info; |
2478 ASSERT_EQ(FAILED_DATABASE_CORRUPT, | 2591 ASSERT_EQ(FAILED_DATABASE_CORRUPT, |
2479 dbs->Load(&entry_bucket, &kernel_load_info)); | 2592 dbs->Load(&entry_bucket, &delete_journals, &kernel_load_info)); |
2480 } | 2593 } |
2481 | 2594 |
2482 TEST_F(DirectoryBackingStoreTest, MigrateVersion81To82) { | 2595 TEST_F(DirectoryBackingStoreTest, MigrateVersion81To82) { |
2483 sql::Connection connection; | 2596 sql::Connection connection; |
2484 ASSERT_TRUE(connection.OpenInMemory()); | 2597 ASSERT_TRUE(connection.OpenInMemory()); |
2485 SetUpVersion81Database(&connection); | 2598 SetUpVersion81Database(&connection); |
2486 ASSERT_FALSE(connection.DoesColumnExist("models", "transaction_version")); | 2599 ASSERT_FALSE(connection.DoesColumnExist("models", "transaction_version")); |
2487 | 2600 |
2488 scoped_ptr<TestDirectoryBackingStore> dbs( | 2601 scoped_ptr<TestDirectoryBackingStore> dbs( |
2489 new TestDirectoryBackingStore(GetUsername(), &connection)); | 2602 new TestDirectoryBackingStore(GetUsername(), &connection)); |
(...skipping 12 matching lines...) Expand all Loading... |
2502 ASSERT_FALSE(connection.DoesColumnExist("metas", "transaction_version")); | 2615 ASSERT_FALSE(connection.DoesColumnExist("metas", "transaction_version")); |
2503 | 2616 |
2504 scoped_ptr<TestDirectoryBackingStore> dbs( | 2617 scoped_ptr<TestDirectoryBackingStore> dbs( |
2505 new TestDirectoryBackingStore(GetUsername(), &connection)); | 2618 new TestDirectoryBackingStore(GetUsername(), &connection)); |
2506 ASSERT_TRUE(dbs->MigrateVersion82To83()); | 2619 ASSERT_TRUE(dbs->MigrateVersion82To83()); |
2507 ASSERT_EQ(83, dbs->GetVersion()); | 2620 ASSERT_EQ(83, dbs->GetVersion()); |
2508 | 2621 |
2509 ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version")); | 2622 ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version")); |
2510 } | 2623 } |
2511 | 2624 |
| 2625 TEST_F(DirectoryBackingStoreTest, MigrateVersion83To84) { |
| 2626 sql::Connection connection; |
| 2627 ASSERT_TRUE(connection.OpenInMemory()); |
| 2628 SetUpVersion83Database(&connection); |
| 2629 ASSERT_FALSE(connection.DoesTableExist("deleted_metas")); |
| 2630 |
| 2631 scoped_ptr<TestDirectoryBackingStore> dbs( |
| 2632 new TestDirectoryBackingStore(GetUsername(), &connection)); |
| 2633 ASSERT_TRUE(dbs->MigrateVersion83To84()); |
| 2634 ASSERT_EQ(84, dbs->GetVersion()); |
| 2635 |
| 2636 ASSERT_TRUE(connection.DoesTableExist("deleted_metas")); |
| 2637 } |
| 2638 |
2512 TEST_P(MigrationTest, ToCurrentVersion) { | 2639 TEST_P(MigrationTest, ToCurrentVersion) { |
2513 sql::Connection connection; | 2640 sql::Connection connection; |
2514 ASSERT_TRUE(connection.OpenInMemory()); | 2641 ASSERT_TRUE(connection.OpenInMemory()); |
2515 switch (GetParam()) { | 2642 switch (GetParam()) { |
2516 case 67: | 2643 case 67: |
2517 SetUpVersion67Database(&connection); | 2644 SetUpVersion67Database(&connection); |
2518 break; | 2645 break; |
2519 case 68: | 2646 case 68: |
2520 SetUpVersion68Database(&connection); | 2647 SetUpVersion68Database(&connection); |
2521 break; | 2648 break; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2554 break; | 2681 break; |
2555 case 80: | 2682 case 80: |
2556 SetUpVersion80Database(&connection); | 2683 SetUpVersion80Database(&connection); |
2557 break; | 2684 break; |
2558 case 81: | 2685 case 81: |
2559 SetUpVersion81Database(&connection); | 2686 SetUpVersion81Database(&connection); |
2560 break; | 2687 break; |
2561 case 82: | 2688 case 82: |
2562 SetUpVersion82Database(&connection); | 2689 SetUpVersion82Database(&connection); |
2563 break; | 2690 break; |
| 2691 case 83: |
| 2692 SetUpVersion83Database(&connection); |
| 2693 break; |
2564 default: | 2694 default: |
2565 // If you see this error, it may mean that you've increased the | 2695 // If you see this error, it may mean that you've increased the |
2566 // database version number but you haven't finished adding unit tests | 2696 // database version number but you haven't finished adding unit tests |
2567 // for the database migration code. You need to need to supply a | 2697 // for the database migration code. You need to need to supply a |
2568 // SetUpVersionXXDatabase function with a dump of the test database | 2698 // SetUpVersionXXDatabase function with a dump of the test database |
2569 // at the old schema. Here's one way to do that: | 2699 // at the old schema. Here's one way to do that: |
2570 // 1. Start on a clean tree (with none of your pending schema changes). | 2700 // 1. Start on a clean tree (with none of your pending schema changes). |
2571 // 2. Set a breakpoint in this function and run the unit test. | 2701 // 2. Set a breakpoint in this function and run the unit test. |
2572 // 3. Allow this test to run to completion (step out of the call), | 2702 // 3. Allow this test to run to completion (step out of the call), |
2573 // without allowing ~MigrationTest to execute. | 2703 // without allowing ~MigrationTest to execute. |
2574 // 4. Examine this->temp_dir_ to determine the location of the | 2704 // 4. Examine this->temp_dir_ to determine the location of the |
2575 // test database (it is currently of the version you need). | 2705 // test database (it is currently of the version you need). |
2576 // 5. Dump this using the sqlite3 command line tool: | 2706 // 5. Dump this using the sqlite3 command line tool: |
2577 // > .output foo_dump.sql | 2707 // > .output foo_dump.sql |
2578 // > .dump | 2708 // > .dump |
2579 // 6. Replace the timestamp columns with META_PROTO_TIMES(x) (or | 2709 // 6. Replace the timestamp columns with META_PROTO_TIMES(x) (or |
2580 // LEGACY_META_PROTO_TIMES(x) if before Version 77). | 2710 // LEGACY_META_PROTO_TIMES(x) if before Version 77). |
2581 FAIL() << "Need to supply database dump for version " << GetParam(); | 2711 FAIL() << "Need to supply database dump for version " << GetParam(); |
2582 } | 2712 } |
2583 | 2713 |
2584 syncable::Directory::KernelLoadInfo dir_info; | 2714 syncable::Directory::KernelLoadInfo dir_info; |
2585 MetahandlesIndex index; | 2715 MetahandlesIndex index; |
| 2716 IdsIndex delete_journals; |
2586 STLElementDeleter<MetahandlesIndex> index_deleter(&index); | 2717 STLElementDeleter<MetahandlesIndex> index_deleter(&index); |
2587 | 2718 |
2588 { | 2719 { |
2589 scoped_ptr<TestDirectoryBackingStore> dbs( | 2720 scoped_ptr<TestDirectoryBackingStore> dbs( |
2590 new TestDirectoryBackingStore(GetUsername(), &connection)); | 2721 new TestDirectoryBackingStore(GetUsername(), &connection)); |
2591 ASSERT_EQ(OPENED, dbs->Load(&index, &dir_info)); | 2722 ASSERT_EQ(OPENED, dbs->Load(&index, &delete_journals, &dir_info)); |
2592 ASSERT_FALSE(dbs->needs_column_refresh_); | 2723 ASSERT_FALSE(dbs->needs_column_refresh_); |
2593 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); | 2724 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); |
2594 } | 2725 } |
2595 | 2726 |
2596 // Columns deleted in Version 67. | 2727 // Columns deleted in Version 67. |
2597 ASSERT_FALSE(connection.DoesColumnExist("metas", "name")); | 2728 ASSERT_FALSE(connection.DoesColumnExist("metas", "name")); |
2598 ASSERT_FALSE(connection.DoesColumnExist("metas", "unsanitized_name")); | 2729 ASSERT_FALSE(connection.DoesColumnExist("metas", "unsanitized_name")); |
2599 ASSERT_FALSE(connection.DoesColumnExist("metas", "server_name")); | 2730 ASSERT_FALSE(connection.DoesColumnExist("metas", "server_name")); |
2600 | 2731 |
2601 // Columns added in Version 68. | 2732 // Columns added in Version 68. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2847 } | 2978 } |
2848 | 2979 |
2849 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { | 2980 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { |
2850 sql::Connection connection; | 2981 sql::Connection connection; |
2851 ASSERT_TRUE(connection.OpenInMemory()); | 2982 ASSERT_TRUE(connection.OpenInMemory()); |
2852 | 2983 |
2853 SetUpCurrentDatabaseAndCheckVersion(&connection); | 2984 SetUpCurrentDatabaseAndCheckVersion(&connection); |
2854 scoped_ptr<TestDirectoryBackingStore> dbs( | 2985 scoped_ptr<TestDirectoryBackingStore> dbs( |
2855 new TestDirectoryBackingStore(GetUsername(), &connection)); | 2986 new TestDirectoryBackingStore(GetUsername(), &connection)); |
2856 MetahandlesIndex index; | 2987 MetahandlesIndex index; |
| 2988 IdsIndex delete_journals; |
2857 Directory::KernelLoadInfo kernel_load_info; | 2989 Directory::KernelLoadInfo kernel_load_info; |
2858 STLElementDeleter<MetahandlesIndex> index_deleter(&index); | 2990 STLElementDeleter<MetahandlesIndex> index_deleter(&index); |
2859 | 2991 |
2860 dbs->Load(&index, &kernel_load_info); | 2992 dbs->Load(&index, &delete_journals, &kernel_load_info); |
2861 size_t initial_size = index.size(); | 2993 size_t initial_size = index.size(); |
2862 ASSERT_LT(0U, initial_size) << "Test requires entries to delete."; | 2994 ASSERT_LT(0U, initial_size) << "Test requires entries to delete."; |
2863 int64 first_to_die = (*index.begin())->ref(META_HANDLE); | 2995 int64 first_to_die = (*index.begin())->ref(META_HANDLE); |
2864 MetahandleSet to_delete; | 2996 MetahandleSet to_delete; |
2865 to_delete.insert(first_to_die); | 2997 to_delete.insert(first_to_die); |
2866 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); | 2998 EXPECT_TRUE(dbs->DeleteEntries(DirectoryBackingStore::DELETE_FROM_METAS, |
| 2999 to_delete)); |
2867 | 3000 |
2868 STLDeleteElements(&index); | 3001 STLDeleteElements(&index); |
2869 dbs->LoadEntries(&index); | 3002 dbs->LoadEntries(&index); |
2870 | 3003 |
2871 EXPECT_EQ(initial_size - 1, index.size()); | 3004 EXPECT_EQ(initial_size - 1, index.size()); |
2872 bool delete_failed = false; | 3005 bool delete_failed = false; |
2873 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); | 3006 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); |
2874 ++it) { | 3007 ++it) { |
2875 if ((*it)->ref(META_HANDLE) == first_to_die) { | 3008 if ((*it)->ref(META_HANDLE) == first_to_die) { |
2876 delete_failed = true; | 3009 delete_failed = true; |
2877 break; | 3010 break; |
2878 } | 3011 } |
2879 } | 3012 } |
2880 EXPECT_FALSE(delete_failed); | 3013 EXPECT_FALSE(delete_failed); |
2881 | 3014 |
2882 to_delete.clear(); | 3015 to_delete.clear(); |
2883 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); | 3016 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); |
2884 ++it) { | 3017 ++it) { |
2885 to_delete.insert((*it)->ref(META_HANDLE)); | 3018 to_delete.insert((*it)->ref(META_HANDLE)); |
2886 } | 3019 } |
2887 | 3020 |
2888 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); | 3021 EXPECT_TRUE(dbs->DeleteEntries(DirectoryBackingStore::DELETE_FROM_METAS, |
| 3022 to_delete)); |
2889 | 3023 |
2890 STLDeleteElements(&index); | 3024 STLDeleteElements(&index); |
2891 dbs->LoadEntries(&index); | 3025 dbs->LoadEntries(&index); |
2892 EXPECT_EQ(0U, index.size()); | 3026 EXPECT_EQ(0U, index.size()); |
2893 } | 3027 } |
2894 | 3028 |
2895 TEST_F(DirectoryBackingStoreTest, GenerateCacheGUID) { | 3029 TEST_F(DirectoryBackingStoreTest, GenerateCacheGUID) { |
2896 const std::string& guid1 = TestDirectoryBackingStore::GenerateCacheGUID(); | 3030 const std::string& guid1 = TestDirectoryBackingStore::GenerateCacheGUID(); |
2897 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); | 3031 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); |
2898 EXPECT_EQ(24U, guid1.size()); | 3032 EXPECT_EQ(24U, guid1.size()); |
2899 EXPECT_EQ(24U, guid2.size()); | 3033 EXPECT_EQ(24U, guid2.size()); |
2900 // In theory this test can fail, but it won't before the universe | 3034 // In theory this test can fail, but it won't before the universe |
2901 // dies of heat death. | 3035 // dies of heat death. |
2902 EXPECT_NE(guid1, guid2); | 3036 EXPECT_NE(guid1, guid2); |
2903 } | 3037 } |
2904 | 3038 |
2905 } // namespace syncable | 3039 } // namespace syncable |
2906 } // namespace syncer | 3040 } // namespace syncer |
OLD | NEW |