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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
« no previous file with comments | « sync/syncable/directory_backing_store.cc ('k') | sync/syncable/directory_change_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sync/syncable/directory_backing_store.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <map>
11 #include <memory>
12 #include <string>
13
14 #include "base/files/file_path.h"
15 #include "base/files/scoped_temp_dir.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h"
18 #include "base/stl_util.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h"
21 #include "build/build_config.h"
22 #include "sql/connection.h"
23 #include "sql/statement.h"
24 #include "sql/test/test_helpers.h"
25 #include "sync/base/sync_export.h"
26 #include "sync/internal_api/public/base/node_ordinal.h"
27 #include "sync/protocol/bookmark_specifics.pb.h"
28 #include "sync/protocol/sync.pb.h"
29 #include "sync/syncable/directory.h"
30 #include "sync/syncable/on_disk_directory_backing_store.h"
31 #include "sync/syncable/syncable-inl.h"
32 #include "sync/test/directory_backing_store_corruption_testing.h"
33 #include "sync/test/test_directory_backing_store.h"
34 #include "sync/util/time.h"
35 #include "testing/gtest/include/gtest/gtest-param-test.h"
36 #include "testing/gtest/include/gtest/gtest.h"
37
38 namespace syncer {
39 namespace syncable {
40 namespace {
41
42 // A handler that simply sets |catastrophic_error_handler_was_called| to true.
43 void CatastrophicErrorHandler(bool* catastrophic_error_handler_was_called) {
44 *catastrophic_error_handler_was_called = true;
45 }
46
47 // Create a dirty EntryKernel with an ID derived from |id| + |id_suffix|.
48 std::unique_ptr<EntryKernel> CreateEntry(int id, const std::string& id_suffix) {
49 std::unique_ptr<EntryKernel> entry(new EntryKernel());
50 std::string id_string = base::Int64ToString(id) + id_suffix;
51 entry->put(ID, Id::CreateFromClientString(id_string));
52 entry->put(META_HANDLE, id);
53 entry->mark_dirty(NULL);
54 return entry;
55 }
56
57 } // namespace
58
59 SYNC_EXPORT extern const int32_t kCurrentPageSizeKB;
60 SYNC_EXPORT extern const int32_t kCurrentDBVersion;
61
62 class MigrationTest : public testing::TestWithParam<int> {
63 public:
64 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
65
66 protected:
67 std::string GetUsername() {
68 return "nick@chromium.org";
69 }
70
71 base::FilePath GetDatabasePath() {
72 return temp_dir_.path().Append(Directory::kSyncDatabaseFilename);
73 }
74
75 static bool LoadAndIgnoreReturnedData(DirectoryBackingStore *dbs) {
76 Directory::MetahandlesMap tmp_handles_map;
77 JournalIndex delete_journals;
78 MetahandleSet metahandles_to_purge;
79 STLValueDeleter<Directory::MetahandlesMap> deleter(&tmp_handles_map);
80 Directory::KernelLoadInfo kernel_load_info;
81 return dbs->Load(&tmp_handles_map, &delete_journals, &metahandles_to_purge,
82 &kernel_load_info) == OPENED;
83 }
84
85 void SetUpVersion67Database(sql::Connection* connection);
86 void SetUpVersion68Database(sql::Connection* connection);
87 void SetUpVersion69Database(sql::Connection* connection);
88 void SetUpVersion70Database(sql::Connection* connection);
89 void SetUpVersion71Database(sql::Connection* connection);
90 void SetUpVersion72Database(sql::Connection* connection);
91 void SetUpVersion73Database(sql::Connection* connection);
92 void SetUpVersion74Database(sql::Connection* connection);
93 void SetUpVersion75Database(sql::Connection* connection);
94 void SetUpVersion76Database(sql::Connection* connection);
95 void SetUpVersion77Database(sql::Connection* connection);
96 void SetUpVersion78Database(sql::Connection* connection);
97 void SetUpVersion79Database(sql::Connection* connection);
98 void SetUpVersion80Database(sql::Connection* connection);
99 void SetUpVersion81Database(sql::Connection* connection);
100 void SetUpVersion82Database(sql::Connection* connection);
101 void SetUpVersion83Database(sql::Connection* connection);
102 void SetUpVersion84Database(sql::Connection* connection);
103 void SetUpVersion85Database(sql::Connection* connection);
104 void SetUpVersion86Database(sql::Connection* connection);
105 void SetUpVersion87Database(sql::Connection* connection);
106 void SetUpVersion88Database(sql::Connection* connection);
107 void SetUpVersion89Database(sql::Connection* connection);
108 void SetUpVersion90Database(sql::Connection* connection);
109
110 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) {
111 SetUpVersion90Database(connection); // Prepopulates data.
112 std::unique_ptr<TestDirectoryBackingStore> dbs(
113 new TestDirectoryBackingStore(GetUsername(), connection));
114 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion());
115
116 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
117 ASSERT_FALSE(dbs->needs_column_refresh());
118 }
119
120 private:
121 base::MessageLoop message_loop_;
122 base::ScopedTempDir temp_dir_;
123 };
124
125 class DirectoryBackingStoreTest : public MigrationTest {};
126
127 #if defined(OS_WIN)
128
129 // On Windows, we used to store timestamps in FILETIME format.
130 #define LEGACY_META_PROTO_TIMES_1 129079956640320000LL
131 #define LEGACY_META_PROTO_TIMES_2 128976886618480000LL
132 #define LEGACY_META_PROTO_TIMES_4 129002163642690000LL
133 #define LEGACY_META_PROTO_TIMES_5 129001555500000000LL
134 #define LEGACY_META_PROTO_TIMES_6 129053976170000000LL
135 #define LEGACY_META_PROTO_TIMES_7 128976864758480000LL
136 #define LEGACY_META_PROTO_TIMES_8 128976864758480000LL
137 #define LEGACY_META_PROTO_TIMES_9 128976864758480000LL
138 #define LEGACY_META_PROTO_TIMES_10 128976864758480000LL
139 #define LEGACY_META_PROTO_TIMES_11 129079956948440000LL
140 #define LEGACY_META_PROTO_TIMES_12 129079957513650000LL
141 #define LEGACY_META_PROTO_TIMES_13 129079957985300000LL
142 #define LEGACY_META_PROTO_TIMES_14 129079958383000000LL
143
144 #define LEGACY_META_PROTO_TIMES_STR_1 "129079956640320000"
145 #define LEGACY_META_PROTO_TIMES_STR_2 "128976886618480000"
146 #define LEGACY_META_PROTO_TIMES_STR_4 "129002163642690000"
147 #define LEGACY_META_PROTO_TIMES_STR_5 "129001555500000000"
148 #define LEGACY_META_PROTO_TIMES_STR_6 "129053976170000000"
149 #define LEGACY_META_PROTO_TIMES_STR_7 "128976864758480000"
150 #define LEGACY_META_PROTO_TIMES_STR_8 "128976864758480000"
151 #define LEGACY_META_PROTO_TIMES_STR_9 "128976864758480000"
152 #define LEGACY_META_PROTO_TIMES_STR_10 "128976864758480000"
153 #define LEGACY_META_PROTO_TIMES_STR_11 "129079956948440000"
154 #define LEGACY_META_PROTO_TIMES_STR_12 "129079957513650000"
155 #define LEGACY_META_PROTO_TIMES_STR_13 "129079957985300000"
156 #define LEGACY_META_PROTO_TIMES_STR_14 "129079958383000000"
157
158 // Generated via:
159 //
160 // ruby -ane '$F[1].sub!("LEGACY_", ""); $F[2] = Integer($F[2].sub!("LL", "")) /
161 // 10000 - 11644473600000; print "#{$F[0]} #{$F[1]} #{$F[2]}LL"'
162 //
163 // Magic numbers taken from
164 // http://stackoverflow.com/questions/5398557/
165 // java-library-for-dealing-with-win32-filetime .
166
167 // Now we store them in Java format (ms since the Unix epoch).
168 #define META_PROTO_TIMES_1 1263522064032LL
169 #define META_PROTO_TIMES_2 1253215061848LL
170 #define META_PROTO_TIMES_4 1255742764269LL
171 #define META_PROTO_TIMES_5 1255681950000LL
172 #define META_PROTO_TIMES_6 1260924017000LL
173 #define META_PROTO_TIMES_7 1253212875848LL
174 #define META_PROTO_TIMES_8 1253212875848LL
175 #define META_PROTO_TIMES_9 1253212875848LL
176 #define META_PROTO_TIMES_10 1253212875848LL
177 #define META_PROTO_TIMES_11 1263522094844LL
178 #define META_PROTO_TIMES_12 1263522151365LL
179 #define META_PROTO_TIMES_13 1263522198530LL
180 #define META_PROTO_TIMES_14 1263522238300LL
181
182 #define META_PROTO_TIMES_STR_1 "1263522064032"
183 #define META_PROTO_TIMES_STR_2 "1253215061848"
184 #define META_PROTO_TIMES_STR_4 "1255742764269"
185 #define META_PROTO_TIMES_STR_5 "1255681950000"
186 #define META_PROTO_TIMES_STR_6 "1260924017000"
187 #define META_PROTO_TIMES_STR_7 "1253212875848"
188 #define META_PROTO_TIMES_STR_8 "1253212875848"
189 #define META_PROTO_TIMES_STR_9 "1253212875848"
190 #define META_PROTO_TIMES_STR_10 "1253212875848"
191 #define META_PROTO_TIMES_STR_11 "1263522094844"
192 #define META_PROTO_TIMES_STR_12 "1263522151365"
193 #define META_PROTO_TIMES_STR_13 "1263522198530"
194 #define META_PROTO_TIMES_STR_14 "1263522238300"
195
196 #else
197
198 // On other platforms, we used to store timestamps in time_t format (s
199 // since the Unix epoch).
200 #define LEGACY_META_PROTO_TIMES_1 1263522064LL
201 #define LEGACY_META_PROTO_TIMES_2 1253215061LL
202 #define LEGACY_META_PROTO_TIMES_4 1255742764LL
203 #define LEGACY_META_PROTO_TIMES_5 1255681950LL
204 #define LEGACY_META_PROTO_TIMES_6 1260924017LL
205 #define LEGACY_META_PROTO_TIMES_7 1253212875LL
206 #define LEGACY_META_PROTO_TIMES_8 1253212875LL
207 #define LEGACY_META_PROTO_TIMES_9 1253212875LL
208 #define LEGACY_META_PROTO_TIMES_10 1253212875LL
209 #define LEGACY_META_PROTO_TIMES_11 1263522094LL
210 #define LEGACY_META_PROTO_TIMES_12 1263522151LL
211 #define LEGACY_META_PROTO_TIMES_13 1263522198LL
212 #define LEGACY_META_PROTO_TIMES_14 1263522238LL
213
214 #define LEGACY_META_PROTO_TIMES_STR_1 "1263522064"
215 #define LEGACY_META_PROTO_TIMES_STR_2 "1253215061"
216 #define LEGACY_META_PROTO_TIMES_STR_4 "1255742764"
217 #define LEGACY_META_PROTO_TIMES_STR_5 "1255681950"
218 #define LEGACY_META_PROTO_TIMES_STR_6 "1260924017"
219 #define LEGACY_META_PROTO_TIMES_STR_7 "1253212875"
220 #define LEGACY_META_PROTO_TIMES_STR_8 "1253212875"
221 #define LEGACY_META_PROTO_TIMES_STR_9 "1253212875"
222 #define LEGACY_META_PROTO_TIMES_STR_10 "1253212875"
223 #define LEGACY_META_PROTO_TIMES_STR_11 "1263522094"
224 #define LEGACY_META_PROTO_TIMES_STR_12 "1263522151"
225 #define LEGACY_META_PROTO_TIMES_STR_13 "1263522198"
226 #define LEGACY_META_PROTO_TIMES_STR_14 "1263522238"
227
228 // Now we store them in Java format (ms since the Unix epoch).
229 #define META_PROTO_TIMES_1 1263522064000LL
230 #define META_PROTO_TIMES_2 1253215061000LL
231 #define META_PROTO_TIMES_4 1255742764000LL
232 #define META_PROTO_TIMES_5 1255681950000LL
233 #define META_PROTO_TIMES_6 1260924017000LL
234 #define META_PROTO_TIMES_7 1253212875000LL
235 #define META_PROTO_TIMES_8 1253212875000LL
236 #define META_PROTO_TIMES_9 1253212875000LL
237 #define META_PROTO_TIMES_10 1253212875000LL
238 #define META_PROTO_TIMES_11 1263522094000LL
239 #define META_PROTO_TIMES_12 1263522151000LL
240 #define META_PROTO_TIMES_13 1263522198000LL
241 #define META_PROTO_TIMES_14 1263522238000LL
242
243 #define META_PROTO_TIMES_STR_1 "1263522064000"
244 #define META_PROTO_TIMES_STR_2 "1253215061000"
245 #define META_PROTO_TIMES_STR_4 "1255742764000"
246 #define META_PROTO_TIMES_STR_5 "1255681950000"
247 #define META_PROTO_TIMES_STR_6 "1260924017000"
248 #define META_PROTO_TIMES_STR_7 "1253212875000"
249 #define META_PROTO_TIMES_STR_8 "1253212875000"
250 #define META_PROTO_TIMES_STR_9 "1253212875000"
251 #define META_PROTO_TIMES_STR_10 "1253212875000"
252 #define META_PROTO_TIMES_STR_11 "1263522094000"
253 #define META_PROTO_TIMES_STR_12 "1263522151000"
254 #define META_PROTO_TIMES_STR_13 "1263522198000"
255 #define META_PROTO_TIMES_STR_14 "1263522238000"
256
257 #endif
258
259 // Helper macros for the database dumps in the SetUpVersion*Database
260 // functions.
261 #define LEGACY_META_PROTO_TIMES(x) LEGACY_META_PROTO_TIMES_##x
262 #define LEGACY_META_PROTO_TIMES_STR(x) LEGACY_META_PROTO_TIMES_STR_##x
263 #define LEGACY_PROTO_TIME_VALS(x) \
264 LEGACY_META_PROTO_TIMES_STR(x) "," \
265 LEGACY_META_PROTO_TIMES_STR(x) "," \
266 LEGACY_META_PROTO_TIMES_STR(x) "," \
267 LEGACY_META_PROTO_TIMES_STR(x)
268 #define META_PROTO_TIMES(x) META_PROTO_TIMES_##x
269 #define META_PROTO_TIMES_STR(x) META_PROTO_TIMES_STR_##x
270 #define META_PROTO_TIMES_VALS(x) \
271 META_PROTO_TIMES_STR(x) "," \
272 META_PROTO_TIMES_STR(x) "," \
273 META_PROTO_TIMES_STR(x) "," \
274 META_PROTO_TIMES_STR(x)
275
276 namespace {
277
278 // Helper functions for testing.
279
280 enum ShouldIncludeDeletedItems {
281 INCLUDE_DELETED_ITEMS,
282 DONT_INCLUDE_DELETED_ITEMS
283 };
284
285 // Returns a map from metahandle -> expected legacy time (in proto
286 // format).
287 std::map<int64_t, int64_t> GetExpectedLegacyMetaProtoTimes(
288 enum ShouldIncludeDeletedItems include_deleted) {
289 std::map<int64_t, int64_t> expected_legacy_meta_proto_times;
290 expected_legacy_meta_proto_times[1] = LEGACY_META_PROTO_TIMES(1);
291 if (include_deleted == INCLUDE_DELETED_ITEMS) {
292 expected_legacy_meta_proto_times[2] = LEGACY_META_PROTO_TIMES(2);
293 expected_legacy_meta_proto_times[4] = LEGACY_META_PROTO_TIMES(4);
294 expected_legacy_meta_proto_times[5] = LEGACY_META_PROTO_TIMES(5);
295 }
296 expected_legacy_meta_proto_times[6] = LEGACY_META_PROTO_TIMES(6);
297 expected_legacy_meta_proto_times[7] = LEGACY_META_PROTO_TIMES(7);
298 expected_legacy_meta_proto_times[8] = LEGACY_META_PROTO_TIMES(8);
299 expected_legacy_meta_proto_times[9] = LEGACY_META_PROTO_TIMES(9);
300 expected_legacy_meta_proto_times[10] = LEGACY_META_PROTO_TIMES(10);
301 expected_legacy_meta_proto_times[11] = LEGACY_META_PROTO_TIMES(11);
302 expected_legacy_meta_proto_times[12] = LEGACY_META_PROTO_TIMES(12);
303 expected_legacy_meta_proto_times[13] = LEGACY_META_PROTO_TIMES(13);
304 expected_legacy_meta_proto_times[14] = LEGACY_META_PROTO_TIMES(14);
305 return expected_legacy_meta_proto_times;
306 }
307
308 // Returns a map from metahandle -> expected time (in proto format).
309 std::map<int64_t, int64_t> GetExpectedMetaProtoTimes(
310 enum ShouldIncludeDeletedItems include_deleted) {
311 std::map<int64_t, int64_t> expected_meta_proto_times;
312 expected_meta_proto_times[1] = META_PROTO_TIMES(1);
313 if (include_deleted == INCLUDE_DELETED_ITEMS) {
314 expected_meta_proto_times[2] = META_PROTO_TIMES(2);
315 expected_meta_proto_times[4] = META_PROTO_TIMES(4);
316 expected_meta_proto_times[5] = META_PROTO_TIMES(5);
317 }
318 expected_meta_proto_times[6] = META_PROTO_TIMES(6);
319 expected_meta_proto_times[7] = META_PROTO_TIMES(7);
320 expected_meta_proto_times[8] = META_PROTO_TIMES(8);
321 expected_meta_proto_times[9] = META_PROTO_TIMES(9);
322 expected_meta_proto_times[10] = META_PROTO_TIMES(10);
323 expected_meta_proto_times[11] = META_PROTO_TIMES(11);
324 expected_meta_proto_times[12] = META_PROTO_TIMES(12);
325 expected_meta_proto_times[13] = META_PROTO_TIMES(13);
326 expected_meta_proto_times[14] = META_PROTO_TIMES(14);
327 return expected_meta_proto_times;
328 }
329
330 // Returns a map from metahandle -> expected time (as a Time object).
331 std::map<int64_t, base::Time> GetExpectedMetaTimes() {
332 std::map<int64_t, base::Time> expected_meta_times;
333 const std::map<int64_t, int64_t>& expected_meta_proto_times =
334 GetExpectedMetaProtoTimes(INCLUDE_DELETED_ITEMS);
335 for (std::map<int64_t, int64_t>::const_iterator it =
336 expected_meta_proto_times.begin();
337 it != expected_meta_proto_times.end(); ++it) {
338 expected_meta_times[it->first] = ProtoTimeToTime(it->second);
339 }
340 return expected_meta_times;
341 }
342
343 // Extracts a map from metahandle -> time (in proto format) from the
344 // given database.
345 std::map<int64_t, int64_t> GetMetaProtoTimes(sql::Connection* db) {
346 sql::Statement s(db->GetCachedStatement(
347 SQL_FROM_HERE,
348 "SELECT metahandle, mtime, server_mtime, ctime, server_ctime "
349 "FROM metas"));
350 EXPECT_EQ(5, s.ColumnCount());
351 std::map<int64_t, int64_t> meta_times;
352 while (s.Step()) {
353 int64_t metahandle = s.ColumnInt64(0);
354 int64_t mtime = s.ColumnInt64(1);
355 int64_t server_mtime = s.ColumnInt64(2);
356 int64_t ctime = s.ColumnInt64(3);
357 int64_t server_ctime = s.ColumnInt64(4);
358 EXPECT_EQ(mtime, server_mtime);
359 EXPECT_EQ(mtime, ctime);
360 EXPECT_EQ(mtime, server_ctime);
361 meta_times[metahandle] = mtime;
362 }
363 EXPECT_TRUE(s.Succeeded());
364 return meta_times;
365 }
366
367 ::testing::AssertionResult AssertTimesMatch(const char* t1_expr,
368 const char* t2_expr,
369 const base::Time& t1,
370 const base::Time& t2) {
371 if (t1 == t2)
372 return ::testing::AssertionSuccess();
373
374 return ::testing::AssertionFailure()
375 << t1_expr << " and " << t2_expr
376 << " (internal values: " << t1.ToInternalValue()
377 << " and " << t2.ToInternalValue()
378 << ") (proto time: " << TimeToProtoTime(t1)
379 << " and " << TimeToProtoTime(t2)
380 << ") do not match";
381 }
382
383 // Expect that all time fields of the given entry kernel will be the
384 // given time.
385 void ExpectTime(const EntryKernel& entry_kernel,
386 const base::Time& expected_time) {
387 EXPECT_PRED_FORMAT2(AssertTimesMatch,
388 expected_time, entry_kernel.ref(CTIME));
389 EXPECT_PRED_FORMAT2(AssertTimesMatch,
390 expected_time, entry_kernel.ref(SERVER_CTIME));
391 EXPECT_PRED_FORMAT2(AssertTimesMatch,
392 expected_time, entry_kernel.ref(MTIME));
393 EXPECT_PRED_FORMAT2(AssertTimesMatch,
394 expected_time, entry_kernel.ref(SERVER_MTIME));
395 }
396
397 // Expect that all the entries in |entries| have times matching those in
398 // the given map (from metahandle to expect time).
399 void ExpectTimes(const Directory::MetahandlesMap& handles_map,
400 const std::map<int64_t, base::Time>& expected_times) {
401 for (Directory::MetahandlesMap::const_iterator it = handles_map.begin();
402 it != handles_map.end(); ++it) {
403 int64_t meta_handle = it->first;
404 SCOPED_TRACE(meta_handle);
405 std::map<int64_t, base::Time>::const_iterator it2 =
406 expected_times.find(meta_handle);
407 if (it2 == expected_times.end()) {
408 ADD_FAILURE() << "Could not find expected time for " << meta_handle;
409 continue;
410 }
411 ExpectTime(*it->second, it2->second);
412 }
413 }
414
415 } // namespace
416
417 void MigrationTest::SetUpVersion67Database(sql::Connection* connection) {
418 // This is a version 67 database dump whose contents were backformed from
419 // the contents of the version 68 database dump (the v68 migration was
420 // actually written first).
421 ASSERT_TRUE(connection->is_open());
422 ASSERT_TRUE(connection->BeginTransaction());
423 ASSERT_TRUE(connection->Execute(
424 "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
425 "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
426 "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL,"
427 "base_version bigint default -1,server_version bigint default 0,"
428 "mtime bigint default 0,server_mtime bigint default 0,"
429 "ctime bigint default 0,server_ctime bigint default 0,"
430 "server_position_in_parent bigint default 0,"
431 "local_external_id bigint default 0,id varchar(255) default 'r',"
432 "parent_id varchar(255) default 'r',"
433 "server_parent_id varchar(255) default 'r',"
434 "prev_id varchar(255) default 'r',next_id varchar(255) default 'r',"
435 "is_unsynced bit default 0,is_unapplied_update bit default 0,"
436 "is_del bit default 0,is_dir bit default 0,"
437 "is_bookmark_object bit default 0,server_is_dir bit default 0,"
438 "server_is_del bit default 0,server_is_bookmark_object bit default 0,"
439 "name varchar(255), " /* COLLATE PATHNAME, */
440 "unsanitized_name varchar(255)," /* COLLATE PATHNAME, */
441 "non_unique_name varchar,"
442 "server_name varchar(255)," /* COLLATE PATHNAME */
443 "server_non_unique_name varchar,"
444 "bookmark_url varchar,server_bookmark_url varchar,"
445 "singleton_tag varchar,bookmark_favicon blob,"
446 "server_bookmark_favicon blob);"
447 "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
448 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,0,0,NULL,"
449 "NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);"
450 "INSERT INTO metas VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
451 ",-2097152,"
452 "4,'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,1,0,1,1,"
453 "'Deleted Item',NULL,'Deleted Item','Deleted Item','Deleted Item',"
454 "'http://www.google.com/','http://www.google.com/2',NULL,'AASGASGA',"
455 "'ASADGADGADG');"
456 "INSERT INTO metas VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
457 ",-3145728,"
458 "3,'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,1,0,1,1,"
459 "'Welcome to Chromium',NULL,'Welcome to Chromium',"
460 "'Welcome to Chromium','Welcome to Chromium',"
461 "'http://www.google.com/chrome/intl/en/welcome.html',"
462 "'http://www.google.com/chrome/intl/en/welcome.html',NULL,NULL,"
463 "NULL);"
464 "INSERT INTO metas VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
465 ",1048576,"
466 "7,'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,1,0,1,1,"
467 "'Google',NULL,'Google','Google','Google','http://www.google.com/',"
468 "'http://www.google.com/',NULL,'AGASGASG','AGFDGASG');"
469 "INSERT INTO metas VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
470 ",-4194304,"
471 "6,'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,1,0,1,"
472 "'The Internet',NULL,'The Internet','The Internet',"
473 "'The Internet',NULL,NULL,NULL,NULL,NULL);"
474 "INSERT INTO metas VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
475 ","
476 "1048576,0,'s_ID_7','r','r','r','r',0,0,0,1,1,1,0,1,"
477 "'Google Chrome',NULL,'Google Chrome','Google Chrome',"
478 "'Google Chrome',NULL,NULL,'google_chrome',NULL,NULL);"
479 "INSERT INTO metas VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
480 ",1048576,"
481 "0,'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,1,0,1,'Bookmarks',"
482 "NULL,'Bookmarks','Bookmarks','Bookmarks',NULL,NULL,"
483 "'google_chrome_bookmarks',NULL,NULL);"
484 "INSERT INTO metas VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
485 ","
486 "1048576,1,'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,1,0,"
487 "1,'Bookmark Bar',NULL,'Bookmark Bar','Bookmark Bar','Bookmark Bar',"
488 "NULL,NULL,'bookmark_bar',NULL,NULL);"
489 "INSERT INTO metas VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
490 ",2097152,"
491 "2,'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,1,0,1,"
492 "'Other Bookmarks',NULL,'Other Bookmarks','Other Bookmarks',"
493 "'Other Bookmarks',NULL,NULL,'other_bookmarks',"
494 "NULL,NULL);"
495 "INSERT INTO metas VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
496 ",-1048576,"
497 "8,'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,1,0,0,1,"
498 "'Home (The Chromium Projects)',NULL,'Home (The Chromium Projects)',"
499 "'Home (The Chromium Projects)','Home (The Chromium Projects)',"
500 "'http://dev.chromium.org/','http://dev.chromium.org/other',NULL,"
501 "'AGATWA','AFAGVASF');"
502 "INSERT INTO metas VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
503 ",0,9,"
504 "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,1,0,1,"
505 "'Extra Bookmarks',NULL,'Extra Bookmarks','Extra Bookmarks',"
506 "'Extra Bookmarks',NULL,NULL,NULL,NULL,NULL);"
507 "INSERT INTO metas VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
508 ",-917504,"
509 "10,'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,1,0,0,"
510 "1,'ICANN | Internet Corporation for Assigned Names and Numbers',"
511 "'ICANN Internet Corporation for Assigned Names and Numbers',"
512 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
513 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
514 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
515 "'http://www.icann.com/','http://www.icann.com/',NULL,"
516 "'PNGAXF0AAFF','DAAFASF');"
517 "INSERT INTO metas VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
518 ",1048576,"
519 "11,'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,1,0,0,1,"
520 "'The WebKit Open Source Project',NULL,"
521 "'The WebKit Open Source Project','The WebKit Open Source Project',"
522 "'The WebKit Open Source Project','http://webkit.org/',"
523 "'http://webkit.org/x',NULL,'PNGX','PNG2Y');"
524 "CREATE TABLE share_info (id VARCHAR(128) primary key, "
525 "last_sync_timestamp INT, name VARCHAR(128), "
526 "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), "
527 "db_create_version VARCHAR(128), db_create_time int, "
528 "next_id bigint default -2, cache_guid VARCHAR(32));"
529 "INSERT INTO share_info VALUES('nick@chromium.org',694,"
530 "'nick@chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb',"
531 "'Unknown',1263522064,-65542,"
532 "'9010788312004066376x-6609234393368420856x');"
533 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
534 "INSERT INTO share_version VALUES('nick@chromium.org',68);"));
535 ASSERT_TRUE(connection->CommitTransaction());
536 }
537
538 void MigrationTest::SetUpVersion68Database(sql::Connection* connection) {
539 // This sets up an actual version 68 database dump. The IDs were
540 // canonicalized to be less huge, and the favicons were overwritten
541 // with random junk so that they didn't contain any unprintable
542 // characters. A few server URLs were tweaked so that they'd be
543 // different from the local URLs. Lastly, the custom collation on
544 // the server_non_unique_name column was removed.
545 ASSERT_TRUE(connection->is_open());
546 ASSERT_TRUE(connection->BeginTransaction());
547 ASSERT_TRUE(connection->Execute(
548 "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
549 "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
550 "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL,"
551 "base_version bigint default -1,server_version bigint default 0,"
552 "mtime bigint default 0,server_mtime bigint default 0,"
553 "ctime bigint default 0,server_ctime bigint default 0,"
554 "server_position_in_parent bigint default 0,"
555 "local_external_id bigint default 0,id varchar(255) default 'r',"
556 "parent_id varchar(255) default 'r',"
557 "server_parent_id varchar(255) default 'r',"
558 "prev_id varchar(255) default 'r',next_id varchar(255) default 'r',"
559 "is_unsynced bit default 0,is_unapplied_update bit default 0,"
560 "is_del bit default 0,is_dir bit default 0,"
561 "is_bookmark_object bit default 0,server_is_dir bit default 0,"
562 "server_is_del bit default 0,"
563 "server_is_bookmark_object bit default 0,"
564 "non_unique_name varchar,server_non_unique_name varchar(255),"
565 "bookmark_url varchar,server_bookmark_url varchar,"
566 "singleton_tag varchar,bookmark_favicon blob,"
567 "server_bookmark_favicon blob);"
568 "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
569 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,0,0,NULL,"
570 "NULL,NULL,NULL,NULL,NULL,NULL);"
571 "INSERT INTO metas VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
572 ",-2097152,"
573 "4,'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,1,0,1,1,"
574 "'Deleted Item','Deleted Item','http://www.google.com/',"
575 "'http://www.google.com/2',NULL,'AASGASGA','ASADGADGADG');"
576 "INSERT INTO metas VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
577 ",-3145728,"
578 "3,'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,1,0,1,1,"
579 "'Welcome to Chromium','Welcome to Chromium',"
580 "'http://www.google.com/chrome/intl/en/welcome.html',"
581 "'http://www.google.com/chrome/intl/en/welcome.html',NULL,NULL,"
582 "NULL);"
583 "INSERT INTO metas VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
584 ",1048576,"
585 "7,'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,1,0,1,1,"
586 "'Google','Google','http://www.google.com/',"
587 "'http://www.google.com/',NULL,'AGASGASG','AGFDGASG');"
588 "INSERT INTO metas VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
589 ",-4194304,"
590 "6,'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,1,0,1,"
591 "'The Internet','The Internet',NULL,NULL,NULL,NULL,NULL);"
592 "INSERT INTO metas VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
593 ","
594 "1048576,0,'s_ID_7','r','r','r','r',0,0,0,1,1,1,0,1,"
595 "'Google Chrome','Google Chrome',NULL,NULL,'google_chrome',NULL,"
596 "NULL);"
597 "INSERT INTO metas VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
598 ",1048576,"
599 "0,'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,1,0,1,'Bookmarks',"
600 "'Bookmarks',NULL,NULL,'google_chrome_bookmarks',NULL,NULL);"
601 "INSERT INTO metas VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
602 ","
603 "1048576,1,'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,1,0,"
604 "1,'Bookmark Bar','Bookmark Bar',NULL,NULL,'bookmark_bar',NULL,"
605 "NULL);"
606 "INSERT INTO metas VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
607 ",2097152,"
608 "2,'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,1,0,1,"
609 "'Other Bookmarks','Other Bookmarks',NULL,NULL,'other_bookmarks',"
610 "NULL,NULL);"
611 "INSERT INTO metas VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
612 ",-1048576,"
613 "8,'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,1,0,0,1,"
614 "'Home (The Chromium Projects)','Home (The Chromium Projects)',"
615 "'http://dev.chromium.org/','http://dev.chromium.org/other',NULL,"
616 "'AGATWA','AFAGVASF');"
617 "INSERT INTO metas VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
618 ",0,9,"
619 "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,1,0,1,"
620 "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,NULL,NULL,NULL);"
621 "INSERT INTO metas VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
622 ",-917504,"
623 "10,'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,1,0,0,"
624 "1,'ICANN | Internet Corporation for Assigned Names and Numbers',"
625 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
626 "'http://www.icann.com/','http://www.icann.com/',NULL,"
627 "'PNGAXF0AAFF','DAAFASF');"
628 "INSERT INTO metas VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
629 ",1048576,"
630 "11,'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,1,0,0,1,"
631 "'The WebKit Open Source Project','The WebKit Open Source Project',"
632 "'http://webkit.org/','http://webkit.org/x',NULL,'PNGX','PNG2Y');"
633 "CREATE TABLE share_info (id VARCHAR(128) primary key, "
634 "last_sync_timestamp INT, name VARCHAR(128), "
635 "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), "
636 "db_create_version VARCHAR(128), db_create_time int, "
637 "next_id bigint default -2, cache_guid VARCHAR(32));"
638 "INSERT INTO share_info VALUES('nick@chromium.org',694,"
639 "'nick@chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb',"
640 "'Unknown',1263522064,-65542,"
641 "'9010788312004066376x-6609234393368420856x');"
642 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
643 "INSERT INTO share_version VALUES('nick@chromium.org',68);"));
644 ASSERT_TRUE(connection->CommitTransaction());
645 }
646
647 void MigrationTest::SetUpVersion69Database(sql::Connection* connection) {
648 ASSERT_TRUE(connection->is_open());
649 ASSERT_TRUE(connection->BeginTransaction());
650 ASSERT_TRUE(connection->Execute(
651 "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
652 "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
653 "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL,"
654 "base_version bigint default -1,server_version bigint default 0,"
655 "mtime bigint default 0,server_mtime bigint default 0,"
656 "ctime bigint default 0,server_ctime bigint default 0,"
657 "server_position_in_parent bigint default 0,"
658 "local_external_id bigint default 0,id varchar(255) default 'r',"
659 "parent_id varchar(255) default 'r',"
660 "server_parent_id varchar(255) default 'r',"
661 "prev_id varchar(255) default 'r',next_id varchar(255) default 'r',"
662 "is_unsynced bit default 0,is_unapplied_update bit default 0,"
663 "is_del bit default 0,is_dir bit default 0,"
664 "is_bookmark_object bit default 0,server_is_dir bit default 0,"
665 "server_is_del bit default 0,"
666 "server_is_bookmark_object bit default 0,"
667 "non_unique_name varchar,server_non_unique_name varchar(255),"
668 "bookmark_url varchar,server_bookmark_url varchar,"
669 "singleton_tag varchar,bookmark_favicon blob,"
670 "server_bookmark_favicon blob, specifics blob, "
671 "server_specifics blob);"
672 "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
673 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,0,0,NULL,NULL,NULL,NULL,NULL,"
674 "NULL,NULL,X'',X'');"
675 "INSERT INTO metas VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
676 ",-2097152,"
677 "4,'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,1,0,1,1,"
678 "'Deleted Item','Deleted Item','http://www.google.com/',"
679 "'http://www.google.com/2',NULL,'AASGASGA','ASADGADGADG',"
680 "X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D2F120841415"
681 "34741534741',X'C28810260A17687474703A2F2F7777772E676F6F676C652E636F"
682 "6D2F32120B4153414447414447414447');"
683 "INSERT INTO metas VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
684 ",-3145728,"
685 "3,'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,1,0,1,1,"
686 "'Welcome to Chromium','Welcome to Chromium',"
687 "'http://www.google.com/chrome/intl/en/welcome.html',"
688 "'http://www.google.com/chrome/intl/en/welcome.html',NULL,NULL,NULL,"
689 "X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
690 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A3168"
691 "7474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F6"
692 "56E2F77656C636F6D652E68746D6C1200');"
693 "INSERT INTO metas VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
694 ",1048576,7,"
695 "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,1,0,1,1,"
696 "'Google','Google','http://www.google.com/',"
697 "'http://www.google.com/',NULL,'AGASGASG','AGFDGASG',X'C28810220A166"
698 "87474703A2F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'"
699 "C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464"
700 "447415347');"
701 "INSERT INTO metas VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
702 ",-4194304,6"
703 ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,1,0,1,'The Internet',"
704 "'The Internet',NULL,NULL,NULL,NULL,NULL,X'C2881000',X'C2881000');"
705 "INSERT INTO metas VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
706 ",1048576,0,"
707 "'s_ID_7','r','r','r','r',0,0,0,1,1,1,0,1,'Google Chrome',"
708 "'Google Chrome',NULL,NULL,'google_chrome',NULL,NULL,NULL,NULL);"
709 "INSERT INTO metas VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
710 ",1048576,0,"
711 "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,1,0,1,'Bookmarks',"
712 "'Bookmarks',NULL,NULL,'google_chrome_bookmarks',NULL,NULL,"
713 "X'C2881000',X'C2881000');"
714 "INSERT INTO metas VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
715 ",1048576,1,"
716 "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,1,0,1,"
717 "'Bookmark Bar','Bookmark Bar',NULL,NULL,'bookmark_bar',NULL,NULL,"
718 "X'C2881000',X'C2881000');"
719 "INSERT INTO metas VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
720 ",2097152,2,"
721 "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,1,0,1,"
722 "'Other Bookmarks','Other Bookmarks',NULL,NULL,'other_bookmarks',"
723 "NULL,NULL,X'C2881000',X'C2881000');"
724 "INSERT INTO metas VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
725 ",-1048576,"
726 "8,'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,1,0,0,1,"
727 "'Home (The Chromium Projects)','Home (The Chromium Projects)',"
728 "'http://dev.chromium.org/','http://dev.chromium.org/other',NULL,"
729 "'AGATWA','AFAGVASF',X'C28810220A18687474703A2F2F6465762E6368726F6D6"
730 "9756D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F646576"
731 "2E6368726F6D69756D2E6F72672F6F7468657212084146414756415346');"
732 "INSERT INTO metas VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
733 ",0,9,"
734 "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,1,0,1,"
735 "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,NULL,NULL,NULL,"
736 "X'C2881000',X'C2881000');"
737 "INSERT INTO metas VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
738 ",-917504,"
739 "10,'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,1,0,0,"
740 "1,'ICANN | Internet Corporation for Assigned Names and Numbers',"
741 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
742 "'http://www.icann.com/','http://www.icann.com/',NULL,'PNGAXF0AAFF',"
743 "'DAAFASF',X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F1"
744 "20B504E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963"
745 "616E6E2E636F6D2F120744414146415346');"
746 "INSERT INTO metas VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
747 ",1048576,11,"
748 "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,1,0,0,1,"
749 "'The WebKit Open Source Project','The WebKit Open Source Project',"
750 "'http://webkit.org/','http://webkit.org/x',NULL,'PNGX','PNG2Y',"
751 "X'C288101A0A12687474703A2F2F7765626B69742E6F72672F1204504E4758',X'C2"
752 "88101C0A13687474703A2F2F7765626B69742E6F72672F781205504E473259');"
753 "CREATE TABLE share_info (id VARCHAR(128) primary key, "
754 "last_sync_timestamp INT, name VARCHAR(128), "
755 "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), "
756 "db_create_version VARCHAR(128), db_create_time int, "
757 "next_id bigint default -2, cache_guid VARCHAR(32));"
758 "INSERT INTO share_info VALUES('nick@chromium.org',694,"
759 "'nick@chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb',"
760 "'Unknown',1263522064,-65542,"
761 "'9010788312004066376x-6609234393368420856x');"
762 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
763 "INSERT INTO share_version VALUES('nick@chromium.org',69);"));
764 ASSERT_TRUE(connection->CommitTransaction());
765 }
766
767 void MigrationTest::SetUpVersion70Database(sql::Connection* connection) {
768 ASSERT_TRUE(connection->is_open());
769 ASSERT_TRUE(connection->BeginTransaction());
770 ASSERT_TRUE(connection->Execute(
771 "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
772 "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
773 "CREATE TABLE share_info (id VARCHAR(128) primary key, "
774 "last_sync_timestamp INT, name VARCHAR(128), "
775 "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), "
776 "db_create_version VARCHAR(128), db_create_time int, "
777 "next_id bigint default -2, cache_guid VARCHAR(32));"
778 "INSERT INTO share_info VALUES('nick@chromium.org',694,"
779 "'nick@chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb',"
780 "'Unknown',1263522064,-65542,"
781 "'9010788312004066376x-6609234393368420856x');"
782 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
783 "INSERT INTO share_version VALUES('nick@chromium.org',70);"
784 "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL,"
785 "base_version bigint default -1,server_version bigint default 0,"
786 "mtime bigint default 0,server_mtime bigint default 0,"
787 "ctime bigint default 0,server_ctime bigint default 0,"
788 "server_position_in_parent bigint default 0,"
789 "local_external_id bigint default 0,id varchar(255) default 'r',"
790 "parent_id varchar(255) default 'r',"
791 "server_parent_id varchar(255) default 'r',"
792 "prev_id varchar(255) default 'r',next_id varchar(255) default 'r',"
793 "is_unsynced bit default 0,is_unapplied_update bit default 0,"
794 "is_del bit default 0,is_dir bit default 0,"
795 "server_is_dir bit default 0,server_is_del bit default 0,"
796 "non_unique_name varchar,server_non_unique_name varchar(255),"
797 "unique_server_tag varchar,unique_client_tag varchar,"
798 "specifics blob,server_specifics blob);"
799 "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
800 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'');"
801 "INSERT INTO metas VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2) ","
802 "-2097152,4,'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,"
803 "1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A"
804 "2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X'C2881026"
805 "0A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B415341444741"
806 "4447414447');"
807 "INSERT INTO metas VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
808 ",-3145728,"
809 "3,'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,"
810 "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A"
811 "31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E74"
812 "6C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F"
813 "2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F7765"
814 "6C636F6D652E68746D6C1200');"
815 "INSERT INTO metas VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
816 ",1048576,7,"
817 "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google',"
818 "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C6"
819 "52E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F77777"
820 "72E676F6F676C652E636F6D2F12084147464447415347');"
821 "INSERT INTO metas VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
822 ",-4194304,"
823 "6,'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet',"
824 "'The Internet',NULL,NULL,X'C2881000',X'C2881000');"
825 "INSERT INTO metas VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
826 ",1048576,0,"
827 "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome',"
828 "'Google Chrome','google_chrome',NULL,NULL,NULL);"
829 "INSERT INTO metas VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
830 ",1048576,0,"
831 "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks',"
832 "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',"
833 "X'C2881000');"
834 "INSERT INTO metas VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
835 ",1048576,"
836 "1,'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,"
837 "'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881000',"
838 "X'C2881000');"
839 "INSERT INTO metas VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
840 ","
841 "2097152,2,'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,"
842 "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,"
843 "X'C2881000',X'C2881000');"
844 "INSERT INTO metas VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
845 ",-1048576,"
846 "8,'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,"
847 "'Home (The Chromium Projects)','Home (The Chromium Projects)',"
848 "NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F"
849 "72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636872"
850 "6F6D69756D2E6F72672F6F7468657212084146414756415346');"
851 "INSERT INTO metas VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
852 ",0,9,"
853 "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,"
854 "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',"
855 "X'C2881000');"
856 "INSERT INTO metas VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
857 ",-917504,"
858 "10,'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,"
859 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
860 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
861 "NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F"
862 "120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772E69"
863 "63616E6E2E636F6D2F120744414146415346');"
864 "INSERT INTO metas VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
865 ",1048576,"
866 "11,'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,"
867 "'The WebKit Open Source Project','The WebKit Open Source Project',"
868 "NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450"
869 "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F78120550"
870 "4E473259');"));
871 ASSERT_TRUE(connection->CommitTransaction());
872 }
873
874 void MigrationTest::SetUpVersion71Database(sql::Connection* connection) {
875 ASSERT_TRUE(connection->is_open());
876 ASSERT_TRUE(connection->BeginTransaction());
877 ASSERT_TRUE(connection->Execute(
878 "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
879 "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
880 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
881 "INSERT INTO 'share_version' VALUES('nick@chromium.org',71);"
882 "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL,"
883 "base_version bigint default -1,server_version bigint default 0,"
884 "mtime bigint default 0,server_mtime bigint default 0,ctime bigint "
885 "default 0,server_ctime bigint default 0,server_position_in_parent "
886 "bigint default 0,local_external_id bigint default 0,id varchar(255) "
887 "default 'r',parent_id varchar(255) default 'r',server_parent_id "
888 "varchar(255) default 'r',prev_id varchar(255) default 'r',next_id "
889 "varchar(255) default 'r',is_unsynced bit default 0,"
890 "is_unapplied_update bit default 0,is_del bit default 0,is_dir bit "
891 "default 0,server_is_dir bit default 0,server_is_del bit default 0,"
892 "non_unique_name varchar,server_non_unique_name varchar(255),"
893 "unique_server_tag varchar,unique_client_tag varchar,specifics blob,"
894 "server_specifics blob);"
895 "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
896 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,"
897 "NULL,NULL,X'',X'');"
898 "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
899 ",-2097152,4,"
900 "'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,"
901 "'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F"
902 "7777772E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A1768"
903 "7474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474144"
904 "47');"
905 "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
906 ",-3145728,3,"
907 "'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,"
908 "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A31"
909 "687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F"
910 "656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7777"
911 "772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D"
912 "652E68746D6C1200');"
913 "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
914 ",1048576,7,"
915 "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google',"
916 "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652"
917 "E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E6"
918 "76F6F676C652E636F6D2F12084147464447415347');"
919 "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
920 ",-4194304,6,"
921 "'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet',"
922 "'The Internet',NULL,NULL,X'C2881000',X'C2881000');"
923 "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
924 ",1048576,0,"
925 "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome'"
926 ",'google_chrome',NULL,NULL,NULL);"
927 "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
928 ",1048576,0,"
929 "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks',"
930 "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
931 "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
932 ",1048576,1,"
933 "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar',"
934 "'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
935 "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
936 ",2097152,2,"
937 "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,"
938 "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,"
939 "X'C2881000',X'C2881000');"
940 "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
941 ",-1048576,8,"
942 "'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,"
943 "'Home (The Chromium Projects)','Home (The Chromium Projects)',NULL,"
944 "NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1"
945 "206414741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756"
946 "D2E6F72672F6F7468657212084146414756415346');"
947 "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
948 ",0,9,"
949 "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,"
950 "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',"
951 "X'C2881000');"
952 "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
953 ",-917504,10,"
954 "'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,"
955 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
956 "'ICANN | Internet Corporation for Assigned Names and Numbers',NULL,"
957 "NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504"
958 "E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963616E6E2"
959 "E636F6D2F120744414146415346');"
960 "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
961 ",1048576,11,"
962 "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,"
963 "'The WebKit Open Source Project','The WebKit Open Source Project',"
964 "NULL,NULL,""X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450"
965 "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E"
966 "473259');"
967 "CREATE TABLE models (model_id BLOB primary key, "
968 "last_download_timestamp INT, initial_sync_ended BOOLEAN default 0);"
969 "INSERT INTO 'models' VALUES(X'C2881000',694,1);"
970 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, "
971 "store_birthday TEXT, db_create_version TEXT, db_create_time INT, "
972 "next_id INT default -2, cache_guid TEXT);"
973 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
974 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,"
975 "'9010788312004066376x-6609234393368420856x');"));
976 ASSERT_TRUE(connection->CommitTransaction());
977 }
978
979 void MigrationTest::SetUpVersion72Database(sql::Connection* connection) {
980 ASSERT_TRUE(connection->is_open());
981 ASSERT_TRUE(connection->BeginTransaction());
982 ASSERT_TRUE(connection->Execute(
983 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
984 "INSERT INTO 'share_version' VALUES('nick@chromium.org',72);"
985 "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL,"
986 "base_version bigint default -1,server_version bigint default 0,"
987 "mtime bigint default 0,server_mtime bigint default 0,ctime bigint "
988 "default 0,server_ctime bigint default 0,server_position_in_parent "
989 "bigint default 0,local_external_id bigint default 0,id varchar(255) "
990 "default 'r',parent_id varchar(255) default 'r',server_parent_id "
991 "varchar(255) default 'r',prev_id varchar(255) default 'r',next_id "
992 "varchar(255) default 'r',is_unsynced bit default 0,"
993 "is_unapplied_update bit default 0,is_del bit default 0,is_dir bit "
994 "default 0,server_is_dir bit default 0,server_is_del bit default 0,"
995 "non_unique_name varchar,server_non_unique_name varchar(255),"
996 "unique_server_tag varchar,unique_client_tag varchar,specifics blob,"
997 "server_specifics blob);"
998 "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
999 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,"
1000 "NULL,NULL,X'',X'');"
1001 "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
1002 ",-2097152,4,"
1003 "'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,"
1004 "'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F"
1005 "7777772E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A1768"
1006 "7474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474144"
1007 "47');"
1008 "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
1009 ",-3145728,3,"
1010 "'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,"
1011 "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A31"
1012 "687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F"
1013 "656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7777"
1014 "772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D"
1015 "652E68746D6C1200');"
1016 "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
1017 ",1048576,7,"
1018 "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google',"
1019 "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652"
1020 "E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E6"
1021 "76F6F676C652E636F6D2F12084147464447415347');"
1022 "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
1023 ",-4194304,6,"
1024 "'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet',"
1025 "'The Internet',NULL,NULL,X'C2881000',X'C2881000');"
1026 "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
1027 ",1048576,0,"
1028 "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome'"
1029 ",'google_chrome',NULL,NULL,NULL);"
1030 "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
1031 ",1048576,0,"
1032 "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks',"
1033 "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
1034 "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
1035 ",1048576,1,"
1036 "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar',"
1037 "'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
1038 "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
1039 ",2097152,2,"
1040 "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,"
1041 "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,"
1042 "X'C2881000',X'C2881000');"
1043 "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
1044 ",-1048576,8,"
1045 "'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,"
1046 "'Home (The Chromium Projects)','Home (The Chromium Projects)',NULL,"
1047 "NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1"
1048 "206414741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756"
1049 "D2E6F72672F6F7468657212084146414756415346');"
1050 "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
1051 ",0,9,"
1052 "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,"
1053 "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',"
1054 "X'C2881000');"
1055 "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
1056 ",-917504,10,"
1057 "'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,"
1058 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
1059 "'ICANN | Internet Corporation for Assigned Names and Numbers',NULL,"
1060 "NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504"
1061 "E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963616E6E2"
1062 "E636F6D2F120744414146415346');"
1063 "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
1064 ",1048576,11,"
1065 "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,"
1066 "'The WebKit Open Source Project','The WebKit Open Source Project',"
1067 "NULL,NULL,""X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450"
1068 "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E"
1069 "473259');"
1070 "CREATE TABLE models (model_id BLOB primary key, "
1071 "last_download_timestamp INT, initial_sync_ended BOOLEAN default 0);"
1072 "INSERT INTO 'models' VALUES(X'C2881000',694,1);"
1073 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, "
1074 "store_birthday TEXT, db_create_version TEXT, db_create_time INT, "
1075 "next_id INT default -2, cache_guid TEXT);"
1076 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1077 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,"
1078 "'9010788312004066376x-6609234393368420856x');"));
1079 ASSERT_TRUE(connection->CommitTransaction());
1080 }
1081
1082 void MigrationTest::SetUpVersion73Database(sql::Connection* connection) {
1083 ASSERT_TRUE(connection->is_open());
1084 ASSERT_TRUE(connection->BeginTransaction());
1085 ASSERT_TRUE(connection->Execute(
1086 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1087 "INSERT INTO 'share_version' VALUES('nick@chromium.org',73);"
1088 "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL,"
1089 "base_version bigint default -1,server_version bigint default 0,"
1090 "mtime bigint default 0,server_mtime bigint default 0,ctime bigint "
1091 "default 0,server_ctime bigint default 0,server_position_in_parent "
1092 "bigint default 0,local_external_id bigint default 0,id varchar(255) "
1093 "default 'r',parent_id varchar(255) default 'r',server_parent_id "
1094 "varchar(255) default 'r',prev_id varchar(255) default 'r',next_id "
1095 "varchar(255) default 'r',is_unsynced bit default 0,"
1096 "is_unapplied_update bit default 0,is_del bit default 0,is_dir bit "
1097 "default 0,server_is_dir bit default 0,server_is_del bit default 0,"
1098 "non_unique_name varchar,server_non_unique_name varchar(255),"
1099 "unique_server_tag varchar,unique_client_tag varchar,specifics blob,"
1100 "server_specifics blob);"
1101 "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
1102 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,"
1103 "NULL,NULL,X'',X'');"
1104 "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
1105 ",-2097152,4,"
1106 "'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,"
1107 "'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F"
1108 "7777772E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A1768"
1109 "7474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474144"
1110 "47');"
1111 "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
1112 ",-3145728,3,"
1113 "'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,"
1114 "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A31"
1115 "687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F"
1116 "656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7777"
1117 "772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D"
1118 "652E68746D6C1200');"
1119 "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
1120 ",1048576,7,"
1121 "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google',"
1122 "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652"
1123 "E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E6"
1124 "76F6F676C652E636F6D2F12084147464447415347');"
1125 "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
1126 ",-4194304,6,"
1127 "'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet',"
1128 "'The Internet',NULL,NULL,X'C2881000',X'C2881000');"
1129 "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
1130 ",1048576,0,"
1131 "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome'"
1132 ",'google_chrome',NULL,NULL,NULL);"
1133 "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
1134 ",1048576,0,"
1135 "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks',"
1136 "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
1137 "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
1138 ",1048576,1,"
1139 "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar',"
1140 "'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
1141 "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
1142 ",2097152,2,"
1143 "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,"
1144 "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,"
1145 "X'C2881000',X'C2881000');"
1146 "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
1147 ",-1048576,8,"
1148 "'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,"
1149 "'Home (The Chromium Projects)','Home (The Chromium Projects)',NULL,"
1150 "NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1"
1151 "206414741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756"
1152 "D2E6F72672F6F7468657212084146414756415346');"
1153 "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
1154 ",0,9,"
1155 "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,"
1156 "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',"
1157 "X'C2881000');"
1158 "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
1159 ",-917504,10,"
1160 "'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,"
1161 "'ICANN | Internet Corporation for Assigned Names and Numbers',"
1162 "'ICANN | Internet Corporation for Assigned Names and Numbers',NULL,"
1163 "NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504"
1164 "E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963616E6E2"
1165 "E636F6D2F120744414146415346');"
1166 "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
1167 ",1048576,11,"
1168 "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,"
1169 "'The WebKit Open Source Project','The WebKit Open Source Project',"
1170 "NULL,NULL,""X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450"
1171 "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E"
1172 "473259');"
1173 "CREATE TABLE models (model_id BLOB primary key, "
1174 "last_download_timestamp INT, initial_sync_ended BOOLEAN default 0);"
1175 "INSERT INTO 'models' VALUES(X'C2881000',694,1);"
1176 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, "
1177 "store_birthday TEXT, db_create_version TEXT, db_create_time INT, "
1178 "next_id INT default -2, cache_guid TEXT, "
1179 "notification_state BLOB);"
1180 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1181 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,"
1182 "'9010788312004066376x-6609234393368420856x',X'C2881000');"));
1183 ASSERT_TRUE(connection->CommitTransaction());
1184 }
1185
1186 void MigrationTest::SetUpVersion74Database(sql::Connection* connection) {
1187 ASSERT_TRUE(connection->is_open());
1188 ASSERT_TRUE(connection->BeginTransaction());
1189 ASSERT_TRUE(connection->Execute(
1190 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1191 "INSERT INTO 'share_version' VALUES('nick@chromium.org',74);"
1192 "CREATE TABLE models (model_id BLOB primary key, last_download_timestamp"
1193 " INT, initial_sync_ended BOOLEAN default 0);"
1194 "INSERT INTO 'models' VALUES(X'C2881000',694,1);"
1195 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthd"
1196 "ay TEXT, db_create_version TEXT, db_create_time INT, next_id INT de"
1197 "fault -2, cache_guid TEXT , notification_state BLOB, autofill_migra"
1198 "tion_state INT default 0, bookmarks_added_during_autofill_migration"
1199 " INT default 0, autofill_migration_time INT default 0, autofill_ent"
1200 "ries_added_during_migration INT default 0, autofill_profiles_added_"
1201 "during_migration INT default 0);"
1202 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'"
1203 ",'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542"
1204 ",'9010788312004066376x-6609234393368420856x',NULL,0,0,0,0,0);"
1205 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,bas"
1206 "e_version bigint default -1,server_version bigint default 0,mtime b"
1207 "igint default 0,server_mtime bigint default 0,ctime bigint default "
1208 "0,server_ctime bigint default 0,server_position_in_parent bigint de"
1209 "fault 0,local_external_id bigint default 0,id varchar(255) default "
1210 "'r',parent_id varchar(255) default 'r',server_parent_id varchar(255"
1211 ") default 'r',prev_id varchar(255) default 'r',next_id varchar(255)"
1212 " default 'r',is_unsynced bit default 0,is_unapplied_update bit defa"
1213 "ult 0,is_del bit default 0,is_dir bit default 0,server_is_dir bit d"
1214 "efault 0,server_is_del bit default 0,non_unique_name varchar,server"
1215 "_non_unique_name varchar(255),unique_server_tag varchar,unique_clie"
1216 "nt_tag varchar,specifics blob,server_specifics blob);"
1217 "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
1218 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'"
1219 "');"
1220 "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
1221 ",-2097152,4,'s_ID_2','s_ID"
1222 "_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,'Deleted Item','Deleted "
1223 "Item',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652E6"
1224 "36F6D2F12084141534741534741',X'C28810260A17687474703A2F2F7777772E67"
1225 "6F6F676C652E636F6D2F32120B4153414447414447414447');"
1226 "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
1227 ",-3145728,3,'s_ID_4','s_ID"
1228 "_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,'Welcome to Chromium','W"
1229 "elcome to Chromium',NULL,NULL,X'C28810350A31687474703A2F2F7777772E6"
1230 "76F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D652E"
1231 "68746D6C1200',X'C28810350A31687474703A2F2F7777772E676F6F676C652E636"
1232 "F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D652E68746D6C1200');"
1233 "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
1234 ",1048576,7,'s_ID_5','s_ID_"
1235 "9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google','Google',NULL,NU"
1236 "LL,X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D2F120841"
1237 "47415347415347',X'C28810220A16687474703A2F2F7777772E676F6F676C652E6"
1238 "36F6D2F12084147464447415347');"
1239 "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
1240 ",-4194304,6,'s_ID_6','s_ID"
1241 "_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet','The Internet',NULL"
1242 ",NULL,X'C2881000',X'C2881000');"
1243 "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
1244 ",1048576,0,'s_ID_7','r','r"
1245 "','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome','google_chrom"
1246 "e',NULL,NULL,NULL);"
1247 "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
1248 ",1048576,0,'s_ID_8','s_ID_"
1249 "7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks','Bookmarks','google_chr"
1250 "ome_bookmarks',NULL,X'C2881000',X'C2881000');"
1251 "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
1252 ",1048576,1,'s_ID_9','s_ID_"
1253 "8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar','Bookmark Bar'"
1254 ",'bookmark_bar',NULL,X'C2881000',X'C2881000');"
1255 "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
1256 ",2097152,2,'s_ID_10','s_I"
1257 "D_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,'Other Bookmarks','Other Boo"
1258 "kmarks','other_bookmarks',NULL,X'C2881000',X'C2881000');"
1259 "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
1260 ",-1048576,8,'s_ID_11','s_"
1261 "ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,'Home (The Chromium Projec"
1262 "ts)','Home (The Chromium Projects)',NULL,NULL,X'C28810220A186874747"
1263 "03A2F2F6465762E6368726F6D69756D2E6F72672F1206414741545741',X'C28810"
1264 "290A1D687474703A2F2F6465762E6368726F6D69756D2E6F72672F6F74686572120"
1265 "84146414756415346');"
1266 "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
1267 ",0,9,'s_ID_12','s_ID_6','"
1268 "s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bo"
1269 "okmarks',NULL,NULL,X'C2881000',X'C2881000');"
1270 "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
1271 ",-917504,10,'s_ID_13','s_"
1272 "ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,'ICANN | Internet Co"
1273 "rporation for Assigned Names and Numbers','ICANN | Internet Corpora"
1274 "tion for Assigned Names and Numbers',NULL,NULL,X'C28810240A15687474"
1275 "703A2F2F7777772E6963616E6E2E636F6D2F120B504E474158463041414646',X'C"
1276 "28810200A15687474703A2F2F7777772E6963616E6E2E636F6D2F12074441414641"
1277 "5346');"
1278 "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
1279 ",1048576,11,'s_ID_14','s_"
1280 "ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,'The WebKit Open Source Pr"
1281 "oject','The WebKit Open Source Project',NULL,NULL,X'C288101A0A12687"
1282 "474703A2F2F7765626B69742E6F72672F1204504E4758',X'C288101C0A13687474"
1283 "703A2F2F7765626B69742E6F72672F781205504E473259');"));
1284 ASSERT_TRUE(connection->CommitTransaction());
1285 }
1286
1287 void MigrationTest::SetUpVersion75Database(sql::Connection* connection) {
1288 ASSERT_TRUE(connection->is_open());
1289 ASSERT_TRUE(connection->BeginTransaction());
1290 ASSERT_TRUE(connection->Execute(
1291 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1292 "INSERT INTO 'share_version' VALUES('nick@chromium.org',75);"
1293 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthd"
1294 "ay TEXT, db_create_version TEXT, db_create_time INT, next_id INT de"
1295 "fault -2, cache_guid TEXT , notification_state BLOB, autofill_migra"
1296 "tion_state INT default 0,bookmarks_added_during_autofill_migration "
1297 "INT default 0, autofill_migration_time INT default 0, autofill_entr"
1298 "ies_added_during_migration INT default 0, autofill_profiles_added_d"
1299 "uring_migration INT default 0);"
1300 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org"
1301 "','c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-655"
1302 "42,'9010788312004066376x-6609234393368420856x',NULL,0,0,0,0,0);"
1303 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, "
1304 "initial_sync_ended BOOLEAN default 0);"
1305 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1306 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,ba"
1307 "se_version bigint default -1,server_version bigint default 0,mtime"
1308 " bigint default 0,server_mtime bigint default 0,ctime bigint defau"
1309 "lt 0,server_ctime bigint default 0,server_position_in_parent bigin"
1310 "t default 0,local_external_id bigint default 0,id varchar(255) def"
1311 "ault 'r',parent_id varchar(255) default 'r',server_parent_id varch"
1312 "ar(255) default 'r',prev_id varchar(255) default 'r',next_id varch"
1313 "ar(255) default 'r',is_unsynced bit default 0,is_unapplied_update "
1314 "bit default 0,is_del bit default 0,is_dir bit default 0,server_is_"
1315 "dir bit default 0,server_is_del bit default 0,non_unique_name varc"
1316 "har,server_non_unique_name varchar(255),unique_server_tag varchar,"
1317 "unique_client_tag varchar,specifics blob,server_specifics blob);"
1318 "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
1319 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NUL"
1320 "L,X'',X'');"
1321 "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
1322 ",-2097152,4,'s_ID_"
1323 "2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,'Deleted Ite"
1324 "m','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F7777772"
1325 "E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A176874"
1326 "74703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474"
1327 "14447');"
1328 "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
1329 ",-3145728,3,'s_ID_"
1330 "4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,'Welcome to "
1331 "Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A316874747"
1332 "03A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F65"
1333 "6E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7"
1334 "777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F7765"
1335 "6C636F6D652E68746D6C1200');"
1336 "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
1337 ",1048576,7,'s_ID_5"
1338 "','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google','Goo"
1339 "gle',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C65"
1340 "2E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F777"
1341 "7772E676F6F676C652E636F6D2F12084147464447415347');"
1342 "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
1343 ",-4194304,6,'s_ID_"
1344 "6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet','The In"
1345 "ternet',NULL,NULL,X'C2881000',X'C2881000');"
1346 "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
1347 ",1048576,0,'s_ID_7"
1348 "','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome','"
1349 "google_chrome',NULL,NULL,NULL);"
1350 "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
1351 ",1048576,0,'s_ID_8"
1352 "','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks','Bookmarks'"
1353 ",'google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
1354 "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
1355 ",1048576,1,'s_ID_9"
1356 "','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar','B"
1357 "ookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
1358 "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
1359 ",2097152,2,'s_ID_"
1360 "10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,'Other Bookmarks"
1361 "','Other Bookmarks','other_bookmarks',NULL,X'C2881000',X'C28810"
1362 "00');"
1363 "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
1364 ",-1048576,8,'s_ID"
1365 "_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,'Home (The Chr"
1366 "omium Projects)','Home (The Chromium Projects)',NULL,NULL,X'C28"
1367 "810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F120641"
1368 "4741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756"
1369 "D2E6F72672F6F7468657212084146414756415346');"
1370 "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
1371 ",0,9,'s_ID_12','s"
1372 "_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,'Extra Bookmark"
1373 "s','Extra Bookmarks',NULL,NULL,X'C2881000',X'C2881000');"
1374 "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
1375 ",-917504,10,'s_ID"
1376 "_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,'ICANN |"
1377 " Internet Corporation for Assigned Names and Numbers','ICANN | "
1378 "Internet Corporation for Assigned Names and Numbers',NULL,NULL,"
1379 "X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504"
1380 "E474158463041414646',X'C28810200A15687474703A2F2F7777772E696361"
1381 "6E6E2E636F6D2F120744414146415346');"
1382 "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
1383 ",1048576,11,'s_ID"
1384 "_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,'The WebKit Op"
1385 "en Source Project','The WebKit Open Source Project',NULL,NULL,X"
1386 "'C288101A0A12687474703A2F2F7765626B69742E6F72672F1204504E4758',"
1387 "X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E473"
1388 "259');"));
1389 ASSERT_TRUE(connection->CommitTransaction());
1390 }
1391
1392 void MigrationTest::SetUpVersion76Database(sql::Connection* connection) {
1393 ASSERT_TRUE(connection->is_open());
1394 ASSERT_TRUE(connection->BeginTransaction());
1395 ASSERT_TRUE(connection->Execute(
1396 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1397 "INSERT INTO 'share_version' VALUES('nick@chromium.org',76);"
1398 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1399 "itial_sync_ended BOOLEAN default 0);"
1400 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1401 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1402 "_version bigint default -1,server_version bigint default 0,mtime big"
1403 "int default 0,server_mtime bigint default 0,ctime bigint default 0,s"
1404 "erver_ctime bigint default 0,server_position_in_parent bigint defaul"
1405 "t 0,local_external_id bigint default 0,id varchar(255) default 'r',p"
1406 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1407 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
1408 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
1409 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
1410 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
1411 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
1412 "har,specifics blob,server_specifics blob);"
1413 "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
1414 ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'')"
1415 ";"
1416 "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
1417 ",-2097152,4,'s_ID_2','s_ID_9"
1418 "','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,'Deleted Item','Deleted Ite"
1419 "m',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6"
1420 "D2F12084141534741534741',X'C28810260A17687474703A2F2F7777772E676F6F6"
1421 "76C652E636F6D2F32120B4153414447414447414447');"
1422 "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
1423 ",-3145728,3,'s_ID_4','s_ID_9"
1424 "','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,'Welcome to Chromium','Welc"
1425 "ome to Chromium',NULL,NULL,X'C28810350A31687474703A2F2F7777772E676F6"
1426 "F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D652E68746"
1427 "D6C1200',X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6"
1428 "368726F6D652F696E746C2F656E2F77656C636F6D652E68746D6C1200');"
1429 "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
1430 ",1048576,7,'s_ID_5','s_ID_9'"
1431 ",'s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google','Google',NULL,NULL,"
1432 "X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D2F1208414741"
1433 "5347415347',X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D"
1434 "2F12084147464447415347');"
1435 "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
1436 ",-4194304,6,'s_ID_6','s_ID_9"
1437 "','s_ID_9','r','r',0,0,0,1,1,0,'The Internet','The Internet',NULL,NU"
1438 "LL,X'C2881000',X'C2881000');"
1439 "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
1440 ",1048576,0,'s_ID_7','r','r',"
1441 "'r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome','google_chrome',"
1442 "NULL,NULL,NULL);"
1443 "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
1444 ",1048576,0,'s_ID_8','s_ID_7'"
1445 ",'s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks','Bookmarks','google_chrome"
1446 "_bookmarks',NULL,X'C2881000',X'C2881000');"
1447 "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
1448 ",1048576,1,'s_ID_9','s_ID_8'"
1449 ",'s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar','Bookmark Bar','b"
1450 "ookmark_bar',NULL,X'C2881000',X'C2881000');"
1451 "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
1452 ",2097152,2,'s_ID_10','s_ID_"
1453 "8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,'Other Bookmarks','Other Bookma"
1454 "rks','other_bookmarks',NULL,X'C2881000',X'C2881000');"
1455 "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
1456 ",-1048576,8,'s_ID_11','s_ID"
1457 "_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,'Home (The Chromium Projects)"
1458 "','Home (The Chromium Projects)',NULL,NULL,X'C28810220A18687474703A2"
1459 "F2F6465762E6368726F6D69756D2E6F72672F1206414741545741',X'C28810290A1"
1460 "D687474703A2F2F6465762E6368726F6D69756D2E6F72672F6F74686572120841464"
1461 "14756415346');"
1462 "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
1463 ",0,9,'s_ID_12','s_ID_6','s_"
1464 "ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookm"
1465 "arks',NULL,NULL,X'C2881000',X'C2881000');"
1466 "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
1467 ",-917504,10,'s_ID_13','s_ID"
1468 "_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,'ICANN | Internet Corpo"
1469 "ration for Assigned Names and Numbers','ICANN | Internet Corporation"
1470 " for Assigned Names and Numbers',NULL,NULL,X'C28810240A15687474703A2"
1471 "F2F7777772E6963616E6E2E636F6D2F120B504E474158463041414646',X'C288102"
1472 "00A15687474703A2F2F7777772E6963616E6E2E636F6D2F120744414146415346');"
1473 "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
1474 ",1048576,11,'s_ID_14','s_ID"
1475 "_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,'The WebKit Open Source Proje"
1476 "ct','The WebKit Open Source Project',NULL,NULL,X'C288101A0A126874747"
1477 "03A2F2F7765626B69742E6F72672F1204504E4758',X'C288101C0A13687474703A2"
1478 "F2F7765626B69742E6F72672F781205504E473259');"
1479 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1480 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1481 "ult -2, cache_guid TEXT , notification_state BLOB);"
1482 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1483 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'"
1484 "9010788312004066376x-6609234393368420856x',NULL);"));
1485 ASSERT_TRUE(connection->CommitTransaction());
1486 }
1487
1488 void MigrationTest::SetUpVersion77Database(sql::Connection* connection) {
1489 ASSERT_TRUE(connection->is_open());
1490 ASSERT_TRUE(connection->BeginTransaction());
1491 ASSERT_TRUE(connection->Execute(
1492 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1493 "INSERT INTO 'share_version' VALUES('nick@chromium.org',77);"
1494 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1495 "itial_sync_ended BOOLEAN default 0);"
1496 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1497 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1498 "_version bigint default -1,server_version bigint default 0,server_po"
1499 "sition_in_parent bigint default 0,local_external_id bigint default 0"
1500 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1501 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1502 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1503 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
1504 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
1505 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
1506 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
1507 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
1508 "har,specifics blob,server_specifics blob);"
1509 "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1)
1510 ",'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'');"
1511 "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
1512 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
1513 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
1514 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
1515 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
1516 "14447414447414447');"
1517 "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
1518 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
1519 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
1520 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
1521 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
1522 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
1523 "E2F77656C636F6D652E68746D6C1200');"
1524 "INSERT INTO 'metas' VALUES(5,677,677,1048576,7," META_PROTO_TIMES_VALS(5)
1525 ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google','"
1526 "Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652E"
1527 "636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E67"
1528 "6F6F676C652E636F6D2F12084147464447415347');"
1529 "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
1530 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
1531 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
1532 ");"
1533 "INSERT INTO 'metas' VALUES(7,663,663,1048576,0," META_PROTO_TIMES_VALS(7)
1534 ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Goo"
1535 "gle Chrome','google_chrome',NULL,NULL,NULL);"
1536 "INSERT INTO 'metas' VALUES(8,664,664,1048576,0," META_PROTO_TIMES_VALS(8)
1537 ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks','Bookmar"
1538 "ks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
1539 "INSERT INTO 'metas' VALUES(9,665,665,1048576,1," META_PROTO_TIMES_VALS(9)
1540 ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar'"
1541 ",'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
1542 "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
1543 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
1544 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
1545 "LL,X'C2881000',X'C2881000');"
1546 "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
1547 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
1548 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
1549 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
1550 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
1551 "8726F6D69756D2E6F72672F6F7468657212084146414756415346');"
1552 "INSERT INTO 'metas' VALUES(12,685,685,0,9," META_PROTO_TIMES_VALS(12)
1553 ",'s_ID_12','s_ID_6','s_"
1554 "ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookm"
1555 "arks',NULL,NULL,X'C2881000',X'C2881000');"
1556 "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
1557 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
1558 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
1559 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
1560 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
1561 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
1562 "E6963616E6E2E636F6D2F120744414146415346');"
1563 "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
1564 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
1565 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
1566 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
1567 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
1568 "81205504E473259');"
1569 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1570 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1571 "ult -2, cache_guid TEXT , notification_state BLOB);"
1572 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1573 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'"
1574 "9010788312004066376x-6609234393368420856x',NULL);"));
1575 ASSERT_TRUE(connection->CommitTransaction());
1576 }
1577
1578 void MigrationTest::SetUpVersion78Database(sql::Connection* connection) {
1579 ASSERT_TRUE(connection->is_open());
1580 ASSERT_TRUE(connection->BeginTransaction());
1581 ASSERT_TRUE(connection->Execute(
1582 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1583 "INSERT INTO 'share_version' VALUES('nick@chromium.org',78);"
1584 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1585 "itial_sync_ended BOOLEAN default 0);"
1586 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1587 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1588 "_version bigint default -1,server_version bigint default 0,server_po"
1589 "sition_in_parent bigint default 0,local_external_id bigint default 0"
1590 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1591 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1592 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1593 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
1594 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
1595 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
1596 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
1597 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
1598 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
1599 ");"
1600 "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
1601 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);"
1602 "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
1603 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
1604 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
1605 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
1606 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
1607 "14447414447414447',NULL);"
1608 "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
1609 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
1610 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
1611 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
1612 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
1613 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
1614 "E2F77656C636F6D652E68746D6C1200',NULL);"
1615 "INSERT INTO 'metas' VALUES(5,677,677,1048576,7,"
1616 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
1617 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
1618 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
1619 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
1620 "ULL);"
1621 "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
1622 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
1623 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
1624 ",NULL);"
1625 "INSERT INTO 'metas' VALUES(7,663,663,1048576,0,"
1626 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
1627 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL);"
1628 "INSERT INTO 'metas' VALUES(8,664,664,1048576,0,"
1629 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
1630 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
1631 "00',X'C2881000',NULL);"
1632 "INSERT INTO 'metas' VALUES(9,665,665,1048576,1,"
1633 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
1634 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
1635 "000',X'C2881000',NULL);"
1636 "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
1637 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
1638 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
1639 "LL,X'C2881000',X'C2881000',NULL);"
1640 "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
1641 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
1642 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
1643 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
1644 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
1645 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);"
1646 "INSERT INTO 'metas' VALUES(12,685,685,0,9,"
1647 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
1648 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
1649 "2881000',X'C2881000',NULL);"
1650 "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
1651 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
1652 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
1653 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
1654 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
1655 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
1656 "E6963616E6E2E636F6D2F120744414146415346',NULL);"
1657 "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
1658 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
1659 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
1660 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
1661 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
1662 "81205504E473259',NULL);"
1663 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1664 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1665 "ult -2, cache_guid TEXT , notification_state BLOB);"
1666 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1667 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'"
1668 "9010788312004066376x-6609234393368420856x',NULL);"));
1669 ASSERT_TRUE(connection->CommitTransaction());
1670 }
1671
1672 void MigrationTest::SetUpVersion79Database(sql::Connection* connection) {
1673 ASSERT_TRUE(connection->is_open());
1674 ASSERT_TRUE(connection->BeginTransaction());
1675 ASSERT_TRUE(connection->Execute(
1676 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1677 "INSERT INTO 'share_version' VALUES('nick@chromium.org',79);"
1678 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1679 "itial_sync_ended BOOLEAN default 0);"
1680 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1681 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1682 "_version bigint default -1,server_version bigint default 0,server_po"
1683 "sition_in_parent bigint default 0,local_external_id bigint default 0"
1684 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1685 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1686 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1687 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
1688 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
1689 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
1690 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
1691 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
1692 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
1693 ");"
1694 "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
1695 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);"
1696 "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
1697 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
1698 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
1699 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
1700 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
1701 "14447414447414447',NULL);"
1702 "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
1703 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
1704 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
1705 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
1706 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
1707 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
1708 "E2F77656C636F6D652E68746D6C1200',NULL);"
1709 "INSERT INTO 'metas' VALUES(5,677,677,1048576,7,"
1710 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
1711 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
1712 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
1713 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
1714 "ULL);"
1715 "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
1716 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
1717 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
1718 ",NULL);"
1719 "INSERT INTO 'metas' VALUES(7,663,663,1048576,0,"
1720 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
1721 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL);"
1722 "INSERT INTO 'metas' VALUES(8,664,664,1048576,0,"
1723 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
1724 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
1725 "00',X'C2881000',NULL);"
1726 "INSERT INTO 'metas' VALUES(9,665,665,1048576,1,"
1727 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
1728 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
1729 "000',X'C2881000',NULL);"
1730 "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
1731 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
1732 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
1733 "LL,X'C2881000',X'C2881000',NULL);"
1734 "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
1735 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
1736 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
1737 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
1738 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
1739 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);"
1740 "INSERT INTO 'metas' VALUES(12,685,685,0,9,"
1741 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
1742 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
1743 "2881000',X'C2881000',NULL);"
1744 "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
1745 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
1746 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
1747 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
1748 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
1749 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
1750 "E6963616E6E2E636F6D2F120744414146415346',NULL);"
1751 "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
1752 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
1753 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
1754 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
1755 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
1756 "81205504E473259',NULL);"
1757 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1758 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1759 "ult -2, cache_guid TEXT , notification_state BLOB);"
1760 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1761 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
1762 "-131078,'9010788312004066376x-6609234393368420856x',NULL);"));
1763 ASSERT_TRUE(connection->CommitTransaction());
1764 }
1765
1766 void MigrationTest::SetUpVersion80Database(sql::Connection* connection) {
1767 ASSERT_TRUE(connection->is_open());
1768 ASSERT_TRUE(connection->BeginTransaction());
1769 ASSERT_TRUE(connection->Execute(
1770 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1771 "INSERT INTO 'share_version' VALUES('nick@chromium.org',80);"
1772 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1773 "itial_sync_ended BOOLEAN default 0);"
1774 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1775 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1776 "_version bigint default -1,server_version bigint default 0,server_po"
1777 "sition_in_parent bigint default 0,local_external_id bigint default 0"
1778 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1779 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1780 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1781 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
1782 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
1783 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
1784 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
1785 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
1786 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
1787 ");"
1788 "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
1789 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);"
1790 "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
1791 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
1792 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
1793 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
1794 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
1795 "14447414447414447',NULL);"
1796 "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
1797 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
1798 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
1799 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
1800 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
1801 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
1802 "E2F77656C636F6D652E68746D6C1200',NULL);"
1803 "INSERT INTO 'metas' VALUES(5,677,677,1048576,7,"
1804 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
1805 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
1806 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
1807 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
1808 "ULL);"
1809 "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
1810 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
1811 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
1812 ",NULL);"
1813 "INSERT INTO 'metas' VALUES(7,663,663,1048576,0,"
1814 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
1815 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL);"
1816 "INSERT INTO 'metas' VALUES(8,664,664,1048576,0,"
1817 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
1818 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
1819 "00',X'C2881000',NULL);"
1820 "INSERT INTO 'metas' VALUES(9,665,665,1048576,1,"
1821 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
1822 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
1823 "000',X'C2881000',NULL);"
1824 "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
1825 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
1826 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
1827 "LL,X'C2881000',X'C2881000',NULL);"
1828 "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
1829 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
1830 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
1831 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
1832 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
1833 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);"
1834 "INSERT INTO 'metas' VALUES(12,685,685,0,9,"
1835 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
1836 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
1837 "2881000',X'C2881000',NULL);"
1838 "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
1839 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
1840 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
1841 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
1842 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
1843 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
1844 "E6963616E6E2E636F6D2F120744414146415346',NULL);"
1845 "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
1846 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
1847 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
1848 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
1849 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
1850 "81205504E473259',NULL);"
1851 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1852 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1853 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
1854 "blob);"
1855 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1856 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
1857 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
1858 ASSERT_TRUE(connection->CommitTransaction());
1859 }
1860
1861
1862 // Helper definitions to create the version 81 DB tables.
1863 namespace {
1864
1865 const int V80_ROW_COUNT = 13;
1866 const int64_t V80_POSITIONS[V80_ROW_COUNT] = {
1867 0, -2097152, -3145728, 1048576, -4194304, 1048576, 1048576,
1868 1048576, 2097152, -1048576, 0, -917504, 1048576};
1869
1870 std::string V81_Ordinal(int n) {
1871 return Int64ToNodeOrdinal(V80_POSITIONS[n]).ToInternalValue();
1872 }
1873
1874 } // namespace
1875
1876 // Unlike the earlier versions, the rows for version 81 are generated
1877 // programmatically to accurately handle unprintable characters for the
1878 // server_ordinal_in_parent field.
1879 void MigrationTest::SetUpVersion81Database(sql::Connection* connection) {
1880 ASSERT_TRUE(connection->is_open());
1881 ASSERT_TRUE(connection->BeginTransaction());
1882 ASSERT_TRUE(connection->Execute(
1883 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1884 "INSERT INTO 'share_version' VALUES('nick@chromium.org',81);"
1885 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1886 "itial_sync_ended BOOLEAN default 0);"
1887 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1888 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1889 "_version bigint default -1,server_version bigint default 0, "
1890 "local_external_id bigint default 0"
1891 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1892 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1893 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1894 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
1895 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
1896 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
1897 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
1898 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
1899 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
1900 ", server_ordinal_in_parent blob);"
1901 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1902 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1903 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
1904 "blob);"
1905 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1906 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
1907 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
1908
1909 const char* insert_stmts[V80_ROW_COUNT] = {
1910 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
1911 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?);",
1912 "INSERT INTO 'metas' VALUES(2,669,669,4,"
1913 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
1914 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
1915 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
1916 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
1917 "14447414447414447',NULL,?);",
1918 "INSERT INTO 'metas' VALUES(4,681,681,3,"
1919 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
1920 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
1921 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
1922 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
1923 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
1924 "E2F77656C636F6D652E68746D6C1200',NULL,?);",
1925 "INSERT INTO 'metas' VALUES(5,677,677,7,"
1926 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
1927 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
1928 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
1929 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
1930 "ULL,?);",
1931 "INSERT INTO 'metas' VALUES(6,694,694,6,"
1932 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
1933 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
1934 ",NULL,?);",
1935 "INSERT INTO 'metas' VALUES(7,663,663,0,"
1936 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
1937 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?);",
1938 "INSERT INTO 'metas' VALUES(8,664,664,0,"
1939 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
1940 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
1941 "00',X'C2881000',NULL,?);",
1942 "INSERT INTO 'metas' VALUES(9,665,665,1,"
1943 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
1944 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
1945 "000',X'C2881000',NULL,?);",
1946 "INSERT INTO 'metas' VALUES(10,666,666,2,"
1947 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
1948 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
1949 "LL,X'C2881000',X'C2881000',NULL,?);",
1950 "INSERT INTO 'metas' VALUES(11,683,683,8,"
1951 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
1952 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
1953 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
1954 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
1955 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?);",
1956 "INSERT INTO 'metas' VALUES(12,685,685,9,"
1957 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
1958 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
1959 "2881000',X'C2881000',NULL,?);",
1960 "INSERT INTO 'metas' VALUES(13,687,687,10,"
1961 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
1962 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
1963 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
1964 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
1965 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
1966 "E6963616E6E2E636F6D2F120744414146415346',NULL,?);",
1967 "INSERT INTO 'metas' VALUES(14,692,692,11,"
1968 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
1969 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
1970 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
1971 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
1972 "81205504E473259',NULL,?);" };
1973
1974 for (int i = 0; i < V80_ROW_COUNT; i++) {
1975 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
1976 std::string ord = V81_Ordinal(i);
1977 s.BindBlob(0, ord.data(), ord.length());
1978 ASSERT_TRUE(s.Run());
1979 s.Reset(true);
1980 }
1981 ASSERT_TRUE(connection->CommitTransaction());
1982 }
1983
1984 void MigrationTest::SetUpVersion82Database(sql::Connection* connection) {
1985 ASSERT_TRUE(connection->is_open());
1986 ASSERT_TRUE(connection->BeginTransaction());
1987 ASSERT_TRUE(connection->Execute(
1988 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1989 "INSERT INTO 'share_version' VALUES('nick@chromium.org',82);"
1990 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1991 "itial_sync_ended BOOLEAN default 0, transaction_version BIGINT "
1992 "default 0);"
1993 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1, 1);"
1994 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1995 "_version bigint default -1,server_version bigint default 0, "
1996 "local_external_id bigint default 0"
1997 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1998 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1999 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
2000 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
2001 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
2002 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
2003 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
2004 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
2005 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
2006 ", server_ordinal_in_parent blob);"
2007 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2008 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
2009 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
2010 "blob);"
2011 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2012 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
2013 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
2014
2015 const char* insert_stmts[V80_ROW_COUNT] = {
2016 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
2017 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?);",
2018 "INSERT INTO 'metas' VALUES(2,669,669,4,"
2019 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
2020 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
2021 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
2022 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
2023 "14447414447414447',NULL,?);",
2024 "INSERT INTO 'metas' VALUES(4,681,681,3,"
2025 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
2026 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
2027 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
2028 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
2029 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
2030 "E2F77656C636F6D652E68746D6C1200',NULL,?);",
2031 "INSERT INTO 'metas' VALUES(5,677,677,7,"
2032 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
2033 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
2034 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
2035 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
2036 "ULL,?);",
2037 "INSERT INTO 'metas' VALUES(6,694,694,6,"
2038 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
2039 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
2040 ",NULL,?);",
2041 "INSERT INTO 'metas' VALUES(7,663,663,0,"
2042 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
2043 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?);",
2044 "INSERT INTO 'metas' VALUES(8,664,664,0,"
2045 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
2046 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
2047 "00',X'C2881000',NULL,?);",
2048 "INSERT INTO 'metas' VALUES(9,665,665,1,"
2049 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
2050 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
2051 "000',X'C2881000',NULL,?);",
2052 "INSERT INTO 'metas' VALUES(10,666,666,2,"
2053 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
2054 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
2055 "LL,X'C2881000',X'C2881000',NULL,?);",
2056 "INSERT INTO 'metas' VALUES(11,683,683,8,"
2057 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
2058 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
2059 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
2060 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
2061 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?);",
2062 "INSERT INTO 'metas' VALUES(12,685,685,9,"
2063 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
2064 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
2065 "2881000',X'C2881000',NULL,?);",
2066 "INSERT INTO 'metas' VALUES(13,687,687,10,"
2067 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
2068 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
2069 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
2070 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
2071 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
2072 "E6963616E6E2E636F6D2F120744414146415346',NULL,?);",
2073 "INSERT INTO 'metas' VALUES(14,692,692,11,"
2074 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
2075 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
2076 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
2077 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
2078 "81205504E473259',NULL,?);" };
2079
2080 for (int i = 0; i < V80_ROW_COUNT; i++) {
2081 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
2082 std::string ord = V81_Ordinal(i);
2083 s.BindBlob(0, ord.data(), ord.length());
2084 ASSERT_TRUE(s.Run());
2085 s.Reset(true);
2086 }
2087 ASSERT_TRUE(connection->CommitTransaction());
2088 }
2089
2090 void MigrationTest::SetUpVersion83Database(sql::Connection* connection) {
2091 ASSERT_TRUE(connection->is_open());
2092 ASSERT_TRUE(connection->BeginTransaction());
2093 ASSERT_TRUE(connection->Execute(
2094 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2095 "INSERT INTO 'share_version' VALUES('nick@chromium.org',83);"
2096 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
2097 "itial_sync_ended BOOLEAN default 0, transaction_version BIGINT "
2098 "default 0);"
2099 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1, 1);"
2100 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
2101 "_version bigint default -1,server_version bigint default 0, "
2102 "local_external_id bigint default 0"
2103 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
2104 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
2105 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
2106 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
2107 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
2108 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
2109 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
2110 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
2111 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
2112 ", server_ordinal_in_parent blob, transaction_version bigint default "
2113 "0);"
2114 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2115 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
2116 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
2117 "blob);"
2118 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2119 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
2120 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
2121
2122 const char* insert_stmts[V80_ROW_COUNT] = {
2123 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
2124 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?,0);",
2125 "INSERT INTO 'metas' VALUES(2,669,669,4,"
2126 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
2127 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
2128 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
2129 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
2130 "14447414447414447',NULL,?,0);",
2131 "INSERT INTO 'metas' VALUES(4,681,681,3,"
2132 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
2133 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
2134 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
2135 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
2136 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
2137 "E2F77656C636F6D652E68746D6C1200',NULL,?,0);",
2138 "INSERT INTO 'metas' VALUES(5,677,677,7,"
2139 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
2140 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
2141 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
2142 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
2143 "ULL,?,0);",
2144 "INSERT INTO 'metas' VALUES(6,694,694,6,"
2145 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
2146 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
2147 ",NULL,?,0);",
2148 "INSERT INTO 'metas' VALUES(7,663,663,0,"
2149 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
2150 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?,0);"
2151 "",
2152 "INSERT INTO 'metas' VALUES(8,664,664,0,"
2153 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
2154 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
2155 "00',X'C2881000',NULL,?,0);",
2156 "INSERT INTO 'metas' VALUES(9,665,665,1,"
2157 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
2158 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
2159 "000',X'C2881000',NULL,?,0);",
2160 "INSERT INTO 'metas' VALUES(10,666,666,2,"
2161 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
2162 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
2163 "LL,X'C2881000',X'C2881000',NULL,?,0);",
2164 "INSERT INTO 'metas' VALUES(11,683,683,8,"
2165 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
2166 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
2167 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
2168 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
2169 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?,0);",
2170 "INSERT INTO 'metas' VALUES(12,685,685,9,"
2171 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
2172 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
2173 "2881000',X'C2881000',NULL,?,0);",
2174 "INSERT INTO 'metas' VALUES(13,687,687,10,"
2175 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
2176 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
2177 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
2178 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
2179 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
2180 "E6963616E6E2E636F6D2F120744414146415346',NULL,?,0);",
2181 "INSERT INTO 'metas' VALUES(14,692,692,11,"
2182 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
2183 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
2184 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
2185 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
2186 "81205504E473259',NULL,?,0);" };
2187
2188 for (int i = 0; i < V80_ROW_COUNT; i++) {
2189 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
2190 std::string ord = V81_Ordinal(i);
2191 s.BindBlob(0, ord.data(), ord.length());
2192 ASSERT_TRUE(s.Run());
2193 s.Reset(true);
2194 }
2195 ASSERT_TRUE(connection->CommitTransaction());
2196 }
2197
2198 void MigrationTest::SetUpVersion84Database(sql::Connection* connection) {
2199 ASSERT_TRUE(connection->is_open());
2200 ASSERT_TRUE(connection->BeginTransaction());
2201 ASSERT_TRUE(connection->Execute(
2202 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2203 "INSERT INTO 'share_version' VALUES('nick@chromium.org',84);"
2204 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
2205 "itial_sync_ended BOOLEAN default 0, transaction_version BIGINT "
2206 "default 0);"
2207 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1, 1);"
2208 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
2209 "_version bigint default -1,server_version bigint default 0, "
2210 "local_external_id bigint default 0"
2211 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
2212 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
2213 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
2214 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
2215 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
2216 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
2217 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
2218 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
2219 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
2220 ", server_ordinal_in_parent blob, transaction_version bigint default "
2221 "0);"
2222 "CREATE TABLE 'deleted_metas'"
2223 "(metahandle bigint primary key ON CONFLICT FAIL,base"
2224 "_version bigint default -1,server_version bigint default 0, "
2225 "local_external_id bigint default 0"
2226 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
2227 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
2228 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
2229 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
2230 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
2231 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
2232 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
2233 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
2234 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
2235 ", server_ordinal_in_parent blob, transaction_version bigint default "
2236 "0);"
2237 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2238 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
2239 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
2240 "blob);"
2241 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2242 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
2243 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
2244
2245 const char* insert_stmts[V80_ROW_COUNT] = {
2246 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
2247 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?,0);",
2248 "INSERT INTO 'metas' VALUES(2,669,669,4,"
2249 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
2250 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
2251 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
2252 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
2253 "14447414447414447',NULL,?,0);",
2254 "INSERT INTO 'metas' VALUES(4,681,681,3,"
2255 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
2256 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
2257 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
2258 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
2259 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
2260 "E2F77656C636F6D652E68746D6C1200',NULL,?,0);",
2261 "INSERT INTO 'metas' VALUES(5,677,677,7,"
2262 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
2263 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
2264 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
2265 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
2266 "ULL,?,0);",
2267 "INSERT INTO 'metas' VALUES(6,694,694,6,"
2268 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
2269 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
2270 ",NULL,?,0);",
2271 "INSERT INTO 'metas' VALUES(7,663,663,0,"
2272 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
2273 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?,0);"
2274 "",
2275 "INSERT INTO 'metas' VALUES(8,664,664,0,"
2276 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
2277 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
2278 "00',X'C2881000',NULL,?,0);",
2279 "INSERT INTO 'metas' VALUES(9,665,665,1,"
2280 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
2281 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
2282 "000',X'C2881000',NULL,?,0);",
2283 "INSERT INTO 'metas' VALUES(10,666,666,2,"
2284 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
2285 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
2286 "LL,X'C2881000',X'C2881000',NULL,?,0);",
2287 "INSERT INTO 'metas' VALUES(11,683,683,8,"
2288 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
2289 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
2290 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
2291 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
2292 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?,0);",
2293 "INSERT INTO 'metas' VALUES(12,685,685,9,"
2294 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
2295 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
2296 "2881000',X'C2881000',NULL,?,0);",
2297 "INSERT INTO 'metas' VALUES(13,687,687,10,"
2298 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
2299 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
2300 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
2301 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
2302 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
2303 "E6963616E6E2E636F6D2F120744414146415346',NULL,?,0);",
2304 "INSERT INTO 'metas' VALUES(14,692,692,11,"
2305 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
2306 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
2307 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
2308 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
2309 "81205504E473259',NULL,?,0);" };
2310
2311 for (int i = 0; i < V80_ROW_COUNT; i++) {
2312 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
2313 std::string ord = V81_Ordinal(i);
2314 s.BindBlob(0, ord.data(), ord.length());
2315 ASSERT_TRUE(s.Run());
2316 s.Reset(true);
2317 }
2318 ASSERT_TRUE(connection->CommitTransaction());
2319 }
2320
2321 void MigrationTest::SetUpVersion85Database(sql::Connection* connection) {
2322 ASSERT_TRUE(connection->is_open());
2323 ASSERT_TRUE(connection->BeginTransaction());
2324 ASSERT_TRUE(connection->Execute(
2325 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2326 "INSERT INTO 'share_version' VALUES('nick@chromium.org',85);"
2327 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, "
2328 "transaction_version BIGINT default 0);"
2329 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605', 1);"
2330 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
2331 "_version bigint default -1,server_version bigint default 0, "
2332 "local_external_id bigint default 0"
2333 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
2334 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
2335 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
2336 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
2337 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
2338 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
2339 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
2340 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
2341 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
2342 ", server_ordinal_in_parent blob, transaction_version bigint default "
2343 "0);"
2344 "CREATE TABLE 'deleted_metas'"
2345 "(metahandle bigint primary key ON CONFLICT FAIL,base"
2346 "_version bigint default -1,server_version bigint default 0, "
2347 "local_external_id bigint default 0"
2348 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
2349 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
2350 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
2351 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
2352 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
2353 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
2354 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
2355 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
2356 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
2357 ", server_ordinal_in_parent blob, transaction_version bigint default "
2358 "0);"
2359 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2360 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
2361 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
2362 "blob);"
2363 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2364 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
2365 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
2366
2367 const char* insert_stmts[V80_ROW_COUNT] = {
2368 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
2369 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?,0);",
2370 "INSERT INTO 'metas' VALUES(2,669,669,4,"
2371 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
2372 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
2373 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
2374 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
2375 "14447414447414447',NULL,?,0);",
2376 "INSERT INTO 'metas' VALUES(4,681,681,3,"
2377 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
2378 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
2379 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
2380 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
2381 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
2382 "E2F77656C636F6D652E68746D6C1200',NULL,?,0);",
2383 "INSERT INTO 'metas' VALUES(5,677,677,7,"
2384 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
2385 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
2386 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
2387 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
2388 "ULL,?,0);",
2389 "INSERT INTO 'metas' VALUES(6,694,694,6,"
2390 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
2391 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
2392 ",NULL,?,0);",
2393 "INSERT INTO 'metas' VALUES(7,663,663,0,"
2394 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
2395 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?,0);"
2396 "",
2397 "INSERT INTO 'metas' VALUES(8,664,664,0,"
2398 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
2399 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
2400 "00',X'C2881000',NULL,?,0);",
2401 "INSERT INTO 'metas' VALUES(9,665,665,1,"
2402 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
2403 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
2404 "000',X'C2881000',NULL,?,0);",
2405 "INSERT INTO 'metas' VALUES(10,666,666,2,"
2406 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
2407 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
2408 "LL,X'C2881000',X'C2881000',NULL,?,0);",
2409 "INSERT INTO 'metas' VALUES(11,683,683,8,"
2410 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
2411 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
2412 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
2413 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
2414 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?,0);",
2415 "INSERT INTO 'metas' VALUES(12,685,685,9,"
2416 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
2417 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
2418 "2881000',X'C2881000',NULL,?,0);",
2419 "INSERT INTO 'metas' VALUES(13,687,687,10,"
2420 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
2421 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
2422 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
2423 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
2424 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
2425 "E6963616E6E2E636F6D2F120744414146415346',NULL,?,0);",
2426 "INSERT INTO 'metas' VALUES(14,692,692,11,"
2427 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
2428 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
2429 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
2430 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
2431 "81205504E473259',NULL,?,0);" };
2432
2433 for (int i = 0; i < V80_ROW_COUNT; i++) {
2434 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
2435 std::string ord = V81_Ordinal(i);
2436 s.BindBlob(0, ord.data(), ord.length());
2437 ASSERT_TRUE(s.Run());
2438 s.Reset(true);
2439 }
2440 ASSERT_TRUE(connection->CommitTransaction());
2441 }
2442
2443 void MigrationTest::SetUpVersion86Database(sql::Connection* connection) {
2444 ASSERT_TRUE(connection->is_open());
2445 ASSERT_TRUE(connection->BeginTransaction());
2446 ASSERT_TRUE(connection->Execute(
2447 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2448 "INSERT INTO 'share_version' VALUES('nick@chromium.org',86);"
2449 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB,"
2450 " transaction_version BIGINT default 0);"
2451 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
2452 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,b"
2453 "ase_version bigint default -1,server_version bigint default 0,local_e"
2454 "xternal_id bigint default 0,transaction_version bigint default 0,mtim"
2455 "e bigint default 0,server_mtime bigint default 0,ctime bigint default"
2456 " 0,server_ctime bigint default 0,id varchar(255) default 'r',parent_i"
2457 "d varchar(255) default 'r',server_parent_id varchar(255) default 'r',"
2458 "is_unsynced bit default 0,is_unapplied_update bit default 0,is_del bi"
2459 "t default 0,is_dir bit default 0,server_is_dir bit default 0,server_i"
2460 "s_del bit default 0,non_unique_name varchar,server_non_unique_name va"
2461 "rchar(255),unique_server_tag varchar,unique_client_tag varchar,unique"
2462 "_bookmark_tag varchar,specifics blob,server_specifics blob,base_serve"
2463 "r_specifics blob,server_unique_position blob,unique_position blob);"
2464 "INSERT INTO 'metas' VALUES(1,-1,0,0,0,"
2465 META_PROTO_TIMES_VALS(1)
2466 ",'r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,"
2467 "X'',X'',X'',NULL,X'2200',X'2200');"
2468 "INSERT INTO 'metas' VALUES(6,694,694,6,0,"
2469 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9',0,0,0,1,1,0,'The"
2470 " Internet','The Internet',NULL,NULL,X'6754307476346749735A5734654D653"
2471 "273625336557753582F77673D',X'C2881000',X'C2881000',NULL,X'22247FFFFFF"
2472 "FFFC000006754307476346749735A5734654D653273625336557753582F77673D',X'"
2473 "22247FFFFFFFFFC000006754307476346749735A5734654D653273625336557753582"
2474 "F77673D');"
2475 "INSERT INTO 'metas' VALUES(7,663,663,0,0,"
2476 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r',0,0,0,1,1,0,'Google Chrome"
2477 "','Google Chrome','google_chrome',NULL,X'',NULL,NULL,NULL,X'2200',X'2"
2478 "200');"
2479 "INSERT INTO 'metas' VALUES(8,664,664,0,0,"
2480 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7',0,0,0,1,1,0,'Boo"
2481 "kmarks','Bookmarks','google_chrome_bookmarks',NULL,X'',X'C2881000',X'"
2482 "C2881000',NULL,X'2200',X'2200');"
2483 "INSERT INTO 'metas' VALUES(9,665,665,1,0,"
2484 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8',0,0,0,1,1,0,'Boo"
2485 "kmark Bar','Bookmark Bar','bookmark_bar',NULL,X'',X'C2881000',X'C2881"
2486 "000',NULL,X'2200',X'2200');"
2487 "INSERT INTO 'metas' VALUES(10,666,666,2,0,"
2488 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8',0,0,0,1,1,0,'O"
2489 "ther Bookmarks','Other Bookmarks','other_bookmarks',NULL,X'',X'C28810"
2490 "00',X'C2881000',NULL,X'2200',X'2200');"
2491 "INSERT INTO 'metas' VALUES(11,683,683,8,0,"
2492 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6',0,0,0,0,0,0,'H"
2493 "ome (The Chromium Projects)','Home (The Chromium Projects)',NULL,NULL"
2494 ",X'50514C784A456D623579366267644237646A7A2B62314130346E493D',X'C28810"
2495 "220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F120641474154574"
2496 "1',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756D2E6F72672F6F74"
2497 "68657212084146414756415346',NULL,X'22247FFFFFFFFFF0000050514C784A456D"
2498 "623579366267644237646A7A2B62314130346E493D',X'22247FFFFFFFFFF00000505"
2499 "14C784A456D623579366267644237646A7A2B62314130346E493D');"
2500 "INSERT INTO 'metas' VALUES(12,685,685,9,0,"
2501 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6',0,0,0,1,1,0,'E"
2502 "xtra Bookmarks','Extra Bookmarks',NULL,NULL,X'7867626A704A646134635A6"
2503 "F616C376A49513338734B46324837773D',X'C2881000',X'C2881000',NULL,X'222"
2504 "480000000000000007867626A704A646134635A6F616C376A49513338734B46324837"
2505 "773D',X'222480000000000000007867626A704A646134635A6F616C376A495133387"
2506 "34B46324837773D');"
2507 "INSERT INTO 'metas' VALUES(13,687,687,10,0,"
2508 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6',0,0,0,0,0,0,'I"
2509 "CANN | Internet Corporation for Assigned Names and Numbers','ICANN | "
2510 "Internet Corporation for Assigned Names and Numbers',NULL,NULL,X'3142"
2511 "756B572F7741766956504179672B304A614A514B3452384A413D',X'C28810240A156"
2512 "87474703A2F2F7777772E6963616E6E2E636F6D2F120B504E474158463041414646',"
2513 "X'C28810200A15687474703A2F2F7777772E6963616E6E2E636F6D2F1207444141464"
2514 "15346',NULL,X'22247FFFFFFFFFF200003142756B572F7741766956504179672B304"
2515 "A614A514B3452384A413D',X'22247FFFFFFFFFF200003142756B572F774176695650"
2516 "4179672B304A614A514B3452384A413D');"
2517 "INSERT INTO 'metas' VALUES(14,692,692,11,0,"
2518 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6',0,0,0,0,0,0,'T"
2519 "he WebKit Open Source Project','The WebKit Open Source Project',NULL,"
2520 "NULL,X'5A5678314E7976364579524D3177494F7236563159552F6E644C553D',X'C2"
2521 "88101A0A12687474703A2F2F7765626B69742E6F72672F1204504E4758',X'C288101"
2522 "C0A13687474703A2F2F7765626B69742E6F72672F781205504E473259',NULL,X'222"
2523 "480000000001000005A5678314E7976364579524D3177494F7236563159552F6E644C"
2524 "553D',X'222480000000001000005A5678314E7976364579524D3177494F723656315"
2525 "9552F6E644C553D');"
2526 "CREATE TABLE deleted_metas (metahandle bigint primary key ON CONFLICT FA"
2527 "IL,base_version bigint default -1,server_version bigint default 0,loc"
2528 "al_external_id bigint default 0,transaction_version bigint default 0,"
2529 "mtime bigint default 0,server_mtime bigint default 0,ctime bigint def"
2530 "ault 0,server_ctime bigint default 0,id varchar(255) default 'r',pare"
2531 "nt_id varchar(255) default 'r',server_parent_id varchar(255) default "
2532 "'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is_de"
2533 "l bit default 0,is_dir bit default 0,server_is_dir bit default 0,serv"
2534 "er_is_del bit default 0,non_unique_name varchar,server_non_unique_nam"
2535 "e varchar(255),unique_server_tag varchar,unique_client_tag varchar,un"
2536 "ique_bookmark_tag varchar,specifics blob,server_specifics blob,base_s"
2537 "erver_specifics blob,server_unique_position blob,unique_position blob"
2538 ");"
2539 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birt"
2540 "hday TEXT, db_create_version TEXT, db_create_time INT, next_id INT de"
2541 "fault -2, cache_guid TEXT, notification_state BLOB, bag_of_chips BLOB"
2542 ");"
2543 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.or"
2544 "g','c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-13107"
2545 "8,'9010788312004066376x-6609234393368420856x',NULL,NULL);"));
2546 ASSERT_TRUE(connection->CommitTransaction());
2547 }
2548
2549 void MigrationTest::SetUpVersion87Database(sql::Connection* connection) {
2550 ASSERT_TRUE(connection->is_open());
2551 ASSERT_TRUE(connection->BeginTransaction());
2552 ASSERT_TRUE(connection->Execute(
2553 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2554 "INSERT INTO 'share_version' VALUES('nick@chromium.org',87);"
2555 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, tr"
2556 "ansaction_version BIGINT default 0);"
2557 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
2558 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
2559 "_version bigint default -1,server_version bigint default 0,local_exte"
2560 "rnal_id bigint default 0,transaction_version bigint default 0,mtime b"
2561 "igint default 0,server_mtime bigint default 0,ctime bigint default 0,"
2562 "server_ctime bigint default 0,id varchar(255) default 'r',parent_id v"
2563 "archar(255) default 'r',server_parent_id varchar(255) default 'r',is_"
2564 "unsynced bit default 0,is_unapplied_update bit default 0,is_del bit d"
2565 "efault 0,is_dir bit default 0,server_is_dir bit default 0,server_is_d"
2566 "el bit default 0,non_unique_name varchar,server_non_unique_name varch"
2567 "ar(255),unique_server_tag varchar,unique_client_tag varchar,unique_bo"
2568 "okmark_tag varchar,specifics blob,server_specifics blob,base_server_s"
2569 "pecifics blob,server_unique_position blob,unique_position blob,attach"
2570 "ment_metadata blob);"
2571 "INSERT INTO 'metas' VALUES(1,-1,0,0,0,"
2572 META_PROTO_TIMES_VALS(1)
2573 ",'r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X''"
2574 ",X'',X'',NULL,X'2200',X'2200',NULL);"
2575 "INSERT INTO 'metas' VALUES(6,694,694,6,0,"
2576 META_PROTO_TIMES_VALS(6)
2577 ",'s_ID_6','s_ID_9','s_ID_9',0,0,0,1,1,0,'The "
2578 "Internet','The Internet',NULL,NULL,X'6754307476346749735A5734654D6532"
2579 "73625336557753582F77673D',X'C2881000',X'C2881000',NULL,X'22247FFFFFFF"
2580 "FFC000006754307476346749735A5734654D653273625336557753582F77673D',X'2"
2581 "2247FFFFFFFFFC000006754307476346749735A5734654D653273625336557753582F"
2582 "77673D',NULL);"
2583 "INSERT INTO 'metas' VALUES(7,663,663,0,0,"
2584 META_PROTO_TIMES_VALS(7)
2585 ",'s_ID_7','r','r',0,0,0,1,1,0,'Google Chrome'"
2586 ",'Google Chrome','google_chrome',NULL,X'',NULL,NULL,NULL,X'2200',X'22"
2587 "00',NULL);"
2588 "INSERT INTO 'metas' VALUES(8,664,664,0,0,"
2589 META_PROTO_TIMES_VALS(8)
2590 ",'s_ID_8','s_ID_7','s_ID_7',0,0,0,1,1,0,'Book"
2591 "marks','Bookmarks','google_chrome_bookmarks',NULL,X'',X'C2881000',X'C"
2592 "2881000',NULL,X'2200',X'2200',NULL);"
2593 "INSERT INTO 'metas' VALUES(9,665,665,1,0,"
2594 META_PROTO_TIMES_VALS(9)
2595 ",'s_ID_9','s_ID_8','s_ID_8',0,0,0,1,1,0,'Book"
2596 "mark Bar','Bookmark Bar','bookmark_bar',NULL,X'',X'C2881000',X'C28810"
2597 "00',NULL,X'2200',X'2200',NULL);"
2598 "INSERT INTO 'metas' VALUES(10,666,666,2,0,"
2599 META_PROTO_TIMES_VALS(10)
2600 ",'s_ID_10','s_ID_8','s_ID_8',0,0,0,1,1,0,'Ot"
2601 "her Bookmarks','Other Bookmarks','other_bookmarks',NULL,X'',X'C288100"
2602 "0',X'C2881000',NULL,X'2200',X'2200',NULL);"
2603 "INSERT INTO 'metas' VALUES(11,683,683,8,0,"
2604 META_PROTO_TIMES_VALS(11)
2605 ",'s_ID_11','s_ID_6','s_ID_6',0,0,0,0,0,0,'Ho"
2606 "me (The Chromium Projects)','Home (The Chromium Projects)',NULL,NULL,"
2607 "X'50514C784A456D623579366267644237646A7A2B62314130346E493D',X'C288102"
2608 "20A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1206414741545741"
2609 "',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756D2E6F72672F6F746"
2610 "8657212084146414756415346',NULL,X'22247FFFFFFFFFF0000050514C784A456D6"
2611 "23579366267644237646A7A2B62314130346E493D',X'22247FFFFFFFFFF000005051"
2612 "4C784A456D623579366267644237646A7A2B62314130346E493D',NULL);"
2613 "INSERT INTO 'metas' VALUES(12,685,685,9,0,"
2614 META_PROTO_TIMES_VALS(12)
2615 ",'s_ID_12','s_ID_6','s_ID_6',0,0,0,1,1,0,'Ex"
2616 "tra Bookmarks','Extra Bookmarks',NULL,NULL,X'7867626A704A646134635A6F"
2617 "616C376A49513338734B46324837773D',X'C2881000',X'C2881000',NULL,X'2224"
2618 "80000000000000007867626A704A646134635A6F616C376A49513338734B463248377"
2619 "73D',X'222480000000000000007867626A704A646134635A6F616C376A4951333873"
2620 "4B46324837773D',NULL);"
2621 "INSERT INTO 'metas' VALUES(13,687,687,10,0,"
2622 META_PROTO_TIMES_VALS(13)
2623 ",'s_ID_13','s_ID_6','s_ID_6',0,0,0,0,0,0,'I"
2624 "CANN | Internet Corporation for Assigned Names and Numbers','ICANN | "
2625 "Internet Corporation for Assigned Names and Numbers',NULL,NULL,X'3142"
2626 "756B572F7741766956504179672B304A614A514B3452384A413D',X'C28810240A156"
2627 "87474703A2F2F7777772E6963616E6E2E636F6D2F120B504E474158463041414646',"
2628 "X'C28810200A15687474703A2F2F7777772E6963616E6E2E636F6D2F1207444141464"
2629 "15346',NULL,X'22247FFFFFFFFFF200003142756B572F7741766956504179672B304"
2630 "A614A514B3452384A413D',X'22247FFFFFFFFFF200003142756B572F774176695650"
2631 "4179672B304A614A514B3452384A413D',NULL);"
2632 "INSERT INTO 'metas' VALUES(14,692,692,11,0,"
2633 META_PROTO_TIMES_VALS(14)
2634 ",'s_ID_14','s_ID_6','s_ID_6',0,0,0,0,0,0,'T"
2635 "he WebKit Open Source Project','The WebKit Open Source Project',NULL,"
2636 "NULL,X'5A5678314E7976364579524D3177494F7236563159552F6E644C553D',X'C2"
2637 "88101A0A12687474703A2F2F7765626B69742E6F72672F1204504E4758',X'C288101"
2638 "C0A13687474703A2F2F7765626B69742E6F72672F781205504E473259',NULL,X'222"
2639 "480000000001000005A5678314E7976364579524D3177494F7236563159552F6E644C"
2640 "553D',X'222480000000001000005A5678314E7976364579524D3177494F723656315"
2641 "9552F6E644C553D',NULL);"
2642 "CREATE TABLE deleted_metas (metahandle bigint primary key ON CONFLICT FA"
2643 "IL,base_version bigint default -1,server_version bigint default 0,loc"
2644 "al_external_id bigint default 0,transaction_version bigint default 0,"
2645 "mtime bigint default 0,server_mtime bigint default 0,ctime bigint def"
2646 "ault 0,server_ctime bigint default 0,id varchar(255) default 'r',pare"
2647 "nt_id varchar(255) default 'r',server_parent_id varchar(255) default "
2648 "'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is_de"
2649 "l bit default 0,is_dir bit default 0,server_is_dir bit default 0,serv"
2650 "er_is_del bit default 0,non_unique_name varchar,server_non_unique_nam"
2651 "e varchar(255),unique_server_tag varchar,unique_client_tag varchar,un"
2652 "ique_bookmark_tag varchar,specifics blob,server_specifics blob,base_s"
2653 "erver_specifics blob,server_unique_position blob,unique_position blob"
2654 ",attachment_metadata blob);"
2655 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2656 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defau"
2657 "lt -2, cache_guid TEXT, notification_state BLOB, bag_of_chips BLOB);"
2658 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2659 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-131078,'"
2660 "9010788312004066376x-6609234393368420856x',NULL,NULL);"));
2661 ASSERT_TRUE(connection->CommitTransaction());
2662 }
2663
2664 void MigrationTest::SetUpVersion88Database(sql::Connection* connection) {
2665 ASSERT_TRUE(connection->is_open());
2666 ASSERT_TRUE(connection->BeginTransaction());
2667 ASSERT_TRUE(connection->Execute(
2668 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2669 "INSERT INTO 'share_version' VALUES('nick@chromium.org',88);"
2670 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB,"
2671 " transaction_version BIGINT default 0, context BLOB);"
2672 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1,NULL);"
2673 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
2674 "_version bigint default -1,server_version bigint default 0,local_exte"
2675 "rnal_id bigint default 0,transaction_version bigint default 0,mtime b"
2676 "igint default 0,server_mtime bigint default 0,ctime bigint default 0,"
2677 "server_ctime bigint default 0,id varchar(255) default 'r',parent_id v"
2678 "archar(255) default 'r',server_parent_id varchar(255) default 'r',is_"
2679 "unsynced bit default 0,is_unapplied_update bit default 0,is_del bit d"
2680 "efault 0,is_dir bit default 0,server_is_dir bit default 0,server_is_d"
2681 "el bit default 0,non_unique_name varchar,server_non_unique_name varch"
2682 "ar(255),unique_server_tag varchar,unique_client_tag varchar,unique_bo"
2683 "okmark_tag varchar,specifics blob,server_specifics blob,base_server_s"
2684 "pecifics blob,server_unique_position blob,unique_position blob,attach"
2685 "ment_metadata blob);"
2686 "INSERT INTO 'metas' VALUES(1,-1,0,0,0,"
2687 META_PROTO_TIMES_VALS(1)
2688 ",'r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X''"
2689 ",X'',X'',NULL,X'2200',X'2200',NULL);"
2690 "INSERT INTO 'metas' VALUES(6,694,694,6,0,"
2691 META_PROTO_TIMES_VALS(6)
2692 ",'s_ID_6','s_ID_9','s_ID_9',0,0,0,1,1,0,'The "
2693 "Internet','The Internet',NULL,NULL,X'6754307476346749735A5734654D6532"
2694 "73625336557753582F77673D',X'C2881000',X'C2881000',NULL,X'22247FFFFFFF"
2695 "FFC000006754307476346749735A5734654D653273625336557753582F77673D',X'2"
2696 "2247FFFFFFFFFC000006754307476346749735A5734654D653273625336557753582F"
2697 "77673D',NULL);"
2698 "INSERT INTO 'metas' VALUES(7,663,663,0,0,"
2699 META_PROTO_TIMES_VALS(7)
2700 ",'s_ID_7','r','r',0,0,0,1,1,0,'Google Chrome'"
2701 ",'Google Chrome','google_chrome',NULL,X'',NULL,NULL,NULL,X'2200',X'22"
2702 "00',NULL);"
2703 "INSERT INTO 'metas' VALUES(8,664,664,0,0,"
2704 META_PROTO_TIMES_VALS(8)
2705 ",'s_ID_8','s_ID_7','s_ID_7',0,0,0,1,1,0,'Book"
2706 "marks','Bookmarks','google_chrome_bookmarks',NULL,X'',X'C2881000',X'C"
2707 "2881000',NULL,X'2200',X'2200',NULL);"
2708 "INSERT INTO 'metas' VALUES(9,665,665,1,0,"
2709 META_PROTO_TIMES_VALS(9)
2710 ",'s_ID_9','s_ID_8','s_ID_8',0,0,0,1,1,0,'Book"
2711 "mark Bar','Bookmark Bar','bookmark_bar',NULL,X'',X'C2881000',X'C28810"
2712 "00',NULL,X'2200',X'2200',NULL);"
2713 "INSERT INTO 'metas' VALUES(10,666,666,2,0,"
2714 META_PROTO_TIMES_VALS(10)
2715 ",'s_ID_10','s_ID_8','s_ID_8',0,0,0,1,1,0,'Ot"
2716 "her Bookmarks','Other Bookmarks','other_bookmarks',NULL,X'',X'C288100"
2717 "0',X'C2881000',NULL,X'2200',X'2200',NULL);"
2718 "INSERT INTO 'metas' VALUES(11,683,683,8,0,"
2719 META_PROTO_TIMES_VALS(11)
2720 ",'s_ID_11','s_ID_6','s_ID_6',0,0,0,0,0,0,'Ho"
2721 "me (The Chromium Projects)','Home (The Chromium Projects)',NULL,NULL,"
2722 "X'50514C784A456D623579366267644237646A7A2B62314130346E493D',X'C288102"
2723 "20A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1206414741545741"
2724 "',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756D2E6F72672F6F746"
2725 "8657212084146414756415346',NULL,X'22247FFFFFFFFFF0000050514C784A456D6"
2726 "23579366267644237646A7A2B62314130346E493D',X'22247FFFFFFFFFF000005051"
2727 "4C784A456D623579366267644237646A7A2B62314130346E493D',NULL);"
2728 "INSERT INTO 'metas' VALUES(12,685,685,9,0,"
2729 META_PROTO_TIMES_VALS(12)
2730 ",'s_ID_12','s_ID_6','s_ID_6',0,0,0,1,1,0,'Ex"
2731 "tra Bookmarks','Extra Bookmarks',NULL,NULL,X'7867626A704A646134635A6F"
2732 "616C376A49513338734B46324837773D',X'C2881000',X'C2881000',NULL,X'2224"
2733 "80000000000000007867626A704A646134635A6F616C376A49513338734B463248377"
2734 "73D',X'222480000000000000007867626A704A646134635A6F616C376A4951333873"
2735 "4B46324837773D',NULL);"
2736 "INSERT INTO 'metas' VALUES(13,687,687,10,0,"
2737 META_PROTO_TIMES_VALS(13)
2738 ",'s_ID_13','s_ID_6','s_ID_6',0,0,0,0,0,0,'I"
2739 "CANN | Internet Corporation for Assigned Names and Numbers','ICANN | "
2740 "Internet Corporation for Assigned Names and Numbers',NULL,NULL,X'3142"
2741 "756B572F7741766956504179672B304A614A514B3452384A413D',X'C28810240A156"
2742 "87474703A2F2F7777772E6963616E6E2E636F6D2F120B504E474158463041414646',"
2743 "X'C28810200A15687474703A2F2F7777772E6963616E6E2E636F6D2F1207444141464"
2744 "15346',NULL,X'22247FFFFFFFFFF200003142756B572F7741766956504179672B304"
2745 "A614A514B3452384A413D',X'22247FFFFFFFFFF200003142756B572F774176695650"
2746 "4179672B304A614A514B3452384A413D',NULL);"
2747 "INSERT INTO 'metas' VALUES(14,692,692,11,0,"
2748 META_PROTO_TIMES_VALS(14)
2749 ",'s_ID_14','s_ID_6','s_ID_6',0,0,0,0,0,0,'T"
2750 "he WebKit Open Source Project','The WebKit Open Source Project',NULL,"
2751 "NULL,X'5A5678314E7976364579524D3177494F7236563159552F6E644C553D',X'C2"
2752 "88101A0A12687474703A2F2F7765626B69742E6F72672F1204504E4758',X'C288101"
2753 "C0A13687474703A2F2F7765626B69742E6F72672F781205504E473259',NULL,X'222"
2754 "480000000001000005A5678314E7976364579524D3177494F7236563159552F6E644C"
2755 "553D',X'222480000000001000005A5678314E7976364579524D3177494F723656315"
2756 "9552F6E644C553D',NULL);"
2757 "CREATE TABLE deleted_metas (metahandle bigint primary key ON CONFLICT FA"
2758 "IL,base_version bigint default -1,server_version bigint default 0,loc"
2759 "al_external_id bigint default 0,transaction_version bigint default 0,"
2760 "mtime bigint default 0,server_mtime bigint default 0,ctime bigint def"
2761 "ault 0,server_ctime bigint default 0,id varchar(255) default 'r',pare"
2762 "nt_id varchar(255) default 'r',server_parent_id varchar(255) default "
2763 "'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is_de"
2764 "l bit default 0,is_dir bit default 0,server_is_dir bit default 0,serv"
2765 "er_is_del bit default 0,non_unique_name varchar,server_non_unique_nam"
2766 "e varchar(255),unique_server_tag varchar,unique_client_tag varchar,un"
2767 "ique_bookmark_tag varchar,specifics blob,server_specifics blob,base_s"
2768 "erver_specifics blob,server_unique_position blob,unique_position blob"
2769 ",attachment_metadata blob);"
2770 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2771 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defau"
2772 "lt -2, cache_guid TEXT, notification_state BLOB, bag_of_chips BLOB);"
2773 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2774 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-131078,'"
2775 "9010788312004066376x-6609234393368420856x',NULL,NULL);"));
2776 ASSERT_TRUE(connection->CommitTransaction());
2777 }
2778
2779 void MigrationTest::SetUpVersion89Database(sql::Connection* connection) {
2780 ASSERT_TRUE(connection->is_open());
2781 ASSERT_TRUE(connection->BeginTransaction());
2782 ASSERT_TRUE(connection->Execute(
2783 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2784 "INSERT INTO 'share_version' VALUES('nick@chromium.org',89);"
2785 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, tr"
2786 "ansaction_version BIGINT default 0, context BLOB);"
2787 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1,NULL);"
2788 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
2789 "_version bigint default -1,server_version bigint default 0,local_exte"
2790 "rnal_id bigint default 0,transaction_version bigint default 0,mtime b"
2791 "igint default 0,server_mtime bigint default 0,ctime bigint default 0,"
2792 "server_ctime bigint default 0,id varchar(255) default 'r',parent_id v"
2793 "archar(255) default 'r',server_parent_id varchar(255) default 'r',is_"
2794 "unsynced bit default 0,is_unapplied_update bit default 0,is_del bit d"
2795 "efault 0,is_dir bit default 0,server_is_dir bit default 0,server_is_d"
2796 "el bit default 0,non_unique_name varchar,server_non_unique_name varch"
2797 "ar(255),unique_server_tag varchar,unique_client_tag varchar,unique_bo"
2798 "okmark_tag varchar,specifics blob,server_specifics blob,base_server_s"
2799 "pecifics blob,server_unique_position blob,unique_position blob,attach"
2800 "ment_metadata blob,server_attachment_metadata blob);"
2801 "INSERT INTO 'metas' VALUES(1,-1,0,0,0,"
2802 META_PROTO_TIMES_VALS(1)
2803 ",'r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',X'',NULL,X'2200'"
2804 ",X'2200',NULL,NULL);"
2805 "INSERT INTO 'metas' VALUES(6,694,694,6,0,"
2806 META_PROTO_TIMES_VALS(6)
2807 ",'s_ID_6','s_ID_9','s_ID_9',0,0,0,1,1,0,'The Internet','The Internet'"
2808 ",NULL,NULL,X'6754307476346749735A5734654D653273625336557753582F77673D"
2809 "',X'C2881000',X'C2881000',NULL,X'22247FFFFFFFFFC000006754307476346749"
2810 "735A5734654D653273625336557753582F77673D',X'22247FFFFFFFFFC0000067543"
2811 "07476346749735A5734654D653273625336557753582F77673D',NULL,NULL);"
2812 "INSERT INTO 'metas' VALUES(7,663,663,0,0,"
2813 META_PROTO_TIMES_VALS(7)
2814 ",'s_ID_7','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome','google"
2815 "_chrome',NULL,X'',NULL,NULL,NULL,X'2200',X'2200',NULL,NULL);"
2816 "INSERT INTO 'metas' VALUES(8,664,664,0,0,"
2817 META_PROTO_TIMES_VALS(8)
2818 ",'s_ID_8','s_ID_7','s_ID_7',0,0,0,1,1,0,'Bookmarks','Bookmarks','goog"
2819 "le_chrome_bookmarks',NULL,X'',X'C2881000',X'C2881000',NULL,X'2200',X'"
2820 "2200',NULL,NULL);"
2821 "INSERT INTO 'metas' VALUES(9,665,665,1,0,"
2822 META_PROTO_TIMES_VALS(9)
2823 ",'s_ID_9','s_ID_8','s_ID_8',0,0,0,1,1,0,'Bookmark Bar','Bookmark Bar'"
2824 ",'bookmark_bar',NULL,X'',X'C2881000',X'C2881000',NULL,X'2200',X'2200'"
2825 ",NULL,NULL);"
2826 "INSERT INTO 'metas' VALUES(10,666,666,2,0,"
2827 META_PROTO_TIMES_VALS(10)
2828 ",'s_ID_10','s_ID_8','s_ID_8',0,0,0,1,1,0,'Other Bookmarks','Other Boo"
2829 "kmarks','other_bookmarks',NULL,X'',X'C2881000',X'C2881000',NULL,X'220"
2830 "0',X'2200',NULL,NULL);"
2831 "INSERT INTO 'metas' VALUES(11,683,683,8,0,"
2832 META_PROTO_TIMES_VALS(11)
2833 ",'s_ID_11','s_ID_6','s_ID_6',0,0,0,0,0,0,'Home (The Chromium Projects"
2834 ")','Home (The Chromium Projects)',NULL,NULL,X'50514C784A456D623579366"
2835 "267644237646A7A2B62314130346E493D',X'C28810220A18687474703A2F2F646576"
2836 "2E6368726F6D69756D2E6F72672F1206414741545741',X'C28810290A1D687474703"
2837 "A2F2F6465762E6368726F6D69756D2E6F72672F6F7468657212084146414756415346"
2838 "',NULL,X'22247FFFFFFFFFF0000050514C784A456D623579366267644237646A7A2B"
2839 "62314130346E493D',X'22247FFFFFFFFFF0000050514C784A456D623579366267644"
2840 "237646A7A2B62314130346E493D',NULL,NULL);"
2841 "INSERT INTO 'metas' VALUES(12,685,685,9,0,"
2842 META_PROTO_TIMES_VALS(12)
2843 ",'s_ID_12','s_ID_6','s_ID_6',0,0,0,1,1,0,'Extra Bookmarks','Extra Boo"
2844 "kmarks',NULL,NULL,X'7867626A704A646134635A6F616C376A49513338734B46324"
2845 "837773D',X'C2881000',X'C2881000',NULL,X'222480000000000000007867626A7"
2846 "04A646134635A6F616C376A49513338734B46324837773D',X'222480000000000000"
2847 "007867626A704A646134635A6F616C376A49513338734B46324837773D',NULL,NULL"
2848 ");"
2849 "INSERT INTO 'metas' VALUES(13,687,687,10,0,"
2850 META_PROTO_TIMES_VALS(13)
2851 ",'s_ID_13','s_ID_6','s_ID_6',0,0,0,0,0,0,'ICANN | Internet Corporatio"
2852 "n for Assigned Names and Numbers','ICANN | Internet Corporation for A"
2853 "ssigned Names and Numbers',NULL,NULL,X'3142756B572F774176695650417967"
2854 "2B304A614A514B3452384A413D',X'C28810240A15687474703A2F2F7777772E69636"
2855 "16E6E2E636F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F"
2856 "2F7777772E6963616E6E2E636F6D2F120744414146415346',NULL,X'22247FFFFFFF"
2857 "FFF200003142756B572F7741766956504179672B304A614A514B3452384A413D',X'2"
2858 "2247FFFFFFFFFF200003142756B572F7741766956504179672B304A614A514B345238"
2859 "4A413D',NULL,NULL);"
2860 "INSERT INTO 'metas' VALUES(14,692,692,11,0,"
2861 META_PROTO_TIMES_VALS(14)
2862 ",'s_ID_14','s_ID_6','s_ID_6',0,0,0,0,0,0,'The WebKit Open Source Proj"
2863 "ect','The WebKit Open Source Project',NULL,NULL,X'5A5678314E797636457"
2864 "9524D3177494F7236563159552F6E644C553D',X'C288101A0A12687474703A2F2F77"
2865 "65626B69742E6F72672F1204504E4758',X'C288101C0A13687474703A2F2F7765626"
2866 "B69742E6F72672F781205504E473259',NULL,X'222480000000001000005A5678314"
2867 "E7976364579524D3177494F7236563159552F6E644C553D',X'222480000000001000"
2868 "005A5678314E7976364579524D3177494F7236563159552F6E644C553D',NULL,NULL"
2869 ");"
2870 "CREATE TABLE deleted_metas (metahandle bigint primary key ON CONFLICT FA"
2871 "IL,base_version bigint default -1,server_version bigint default 0,loc"
2872 "al_external_id bigint default 0,transaction_version bigint default 0,"
2873 "mtime bigint default 0,server_mtime bigint default 0,ctime bigint def"
2874 "ault 0,server_ctime bigint default 0,id varchar(255) default 'r',pare"
2875 "nt_id varchar(255) default 'r',server_parent_id varchar(255) default "
2876 "'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is_de"
2877 "l bit default 0,is_dir bit default 0,server_is_dir bit default 0,serv"
2878 "er_is_del bit default 0,non_unique_name varchar,server_non_unique_nam"
2879 "e varchar(255),unique_server_tag varchar,unique_client_tag varchar,un"
2880 "ique_bookmark_tag varchar,specifics blob,server_specifics blob,base_s"
2881 "erver_specifics blob,server_unique_position blob,unique_position blob"
2882 ",attachment_metadata blob,server_attachment_metadata blob);"
2883 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2884 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defau"
2885 "lt -2, cache_guid TEXT, notification_state BLOB, bag_of_chips BLOB);"
2886 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2887 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-131078,'"
2888 "9010788312004066376x-6609234393368420856x',NULL,NULL);"));
2889 ASSERT_TRUE(connection->CommitTransaction());
2890 }
2891
2892 void MigrationTest::SetUpVersion90Database(sql::Connection* connection) {
2893 ASSERT_TRUE(connection->is_open());
2894 ASSERT_TRUE(connection->BeginTransaction());
2895 ASSERT_TRUE(connection->Execute(
2896 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
2897 "INSERT INTO 'share_version' VALUES('nick@chromium.org',90);"
2898 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, tr"
2899 "ansaction_version BIGINT default 0, context BLOB);"
2900 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1,NULL);"
2901 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
2902 "_version bigint default -1,server_version bigint default 0,local_exte"
2903 "rnal_id bigint default 0,transaction_version bigint default 0,mtime b"
2904 "igint default 0,server_mtime bigint default 0,ctime bigint default 0,"
2905 "server_ctime bigint default 0,id varchar(255) default 'r',parent_id v"
2906 "archar(255) default 'r',server_parent_id varchar(255) default 'r',is_"
2907 "unsynced bit default 0,is_unapplied_update bit default 0,is_del bit d"
2908 "efault 0,is_dir bit default 0,server_is_dir bit default 0,server_is_d"
2909 "el bit default 0,non_unique_name varchar,server_non_unique_name varch"
2910 "ar(255),unique_server_tag varchar,unique_client_tag varchar,unique_bo"
2911 "okmark_tag varchar,specifics blob,server_specifics blob,base_server_s"
2912 "pecifics blob,server_unique_position blob,unique_position blob,attach"
2913 "ment_metadata blob,server_attachment_metadata blob);"
2914 "INSERT INTO 'metas' VALUES(1,-1,0,0,0,"
2915 META_PROTO_TIMES_VALS(1)
2916 ",'r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',X'',NULL,X'2200'"
2917 ",X'2200',NULL,NULL);"
2918 "INSERT INTO 'metas' VALUES(6,694,694,6,0,"
2919 META_PROTO_TIMES_VALS(6)
2920 ",'s_ID_6','s_ID_9','s_ID_9',0,0,0,1,1,0,'The Internet','The Internet'"
2921 ",NULL,NULL,X'6754307476346749735A5734654D653273625336557753582F77673D"
2922 "',X'C2881000',X'C2881000',NULL,X'22247FFFFFFFFFC000006754307476346749"
2923 "735A5734654D653273625336557753582F77673D',X'22247FFFFFFFFFC0000067543"
2924 "07476346749735A5734654D653273625336557753582F77673D',NULL,NULL);"
2925 "INSERT INTO 'metas' VALUES(7,663,663,0,0,"
2926 META_PROTO_TIMES_VALS(7)
2927 ",'s_ID_7','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome','google"
2928 "_chrome',NULL,X'',NULL,NULL,NULL,X'2200',X'2200',NULL,NULL);"
2929 "INSERT INTO 'metas' VALUES(8,664,664,0,0,"
2930 META_PROTO_TIMES_VALS(8)
2931 ",'s_ID_8','s_ID_7','s_ID_7',0,0,0,1,1,0,'Bookmarks','Bookmarks','goog"
2932 "le_chrome_bookmarks',NULL,X'',X'C2881000',X'C2881000',NULL,X'2200',X'"
2933 "2200',NULL,NULL);"
2934 "INSERT INTO 'metas' VALUES(9,665,665,1,0,"
2935 META_PROTO_TIMES_VALS(9)
2936 ",'s_ID_9','s_ID_8','s_ID_8',0,0,0,1,1,0,'Bookmark Bar','Bookmark Bar'"
2937 ",'bookmark_bar',NULL,X'',X'C2881000',X'C2881000',NULL,X'2200',X'2200'"
2938 ",NULL,NULL);"
2939 "INSERT INTO 'metas' VALUES(10,666,666,2,0,"
2940 META_PROTO_TIMES_VALS(10)
2941 ",'s_ID_10','s_ID_8','s_ID_8',0,0,0,1,1,0,'Other Bookmarks','Other Boo"
2942 "kmarks','other_bookmarks',NULL,X'',X'C2881000',X'C2881000',NULL,X'220"
2943 "0',X'2200',NULL,NULL);"
2944 "INSERT INTO 'metas' VALUES(11,683,683,8,0,"
2945 META_PROTO_TIMES_VALS(11)
2946 ",'s_ID_11','s_ID_6','s_ID_6',0,0,0,0,0,0,'Home (The Chromium Projects"
2947 ")','Home (The Chromium Projects)',NULL,NULL,X'50514C784A456D623579366"
2948 "267644237646A7A2B62314130346E493D',X'C28810220A18687474703A2F2F646576"
2949 "2E6368726F6D69756D2E6F72672F1206414741545741',X'C28810290A1D687474703"
2950 "A2F2F6465762E6368726F6D69756D2E6F72672F6F7468657212084146414756415346"
2951 "',NULL,X'22247FFFFFFFFFF0000050514C784A456D623579366267644237646A7A2B"
2952 "62314130346E493D',X'22247FFFFFFFFFF0000050514C784A456D623579366267644"
2953 "237646A7A2B62314130346E493D',NULL,NULL);"
2954 "INSERT INTO 'metas' VALUES(12,685,685,9,0,"
2955 META_PROTO_TIMES_VALS(12)
2956 ",'s_ID_12','s_ID_6','s_ID_6',0,0,0,1,1,0,'Extra Bookmarks','Extra Boo"
2957 "kmarks',NULL,NULL,X'7867626A704A646134635A6F616C376A49513338734B46324"
2958 "837773D',X'C2881000',X'C2881000',NULL,X'222480000000000000007867626A7"
2959 "04A646134635A6F616C376A49513338734B46324837773D',X'222480000000000000"
2960 "007867626A704A646134635A6F616C376A49513338734B46324837773D',NULL,NULL"
2961 ");"
2962 "INSERT INTO 'metas' VALUES(13,687,687,10,0,"
2963 META_PROTO_TIMES_VALS(13)
2964 ",'s_ID_13','s_ID_6','s_ID_6',0,0,0,0,0,0,'ICANN | Internet Corporatio"
2965 "n for Assigned Names and Numbers','ICANN | Internet Corporation for A"
2966 "ssigned Names and Numbers',NULL,NULL,X'3142756B572F774176695650417967"
2967 "2B304A614A514B3452384A413D',X'C28810240A15687474703A2F2F7777772E69636"
2968 "16E6E2E636F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F"
2969 "2F7777772E6963616E6E2E636F6D2F120744414146415346',NULL,X'22247FFFFFFF"
2970 "FFF200003142756B572F7741766956504179672B304A614A514B3452384A413D',X'2"
2971 "2247FFFFFFFFFF200003142756B572F7741766956504179672B304A614A514B345238"
2972 "4A413D',NULL,NULL);"
2973 "INSERT INTO 'metas' VALUES(14,692,692,11,0,"
2974 META_PROTO_TIMES_VALS(14)
2975 ",'s_ID_14','s_ID_6','s_ID_6',0,0,0,0,0,0,'The WebKit Open Source Proj"
2976 "ect','The WebKit Open Source Project',NULL,NULL,X'5A5678314E797636457"
2977 "9524D3177494F7236563159552F6E644C553D',X'C288101A0A12687474703A2F2F77"
2978 "65626B69742E6F72672F1204504E4758',X'C288101C0A13687474703A2F2F7765626"
2979 "B69742E6F72672F781205504E473259',NULL,X'222480000000001000005A5678314"
2980 "E7976364579524D3177494F7236563159552F6E644C553D',X'222480000000001000"
2981 "005A5678314E7976364579524D3177494F7236563159552F6E644C553D',NULL,NULL"
2982 ");"
2983 "CREATE TABLE deleted_metas (metahandle bigint primary key ON CONFLICT FA"
2984 "IL,base_version bigint default -1,server_version bigint default 0,loc"
2985 "al_external_id bigint default 0,transaction_version bigint default 0,"
2986 "mtime bigint default 0,server_mtime bigint default 0,ctime bigint def"
2987 "ault 0,server_ctime bigint default 0,id varchar(255) default 'r',pare"
2988 "nt_id varchar(255) default 'r',server_parent_id varchar(255) default "
2989 "'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is_de"
2990 "l bit default 0,is_dir bit default 0,server_is_dir bit default 0,serv"
2991 "er_is_del bit default 0,non_unique_name varchar,server_non_unique_nam"
2992 "e varchar(255),unique_server_tag varchar,unique_client_tag varchar,un"
2993 "ique_bookmark_tag varchar,specifics blob,server_specifics blob,base_s"
2994 "erver_specifics blob,server_unique_position blob,unique_position blob"
2995 ",attachment_metadata blob,server_attachment_metadata blob);"
2996 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
2997 "y TEXT, cache_guid TEXT, bag_of_chips BLOB);"
2998 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
2999 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','9010788312004066376x-66092343"
3000 "93368420856x',NULL);"));
3001 ASSERT_TRUE(connection->CommitTransaction());
3002 }
3003
3004 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) {
3005 sql::Connection connection;
3006 ASSERT_TRUE(connection.OpenInMemory());
3007
3008 SetUpVersion67Database(&connection);
3009
3010 // Columns existing before version 67.
3011 ASSERT_TRUE(connection.DoesColumnExist("metas", "name"));
3012 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name"));
3013 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name"));
3014
3015 std::unique_ptr<TestDirectoryBackingStore> dbs(
3016 new TestDirectoryBackingStore(GetUsername(), &connection));
3017
3018 ASSERT_FALSE(dbs->needs_column_refresh());
3019 ASSERT_TRUE(dbs->MigrateVersion67To68());
3020 ASSERT_EQ(68, dbs->GetVersion());
3021 ASSERT_TRUE(dbs->needs_column_refresh());
3022 }
3023
3024 TEST_F(DirectoryBackingStoreTest, MigrateVersion68To69) {
3025 sql::Connection connection;
3026 ASSERT_TRUE(connection.OpenInMemory());
3027 SetUpVersion68Database(&connection);
3028
3029 {
3030 std::unique_ptr<TestDirectoryBackingStore> dbs(
3031 new TestDirectoryBackingStore(GetUsername(), &connection));
3032
3033 ASSERT_FALSE(dbs->needs_column_refresh());
3034 ASSERT_TRUE(dbs->MigrateVersion68To69());
3035 ASSERT_EQ(69, dbs->GetVersion());
3036 ASSERT_TRUE(dbs->needs_column_refresh());
3037 }
3038
3039 ASSERT_TRUE(connection.DoesColumnExist("metas", "specifics"));
3040 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_specifics"));
3041 sql::Statement s(connection.GetUniqueStatement("SELECT non_unique_name,"
3042 "is_del, is_dir, id, specifics, server_specifics FROM metas "
3043 "WHERE metahandle = 2"));
3044 ASSERT_TRUE(s.Step());
3045 ASSERT_EQ("Deleted Item", s.ColumnString(0));
3046 ASSERT_TRUE(s.ColumnBool(1));
3047 ASSERT_FALSE(s.ColumnBool(2));
3048 ASSERT_EQ("s_ID_2", s.ColumnString(3));
3049 sync_pb::EntitySpecifics specifics;
3050 specifics.ParseFromArray(s.ColumnBlob(4), s.ColumnByteLength(4));
3051 ASSERT_TRUE(specifics.has_bookmark());
3052 ASSERT_EQ("http://www.google.com/", specifics.bookmark().url());
3053 ASSERT_EQ("AASGASGA", specifics.bookmark().favicon());
3054 specifics.ParseFromArray(s.ColumnBlob(5), s.ColumnByteLength(5));
3055 ASSERT_TRUE(specifics.has_bookmark());
3056 ASSERT_EQ("http://www.google.com/2", specifics.bookmark().url());
3057 ASSERT_EQ("ASADGADGADG", specifics.bookmark().favicon());
3058 ASSERT_FALSE(s.Step());
3059 }
3060
3061 TEST_F(DirectoryBackingStoreTest, MigrateVersion69To70) {
3062 sql::Connection connection;
3063 ASSERT_TRUE(connection.OpenInMemory());
3064 SetUpVersion69Database(&connection);
3065
3066 ASSERT_TRUE(connection.DoesColumnExist("metas", "singleton_tag"));
3067 ASSERT_FALSE(connection.DoesColumnExist("metas", "unique_server_tag"));
3068 ASSERT_FALSE(connection.DoesColumnExist("metas", "unique_client_tag"));
3069
3070 {
3071 std::unique_ptr<TestDirectoryBackingStore> dbs(
3072 new TestDirectoryBackingStore(GetUsername(), &connection));
3073
3074 ASSERT_FALSE(dbs->needs_column_refresh());
3075 ASSERT_TRUE(dbs->MigrateVersion69To70());
3076 ASSERT_EQ(70, dbs->GetVersion());
3077 ASSERT_TRUE(dbs->needs_column_refresh());
3078 }
3079
3080 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag"));
3081 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag"));
3082 sql::Statement s(connection.GetUniqueStatement("SELECT id"
3083 " FROM metas WHERE unique_server_tag = 'google_chrome'"));
3084 ASSERT_TRUE(s.Step());
3085 EXPECT_EQ("s_ID_7", s.ColumnString(0));
3086 }
3087
3088 TEST_F(DirectoryBackingStoreTest, MigrateVersion70To71) {
3089 sql::Connection connection;
3090 ASSERT_TRUE(connection.OpenInMemory());
3091 SetUpVersion70Database(&connection);
3092
3093 ASSERT_TRUE(connection.DoesColumnExist("share_info", "last_sync_timestamp"));
3094 ASSERT_TRUE(connection.DoesColumnExist("share_info", "initial_sync_ended"));
3095 ASSERT_FALSE(connection.DoesTableExist("models"));
3096
3097 {
3098 std::unique_ptr<TestDirectoryBackingStore> dbs(
3099 new TestDirectoryBackingStore(GetUsername(), &connection));
3100
3101 ASSERT_FALSE(dbs->needs_column_refresh());
3102 ASSERT_TRUE(dbs->MigrateVersion70To71());
3103 ASSERT_EQ(71, dbs->GetVersion());
3104 ASSERT_FALSE(dbs->needs_column_refresh());
3105 }
3106
3107 ASSERT_FALSE(connection.DoesColumnExist("share_info", "last_sync_timestamp"));
3108 ASSERT_FALSE(connection.DoesColumnExist("share_info", "initial_sync_ended"));
3109 ASSERT_TRUE(connection.DoesTableExist("models"));
3110 ASSERT_TRUE(connection.DoesColumnExist("models", "initial_sync_ended"));
3111 ASSERT_TRUE(connection.DoesColumnExist("models", "last_download_timestamp"));
3112 ASSERT_TRUE(connection.DoesColumnExist("models", "model_id"));
3113
3114 sql::Statement s(connection.GetUniqueStatement("SELECT model_id, "
3115 "initial_sync_ended, last_download_timestamp FROM models"));
3116 ASSERT_TRUE(s.Step());
3117 std::string model_id = s.ColumnString(0);
3118 EXPECT_EQ("C2881000", base::HexEncode(model_id.data(), model_id.size()))
3119 << "Model ID is expected to be the empty BookmarkSpecifics proto.";
3120 EXPECT_TRUE(s.ColumnBool(1));
3121 EXPECT_EQ(694, s.ColumnInt64(2));
3122 ASSERT_FALSE(s.Step());
3123 }
3124
3125
3126 TEST_F(DirectoryBackingStoreTest, MigrateVersion71To72) {
3127 sql::Connection connection;
3128 ASSERT_TRUE(connection.OpenInMemory());
3129 SetUpVersion71Database(&connection);
3130
3131 ASSERT_TRUE(connection.DoesTableExist("extended_attributes"));
3132
3133 {
3134 std::unique_ptr<TestDirectoryBackingStore> dbs(
3135 new TestDirectoryBackingStore(GetUsername(), &connection));
3136
3137 ASSERT_FALSE(dbs->needs_column_refresh());
3138 ASSERT_TRUE(dbs->MigrateVersion71To72());
3139 ASSERT_EQ(72, dbs->GetVersion());
3140 ASSERT_FALSE(dbs->needs_column_refresh());
3141 }
3142
3143 ASSERT_FALSE(connection.DoesTableExist("extended_attributes"));
3144 }
3145
3146 TEST_F(DirectoryBackingStoreTest, MigrateVersion72To73) {
3147 sql::Connection connection;
3148 ASSERT_TRUE(connection.OpenInMemory());
3149 SetUpVersion72Database(&connection);
3150
3151 ASSERT_FALSE(connection.DoesColumnExist("share_info", "notification_state"));
3152
3153 {
3154 std::unique_ptr<TestDirectoryBackingStore> dbs(
3155 new TestDirectoryBackingStore(GetUsername(), &connection));
3156
3157 ASSERT_FALSE(dbs->needs_column_refresh());
3158 ASSERT_TRUE(dbs->MigrateVersion72To73());
3159 ASSERT_EQ(73, dbs->GetVersion());
3160 ASSERT_FALSE(dbs->needs_column_refresh());
3161 }
3162
3163 ASSERT_TRUE(connection.DoesColumnExist("share_info", "notification_state"));
3164 }
3165
3166 TEST_F(DirectoryBackingStoreTest, MigrateVersion73To74) {
3167 sql::Connection connection;
3168 ASSERT_TRUE(connection.OpenInMemory());
3169 SetUpVersion73Database(&connection);
3170
3171 ASSERT_FALSE(
3172 connection.DoesColumnExist("share_info", "autofill_migration_state"));
3173 ASSERT_FALSE(
3174 connection.DoesColumnExist("share_info",
3175 "bookmarks_added_during_autofill_migration"));
3176 ASSERT_FALSE(
3177 connection.DoesColumnExist("share_info", "autofill_migration_time"));
3178 ASSERT_FALSE(
3179 connection.DoesColumnExist("share_info",
3180 "autofill_entries_added_during_migration"));
3181
3182 ASSERT_FALSE(
3183 connection.DoesColumnExist("share_info",
3184 "autofill_profiles_added_during_migration"));
3185
3186 {
3187 std::unique_ptr<TestDirectoryBackingStore> dbs(
3188 new TestDirectoryBackingStore(GetUsername(), &connection));
3189
3190 ASSERT_FALSE(dbs->needs_column_refresh());
3191 ASSERT_TRUE(dbs->MigrateVersion73To74());
3192 ASSERT_EQ(74, dbs->GetVersion());
3193 ASSERT_FALSE(dbs->needs_column_refresh());
3194 }
3195
3196 ASSERT_TRUE(
3197 connection.DoesColumnExist("share_info", "autofill_migration_state"));
3198 ASSERT_TRUE(
3199 connection.DoesColumnExist("share_info",
3200 "bookmarks_added_during_autofill_migration"));
3201 ASSERT_TRUE(
3202 connection.DoesColumnExist("share_info", "autofill_migration_time"));
3203 ASSERT_TRUE(
3204 connection.DoesColumnExist("share_info",
3205 "autofill_entries_added_during_migration"));
3206
3207 ASSERT_TRUE(
3208 connection.DoesColumnExist("share_info",
3209 "autofill_profiles_added_during_migration"));
3210 }
3211
3212 TEST_F(DirectoryBackingStoreTest, MigrateVersion74To75) {
3213 sql::Connection connection;
3214 ASSERT_TRUE(connection.OpenInMemory());
3215 SetUpVersion74Database(&connection);
3216
3217 ASSERT_FALSE(connection.DoesColumnExist("models", "progress_marker"));
3218 ASSERT_TRUE(connection.DoesColumnExist("models", "last_download_timestamp"));
3219
3220 {
3221 std::unique_ptr<TestDirectoryBackingStore> dbs(
3222 new TestDirectoryBackingStore(GetUsername(), &connection));
3223
3224 ASSERT_FALSE(dbs->needs_column_refresh());
3225 ASSERT_TRUE(dbs->MigrateVersion74To75());
3226 ASSERT_EQ(75, dbs->GetVersion());
3227 ASSERT_FALSE(dbs->needs_column_refresh());
3228 }
3229
3230 ASSERT_TRUE(connection.DoesColumnExist("models", "progress_marker"));
3231 ASSERT_FALSE(connection.DoesColumnExist("models", "last_download_timestamp"));
3232 }
3233
3234 TEST_F(DirectoryBackingStoreTest, MigrateVersion75To76) {
3235 sql::Connection connection;
3236 ASSERT_TRUE(connection.OpenInMemory());
3237 SetUpVersion75Database(&connection);
3238
3239 ASSERT_TRUE(
3240 connection.DoesColumnExist("share_info", "autofill_migration_state"));
3241 ASSERT_TRUE(connection.DoesColumnExist("share_info",
3242 "bookmarks_added_during_autofill_migration"));
3243 ASSERT_TRUE(
3244 connection.DoesColumnExist("share_info", "autofill_migration_time"));
3245 ASSERT_TRUE(connection.DoesColumnExist("share_info",
3246 "autofill_entries_added_during_migration"));
3247 ASSERT_TRUE(connection.DoesColumnExist("share_info",
3248 "autofill_profiles_added_during_migration"));
3249
3250 std::unique_ptr<TestDirectoryBackingStore> dbs(
3251 new TestDirectoryBackingStore(GetUsername(), &connection));
3252 ASSERT_FALSE(dbs->needs_column_refresh());
3253 ASSERT_TRUE(dbs->MigrateVersion75To76());
3254 ASSERT_EQ(76, dbs->GetVersion());
3255 ASSERT_TRUE(dbs->needs_column_refresh());
3256 // Cannot actual refresh columns due to version 76 not containing all
3257 // necessary columns.
3258 }
3259
3260 TEST_F(DirectoryBackingStoreTest, MigrateVersion76To77) {
3261 sql::Connection connection;
3262 ASSERT_TRUE(connection.OpenInMemory());
3263 SetUpVersion76Database(&connection);
3264
3265 std::unique_ptr<TestDirectoryBackingStore> dbs(
3266 new TestDirectoryBackingStore(GetUsername(), &connection));
3267 ASSERT_FALSE(dbs->needs_column_refresh());
3268
3269 EXPECT_EQ(GetExpectedLegacyMetaProtoTimes(INCLUDE_DELETED_ITEMS),
3270 GetMetaProtoTimes(&connection));
3271 // Since the proto times are expected to be in a legacy format, they may not
3272 // be compatible with ProtoTimeToTime, so we don't call ExpectTimes().
3273
3274 ASSERT_TRUE(dbs->MigrateVersion76To77());
3275 ASSERT_EQ(77, dbs->GetVersion());
3276
3277 EXPECT_EQ(GetExpectedMetaProtoTimes(INCLUDE_DELETED_ITEMS),
3278 GetMetaProtoTimes(&connection));
3279 // Cannot actually load entries due to version 77 not having all required
3280 // columns.
3281 ASSERT_FALSE(dbs->needs_column_refresh());
3282 }
3283
3284 TEST_F(DirectoryBackingStoreTest, MigrateVersion77To78) {
3285 sql::Connection connection;
3286 ASSERT_TRUE(connection.OpenInMemory());
3287 SetUpVersion77Database(&connection);
3288
3289 ASSERT_FALSE(connection.DoesColumnExist("metas", "BASE_SERVER_SPECIFICS"));
3290
3291 {
3292 std::unique_ptr<TestDirectoryBackingStore> dbs(
3293 new TestDirectoryBackingStore(GetUsername(), &connection));
3294 ASSERT_FALSE(dbs->needs_column_refresh());
3295 ASSERT_TRUE(dbs->MigrateVersion77To78());
3296 ASSERT_EQ(78, dbs->GetVersion());
3297
3298 ASSERT_FALSE(dbs->needs_column_refresh());
3299 }
3300
3301 ASSERT_TRUE(connection.DoesColumnExist("metas", "base_server_specifics"));
3302 }
3303
3304 TEST_F(DirectoryBackingStoreTest, MigrateVersion78To79) {
3305 sql::Connection connection;
3306 ASSERT_TRUE(connection.OpenInMemory());
3307 SetUpVersion78Database(&connection);
3308
3309 std::unique_ptr<TestDirectoryBackingStore> dbs(
3310 new TestDirectoryBackingStore(GetUsername(), &connection));
3311 ASSERT_FALSE(dbs->needs_column_refresh());
3312 ASSERT_TRUE(dbs->MigrateVersion78To79());
3313 ASSERT_EQ(79, dbs->GetVersion());
3314 ASSERT_FALSE(dbs->needs_column_refresh());
3315 }
3316
3317 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) {
3318 sql::Connection connection;
3319 ASSERT_TRUE(connection.OpenInMemory());
3320 SetUpVersion79Database(&connection);
3321
3322 std::unique_ptr<TestDirectoryBackingStore> dbs(
3323 new TestDirectoryBackingStore(GetUsername(), &connection));
3324 ASSERT_FALSE(dbs->needs_column_refresh());
3325 ASSERT_TRUE(dbs->MigrateVersion79To80());
3326 ASSERT_EQ(80, dbs->GetVersion());
3327 ASSERT_FALSE(dbs->needs_column_refresh());
3328
3329 // Ensure the bag_of_chips has been set.
3330 Directory::MetahandlesMap handles_map;
3331 JournalIndex delete_journals;
3332 MetahandleSet metahandles_to_purge;
3333 STLValueDeleter<Directory::MetahandlesMap> deleter(&handles_map);
3334 Directory::KernelLoadInfo load_info;
3335
3336 ASSERT_TRUE(dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge,
3337 &load_info));
3338 // Check that the initial value is the serialization of an empty ChipBag.
3339 sync_pb::ChipBag chip_bag;
3340 std::string serialized_chip_bag;
3341 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag));
3342 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips);
3343 }
3344
3345 TEST_F(DirectoryBackingStoreTest, MigrateVersion80To81) {
3346 sql::Connection connection;
3347 ASSERT_TRUE(connection.OpenInMemory());
3348 SetUpVersion80Database(&connection);
3349
3350 sql::Statement s(connection.GetUniqueStatement(
3351 "SELECT metahandle, server_position_in_parent "
3352 "FROM metas WHERE unique_server_tag = 'google_chrome'"));
3353 ASSERT_TRUE(s.Step());
3354 ASSERT_EQ(sql::COLUMN_TYPE_INTEGER, s.ColumnType(1));
3355
3356 std::unique_ptr<TestDirectoryBackingStore> dbs(
3357 new TestDirectoryBackingStore(GetUsername(), &connection));
3358 ASSERT_TRUE(dbs->MigrateVersion80To81());
3359 ASSERT_EQ(81, dbs->GetVersion());
3360
3361 // Test that ordinal values are preserved correctly.
3362 sql::Statement new_s(connection.GetUniqueStatement(
3363 "SELECT metahandle, server_ordinal_in_parent "
3364 "FROM metas WHERE unique_server_tag = 'google_chrome'"));
3365 ASSERT_TRUE(new_s.Step());
3366 ASSERT_EQ(sql::COLUMN_TYPE_BLOB, new_s.ColumnType(1));
3367
3368 std::string expected_ordinal = Int64ToNodeOrdinal(1048576).ToInternalValue();
3369 std::string actual_ordinal;
3370 new_s.ColumnBlobAsString(1, &actual_ordinal);
3371 ASSERT_EQ(expected_ordinal, actual_ordinal);
3372 }
3373
3374 TEST_F(DirectoryBackingStoreTest, MigrateVersion81To82) {
3375 sql::Connection connection;
3376 ASSERT_TRUE(connection.OpenInMemory());
3377 SetUpVersion81Database(&connection);
3378 ASSERT_FALSE(connection.DoesColumnExist("models", "transaction_version"));
3379
3380 std::unique_ptr<TestDirectoryBackingStore> dbs(
3381 new TestDirectoryBackingStore(GetUsername(), &connection));
3382 ASSERT_FALSE(dbs->needs_column_refresh());
3383 ASSERT_TRUE(dbs->MigrateVersion81To82());
3384 ASSERT_EQ(82, dbs->GetVersion());
3385 ASSERT_FALSE(dbs->needs_column_refresh());
3386
3387 ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version"));
3388 }
3389
3390 TEST_F(DirectoryBackingStoreTest, MigrateVersion82To83) {
3391 sql::Connection connection;
3392 ASSERT_TRUE(connection.OpenInMemory());
3393 SetUpVersion82Database(&connection);
3394 ASSERT_FALSE(connection.DoesColumnExist("metas", "transaction_version"));
3395
3396 std::unique_ptr<TestDirectoryBackingStore> dbs(
3397 new TestDirectoryBackingStore(GetUsername(), &connection));
3398 ASSERT_TRUE(dbs->MigrateVersion82To83());
3399 ASSERT_EQ(83, dbs->GetVersion());
3400
3401 ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version"));
3402 }
3403
3404 TEST_F(DirectoryBackingStoreTest, MigrateVersion83To84) {
3405 sql::Connection connection;
3406 ASSERT_TRUE(connection.OpenInMemory());
3407 SetUpVersion83Database(&connection);
3408 ASSERT_FALSE(connection.DoesTableExist("deleted_metas"));
3409
3410 std::unique_ptr<TestDirectoryBackingStore> dbs(
3411 new TestDirectoryBackingStore(GetUsername(), &connection));
3412 ASSERT_TRUE(dbs->MigrateVersion83To84());
3413 ASSERT_EQ(84, dbs->GetVersion());
3414
3415 ASSERT_TRUE(connection.DoesTableExist("deleted_metas"));
3416 }
3417
3418 TEST_F(DirectoryBackingStoreTest, MigrateVersion84To85) {
3419 sql::Connection connection;
3420 ASSERT_TRUE(connection.OpenInMemory());
3421 SetUpVersion84Database(&connection);
3422 ASSERT_TRUE(connection.DoesColumnExist("models", "initial_sync_ended"));
3423
3424 std::unique_ptr<TestDirectoryBackingStore> dbs(
3425 new TestDirectoryBackingStore(GetUsername(), &connection));
3426 ASSERT_TRUE(dbs->MigrateVersion84To85());
3427 ASSERT_EQ(85, dbs->GetVersion());
3428 ASSERT_FALSE(connection.DoesColumnExist("models", "initial_sync_ended"));
3429 }
3430
3431 TEST_F(DirectoryBackingStoreTest, MigrateVersion85To86) {
3432 sql::Connection connection;
3433 ASSERT_TRUE(connection.OpenInMemory());
3434 SetUpVersion85Database(&connection);
3435 EXPECT_TRUE(connection.DoesColumnExist("metas", "next_id"));
3436 EXPECT_TRUE(connection.DoesColumnExist("metas", "prev_id"));
3437 EXPECT_TRUE(connection.DoesColumnExist("metas", "server_ordinal_in_parent"));
3438 EXPECT_FALSE(connection.DoesColumnExist("metas", "unique_position"));
3439 EXPECT_FALSE(connection.DoesColumnExist("metas", "server_unique_position"));
3440 EXPECT_FALSE(connection.DoesColumnExist("metas", "unique_bookmark_tag"));
3441
3442 std::unique_ptr<TestDirectoryBackingStore> dbs(
3443 new TestDirectoryBackingStore(GetUsername(), &connection));
3444 ASSERT_TRUE(dbs->MigrateVersion85To86());
3445 EXPECT_EQ(86, dbs->GetVersion());
3446 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_position"));
3447 EXPECT_TRUE(connection.DoesColumnExist("metas", "server_unique_position"));
3448 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_bookmark_tag"));
3449 ASSERT_TRUE(dbs->needs_column_refresh());
3450 }
3451
3452 TEST_F(DirectoryBackingStoreTest, MigrateVersion86To87) {
3453 sql::Connection connection;
3454 EXPECT_TRUE(connection.OpenInMemory());
3455 SetUpVersion86Database(&connection);
3456 EXPECT_FALSE(connection.DoesColumnExist("metas", "attachment_metadata"));
3457
3458 std::unique_ptr<TestDirectoryBackingStore> dbs(
3459 new TestDirectoryBackingStore(GetUsername(), &connection));
3460 EXPECT_TRUE(dbs->MigrateVersion86To87());
3461 EXPECT_EQ(87, dbs->GetVersion());
3462 EXPECT_TRUE(connection.DoesColumnExist("metas", "attachment_metadata"));
3463 EXPECT_TRUE(dbs->needs_column_refresh());
3464 }
3465
3466 TEST_F(DirectoryBackingStoreTest, MigrateVersion87To88) {
3467 sql::Connection connection;
3468 ASSERT_TRUE(connection.OpenInMemory());
3469 SetUpVersion87Database(&connection);
3470
3471 std::unique_ptr<TestDirectoryBackingStore> dbs(
3472 new TestDirectoryBackingStore(GetUsername(), &connection));
3473 ASSERT_TRUE(dbs->MigrateVersion87To88());
3474 ASSERT_EQ(88, dbs->GetVersion());
3475 ASSERT_TRUE(connection.DoesColumnExist("models", "context"));
3476 }
3477
3478 TEST_F(DirectoryBackingStoreTest, MigrateVersion88To89) {
3479 sql::Connection connection;
3480 ASSERT_TRUE(connection.OpenInMemory());
3481 SetUpVersion88Database(&connection);
3482 ASSERT_FALSE(
3483 connection.DoesColumnExist("metas", "server_attachment_metadata"));
3484
3485 std::unique_ptr<TestDirectoryBackingStore> dbs(
3486 new TestDirectoryBackingStore(GetUsername(), &connection));
3487 ASSERT_TRUE(dbs->MigrateVersion88To89());
3488 ASSERT_EQ(89, dbs->GetVersion());
3489 EXPECT_TRUE(
3490 connection.DoesColumnExist("metas", "server_attachment_metadata"));
3491 EXPECT_TRUE(dbs->needs_column_refresh());
3492 }
3493
3494 TEST_F(DirectoryBackingStoreTest, MigrateVersion89To90) {
3495 sql::Connection connection;
3496 ASSERT_TRUE(connection.OpenInMemory());
3497 SetUpVersion89Database(&connection);
3498 ASSERT_TRUE(connection.DoesColumnExist("share_info", "db_create_version"));
3499 ASSERT_TRUE(connection.DoesColumnExist("share_info", "db_create_time"));
3500 ASSERT_TRUE(connection.DoesColumnExist("share_info", "next_id"));
3501 ASSERT_TRUE(connection.DoesColumnExist("share_info", "notification_state"));
3502
3503 std::unique_ptr<TestDirectoryBackingStore> dbs(
3504 new TestDirectoryBackingStore(GetUsername(), &connection));
3505 ASSERT_TRUE(dbs->MigrateVersion89To90());
3506 ASSERT_EQ(90, dbs->GetVersion());
3507 EXPECT_TRUE(dbs->needs_column_refresh());
3508
3509 ASSERT_TRUE(dbs->RefreshColumns());
3510 EXPECT_FALSE(dbs->needs_column_refresh());
3511
3512 ASSERT_FALSE(connection.DoesColumnExist("share_info", "db_create_version"));
3513 ASSERT_FALSE(connection.DoesColumnExist("share_info", "db_create_time"));
3514 ASSERT_FALSE(connection.DoesColumnExist("share_info", "next_id"));
3515 ASSERT_FALSE(connection.DoesColumnExist("share_info", "notification_state"));
3516 }
3517
3518 // The purpose of this test case is to make it easier to get a dump of the
3519 // database so you can implement a SetUpVersionYDatabase method. Here's what
3520 // you should do:
3521 //
3522 // 1. Say you're going from version X to version Y. Write the migration
3523 // method MigrateVersionXToY.
3524 // 2. Update the test below to call SetUpVersionXDatabase and then
3525 // MigrateVersionXToY. You now have a database at version Y. Let's dump it.
3526 // 3. Set a breakpoint to stop execution just after the connection is
3527 // destroyed. Examine temp_dir_ to find the version Y database that was
3528 // created on disk. E.g. (gdb) p temp_dir_.path().value().c_str()
3529 // 4. Dump the database using the sqlite3 command line tool:
3530 // > .output foo_dump.sql
3531 // > .dump
3532 // 5. Replace the timestamp columns with META_PROTO_TIMES(x) (or
3533 // LEGACY_META_PROTO_TIMES(x) if before Version 77). Use this dump to write
3534 // a SetupVersionYDatabase method.
3535 TEST_F(DirectoryBackingStoreTest, MigrateToLatestAndDump) {
3536 {
3537 sql::Connection connection;
3538 ASSERT_TRUE(connection.Open(GetDatabasePath()));
3539 SetUpVersion89Database(&connection); // Update this.
3540
3541 std::unique_ptr<TestDirectoryBackingStore> dbs(
3542 new TestDirectoryBackingStore(GetUsername(), &connection));
3543 ASSERT_TRUE(dbs->MigrateVersion89To90()); // Update this.
3544 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
3545 EXPECT_EQ(90, dbs->GetVersion()); // Update this.
3546 ASSERT_FALSE(dbs->needs_column_refresh());
3547 }
3548 // Set breakpoint here.
3549 }
3550
3551 TEST_F(DirectoryBackingStoreTest, DetectInvalidPosition) {
3552 sql::Connection connection;
3553 ASSERT_TRUE(connection.OpenInMemory());
3554 SetUpVersion86Database(&connection);
3555
3556 std::unique_ptr<TestDirectoryBackingStore> dbs(
3557 new TestDirectoryBackingStore(GetUsername(), &connection));
3558 ASSERT_EQ(86, dbs->GetVersion());
3559
3560 // Insert row with bad position.
3561 sql::Statement s(connection.GetUniqueStatement(
3562 "INSERT INTO metas "
3563 "( id, metahandle, is_dir, ctime, mtime,"
3564 " unique_position, server_unique_position) "
3565 "VALUES('c-invalid', 9999, 1, 0, 0, 'BAD_POS', 'BAD_POS')"));
3566 ASSERT_TRUE(s.Run());
3567
3568 // Trying to unpack this entry should signal that the DB is corrupted.
3569 Directory::MetahandlesMap handles_map;
3570 JournalIndex delete_journals;
3571 MetahandleSet metahandles_to_purge;
3572 STLValueDeleter<Directory::MetahandlesMap> deleter(&handles_map);
3573 Directory::KernelLoadInfo kernel_load_info;
3574 ASSERT_EQ(FAILED_DATABASE_CORRUPT,
3575 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge,
3576 &kernel_load_info));
3577 }
3578
3579 TEST_P(MigrationTest, ToCurrentVersion) {
3580 sql::Connection connection;
3581 ASSERT_TRUE(connection.Open(GetDatabasePath()));
3582 // Assume all old versions have an old page size.
3583 connection.set_page_size(4096);
3584 switch (GetParam()) {
3585 case 67:
3586 SetUpVersion67Database(&connection);
3587 break;
3588 case 68:
3589 SetUpVersion68Database(&connection);
3590 break;
3591 case 69:
3592 SetUpVersion69Database(&connection);
3593 break;
3594 case 70:
3595 SetUpVersion70Database(&connection);
3596 break;
3597 case 71:
3598 SetUpVersion71Database(&connection);
3599 break;
3600 case 72:
3601 SetUpVersion72Database(&connection);
3602 break;
3603 case 73:
3604 SetUpVersion73Database(&connection);
3605 break;
3606 case 74:
3607 SetUpVersion74Database(&connection);
3608 break;
3609 case 75:
3610 SetUpVersion75Database(&connection);
3611 break;
3612 case 76:
3613 SetUpVersion76Database(&connection);
3614 break;
3615 case 77:
3616 SetUpVersion77Database(&connection);
3617 break;
3618 case 78:
3619 SetUpVersion78Database(&connection);
3620 break;
3621 case 79:
3622 SetUpVersion79Database(&connection);
3623 break;
3624 case 80:
3625 SetUpVersion80Database(&connection);
3626 break;
3627 case 81:
3628 SetUpVersion81Database(&connection);
3629 break;
3630 case 82:
3631 SetUpVersion82Database(&connection);
3632 break;
3633 case 83:
3634 SetUpVersion83Database(&connection);
3635 break;
3636 case 84:
3637 SetUpVersion84Database(&connection);
3638 break;
3639 case 85:
3640 SetUpVersion85Database(&connection);
3641 break;
3642 case 86:
3643 SetUpVersion86Database(&connection);
3644 break;
3645 case 87:
3646 SetUpVersion87Database(&connection);
3647 break;
3648 case 88:
3649 SetUpVersion88Database(&connection);
3650 break;
3651 case 89:
3652 SetUpVersion89Database(&connection);
3653 break;
3654 case 90:
3655 SetUpVersion90Database(&connection);
3656 break;
3657 default:
3658 // If you see this error, it may mean that you've increased the
3659 // database version number but you haven't finished adding unit tests
3660 // for the database migration code. You need to need to supply a
3661 // SetUpVersionYDatabase function with a dump of the test database
3662 // at the new schema. See the MigrateToLatestAndDump test case.
3663 FAIL() << "Need to supply database dump for version " << GetParam();
3664 }
3665 connection.Close();
3666
3667 syncable::Directory::KernelLoadInfo dir_info;
3668 Directory::MetahandlesMap handles_map;
3669 JournalIndex delete_journals;
3670 MetahandleSet metahandles_to_purge;
3671 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
3672
3673 {
3674 std::unique_ptr<OnDiskDirectoryBackingStore> dbs(
3675 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
3676 ASSERT_EQ(OPENED, dbs->Load(&handles_map, &delete_journals,
3677 &metahandles_to_purge, &dir_info));
3678 if (!metahandles_to_purge.empty())
3679 dbs->DeleteEntries(DirectoryBackingStore::METAS_TABLE,
3680 metahandles_to_purge);
3681 ASSERT_FALSE(dbs->needs_column_refresh());
3682 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion());
3683 int pageSize = 0;
3684 ASSERT_TRUE(dbs->GetDatabasePageSize(&pageSize));
3685 ASSERT_EQ(kCurrentPageSizeKB, pageSize);
3686 }
3687
3688 ASSERT_TRUE(connection.Open(GetDatabasePath()));
3689
3690 // Columns deleted in Version 67.
3691 ASSERT_FALSE(connection.DoesColumnExist("metas", "name"));
3692 ASSERT_FALSE(connection.DoesColumnExist("metas", "unsanitized_name"));
3693 ASSERT_FALSE(connection.DoesColumnExist("metas", "server_name"));
3694
3695 // Columns added in Version 68.
3696 ASSERT_TRUE(connection.DoesColumnExist("metas", "specifics"));
3697 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_specifics"));
3698
3699 // Columns deleted in Version 68.
3700 ASSERT_FALSE(connection.DoesColumnExist("metas", "is_bookmark_object"));
3701 ASSERT_FALSE(connection.DoesColumnExist("metas",
3702 "server_is_bookmark_object"));
3703 ASSERT_FALSE(connection.DoesColumnExist("metas", "bookmark_favicon"));
3704 ASSERT_FALSE(connection.DoesColumnExist("metas", "bookmark_url"));
3705 ASSERT_FALSE(connection.DoesColumnExist("metas", "server_bookmark_url"));
3706
3707 // Renamed a column in Version 70
3708 ASSERT_FALSE(connection.DoesColumnExist("metas", "singleton_tag"));
3709 ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag"));
3710 ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag"));
3711
3712 // Removed extended attributes in Version 72.
3713 ASSERT_FALSE(connection.DoesTableExist("extended_attributes"));
3714
3715 // Column replaced in version 75.
3716 ASSERT_TRUE(connection.DoesColumnExist("models", "progress_marker"));
3717 ASSERT_FALSE(connection.DoesColumnExist("models", "last_download_timestamp"));
3718
3719 // Columns removed in version 76.
3720 ASSERT_FALSE(
3721 connection.DoesColumnExist("share_info", "autofill_migration_state"));
3722 ASSERT_FALSE(connection.DoesColumnExist("share_info",
3723 "bookmarks_added_during_autofill_migration"));
3724 ASSERT_FALSE(
3725 connection.DoesColumnExist("share_info", "autofill_migration_time"));
3726 ASSERT_FALSE(connection.DoesColumnExist("share_info",
3727 "autofill_entries_added_during_migration"));
3728 ASSERT_FALSE(connection.DoesColumnExist("share_info",
3729 "autofill_profiles_added_during_migration"));
3730
3731 // Column added in version 78.
3732 ASSERT_TRUE(connection.DoesColumnExist("metas", "base_server_specifics"));
3733
3734 // Column added in version 82.
3735 ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version"));
3736
3737 // Column added in version 83.
3738 ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version"));
3739
3740 // Table added in version 84.
3741 ASSERT_TRUE(connection.DoesTableExist("deleted_metas"));
3742
3743 // Column removed in version 85.
3744 ASSERT_FALSE(connection.DoesColumnExist("models", "initial_sync_ended"));
3745
3746 // Columns removed in version 86.
3747 ASSERT_FALSE(connection.DoesColumnExist("metas", "next_id"));
3748 ASSERT_FALSE(connection.DoesColumnExist("metas", "prev_id"));
3749 ASSERT_FALSE(connection.DoesColumnExist("metas", "server_ordinal_in_parent"));
3750
3751 // Column added in version 87.
3752 ASSERT_TRUE(connection.DoesColumnExist("metas", "attachment_metadata"));
3753
3754 // Column added in version 88.
3755 ASSERT_TRUE(connection.DoesColumnExist("models", "context"));
3756
3757 // Column added in version 89.
3758 ASSERT_TRUE(
3759 connection.DoesColumnExist("metas", "server_attachment_metadata"));
3760
3761 // Columns removed in version 90.
3762 ASSERT_FALSE(connection.DoesColumnExist("share_info", "db_create_version"));
3763 ASSERT_FALSE(connection.DoesColumnExist("share_info", "db_create_time"));
3764 ASSERT_FALSE(connection.DoesColumnExist("share_info", "next_id"));
3765 ASSERT_FALSE(connection.DoesColumnExist("share_info", "notification_state"));
3766
3767 // Check download_progress state (v75 migration)
3768 ASSERT_EQ(694,
3769 dir_info.kernel_info.download_progress[BOOKMARKS]
3770 .timestamp_token_for_migration());
3771 ASSERT_FALSE(
3772 dir_info.kernel_info.download_progress[BOOKMARKS]
3773 .has_token());
3774 ASSERT_EQ(32904,
3775 dir_info.kernel_info.download_progress[BOOKMARKS]
3776 .data_type_id());
3777 ASSERT_FALSE(
3778 dir_info.kernel_info.download_progress[THEMES]
3779 .has_timestamp_token_for_migration());
3780 ASSERT_TRUE(
3781 dir_info.kernel_info.download_progress[THEMES]
3782 .has_token());
3783 ASSERT_TRUE(
3784 dir_info.kernel_info.download_progress[THEMES]
3785 .token().empty());
3786 ASSERT_EQ(41210,
3787 dir_info.kernel_info.download_progress[THEMES]
3788 .data_type_id());
3789
3790 // Check metas
3791 EXPECT_EQ(GetExpectedMetaProtoTimes(DONT_INCLUDE_DELETED_ITEMS),
3792 GetMetaProtoTimes(&connection));
3793 ExpectTimes(handles_map, GetExpectedMetaTimes());
3794
3795 Directory::MetahandlesMap::iterator it = handles_map.find(1);
3796 ASSERT_TRUE(it != handles_map.end());
3797 ASSERT_EQ(1, it->second->ref(META_HANDLE));
3798 EXPECT_TRUE(it->second->ref(ID).IsRoot());
3799 EXPECT_FALSE(it->second->ref(UNIQUE_POSITION).IsValid());
3800 EXPECT_FALSE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3801 EXPECT_TRUE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
3802 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3803 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3804
3805 // Items 2, 4, and 5 were deleted.
3806 it = handles_map.find(2);
3807 ASSERT_TRUE(it == handles_map.end());
3808 it = handles_map.find(4);
3809 ASSERT_TRUE(it == handles_map.end());
3810 it = handles_map.find(5);
3811 ASSERT_TRUE(it == handles_map.end());
3812
3813 it = handles_map.find(6);
3814 ASSERT_EQ(6, it->second->ref(META_HANDLE));
3815 EXPECT_TRUE(it->second->ref(IS_DIR));
3816 EXPECT_TRUE(it->second->ref(SERVER_IS_DIR));
3817 EXPECT_FALSE(it->second->ref(SPECIFICS).bookmark().has_url());
3818 EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_url());
3819 EXPECT_FALSE(it->second->ref(SPECIFICS).bookmark().has_favicon());
3820 EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_favicon());
3821 EXPECT_TRUE(it->second->ref(UNIQUE_POSITION).IsValid());
3822 EXPECT_TRUE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3823 EXPECT_EQ(UniquePosition::kSuffixLength,
3824 it->second->ref(UNIQUE_BOOKMARK_TAG).length());
3825 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3826 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3827
3828 it = handles_map.find(7);
3829 ASSERT_EQ(7, it->second->ref(META_HANDLE));
3830 EXPECT_EQ("google_chrome", it->second->ref(UNIQUE_SERVER_TAG));
3831 EXPECT_FALSE(it->second->ref(SPECIFICS).has_bookmark());
3832 EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
3833 // Make sure we didn't assign positions to google_chrome.
3834 EXPECT_FALSE(it->second->ref(UNIQUE_POSITION).IsValid());
3835 EXPECT_FALSE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3836 EXPECT_TRUE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
3837 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3838 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3839
3840 it = handles_map.find(8);
3841 ASSERT_EQ(8, it->second->ref(META_HANDLE));
3842 EXPECT_EQ("google_chrome_bookmarks", it->second->ref(UNIQUE_SERVER_TAG));
3843 EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
3844 EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
3845 ASSERT_EQ(it->second->ref(ID).value(), "s_ID_8");
3846 // Make sure we didn't mistake the bookmark root node for a real bookmark.
3847 EXPECT_FALSE(it->second->ref(UNIQUE_POSITION).IsValid());
3848 EXPECT_FALSE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3849 EXPECT_TRUE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
3850 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3851 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3852
3853 it = handles_map.find(9);
3854 ASSERT_EQ(9, it->second->ref(META_HANDLE));
3855 EXPECT_EQ("bookmark_bar", it->second->ref(UNIQUE_SERVER_TAG));
3856 EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
3857 EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
3858 // Make sure we didn't assign positions to bookmark_bar.
3859 EXPECT_FALSE(it->second->ref(UNIQUE_POSITION).IsValid());
3860 EXPECT_FALSE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3861 EXPECT_TRUE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
3862 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3863 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3864
3865 it = handles_map.find(10);
3866 ASSERT_EQ(10, it->second->ref(META_HANDLE));
3867 EXPECT_FALSE(it->second->ref(IS_DEL));
3868 EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
3869 EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
3870 EXPECT_FALSE(it->second->ref(SPECIFICS).bookmark().has_url());
3871 EXPECT_FALSE(it->second->ref(SPECIFICS).bookmark().has_favicon());
3872 EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_url());
3873 EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_favicon());
3874 EXPECT_EQ("other_bookmarks", it->second->ref(UNIQUE_SERVER_TAG));
3875 EXPECT_EQ("Other Bookmarks", it->second->ref(NON_UNIQUE_NAME));
3876 EXPECT_EQ("Other Bookmarks", it->second->ref(SERVER_NON_UNIQUE_NAME));
3877 ASSERT_EQ(it->second->ref(ID).value(), "s_ID_10");
3878 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3879 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3880 // Make sure we didn't assign positions to server-created folders, either.
3881 EXPECT_FALSE(it->second->ref(UNIQUE_POSITION).IsValid());
3882 EXPECT_FALSE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3883 EXPECT_TRUE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
3884 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3885 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3886
3887 it = handles_map.find(11);
3888 ASSERT_EQ(11, it->second->ref(META_HANDLE));
3889 EXPECT_FALSE(it->second->ref(IS_DEL));
3890 EXPECT_FALSE(it->second->ref(IS_DIR));
3891 EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
3892 EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
3893 EXPECT_EQ("http://dev.chromium.org/",
3894 it->second->ref(SPECIFICS).bookmark().url());
3895 EXPECT_EQ("AGATWA", it->second->ref(SPECIFICS).bookmark().favicon());
3896 EXPECT_EQ("http://dev.chromium.org/other",
3897 it->second->ref(SERVER_SPECIFICS).bookmark().url());
3898 EXPECT_EQ("AFAGVASF", it->second->ref(SERVER_SPECIFICS).bookmark().favicon());
3899 EXPECT_EQ("", it->second->ref(UNIQUE_SERVER_TAG));
3900 EXPECT_EQ("Home (The Chromium Projects)", it->second->ref(NON_UNIQUE_NAME));
3901 EXPECT_EQ("Home (The Chromium Projects)",
3902 it->second->ref(SERVER_NON_UNIQUE_NAME));
3903 EXPECT_TRUE(it->second->ref(UNIQUE_POSITION).IsValid());
3904 EXPECT_TRUE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3905 EXPECT_EQ(UniquePosition::kSuffixLength,
3906 it->second->ref(UNIQUE_BOOKMARK_TAG).length());
3907 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3908
3909 it = handles_map.find(12);
3910 ASSERT_EQ(12, it->second->ref(META_HANDLE));
3911 EXPECT_FALSE(it->second->ref(IS_DEL));
3912 EXPECT_TRUE(it->second->ref(IS_DIR));
3913 EXPECT_EQ("Extra Bookmarks", it->second->ref(NON_UNIQUE_NAME));
3914 EXPECT_EQ("Extra Bookmarks", it->second->ref(SERVER_NON_UNIQUE_NAME));
3915 EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
3916 EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
3917 EXPECT_FALSE(it->second->ref(SPECIFICS).bookmark().has_url());
3918 EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_url());
3919 EXPECT_FALSE(it->second->ref(SPECIFICS).bookmark().has_favicon());
3920 EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_favicon());
3921 EXPECT_TRUE(it->second->ref(UNIQUE_POSITION).IsValid());
3922 EXPECT_TRUE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3923 EXPECT_EQ(UniquePosition::kSuffixLength,
3924 it->second->ref(UNIQUE_BOOKMARK_TAG).length());
3925 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3926 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3927
3928 it = handles_map.find(13);
3929 ASSERT_EQ(13, it->second->ref(META_HANDLE));
3930 EXPECT_TRUE(it->second->ref(UNIQUE_POSITION).IsValid());
3931 EXPECT_TRUE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3932 EXPECT_EQ(UniquePosition::kSuffixLength,
3933 it->second->ref(UNIQUE_BOOKMARK_TAG).length());
3934 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3935 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3936
3937 it = handles_map.find(14);
3938 ASSERT_EQ(14, it->second->ref(META_HANDLE));
3939 EXPECT_TRUE(it->second->ref(UNIQUE_POSITION).IsValid());
3940 EXPECT_TRUE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3941 EXPECT_EQ(UniquePosition::kSuffixLength,
3942 it->second->ref(UNIQUE_BOOKMARK_TAG).length());
3943 EXPECT_TRUE(it->second->ref(ATTACHMENT_METADATA).IsInitialized());
3944 EXPECT_TRUE(it->second->ref(SERVER_ATTACHMENT_METADATA).IsInitialized());
3945
3946 ASSERT_EQ(static_cast<size_t>(10), handles_map.size());
3947
3948 // Make sure that the syncable::Directory and the migration code agree on
3949 // which items should or should not have unique position values. This test
3950 // may become obsolete if the directory's definition of that function
3951 // changes, but, until then, this is a useful test.
3952 for (it = handles_map.begin(); it != handles_map.end(); it++) {
3953 SCOPED_TRACE(it->second->ref(ID));
3954 if (it->second->ShouldMaintainPosition()) {
3955 EXPECT_TRUE(it->second->ref(UNIQUE_POSITION).IsValid());
3956 EXPECT_TRUE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3957 EXPECT_FALSE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
3958 } else {
3959 EXPECT_FALSE(it->second->ref(UNIQUE_POSITION).IsValid());
3960 EXPECT_FALSE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
3961 EXPECT_TRUE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
3962 }
3963 }
3964 }
3965
3966 INSTANTIATE_TEST_CASE_P(DirectoryBackingStore, MigrationTest,
3967 testing::Range(67, kCurrentDBVersion + 1));
3968
3969 TEST_F(DirectoryBackingStoreTest, ModelTypeIds) {
3970 ModelTypeSet protocol_types = ProtocolTypes();
3971 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
3972 iter.Inc()) {
3973 std::string model_id =
3974 TestDirectoryBackingStore::ModelTypeEnumToModelId(iter.Get());
3975 EXPECT_EQ(iter.Get(),
3976 TestDirectoryBackingStore::ModelIdToModelTypeEnum(model_id.data(),
3977 model_id.size()));
3978 }
3979 }
3980
3981 namespace {
3982
3983 class OnDiskDirectoryBackingStoreForTest : public OnDiskDirectoryBackingStore {
3984 public:
3985 OnDiskDirectoryBackingStoreForTest(const std::string& dir_name,
3986 const base::FilePath& backing_filepath);
3987 ~OnDiskDirectoryBackingStoreForTest() override;
3988 bool DidFailFirstOpenAttempt();
3989
3990 protected:
3991 void ReportFirstTryOpenFailure() override;
3992
3993 private:
3994 bool first_open_failed_;
3995 };
3996
3997 OnDiskDirectoryBackingStoreForTest::OnDiskDirectoryBackingStoreForTest(
3998 const std::string& dir_name,
3999 const base::FilePath& backing_filepath) :
4000 OnDiskDirectoryBackingStore(dir_name, backing_filepath),
4001 first_open_failed_(false) { }
4002
4003 OnDiskDirectoryBackingStoreForTest::~OnDiskDirectoryBackingStoreForTest() { }
4004
4005 void OnDiskDirectoryBackingStoreForTest::ReportFirstTryOpenFailure() {
4006 // Do nothing, just like we would in release-mode. In debug mode, we DCHECK.
4007 first_open_failed_ = true;
4008 }
4009
4010 bool OnDiskDirectoryBackingStoreForTest::DidFailFirstOpenAttempt() {
4011 return first_open_failed_;
4012 }
4013
4014 } // namespace
4015
4016 // This is a whitebox test intended to exercise the code path where the on-disk
4017 // directory load code decides to delete the current directory and start fresh.
4018 //
4019 // This is considered "minor" corruption because the database recreation is
4020 // expected to succeed. The alternative, where recreation does not succeed (ie.
4021 // due to read-only file system), is not tested here.
4022 TEST_F(DirectoryBackingStoreTest, MinorCorruption) {
4023 {
4024 std::unique_ptr<OnDiskDirectoryBackingStore> dbs(
4025 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
4026 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4027 }
4028
4029 // Corrupt the root node.
4030 {
4031 sql::Connection connection;
4032 ASSERT_TRUE(connection.Open(GetDatabasePath()));
4033 ASSERT_TRUE(connection.Execute(
4034 "UPDATE metas SET parent_id='bogus' WHERE id = 'r';"));
4035 }
4036
4037 {
4038 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4039 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4040 GetDatabasePath()));
4041
4042 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4043 EXPECT_TRUE(dbs->DidFailFirstOpenAttempt());
4044 }
4045 }
4046
4047 TEST_F(DirectoryBackingStoreTest, MinorCorruptionAndUpgrade) {
4048 {
4049 std::unique_ptr<OnDiskDirectoryBackingStore> dbs(
4050 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
4051 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4052 }
4053
4054 // Make the node look outdated with an invalid version.
4055 {
4056 sql::Connection connection;
4057 ASSERT_TRUE(connection.Open(GetDatabasePath()));
4058 ASSERT_TRUE(connection.Execute("UPDATE share_version SET data = 0;"));
4059 ASSERT_TRUE(connection.Execute("PRAGMA page_size=4096;"));
4060 ASSERT_TRUE(connection.Execute("VACUUM;"));
4061 }
4062
4063 {
4064 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4065 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4066 GetDatabasePath()));
4067 dbs->SetCatastrophicErrorHandler(base::Bind(&base::DoNothing));
4068
4069 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4070 EXPECT_TRUE(dbs->DidFailFirstOpenAttempt());
4071
4072 int page_size = 0;
4073 ASSERT_TRUE(dbs->GetDatabasePageSize(&page_size));
4074 EXPECT_EQ(kCurrentPageSizeKB, page_size);
4075 }
4076 }
4077
4078 TEST_F(DirectoryBackingStoreTest, DeleteEntries) {
4079 sql::Connection connection;
4080 ASSERT_TRUE(connection.OpenInMemory());
4081
4082 SetUpCurrentDatabaseAndCheckVersion(&connection);
4083 std::unique_ptr<TestDirectoryBackingStore> dbs(
4084 new TestDirectoryBackingStore(GetUsername(), &connection));
4085 Directory::MetahandlesMap handles_map;
4086 JournalIndex delete_journals;
4087 MetahandleSet metahandles_to_purge;
4088 Directory::KernelLoadInfo kernel_load_info;
4089 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
4090
4091 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge,
4092 &kernel_load_info);
4093 size_t initial_size = handles_map.size();
4094 ASSERT_LT(0U, initial_size) << "Test requires handles_map to delete.";
4095 int64_t first_to_die = handles_map.begin()->second->ref(META_HANDLE);
4096 MetahandleSet to_delete;
4097 to_delete.insert(first_to_die);
4098 EXPECT_TRUE(dbs->DeleteEntries(to_delete));
4099
4100 STLDeleteValues(&handles_map);
4101 metahandles_to_purge.clear();
4102 dbs->LoadEntries(&handles_map, &metahandles_to_purge);
4103
4104 EXPECT_EQ(initial_size - 1, handles_map.size());
4105 bool delete_failed = false;
4106 for (Directory::MetahandlesMap::iterator it = handles_map.begin();
4107 it != handles_map.end(); ++it) {
4108 if (it->first == first_to_die) {
4109 delete_failed = true;
4110 break;
4111 }
4112 }
4113 EXPECT_FALSE(delete_failed);
4114
4115 to_delete.clear();
4116 for (Directory::MetahandlesMap::iterator it = handles_map.begin();
4117 it != handles_map.end(); ++it) {
4118 to_delete.insert(it->first);
4119 }
4120
4121 EXPECT_TRUE(dbs->DeleteEntries(to_delete));
4122
4123 STLDeleteValues(&handles_map);
4124 metahandles_to_purge.clear();
4125 dbs->LoadEntries(&handles_map, &metahandles_to_purge);
4126 EXPECT_EQ(0U, handles_map.size());
4127 }
4128
4129 TEST_F(DirectoryBackingStoreTest, GenerateCacheGUID) {
4130 const std::string& guid1 = TestDirectoryBackingStore::GenerateCacheGUID();
4131 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID();
4132 EXPECT_EQ(24U, guid1.size());
4133 EXPECT_EQ(24U, guid2.size());
4134 // In theory this test can fail, but it won't before the universe
4135 // dies of heat death.
4136 EXPECT_NE(guid1, guid2);
4137 }
4138
4139 TEST_F(DirectoryBackingStoreTest, IncreaseDatabasePageSizeFrom4KTo32K) {
4140 sql::Connection connection;
4141 ASSERT_TRUE(connection.Open(GetDatabasePath()));
4142
4143 SetUpCurrentDatabaseAndCheckVersion(&connection);
4144 std::unique_ptr<TestDirectoryBackingStore> dbs(
4145 new TestDirectoryBackingStore(GetUsername(), &connection));
4146 Directory::MetahandlesMap handles_map;
4147 JournalIndex delete_journals;
4148 MetahandleSet metahandles_to_purge;
4149 Directory::KernelLoadInfo kernel_load_info;
4150 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
4151
4152 DirOpenResult open_result = dbs->Load(
4153 &handles_map, &delete_journals, &metahandles_to_purge, &kernel_load_info);
4154 EXPECT_EQ(open_result, OPENED);
4155
4156 // Set up database's page size to 4096
4157 EXPECT_TRUE(dbs->db_->Execute("PRAGMA page_size=4096;"));
4158 EXPECT_TRUE(dbs->Vacuum());
4159
4160 // Check if update is successful.
4161 int pageSize = 0;
4162 EXPECT_TRUE(dbs->GetDatabasePageSize(&pageSize));
4163 EXPECT_NE(kCurrentPageSizeKB, pageSize);
4164 EXPECT_TRUE(dbs->UpdatePageSizeIfNecessary());
4165 pageSize = 0;
4166 EXPECT_TRUE(dbs->GetDatabasePageSize(&pageSize));
4167 EXPECT_EQ(kCurrentPageSizeKB, pageSize);
4168 }
4169
4170 // See that a catastrophic error handler remains set across instances of the
4171 // underlying sql:Connection.
4172 TEST_F(DirectoryBackingStoreTest, CatastrophicErrorHandler_KeptAcrossReset) {
4173 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4174 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath()));
4175 // See that by default there is no catastrophic error handler.
4176 ASSERT_FALSE(dbs->db_->has_error_callback());
4177 // Set one and see that it was set.
4178 dbs->SetCatastrophicErrorHandler(
4179 base::Bind(&CatastrophicErrorHandler, nullptr));
4180 ASSERT_TRUE(dbs->db_->has_error_callback());
4181 // Recreate the Connection and see that the handler remains set.
4182 dbs->ResetAndCreateConnection();
4183 ASSERT_TRUE(dbs->db_->has_error_callback());
4184 }
4185
4186 // Verify that database corruption encountered during Load will trigger the
4187 // catastrohpic error handler.
4188 TEST_F(DirectoryBackingStoreTest,
4189 CatastrophicErrorHandler_InvocationDuringLoad) {
4190 bool was_called = false;
4191 const base::Closure handler =
4192 base::Bind(&CatastrophicErrorHandler, &was_called);
4193 {
4194 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4195 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4196 GetDatabasePath()));
4197 dbs->SetCatastrophicErrorHandler(handler);
4198 ASSERT_TRUE(dbs->db_->has_error_callback());
4199 // Load the DB, and save one entry.
4200 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4201 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt());
4202 Directory::SaveChangesSnapshot snapshot;
4203 snapshot.dirty_metas.insert(CreateEntry(2, "").release());
4204 ASSERT_TRUE(dbs->SaveChanges(snapshot));
4205 }
4206
4207 base::RunLoop().RunUntilIdle();
4208 // No catastrophic errors have happened. See that it hasn't be called yet.
4209 ASSERT_FALSE(was_called);
4210
4211 // Corrupt the DB. Some forms of corruption (like this one) will be detected
4212 // upon loading the Sync DB.
4213 ASSERT_TRUE(sql::test::CorruptSizeInHeader(GetDatabasePath()));
4214
4215 {
4216 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4217 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4218 GetDatabasePath()));
4219 dbs->SetCatastrophicErrorHandler(handler);
4220 ASSERT_TRUE(dbs->db_->has_error_callback());
4221 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4222
4223 // See that the first open failed as expected.
4224 ASSERT_TRUE(dbs->DidFailFirstOpenAttempt());
4225 }
4226
4227 // At this point the handler has been posted but not executed.
4228 ASSERT_FALSE(was_called);
4229 // Pump the message loop and see that it is executed.
4230 base::RunLoop().RunUntilIdle();
4231 ASSERT_TRUE(was_called);
4232 }
4233
4234 // Verify that database corruption encountered during SaveChanges will trigger
4235 // the catastrohpic error handler.
4236 TEST_F(DirectoryBackingStoreTest,
4237 CatastrophicErrorHandler_InvocationDuringSaveChanges) {
4238 bool was_called = false;
4239 const base::Closure handler =
4240 base::Bind(&CatastrophicErrorHandler, &was_called);
4241 // Create a DB with many entries.
4242 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4243 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath()));
4244 dbs->SetCatastrophicErrorHandler(handler);
4245 ASSERT_TRUE(dbs->db_->has_error_callback());
4246 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4247 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt());
4248 Directory::SaveChangesSnapshot snapshot;
4249 const std::string suffix(400, 'o');
4250 for (int i = 0; i < corruption_testing::kNumEntriesRequiredForCorruption;
4251 ++i) {
4252 std::unique_ptr<EntryKernel> large_entry = CreateEntry(i, suffix);
4253 snapshot.dirty_metas.insert(large_entry.release());
4254 }
4255 ASSERT_TRUE(dbs->SaveChanges(snapshot));
4256 // Corrupt it.
4257 ASSERT_TRUE(corruption_testing::CorruptDatabase(GetDatabasePath()));
4258 // Attempt to save all those entries again. See that it fails (because of the
4259 // corruption).
4260 //
4261 // If this test fails because SaveChanges returned true, it may mean you need
4262 // to increase the number of entries written to the DB. See also
4263 // |kNumEntriesRequiredForCorruption|.
4264 ASSERT_FALSE(dbs->SaveChanges(snapshot));
4265 // At this point the handler has been posted but not executed.
4266 ASSERT_FALSE(was_called);
4267 // Pump the message loop and see that it is executed.
4268 base::RunLoop().RunUntilIdle();
4269 ASSERT_TRUE(was_called);
4270 }
4271
4272 } // namespace syncable
4273 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_backing_store.cc ('k') | sync/syncable/directory_change_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698