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

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

Issue 11474036: Remove initial_sync_ended bits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add another test Created 8 years 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 | Annotate | Revision Log
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"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 void SetUpVersion73Database(sql::Connection* connection); 60 void SetUpVersion73Database(sql::Connection* connection);
61 void SetUpVersion74Database(sql::Connection* connection); 61 void SetUpVersion74Database(sql::Connection* connection);
62 void SetUpVersion75Database(sql::Connection* connection); 62 void SetUpVersion75Database(sql::Connection* connection);
63 void SetUpVersion76Database(sql::Connection* connection); 63 void SetUpVersion76Database(sql::Connection* connection);
64 void SetUpVersion77Database(sql::Connection* connection); 64 void SetUpVersion77Database(sql::Connection* connection);
65 void SetUpVersion78Database(sql::Connection* connection); 65 void SetUpVersion78Database(sql::Connection* connection);
66 void SetUpVersion79Database(sql::Connection* connection); 66 void SetUpVersion79Database(sql::Connection* connection);
67 void SetUpVersion80Database(sql::Connection* connection); 67 void SetUpVersion80Database(sql::Connection* connection);
68 void SetUpVersion81Database(sql::Connection* connection); 68 void SetUpVersion81Database(sql::Connection* connection);
69 void SetUpVersion82Database(sql::Connection* connection); 69 void SetUpVersion82Database(sql::Connection* connection);
70 void SetUpVersion83Database(sql::Connection* connection);
70 71
71 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { 72 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) {
72 SetUpVersion77Database(connection); // Prepopulates data. 73 SetUpVersion77Database(connection); // Prepopulates data.
73 scoped_ptr<TestDirectoryBackingStore> dbs( 74 scoped_ptr<TestDirectoryBackingStore> dbs(
74 new TestDirectoryBackingStore(GetUsername(), connection)); 75 new TestDirectoryBackingStore(GetUsername(), connection));
75 76
76 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 77 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
77 ASSERT_FALSE(dbs->needs_column_refresh_); 78 ASSERT_FALSE(dbs->needs_column_refresh_);
78 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); 79 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion());
79 } 80 }
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 for (int i = 0; i < V80_ROW_COUNT; i++) { 2062 for (int i = 0; i < V80_ROW_COUNT; i++) {
2062 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i])); 2063 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
2063 std::string ord = V81_Ordinal(i); 2064 std::string ord = V81_Ordinal(i);
2064 s.BindBlob(0, ord.data(), ord.length()); 2065 s.BindBlob(0, ord.data(), ord.length());
2065 ASSERT_TRUE(s.Run()); 2066 ASSERT_TRUE(s.Run());
2066 s.Reset(true); 2067 s.Reset(true);
2067 } 2068 }
2068 ASSERT_TRUE(connection->CommitTransaction()); 2069 ASSERT_TRUE(connection->CommitTransaction());
2069 } 2070 }
2070 2071
2072 void MigrationTest::SetUpVersion83Database(sql::Connection* connection) {
2073 ASSERT_TRUE(connection->is_open());
2074 ASSERT_TRUE(connection->BeginTransaction());
2075 ASSERT_TRUE(connection->Execute(
2076 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2077 "INSERT INTO 'share_version' VALUES('nick@chromium.org',81);"
2078 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, "
2079 " transaction_version BIGINT default 0);"
2080 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605', 1);"
2081 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
2082 "_version bigint default -1,server_version bigint default 0, "
2083 "local_external_id bigint default 0"
2084 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
2085 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
2086 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
2087 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
2088 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
2089 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
2090 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
2091 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
2092 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
2093 ", server_ordinal_in_parent blob);"
2094 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2095 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
2096 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
2097 "blob);"
2098 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2099 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
2100 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
2101
2102 const char* insert_stmts[V80_ROW_COUNT] = {
2103 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
2104 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?);",
2105 "INSERT INTO 'metas' VALUES(2,669,669,4,"
2106 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
2107 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
2108 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
2109 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
2110 "14447414447414447',NULL,?);",
2111 "INSERT INTO 'metas' VALUES(4,681,681,3,"
2112 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
2113 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
2114 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
2115 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
2116 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
2117 "E2F77656C636F6D652E68746D6C1200',NULL,?);",
2118 "INSERT INTO 'metas' VALUES(5,677,677,7,"
2119 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
2120 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
2121 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
2122 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
2123 "ULL,?);",
2124 "INSERT INTO 'metas' VALUES(6,694,694,6,"
2125 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
2126 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
2127 ",NULL,?);",
2128 "INSERT INTO 'metas' VALUES(7,663,663,0,"
2129 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
2130 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?);",
2131 "INSERT INTO 'metas' VALUES(8,664,664,0,"
2132 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
2133 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
2134 "00',X'C2881000',NULL,?);",
2135 "INSERT INTO 'metas' VALUES(9,665,665,1,"
2136 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
2137 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
2138 "000',X'C2881000',NULL,?);",
2139 "INSERT INTO 'metas' VALUES(10,666,666,2,"
2140 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
2141 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
2142 "LL,X'C2881000',X'C2881000',NULL,?);",
2143 "INSERT INTO 'metas' VALUES(11,683,683,8,"
2144 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
2145 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
2146 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
2147 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
2148 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?);",
2149 "INSERT INTO 'metas' VALUES(12,685,685,9,"
2150 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
2151 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
2152 "2881000',X'C2881000',NULL,?);",
2153 "INSERT INTO 'metas' VALUES(13,687,687,10,"
2154 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
2155 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
2156 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
2157 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
2158 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
2159 "E6963616E6E2E636F6D2F120744414146415346',NULL,?);",
2160 "INSERT INTO 'metas' VALUES(14,692,692,11,"
2161 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
2162 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
2163 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
2164 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
2165 "81205504E473259',NULL,?);" };
2166
2167 for (int i = 0; i < V80_ROW_COUNT; i++) {
2168 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
2169 std::string ord = V81_Ordinal(i);
2170 s.BindBlob(0, ord.data(), ord.length());
2171 ASSERT_TRUE(s.Run());
2172 s.Reset(true);
2173 }
2174 ASSERT_TRUE(connection->CommitTransaction());
2175 }
2176
2071 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { 2177 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) {
2072 sql::Connection connection; 2178 sql::Connection connection;
2073 ASSERT_TRUE(connection.OpenInMemory()); 2179 ASSERT_TRUE(connection.OpenInMemory());
2074 2180
2075 SetUpVersion67Database(&connection); 2181 SetUpVersion67Database(&connection);
2076 2182
2077 // Columns existing before version 67. 2183 // Columns existing before version 67.
2078 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); 2184 ASSERT_TRUE(connection.DoesColumnExist("metas", "name"));
2079 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); 2185 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name"));
2080 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); 2186 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name"));
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
2554 break; 2660 break;
2555 case 80: 2661 case 80:
2556 SetUpVersion80Database(&connection); 2662 SetUpVersion80Database(&connection);
2557 break; 2663 break;
2558 case 81: 2664 case 81:
2559 SetUpVersion81Database(&connection); 2665 SetUpVersion81Database(&connection);
2560 break; 2666 break;
2561 case 82: 2667 case 82:
2562 SetUpVersion82Database(&connection); 2668 SetUpVersion82Database(&connection);
2563 break; 2669 break;
2670 case 83:
2671 SetUpVersion83Database(&connection);
2672 break;
2564 default: 2673 default:
2565 // If you see this error, it may mean that you've increased the 2674 // 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 2675 // database version number but you haven't finished adding unit tests
2567 // for the database migration code. You need to need to supply a 2676 // for the database migration code. You need to need to supply a
2568 // SetUpVersionXXDatabase function with a dump of the test database 2677 // SetUpVersionXXDatabase function with a dump of the test database
2569 // at the old schema. Here's one way to do that: 2678 // 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). 2679 // 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. 2680 // 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), 2681 // 3. Allow this test to run to completion (step out of the call),
2573 // without allowing ~MigrationTest to execute. 2682 // without allowing ~MigrationTest to execute.
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2897 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); 3006 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID();
2898 EXPECT_EQ(24U, guid1.size()); 3007 EXPECT_EQ(24U, guid1.size());
2899 EXPECT_EQ(24U, guid2.size()); 3008 EXPECT_EQ(24U, guid2.size());
2900 // In theory this test can fail, but it won't before the universe 3009 // In theory this test can fail, but it won't before the universe
2901 // dies of heat death. 3010 // dies of heat death.
2902 EXPECT_NE(guid1, guid2); 3011 EXPECT_NE(guid1, guid2);
2903 } 3012 }
2904 3013
2905 } // namespace syncable 3014 } // namespace syncable
2906 } // namespace syncer 3015 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698