Home | History | Annotate | Download | only in syncable
      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 "testing/gtest/include/gtest/gtest.h"
      6 
      7 #include <string>
      8 
      9 #include "base/file_util.h"
     10 #include "base/files/file_path.h"
     11 #include "base/files/scoped_temp_dir.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/stl_util.h"
     14 #include "base/strings/string_number_conversions.h"
     15 #include "sql/connection.h"
     16 #include "sql/statement.h"
     17 #include "sync/base/sync_export.h"
     18 #include "sync/internal_api/public/base/node_ordinal.h"
     19 #include "sync/protocol/bookmark_specifics.pb.h"
     20 #include "sync/protocol/sync.pb.h"
     21 #include "sync/syncable/directory_backing_store.h"
     22 #include "sync/syncable/on_disk_directory_backing_store.h"
     23 #include "sync/syncable/syncable-inl.h"
     24 #include "sync/test/test_directory_backing_store.h"
     25 #include "sync/util/time.h"
     26 #include "testing/gtest/include/gtest/gtest-param-test.h"
     27 
     28 namespace syncer {
     29 namespace syncable {
     30 
     31 SYNC_EXPORT_PRIVATE extern const int32 kCurrentDBVersion;
     32 
     33 class MigrationTest : public testing::TestWithParam<int> {
     34  public:
     35   virtual void SetUp() {
     36     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
     37   }
     38 
     39  protected:
     40   std::string GetUsername() {
     41     return "nick (at) chromium.org";
     42   }
     43 
     44   base::FilePath GetDatabasePath() {
     45     return temp_dir_.path().Append(Directory::kSyncDatabaseFilename);
     46   }
     47 
     48   static bool LoadAndIgnoreReturnedData(DirectoryBackingStore *dbs) {
     49     Directory::MetahandlesMap tmp_handles_map;
     50     JournalIndex  delete_journals;
     51     STLValueDeleter<Directory::MetahandlesMap> deleter(&tmp_handles_map);
     52     Directory::KernelLoadInfo kernel_load_info;
     53     return dbs->Load(&tmp_handles_map, &delete_journals, &kernel_load_info) ==
     54         OPENED;
     55   }
     56 
     57   void SetUpVersion67Database(sql::Connection* connection);
     58   void SetUpVersion68Database(sql::Connection* connection);
     59   void SetUpVersion69Database(sql::Connection* connection);
     60   void SetUpVersion70Database(sql::Connection* connection);
     61   void SetUpVersion71Database(sql::Connection* connection);
     62   void SetUpVersion72Database(sql::Connection* connection);
     63   void SetUpVersion73Database(sql::Connection* connection);
     64   void SetUpVersion74Database(sql::Connection* connection);
     65   void SetUpVersion75Database(sql::Connection* connection);
     66   void SetUpVersion76Database(sql::Connection* connection);
     67   void SetUpVersion77Database(sql::Connection* connection);
     68   void SetUpVersion78Database(sql::Connection* connection);
     69   void SetUpVersion79Database(sql::Connection* connection);
     70   void SetUpVersion80Database(sql::Connection* connection);
     71   void SetUpVersion81Database(sql::Connection* connection);
     72   void SetUpVersion82Database(sql::Connection* connection);
     73   void SetUpVersion83Database(sql::Connection* connection);
     74   void SetUpVersion84Database(sql::Connection* connection);
     75   void SetUpVersion85Database(sql::Connection* connection);
     76   void SetUpVersion86Database(sql::Connection* connection);
     77 
     78   void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) {
     79     SetUpVersion86Database(connection);  // Prepopulates data.
     80     scoped_ptr<TestDirectoryBackingStore> dbs(
     81         new TestDirectoryBackingStore(GetUsername(), connection));
     82     ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion());
     83 
     84     ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
     85     ASSERT_FALSE(dbs->needs_column_refresh_);
     86   }
     87 
     88  private:
     89   base::ScopedTempDir temp_dir_;
     90 };
     91 
     92 class DirectoryBackingStoreTest : public MigrationTest {};
     93 
     94 #if defined(OS_WIN)
     95 
     96 // On Windows, we used to store timestamps in FILETIME format.
     97 #define LEGACY_META_PROTO_TIMES_1 129079956640320000LL
     98 #define LEGACY_META_PROTO_TIMES_2 128976886618480000LL
     99 #define LEGACY_META_PROTO_TIMES_4 129002163642690000LL
    100 #define LEGACY_META_PROTO_TIMES_5 129001555500000000LL
    101 #define LEGACY_META_PROTO_TIMES_6 129053976170000000LL
    102 #define LEGACY_META_PROTO_TIMES_7 128976864758480000LL
    103 #define LEGACY_META_PROTO_TIMES_8 128976864758480000LL
    104 #define LEGACY_META_PROTO_TIMES_9 128976864758480000LL
    105 #define LEGACY_META_PROTO_TIMES_10 128976864758480000LL
    106 #define LEGACY_META_PROTO_TIMES_11 129079956948440000LL
    107 #define LEGACY_META_PROTO_TIMES_12 129079957513650000LL
    108 #define LEGACY_META_PROTO_TIMES_13 129079957985300000LL
    109 #define LEGACY_META_PROTO_TIMES_14 129079958383000000LL
    110 
    111 #define LEGACY_META_PROTO_TIMES_STR_1 "129079956640320000"
    112 #define LEGACY_META_PROTO_TIMES_STR_2 "128976886618480000"
    113 #define LEGACY_META_PROTO_TIMES_STR_4 "129002163642690000"
    114 #define LEGACY_META_PROTO_TIMES_STR_5 "129001555500000000"
    115 #define LEGACY_META_PROTO_TIMES_STR_6 "129053976170000000"
    116 #define LEGACY_META_PROTO_TIMES_STR_7 "128976864758480000"
    117 #define LEGACY_META_PROTO_TIMES_STR_8 "128976864758480000"
    118 #define LEGACY_META_PROTO_TIMES_STR_9 "128976864758480000"
    119 #define LEGACY_META_PROTO_TIMES_STR_10 "128976864758480000"
    120 #define LEGACY_META_PROTO_TIMES_STR_11 "129079956948440000"
    121 #define LEGACY_META_PROTO_TIMES_STR_12 "129079957513650000"
    122 #define LEGACY_META_PROTO_TIMES_STR_13 "129079957985300000"
    123 #define LEGACY_META_PROTO_TIMES_STR_14 "129079958383000000"
    124 
    125 // Generated via:
    126 //
    127 // ruby -ane '$F[1].sub!("LEGACY_", ""); $F[2] = Integer($F[2].sub!("LL", "")) /
    128 //    10000 - 11644473600000; print "#{$F[0]} #{$F[1]} #{$F[2]}LL"'
    129 //
    130 // Magic numbers taken from
    131 // http://stackoverflow.com/questions/5398557/
    132 //    java-library-for-dealing-with-win32-filetime .
    133 
    134 // Now we store them in Java format (ms since the Unix epoch).
    135 #define META_PROTO_TIMES_1 1263522064032LL
    136 #define META_PROTO_TIMES_2 1253215061848LL
    137 #define META_PROTO_TIMES_4 1255742764269LL
    138 #define META_PROTO_TIMES_5 1255681950000LL
    139 #define META_PROTO_TIMES_6 1260924017000LL
    140 #define META_PROTO_TIMES_7 1253212875848LL
    141 #define META_PROTO_TIMES_8 1253212875848LL
    142 #define META_PROTO_TIMES_9 1253212875848LL
    143 #define META_PROTO_TIMES_10 1253212875848LL
    144 #define META_PROTO_TIMES_11 1263522094844LL
    145 #define META_PROTO_TIMES_12 1263522151365LL
    146 #define META_PROTO_TIMES_13 1263522198530LL
    147 #define META_PROTO_TIMES_14 1263522238300LL
    148 
    149 #define META_PROTO_TIMES_STR_1 "1263522064032"
    150 #define META_PROTO_TIMES_STR_2 "1253215061848"
    151 #define META_PROTO_TIMES_STR_4 "1255742764269"
    152 #define META_PROTO_TIMES_STR_5 "1255681950000"
    153 #define META_PROTO_TIMES_STR_6 "1260924017000"
    154 #define META_PROTO_TIMES_STR_7 "1253212875848"
    155 #define META_PROTO_TIMES_STR_8 "1253212875848"
    156 #define META_PROTO_TIMES_STR_9 "1253212875848"
    157 #define META_PROTO_TIMES_STR_10 "1253212875848"
    158 #define META_PROTO_TIMES_STR_11 "1263522094844"
    159 #define META_PROTO_TIMES_STR_12 "1263522151365"
    160 #define META_PROTO_TIMES_STR_13 "1263522198530"
    161 #define META_PROTO_TIMES_STR_14 "1263522238300"
    162 
    163 #else
    164 
    165 // On other platforms, we used to store timestamps in time_t format (s
    166 // since the Unix epoch).
    167 #define LEGACY_META_PROTO_TIMES_1 1263522064LL
    168 #define LEGACY_META_PROTO_TIMES_2 1253215061LL
    169 #define LEGACY_META_PROTO_TIMES_4 1255742764LL
    170 #define LEGACY_META_PROTO_TIMES_5 1255681950LL
    171 #define LEGACY_META_PROTO_TIMES_6 1260924017LL
    172 #define LEGACY_META_PROTO_TIMES_7 1253212875LL
    173 #define LEGACY_META_PROTO_TIMES_8 1253212875LL
    174 #define LEGACY_META_PROTO_TIMES_9 1253212875LL
    175 #define LEGACY_META_PROTO_TIMES_10 1253212875LL
    176 #define LEGACY_META_PROTO_TIMES_11 1263522094LL
    177 #define LEGACY_META_PROTO_TIMES_12 1263522151LL
    178 #define LEGACY_META_PROTO_TIMES_13 1263522198LL
    179 #define LEGACY_META_PROTO_TIMES_14 1263522238LL
    180 
    181 #define LEGACY_META_PROTO_TIMES_STR_1 "1263522064"
    182 #define LEGACY_META_PROTO_TIMES_STR_2 "1253215061"
    183 #define LEGACY_META_PROTO_TIMES_STR_4 "1255742764"
    184 #define LEGACY_META_PROTO_TIMES_STR_5 "1255681950"
    185 #define LEGACY_META_PROTO_TIMES_STR_6 "1260924017"
    186 #define LEGACY_META_PROTO_TIMES_STR_7 "1253212875"
    187 #define LEGACY_META_PROTO_TIMES_STR_8 "1253212875"
    188 #define LEGACY_META_PROTO_TIMES_STR_9 "1253212875"
    189 #define LEGACY_META_PROTO_TIMES_STR_10 "1253212875"
    190 #define LEGACY_META_PROTO_TIMES_STR_11 "1263522094"
    191 #define LEGACY_META_PROTO_TIMES_STR_12 "1263522151"
    192 #define LEGACY_META_PROTO_TIMES_STR_13 "1263522198"
    193 #define LEGACY_META_PROTO_TIMES_STR_14 "1263522238"
    194 
    195 // Now we store them in Java format (ms since the Unix epoch).
    196 #define META_PROTO_TIMES_1 1263522064000LL
    197 #define META_PROTO_TIMES_2 1253215061000LL
    198 #define META_PROTO_TIMES_4 1255742764000LL
    199 #define META_PROTO_TIMES_5 1255681950000LL
    200 #define META_PROTO_TIMES_6 1260924017000LL
    201 #define META_PROTO_TIMES_7 1253212875000LL
    202 #define META_PROTO_TIMES_8 1253212875000LL
    203 #define META_PROTO_TIMES_9 1253212875000LL
    204 #define META_PROTO_TIMES_10 1253212875000LL
    205 #define META_PROTO_TIMES_11 1263522094000LL
    206 #define META_PROTO_TIMES_12 1263522151000LL
    207 #define META_PROTO_TIMES_13 1263522198000LL
    208 #define META_PROTO_TIMES_14 1263522238000LL
    209 
    210 #define META_PROTO_TIMES_STR_1 "1263522064000"
    211 #define META_PROTO_TIMES_STR_2 "1253215061000"
    212 #define META_PROTO_TIMES_STR_4 "1255742764000"
    213 #define META_PROTO_TIMES_STR_5 "1255681950000"
    214 #define META_PROTO_TIMES_STR_6 "1260924017000"
    215 #define META_PROTO_TIMES_STR_7 "1253212875000"
    216 #define META_PROTO_TIMES_STR_8 "1253212875000"
    217 #define META_PROTO_TIMES_STR_9 "1253212875000"
    218 #define META_PROTO_TIMES_STR_10 "1253212875000"
    219 #define META_PROTO_TIMES_STR_11 "1263522094000"
    220 #define META_PROTO_TIMES_STR_12 "1263522151000"
    221 #define META_PROTO_TIMES_STR_13 "1263522198000"
    222 #define META_PROTO_TIMES_STR_14 "1263522238000"
    223 
    224 #endif
    225 
    226 // Helper macros for the database dumps in the SetUpVersion*Database
    227 // functions.
    228 #define LEGACY_META_PROTO_TIMES(x) LEGACY_META_PROTO_TIMES_##x
    229 #define LEGACY_META_PROTO_TIMES_STR(x) LEGACY_META_PROTO_TIMES_STR_##x
    230 #define LEGACY_PROTO_TIME_VALS(x)    \
    231   LEGACY_META_PROTO_TIMES_STR(x) "," \
    232   LEGACY_META_PROTO_TIMES_STR(x) "," \
    233   LEGACY_META_PROTO_TIMES_STR(x) "," \
    234   LEGACY_META_PROTO_TIMES_STR(x)
    235 #define META_PROTO_TIMES(x) META_PROTO_TIMES_##x
    236 #define META_PROTO_TIMES_STR(x) META_PROTO_TIMES_STR_##x
    237 #define META_PROTO_TIMES_VALS(x)    \
    238   META_PROTO_TIMES_STR(x) "," \
    239   META_PROTO_TIMES_STR(x) "," \
    240   META_PROTO_TIMES_STR(x) "," \
    241   META_PROTO_TIMES_STR(x)
    242 
    243 namespace {
    244 
    245 // Helper functions for testing.
    246 
    247 enum ShouldIncludeDeletedItems {
    248   INCLUDE_DELETED_ITEMS,
    249   DONT_INCLUDE_DELETED_ITEMS
    250 };
    251 
    252 // Returns a map from metahandle -> expected legacy time (in proto
    253 // format).
    254 std::map<int64, int64> GetExpectedLegacyMetaProtoTimes(
    255     enum ShouldIncludeDeletedItems include_deleted) {
    256   std::map<int64, int64> expected_legacy_meta_proto_times;
    257   expected_legacy_meta_proto_times[1] = LEGACY_META_PROTO_TIMES(1);
    258   if (include_deleted == INCLUDE_DELETED_ITEMS) {
    259     expected_legacy_meta_proto_times[2] = LEGACY_META_PROTO_TIMES(2);
    260     expected_legacy_meta_proto_times[4] = LEGACY_META_PROTO_TIMES(4);
    261     expected_legacy_meta_proto_times[5] = LEGACY_META_PROTO_TIMES(5);
    262   }
    263   expected_legacy_meta_proto_times[6] = LEGACY_META_PROTO_TIMES(6);
    264   expected_legacy_meta_proto_times[7] = LEGACY_META_PROTO_TIMES(7);
    265   expected_legacy_meta_proto_times[8] = LEGACY_META_PROTO_TIMES(8);
    266   expected_legacy_meta_proto_times[9] = LEGACY_META_PROTO_TIMES(9);
    267   expected_legacy_meta_proto_times[10] = LEGACY_META_PROTO_TIMES(10);
    268   expected_legacy_meta_proto_times[11] = LEGACY_META_PROTO_TIMES(11);
    269   expected_legacy_meta_proto_times[12] = LEGACY_META_PROTO_TIMES(12);
    270   expected_legacy_meta_proto_times[13] = LEGACY_META_PROTO_TIMES(13);
    271   expected_legacy_meta_proto_times[14] = LEGACY_META_PROTO_TIMES(14);
    272   return expected_legacy_meta_proto_times;
    273 }
    274 
    275 // Returns a map from metahandle -> expected time (in proto format).
    276 std::map<int64, int64> GetExpectedMetaProtoTimes(
    277     enum ShouldIncludeDeletedItems include_deleted) {
    278   std::map<int64, int64> expected_meta_proto_times;
    279   expected_meta_proto_times[1] = META_PROTO_TIMES(1);
    280   if (include_deleted == INCLUDE_DELETED_ITEMS) {
    281     expected_meta_proto_times[2] = META_PROTO_TIMES(2);
    282     expected_meta_proto_times[4] = META_PROTO_TIMES(4);
    283     expected_meta_proto_times[5] = META_PROTO_TIMES(5);
    284   }
    285   expected_meta_proto_times[6] = META_PROTO_TIMES(6);
    286   expected_meta_proto_times[7] = META_PROTO_TIMES(7);
    287   expected_meta_proto_times[8] = META_PROTO_TIMES(8);
    288   expected_meta_proto_times[9] = META_PROTO_TIMES(9);
    289   expected_meta_proto_times[10] = META_PROTO_TIMES(10);
    290   expected_meta_proto_times[11] = META_PROTO_TIMES(11);
    291   expected_meta_proto_times[12] = META_PROTO_TIMES(12);
    292   expected_meta_proto_times[13] = META_PROTO_TIMES(13);
    293   expected_meta_proto_times[14] = META_PROTO_TIMES(14);
    294   return expected_meta_proto_times;
    295 }
    296 
    297 // Returns a map from metahandle -> expected time (as a Time object).
    298 std::map<int64, base::Time> GetExpectedMetaTimes() {
    299   std::map<int64, base::Time> expected_meta_times;
    300   const std::map<int64, int64>& expected_meta_proto_times =
    301       GetExpectedMetaProtoTimes(INCLUDE_DELETED_ITEMS);
    302   for (std::map<int64, int64>::const_iterator it =
    303            expected_meta_proto_times.begin();
    304        it != expected_meta_proto_times.end(); ++it) {
    305     expected_meta_times[it->first] = ProtoTimeToTime(it->second);
    306   }
    307   return expected_meta_times;
    308 }
    309 
    310 // Extracts a map from metahandle -> time (in proto format) from the
    311 // given database.
    312 std::map<int64, int64> GetMetaProtoTimes(sql::Connection *db) {
    313   sql::Statement s(db->GetCachedStatement(
    314           SQL_FROM_HERE,
    315           "SELECT metahandle, mtime, server_mtime, ctime, server_ctime "
    316           "FROM metas"));
    317   EXPECT_EQ(5, s.ColumnCount());
    318   std::map<int64, int64> meta_times;
    319   while (s.Step()) {
    320     int64 metahandle = s.ColumnInt64(0);
    321     int64 mtime = s.ColumnInt64(1);
    322     int64 server_mtime = s.ColumnInt64(2);
    323     int64 ctime = s.ColumnInt64(3);
    324     int64 server_ctime = s.ColumnInt64(4);
    325     EXPECT_EQ(mtime, server_mtime);
    326     EXPECT_EQ(mtime, ctime);
    327     EXPECT_EQ(mtime, server_ctime);
    328     meta_times[metahandle] = mtime;
    329   }
    330   EXPECT_TRUE(s.Succeeded());
    331   return meta_times;
    332 }
    333 
    334 ::testing::AssertionResult AssertTimesMatch(const char* t1_expr,
    335                                             const char* t2_expr,
    336                                             const base::Time& t1,
    337                                             const base::Time& t2) {
    338   if (t1 == t2)
    339     return ::testing::AssertionSuccess();
    340 
    341   return ::testing::AssertionFailure()
    342       << t1_expr << " and " << t2_expr
    343       << " (internal values: " << t1.ToInternalValue()
    344       << " and " << t2.ToInternalValue()
    345       << ") (proto time: " << TimeToProtoTime(t1)
    346       << " and " << TimeToProtoTime(t2)
    347       << ") do not match";
    348 }
    349 
    350 // Expect that all time fields of the given entry kernel will be the
    351 // given time.
    352 void ExpectTime(const EntryKernel& entry_kernel,
    353                 const base::Time& expected_time) {
    354   EXPECT_PRED_FORMAT2(AssertTimesMatch,
    355                       expected_time, entry_kernel.ref(CTIME));
    356   EXPECT_PRED_FORMAT2(AssertTimesMatch,
    357                       expected_time, entry_kernel.ref(SERVER_CTIME));
    358   EXPECT_PRED_FORMAT2(AssertTimesMatch,
    359                       expected_time, entry_kernel.ref(MTIME));
    360   EXPECT_PRED_FORMAT2(AssertTimesMatch,
    361                       expected_time, entry_kernel.ref(SERVER_MTIME));
    362 }
    363 
    364 // Expect that all the entries in |entries| have times matching those in
    365 // the given map (from metahandle to expect time).
    366 void ExpectTimes(const Directory::MetahandlesMap& handles_map,
    367                  const std::map<int64, base::Time>& expected_times) {
    368   for (Directory::MetahandlesMap::const_iterator it = handles_map.begin();
    369        it != handles_map.end(); ++it) {
    370     int64 meta_handle = it->first;
    371     SCOPED_TRACE(meta_handle);
    372     std::map<int64, base::Time>::const_iterator it2 =
    373         expected_times.find(meta_handle);
    374     if (it2 == expected_times.end()) {
    375       ADD_FAILURE() << "Could not find expected time for " << meta_handle;
    376       continue;
    377     }
    378     ExpectTime(*it->second, it2->second);
    379   }
    380 }
    381 
    382 }  // namespace
    383 
    384 void MigrationTest::SetUpVersion67Database(sql::Connection* connection) {
    385   // This is a version 67 database dump whose contents were backformed from
    386   // the contents of the version 68 database dump (the v68 migration was
    387   // actually written first).
    388   ASSERT_TRUE(connection->is_open());
    389   ASSERT_TRUE(connection->BeginTransaction());
    390   ASSERT_TRUE(connection->Execute(
    391       "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
    392           "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
    393       "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL,"
    394           "base_version bigint default -1,server_version bigint default 0,"
    395           "mtime bigint default 0,server_mtime bigint default 0,"
    396           "ctime bigint default 0,server_ctime bigint default 0,"
    397           "server_position_in_parent bigint default 0,"
    398           "local_external_id bigint default 0,id varchar(255) default 'r',"
    399           "parent_id varchar(255) default 'r',"
    400           "server_parent_id varchar(255) default 'r',"
    401           "prev_id varchar(255) default 'r',next_id varchar(255) default 'r',"
    402           "is_unsynced bit default 0,is_unapplied_update bit default 0,"
    403           "is_del bit default 0,is_dir bit default 0,"
    404           "is_bookmark_object bit default 0,server_is_dir bit default 0,"
    405           "server_is_del bit default 0,server_is_bookmark_object bit default 0,"
    406           "name varchar(255), "  /* COLLATE PATHNAME, */
    407           "unsanitized_name varchar(255)," /* COLLATE PATHNAME, */
    408           "non_unique_name varchar,"
    409           "server_name varchar(255),"  /* COLLATE PATHNAME */
    410           "server_non_unique_name varchar,"
    411           "bookmark_url varchar,server_bookmark_url varchar,"
    412           "singleton_tag varchar,bookmark_favicon blob,"
    413           "server_bookmark_favicon blob);"
    414       "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
    415           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,0,0,NULL,"
    416           "NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);"
    417       "INSERT INTO metas VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
    418           ",-2097152,"
    419           "4,'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,1,0,1,1,"
    420           "'Deleted Item',NULL,'Deleted Item','Deleted Item','Deleted Item',"
    421           "'http://www.google.com/','http://www.google.com/2',NULL,'AASGASGA',"
    422           "'ASADGADGADG');"
    423       "INSERT INTO metas VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
    424           ",-3145728,"
    425           "3,'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,1,0,1,1,"
    426           "'Welcome to Chromium',NULL,'Welcome to Chromium',"
    427           "'Welcome to Chromium','Welcome to Chromium',"
    428           "'http://www.google.com/chrome/intl/en/welcome.html',"
    429           "'http://www.google.com/chrome/intl/en/welcome.html',NULL,NULL,"
    430           "NULL);"
    431       "INSERT INTO metas VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
    432           ",1048576,"
    433           "7,'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,1,0,1,1,"
    434           "'Google',NULL,'Google','Google','Google','http://www.google.com/',"
    435           "'http://www.google.com/',NULL,'AGASGASG','AGFDGASG');"
    436       "INSERT INTO metas VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
    437           ",-4194304,"
    438           "6,'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,1,0,1,"
    439           "'The Internet',NULL,'The Internet','The Internet',"
    440           "'The Internet',NULL,NULL,NULL,NULL,NULL);"
    441       "INSERT INTO metas VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
    442           ","
    443           "1048576,0,'s_ID_7','r','r','r','r',0,0,0,1,1,1,0,1,"
    444           "'Google Chrome',NULL,'Google Chrome','Google Chrome',"
    445           "'Google Chrome',NULL,NULL,'google_chrome',NULL,NULL);"
    446       "INSERT INTO metas VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
    447           ",1048576,"
    448           "0,'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,1,0,1,'Bookmarks',"
    449           "NULL,'Bookmarks','Bookmarks','Bookmarks',NULL,NULL,"
    450           "'google_chrome_bookmarks',NULL,NULL);"
    451       "INSERT INTO metas VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
    452           ","
    453           "1048576,1,'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,1,0,"
    454           "1,'Bookmark Bar',NULL,'Bookmark Bar','Bookmark Bar','Bookmark Bar',"
    455           "NULL,NULL,'bookmark_bar',NULL,NULL);"
    456       "INSERT INTO metas VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
    457           ",2097152,"
    458           "2,'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,1,0,1,"
    459           "'Other Bookmarks',NULL,'Other Bookmarks','Other Bookmarks',"
    460           "'Other Bookmarks',NULL,NULL,'other_bookmarks',"
    461           "NULL,NULL);"
    462       "INSERT INTO metas VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
    463           ",-1048576,"
    464           "8,'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,1,0,0,1,"
    465           "'Home (The Chromium Projects)',NULL,'Home (The Chromium Projects)',"
    466           "'Home (The Chromium Projects)','Home (The Chromium Projects)',"
    467           "'http://dev.chromium.org/','http://dev.chromium.org/other',NULL,"
    468           "'AGATWA','AFAGVASF');"
    469       "INSERT INTO metas VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
    470           ",0,9,"
    471           "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,1,0,1,"
    472           "'Extra Bookmarks',NULL,'Extra Bookmarks','Extra Bookmarks',"
    473           "'Extra Bookmarks',NULL,NULL,NULL,NULL,NULL);"
    474       "INSERT INTO metas VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
    475           ",-917504,"
    476           "10,'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,1,0,0,"
    477           "1,'ICANN | Internet Corporation for Assigned Names and Numbers',"
    478           "'ICANN  Internet Corporation for Assigned Names and Numbers',"
    479           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
    480           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
    481           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
    482           "'http://www.icann.com/','http://www.icann.com/',NULL,"
    483           "'PNGAXF0AAFF','DAAFASF');"
    484       "INSERT INTO metas VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
    485           ",1048576,"
    486           "11,'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,1,0,0,1,"
    487           "'The WebKit Open Source Project',NULL,"
    488           "'The WebKit Open Source Project','The WebKit Open Source Project',"
    489           "'The WebKit Open Source Project','http://webkit.org/',"
    490           "'http://webkit.org/x',NULL,'PNGX','PNG2Y');"
    491       "CREATE TABLE share_info (id VARCHAR(128) primary key, "
    492           "last_sync_timestamp INT, name VARCHAR(128), "
    493           "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), "
    494           "db_create_version VARCHAR(128), db_create_time int, "
    495           "next_id bigint default -2, cache_guid VARCHAR(32));"
    496       "INSERT INTO share_info VALUES('nick (at) chromium.org',694,"
    497           "'nick (at) chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb',"
    498           "'Unknown',1263522064,-65542,"
    499           "'9010788312004066376x-6609234393368420856x');"
    500       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
    501       "INSERT INTO share_version VALUES('nick (at) chromium.org',68);"));
    502   ASSERT_TRUE(connection->CommitTransaction());
    503 }
    504 
    505 void MigrationTest::SetUpVersion68Database(sql::Connection* connection) {
    506   // This sets up an actual version 68 database dump.  The IDs were
    507   // canonicalized to be less huge, and the favicons were overwritten
    508   // with random junk so that they didn't contain any unprintable
    509   // characters.  A few server URLs were tweaked so that they'd be
    510   // different from the local URLs.  Lastly, the custom collation on
    511   // the server_non_unique_name column was removed.
    512   ASSERT_TRUE(connection->is_open());
    513   ASSERT_TRUE(connection->BeginTransaction());
    514   ASSERT_TRUE(connection->Execute(
    515       "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
    516           "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
    517       "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL,"
    518           "base_version bigint default -1,server_version bigint default 0,"
    519           "mtime bigint default 0,server_mtime bigint default 0,"
    520           "ctime bigint default 0,server_ctime bigint default 0,"
    521           "server_position_in_parent bigint default 0,"
    522           "local_external_id bigint default 0,id varchar(255) default 'r',"
    523           "parent_id varchar(255) default 'r',"
    524           "server_parent_id varchar(255) default 'r',"
    525           "prev_id varchar(255) default 'r',next_id varchar(255) default 'r',"
    526           "is_unsynced bit default 0,is_unapplied_update bit default 0,"
    527           "is_del bit default 0,is_dir bit default 0,"
    528           "is_bookmark_object bit default 0,server_is_dir bit default 0,"
    529           "server_is_del bit default 0,"
    530           "server_is_bookmark_object bit default 0,"
    531           "non_unique_name varchar,server_non_unique_name varchar(255),"
    532           "bookmark_url varchar,server_bookmark_url varchar,"
    533           "singleton_tag varchar,bookmark_favicon blob,"
    534           "server_bookmark_favicon blob);"
    535       "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
    536           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,0,0,NULL,"
    537           "NULL,NULL,NULL,NULL,NULL,NULL);"
    538       "INSERT INTO metas VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
    539           ",-2097152,"
    540           "4,'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,1,0,1,1,"
    541           "'Deleted Item','Deleted Item','http://www.google.com/',"
    542           "'http://www.google.com/2',NULL,'AASGASGA','ASADGADGADG');"
    543       "INSERT INTO metas VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
    544           ",-3145728,"
    545           "3,'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,1,0,1,1,"
    546           "'Welcome to Chromium','Welcome to Chromium',"
    547           "'http://www.google.com/chrome/intl/en/welcome.html',"
    548           "'http://www.google.com/chrome/intl/en/welcome.html',NULL,NULL,"
    549           "NULL);"
    550       "INSERT INTO metas VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
    551           ",1048576,"
    552           "7,'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,1,0,1,1,"
    553           "'Google','Google','http://www.google.com/',"
    554           "'http://www.google.com/',NULL,'AGASGASG','AGFDGASG');"
    555       "INSERT INTO metas VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
    556           ",-4194304,"
    557           "6,'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,1,0,1,"
    558           "'The Internet','The Internet',NULL,NULL,NULL,NULL,NULL);"
    559       "INSERT INTO metas VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
    560           ","
    561           "1048576,0,'s_ID_7','r','r','r','r',0,0,0,1,1,1,0,1,"
    562           "'Google Chrome','Google Chrome',NULL,NULL,'google_chrome',NULL,"
    563           "NULL);"
    564       "INSERT INTO metas VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
    565           ",1048576,"
    566           "0,'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,1,0,1,'Bookmarks',"
    567           "'Bookmarks',NULL,NULL,'google_chrome_bookmarks',NULL,NULL);"
    568       "INSERT INTO metas VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
    569           ","
    570           "1048576,1,'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,1,0,"
    571           "1,'Bookmark Bar','Bookmark Bar',NULL,NULL,'bookmark_bar',NULL,"
    572           "NULL);"
    573       "INSERT INTO metas VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
    574           ",2097152,"
    575           "2,'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,1,0,1,"
    576           "'Other Bookmarks','Other Bookmarks',NULL,NULL,'other_bookmarks',"
    577           "NULL,NULL);"
    578       "INSERT INTO metas VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
    579           ",-1048576,"
    580           "8,'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,1,0,0,1,"
    581           "'Home (The Chromium Projects)','Home (The Chromium Projects)',"
    582           "'http://dev.chromium.org/','http://dev.chromium.org/other',NULL,"
    583           "'AGATWA','AFAGVASF');"
    584       "INSERT INTO metas VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
    585           ",0,9,"
    586           "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,1,0,1,"
    587           "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,NULL,NULL,NULL);"
    588       "INSERT INTO metas VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
    589           ",-917504,"
    590           "10,'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,1,0,0,"
    591           "1,'ICANN | Internet Corporation for Assigned Names and Numbers',"
    592           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
    593           "'http://www.icann.com/','http://www.icann.com/',NULL,"
    594           "'PNGAXF0AAFF','DAAFASF');"
    595       "INSERT INTO metas VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
    596           ",1048576,"
    597           "11,'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,1,0,0,1,"
    598           "'The WebKit Open Source Project','The WebKit Open Source Project',"
    599           "'http://webkit.org/','http://webkit.org/x',NULL,'PNGX','PNG2Y');"
    600       "CREATE TABLE share_info (id VARCHAR(128) primary key, "
    601           "last_sync_timestamp INT, name VARCHAR(128), "
    602           "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), "
    603           "db_create_version VARCHAR(128), db_create_time int, "
    604           "next_id bigint default -2, cache_guid VARCHAR(32));"
    605       "INSERT INTO share_info VALUES('nick (at) chromium.org',694,"
    606           "'nick (at) chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb',"
    607           "'Unknown',1263522064,-65542,"
    608           "'9010788312004066376x-6609234393368420856x');"
    609       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
    610       "INSERT INTO share_version VALUES('nick (at) chromium.org',68);"));
    611   ASSERT_TRUE(connection->CommitTransaction());
    612 }
    613 
    614 void MigrationTest::SetUpVersion69Database(sql::Connection* connection) {
    615   ASSERT_TRUE(connection->is_open());
    616   ASSERT_TRUE(connection->BeginTransaction());
    617   ASSERT_TRUE(connection->Execute(
    618       "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
    619           "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
    620       "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL,"
    621           "base_version bigint default -1,server_version bigint default 0,"
    622           "mtime bigint default 0,server_mtime bigint default 0,"
    623           "ctime bigint default 0,server_ctime bigint default 0,"
    624           "server_position_in_parent bigint default 0,"
    625           "local_external_id bigint default 0,id varchar(255) default 'r',"
    626           "parent_id varchar(255) default 'r',"
    627           "server_parent_id varchar(255) default 'r',"
    628           "prev_id varchar(255) default 'r',next_id varchar(255) default 'r',"
    629           "is_unsynced bit default 0,is_unapplied_update bit default 0,"
    630           "is_del bit default 0,is_dir bit default 0,"
    631           "is_bookmark_object bit default 0,server_is_dir bit default 0,"
    632           "server_is_del bit default 0,"
    633           "server_is_bookmark_object bit default 0,"
    634           "non_unique_name varchar,server_non_unique_name varchar(255),"
    635           "bookmark_url varchar,server_bookmark_url varchar,"
    636           "singleton_tag varchar,bookmark_favicon blob,"
    637           "server_bookmark_favicon blob, specifics blob, "
    638           "server_specifics blob);"
    639       "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
    640           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,0,0,NULL,NULL,NULL,NULL,NULL,"
    641           "NULL,NULL,X'',X'');"
    642       "INSERT INTO metas VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
    643           ",-2097152,"
    644           "4,'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,1,0,1,1,"
    645           "'Deleted Item','Deleted Item','http://www.google.com/',"
    646           "'http://www.google.com/2',NULL,'AASGASGA','ASADGADGADG',"
    647           "X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D2F120841415"
    648           "34741534741',X'C28810260A17687474703A2F2F7777772E676F6F676C652E636F"
    649           "6D2F32120B4153414447414447414447');"
    650       "INSERT INTO metas VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
    651           ",-3145728,"
    652           "3,'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,1,0,1,1,"
    653           "'Welcome to Chromium','Welcome to Chromium',"
    654           "'http://www.google.com/chrome/intl/en/welcome.html',"
    655           "'http://www.google.com/chrome/intl/en/welcome.html',NULL,NULL,NULL,"
    656           "X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
    657           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A3168"
    658           "7474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F6"
    659           "56E2F77656C636F6D652E68746D6C1200');"
    660       "INSERT INTO metas VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
    661           ",1048576,7,"
    662           "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,1,0,1,1,"
    663           "'Google','Google','http://www.google.com/',"
    664           "'http://www.google.com/',NULL,'AGASGASG','AGFDGASG',X'C28810220A166"
    665           "87474703A2F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'"
    666           "C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464"
    667           "447415347');"
    668       "INSERT INTO metas VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
    669           ",-4194304,6"
    670           ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,1,0,1,'The Internet',"
    671           "'The Internet',NULL,NULL,NULL,NULL,NULL,X'C2881000',X'C2881000');"
    672       "INSERT INTO metas VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
    673           ",1048576,0,"
    674           "'s_ID_7','r','r','r','r',0,0,0,1,1,1,0,1,'Google Chrome',"
    675           "'Google Chrome',NULL,NULL,'google_chrome',NULL,NULL,NULL,NULL);"
    676       "INSERT INTO metas VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
    677           ",1048576,0,"
    678           "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,1,0,1,'Bookmarks',"
    679           "'Bookmarks',NULL,NULL,'google_chrome_bookmarks',NULL,NULL,"
    680           "X'C2881000',X'C2881000');"
    681       "INSERT INTO metas VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
    682           ",1048576,1,"
    683           "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,1,0,1,"
    684           "'Bookmark Bar','Bookmark Bar',NULL,NULL,'bookmark_bar',NULL,NULL,"
    685           "X'C2881000',X'C2881000');"
    686       "INSERT INTO metas VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
    687           ",2097152,2,"
    688           "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,1,0,1,"
    689           "'Other Bookmarks','Other Bookmarks',NULL,NULL,'other_bookmarks',"
    690           "NULL,NULL,X'C2881000',X'C2881000');"
    691       "INSERT INTO metas VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
    692           ",-1048576,"
    693           "8,'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,1,0,0,1,"
    694           "'Home (The Chromium Projects)','Home (The Chromium Projects)',"
    695           "'http://dev.chromium.org/','http://dev.chromium.org/other',NULL,"
    696           "'AGATWA','AFAGVASF',X'C28810220A18687474703A2F2F6465762E6368726F6D6"
    697           "9756D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F646576"
    698           "2E6368726F6D69756D2E6F72672F6F7468657212084146414756415346');"
    699       "INSERT INTO metas VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
    700           ",0,9,"
    701           "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,1,0,1,"
    702           "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,NULL,NULL,NULL,"
    703           "X'C2881000',X'C2881000');"
    704       "INSERT INTO metas VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
    705           ",-917504,"
    706           "10,'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,1,0,0,"
    707           "1,'ICANN | Internet Corporation for Assigned Names and Numbers',"
    708           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
    709           "'http://www.icann.com/','http://www.icann.com/',NULL,'PNGAXF0AAFF',"
    710           "'DAAFASF',X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F1"
    711           "20B504E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963"
    712           "616E6E2E636F6D2F120744414146415346');"
    713       "INSERT INTO metas VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
    714           ",1048576,11,"
    715           "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,1,0,0,1,"
    716           "'The WebKit Open Source Project','The WebKit Open Source Project',"
    717           "'http://webkit.org/','http://webkit.org/x',NULL,'PNGX','PNG2Y',"
    718           "X'C288101A0A12687474703A2F2F7765626B69742E6F72672F1204504E4758',X'C2"
    719           "88101C0A13687474703A2F2F7765626B69742E6F72672F781205504E473259');"
    720       "CREATE TABLE share_info (id VARCHAR(128) primary key, "
    721           "last_sync_timestamp INT, name VARCHAR(128), "
    722           "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), "
    723           "db_create_version VARCHAR(128), db_create_time int, "
    724           "next_id bigint default -2, cache_guid VARCHAR(32));"
    725       "INSERT INTO share_info VALUES('nick (at) chromium.org',694,"
    726           "'nick (at) chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb',"
    727           "'Unknown',1263522064,-65542,"
    728           "'9010788312004066376x-6609234393368420856x');"
    729       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
    730       "INSERT INTO share_version VALUES('nick (at) chromium.org',69);"
    731   ));
    732   ASSERT_TRUE(connection->CommitTransaction());
    733 }
    734 
    735 void MigrationTest::SetUpVersion70Database(sql::Connection* connection) {
    736   ASSERT_TRUE(connection->is_open());
    737   ASSERT_TRUE(connection->BeginTransaction());
    738   ASSERT_TRUE(connection->Execute(
    739       "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
    740           "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
    741       "CREATE TABLE share_info (id VARCHAR(128) primary key, "
    742           "last_sync_timestamp INT, name VARCHAR(128), "
    743           "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), "
    744           "db_create_version VARCHAR(128), db_create_time int, "
    745           "next_id bigint default -2, cache_guid VARCHAR(32));"
    746       "INSERT INTO share_info VALUES('nick (at) chromium.org',694,"
    747           "'nick (at) chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb',"
    748           "'Unknown',1263522064,-65542,"
    749           "'9010788312004066376x-6609234393368420856x');"
    750       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
    751       "INSERT INTO share_version VALUES('nick (at) chromium.org',70);"
    752       "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL,"
    753           "base_version bigint default -1,server_version bigint default 0,"
    754           "mtime bigint default 0,server_mtime bigint default 0,"
    755           "ctime bigint default 0,server_ctime bigint default 0,"
    756           "server_position_in_parent bigint default 0,"
    757           "local_external_id bigint default 0,id varchar(255) default 'r',"
    758           "parent_id varchar(255) default 'r',"
    759           "server_parent_id varchar(255) default 'r',"
    760           "prev_id varchar(255) default 'r',next_id varchar(255) default 'r',"
    761           "is_unsynced bit default 0,is_unapplied_update bit default 0,"
    762           "is_del bit default 0,is_dir bit default 0,"
    763           "server_is_dir bit default 0,server_is_del bit default 0,"
    764           "non_unique_name varchar,server_non_unique_name varchar(255),"
    765           "unique_server_tag varchar,unique_client_tag varchar,"
    766           "specifics blob,server_specifics blob);"
    767       "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
    768           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'');"
    769       "INSERT INTO metas VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2) ","
    770           "-2097152,4,'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,"
    771           "1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A"
    772           "2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X'C2881026"
    773           "0A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B415341444741"
    774           "4447414447');"
    775       "INSERT INTO metas VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
    776           ",-3145728,"
    777           "3,'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,"
    778           "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A"
    779           "31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E74"
    780           "6C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F"
    781           "2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F7765"
    782           "6C636F6D652E68746D6C1200');"
    783       "INSERT INTO metas VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
    784           ",1048576,7,"
    785           "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google',"
    786           "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C6"
    787           "52E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F77777"
    788           "72E676F6F676C652E636F6D2F12084147464447415347');"
    789       "INSERT INTO metas VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
    790           ",-4194304,"
    791           "6,'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet',"
    792           "'The Internet',NULL,NULL,X'C2881000',X'C2881000');"
    793       "INSERT INTO metas VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
    794           ",1048576,0,"
    795           "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome',"
    796           "'Google Chrome','google_chrome',NULL,NULL,NULL);"
    797       "INSERT INTO metas VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
    798           ",1048576,0,"
    799           "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks',"
    800           "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',"
    801           "X'C2881000');"
    802       "INSERT INTO metas VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
    803           ",1048576,"
    804           "1,'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,"
    805           "'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881000',"
    806           "X'C2881000');"
    807       "INSERT INTO metas VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
    808           ","
    809           "2097152,2,'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,"
    810           "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,"
    811           "X'C2881000',X'C2881000');"
    812       "INSERT INTO metas VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
    813           ",-1048576,"
    814           "8,'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,"
    815           "'Home (The Chromium Projects)','Home (The Chromium Projects)',"
    816           "NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F"
    817           "72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636872"
    818           "6F6D69756D2E6F72672F6F7468657212084146414756415346');"
    819       "INSERT INTO metas VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
    820           ",0,9,"
    821           "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,"
    822           "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',"
    823           "X'C2881000');"
    824       "INSERT INTO metas VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
    825           ",-917504,"
    826           "10,'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,"
    827           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
    828           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
    829           "NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F"
    830           "120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772E69"
    831           "63616E6E2E636F6D2F120744414146415346');"
    832       "INSERT INTO metas VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
    833           ",1048576,"
    834           "11,'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,"
    835           "'The WebKit Open Source Project','The WebKit Open Source Project',"
    836           "NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450"
    837           "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F78120550"
    838           "4E473259');"
    839       ));
    840   ASSERT_TRUE(connection->CommitTransaction());
    841 }
    842 
    843 void MigrationTest::SetUpVersion71Database(sql::Connection* connection) {
    844   ASSERT_TRUE(connection->is_open());
    845   ASSERT_TRUE(connection->BeginTransaction());
    846   ASSERT_TRUE(connection->Execute(
    847       "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), "
    848           "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);"
    849       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
    850       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',71);"
    851       "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL,"
    852           "base_version bigint default -1,server_version bigint default 0,"
    853           "mtime bigint default 0,server_mtime bigint default 0,ctime bigint "
    854           "default 0,server_ctime bigint default 0,server_position_in_parent "
    855           "bigint default 0,local_external_id bigint default 0,id varchar(255) "
    856           "default 'r',parent_id varchar(255) default 'r',server_parent_id "
    857           "varchar(255) default 'r',prev_id varchar(255) default 'r',next_id "
    858           "varchar(255) default 'r',is_unsynced bit default 0,"
    859           "is_unapplied_update bit default 0,is_del bit default 0,is_dir bit "
    860           "default 0,server_is_dir bit default 0,server_is_del bit default 0,"
    861           "non_unique_name varchar,server_non_unique_name varchar(255),"
    862           "unique_server_tag varchar,unique_client_tag varchar,specifics blob,"
    863           "server_specifics blob);"
    864       "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
    865           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,"
    866           "NULL,NULL,X'',X'');"
    867       "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
    868           ",-2097152,4,"
    869           "'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,"
    870           "'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F"
    871           "7777772E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A1768"
    872           "7474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474144"
    873           "47');"
    874       "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
    875           ",-3145728,3,"
    876           "'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,"
    877           "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A31"
    878           "687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F"
    879           "656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7777"
    880           "772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D"
    881           "652E68746D6C1200');"
    882       "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
    883           ",1048576,7,"
    884           "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google',"
    885           "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652"
    886           "E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E6"
    887           "76F6F676C652E636F6D2F12084147464447415347');"
    888       "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
    889           ",-4194304,6,"
    890           "'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet',"
    891           "'The Internet',NULL,NULL,X'C2881000',X'C2881000');"
    892       "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
    893           ",1048576,0,"
    894           "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome'"
    895           ",'google_chrome',NULL,NULL,NULL);"
    896       "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
    897           ",1048576,0,"
    898           "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks',"
    899           "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
    900       "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
    901           ",1048576,1,"
    902           "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar',"
    903           "'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
    904       "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
    905           ",2097152,2,"
    906           "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,"
    907           "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,"
    908           "X'C2881000',X'C2881000');"
    909       "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
    910           ",-1048576,8,"
    911           "'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,"
    912           "'Home (The Chromium Projects)','Home (The Chromium Projects)',NULL,"
    913           "NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1"
    914           "206414741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756"
    915           "D2E6F72672F6F7468657212084146414756415346');"
    916       "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
    917           ",0,9,"
    918           "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,"
    919           "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',"
    920           "X'C2881000');"
    921       "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
    922           ",-917504,10,"
    923           "'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,"
    924           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
    925           "'ICANN | Internet Corporation for Assigned Names and Numbers',NULL,"
    926           "NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504"
    927           "E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963616E6E2"
    928           "E636F6D2F120744414146415346');"
    929       "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
    930           ",1048576,11,"
    931           "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,"
    932           "'The WebKit Open Source Project','The WebKit Open Source Project',"
    933           "NULL,NULL,""X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450"
    934           "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E"
    935           "473259');"
    936       "CREATE TABLE models (model_id BLOB primary key, "
    937           "last_download_timestamp INT, initial_sync_ended BOOLEAN default 0);"
    938       "INSERT INTO 'models' VALUES(X'C2881000',694,1);"
    939       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, "
    940           "store_birthday TEXT, db_create_version TEXT, db_create_time INT, "
    941           "next_id INT default -2, cache_guid TEXT);"
    942       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
    943           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,"
    944           "'9010788312004066376x-6609234393368420856x');"));
    945   ASSERT_TRUE(connection->CommitTransaction());
    946 }
    947 
    948 void MigrationTest::SetUpVersion72Database(sql::Connection* connection) {
    949   ASSERT_TRUE(connection->is_open());
    950   ASSERT_TRUE(connection->BeginTransaction());
    951   ASSERT_TRUE(connection->Execute(
    952       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
    953       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',72);"
    954       "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL,"
    955           "base_version bigint default -1,server_version bigint default 0,"
    956           "mtime bigint default 0,server_mtime bigint default 0,ctime bigint "
    957           "default 0,server_ctime bigint default 0,server_position_in_parent "
    958           "bigint default 0,local_external_id bigint default 0,id varchar(255) "
    959           "default 'r',parent_id varchar(255) default 'r',server_parent_id "
    960           "varchar(255) default 'r',prev_id varchar(255) default 'r',next_id "
    961           "varchar(255) default 'r',is_unsynced bit default 0,"
    962           "is_unapplied_update bit default 0,is_del bit default 0,is_dir bit "
    963           "default 0,server_is_dir bit default 0,server_is_del bit default 0,"
    964           "non_unique_name varchar,server_non_unique_name varchar(255),"
    965           "unique_server_tag varchar,unique_client_tag varchar,specifics blob,"
    966           "server_specifics blob);"
    967       "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
    968           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,"
    969           "NULL,NULL,X'',X'');"
    970       "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
    971           ",-2097152,4,"
    972           "'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,"
    973           "'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F"
    974           "7777772E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A1768"
    975           "7474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474144"
    976           "47');"
    977       "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
    978           ",-3145728,3,"
    979           "'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,"
    980           "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A31"
    981           "687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F"
    982           "656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7777"
    983           "772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D"
    984           "652E68746D6C1200');"
    985       "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
    986           ",1048576,7,"
    987           "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google',"
    988           "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652"
    989           "E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E6"
    990           "76F6F676C652E636F6D2F12084147464447415347');"
    991       "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
    992           ",-4194304,6,"
    993           "'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet',"
    994           "'The Internet',NULL,NULL,X'C2881000',X'C2881000');"
    995       "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
    996           ",1048576,0,"
    997           "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome'"
    998           ",'google_chrome',NULL,NULL,NULL);"
    999       "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
   1000           ",1048576,0,"
   1001           "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks',"
   1002           "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
   1003       "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
   1004           ",1048576,1,"
   1005           "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar',"
   1006           "'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
   1007       "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
   1008           ",2097152,2,"
   1009           "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,"
   1010           "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,"
   1011           "X'C2881000',X'C2881000');"
   1012       "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
   1013           ",-1048576,8,"
   1014           "'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,"
   1015           "'Home (The Chromium Projects)','Home (The Chromium Projects)',NULL,"
   1016           "NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1"
   1017           "206414741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756"
   1018           "D2E6F72672F6F7468657212084146414756415346');"
   1019       "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
   1020           ",0,9,"
   1021           "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,"
   1022           "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',"
   1023           "X'C2881000');"
   1024       "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
   1025           ",-917504,10,"
   1026           "'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,"
   1027           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
   1028           "'ICANN | Internet Corporation for Assigned Names and Numbers',NULL,"
   1029           "NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504"
   1030           "E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963616E6E2"
   1031           "E636F6D2F120744414146415346');"
   1032       "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
   1033           ",1048576,11,"
   1034           "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,"
   1035           "'The WebKit Open Source Project','The WebKit Open Source Project',"
   1036           "NULL,NULL,""X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450"
   1037           "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E"
   1038           "473259');"
   1039       "CREATE TABLE models (model_id BLOB primary key, "
   1040           "last_download_timestamp INT, initial_sync_ended BOOLEAN default 0);"
   1041       "INSERT INTO 'models' VALUES(X'C2881000',694,1);"
   1042       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, "
   1043           "store_birthday TEXT, db_create_version TEXT, db_create_time INT, "
   1044           "next_id INT default -2, cache_guid TEXT);"
   1045       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   1046           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,"
   1047           "'9010788312004066376x-6609234393368420856x');"));
   1048   ASSERT_TRUE(connection->CommitTransaction());
   1049 }
   1050 
   1051 void MigrationTest::SetUpVersion73Database(sql::Connection* connection) {
   1052   ASSERT_TRUE(connection->is_open());
   1053   ASSERT_TRUE(connection->BeginTransaction());
   1054   ASSERT_TRUE(connection->Execute(
   1055       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1056       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',73);"
   1057       "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL,"
   1058           "base_version bigint default -1,server_version bigint default 0,"
   1059           "mtime bigint default 0,server_mtime bigint default 0,ctime bigint "
   1060           "default 0,server_ctime bigint default 0,server_position_in_parent "
   1061           "bigint default 0,local_external_id bigint default 0,id varchar(255) "
   1062           "default 'r',parent_id varchar(255) default 'r',server_parent_id "
   1063           "varchar(255) default 'r',prev_id varchar(255) default 'r',next_id "
   1064           "varchar(255) default 'r',is_unsynced bit default 0,"
   1065           "is_unapplied_update bit default 0,is_del bit default 0,is_dir bit "
   1066           "default 0,server_is_dir bit default 0,server_is_del bit default 0,"
   1067           "non_unique_name varchar,server_non_unique_name varchar(255),"
   1068           "unique_server_tag varchar,unique_client_tag varchar,specifics blob,"
   1069           "server_specifics blob);"
   1070       "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
   1071           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,"
   1072           "NULL,NULL,X'',X'');"
   1073       "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
   1074           ",-2097152,4,"
   1075           "'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,"
   1076           "'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F"
   1077           "7777772E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A1768"
   1078           "7474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474144"
   1079           "47');"
   1080       "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
   1081           ",-3145728,3,"
   1082           "'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,"
   1083           "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A31"
   1084           "687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F"
   1085           "656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7777"
   1086           "772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D"
   1087           "652E68746D6C1200');"
   1088       "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
   1089           ",1048576,7,"
   1090           "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google',"
   1091           "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652"
   1092           "E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E6"
   1093           "76F6F676C652E636F6D2F12084147464447415347');"
   1094       "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
   1095           ",-4194304,6,"
   1096           "'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet',"
   1097           "'The Internet',NULL,NULL,X'C2881000',X'C2881000');"
   1098       "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
   1099           ",1048576,0,"
   1100           "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome'"
   1101           ",'google_chrome',NULL,NULL,NULL);"
   1102       "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
   1103           ",1048576,0,"
   1104           "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks',"
   1105           "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
   1106       "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
   1107           ",1048576,1,"
   1108           "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar',"
   1109           "'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
   1110       "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
   1111           ",2097152,2,"
   1112           "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,"
   1113           "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,"
   1114           "X'C2881000',X'C2881000');"
   1115       "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
   1116           ",-1048576,8,"
   1117           "'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,"
   1118           "'Home (The Chromium Projects)','Home (The Chromium Projects)',NULL,"
   1119           "NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1"
   1120           "206414741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756"
   1121           "D2E6F72672F6F7468657212084146414756415346');"
   1122       "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
   1123           ",0,9,"
   1124           "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,"
   1125           "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',"
   1126           "X'C2881000');"
   1127       "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
   1128           ",-917504,10,"
   1129           "'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,"
   1130           "'ICANN | Internet Corporation for Assigned Names and Numbers',"
   1131           "'ICANN | Internet Corporation for Assigned Names and Numbers',NULL,"
   1132           "NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504"
   1133           "E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963616E6E2"
   1134           "E636F6D2F120744414146415346');"
   1135       "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
   1136           ",1048576,11,"
   1137           "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,"
   1138           "'The WebKit Open Source Project','The WebKit Open Source Project',"
   1139           "NULL,NULL,""X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450"
   1140           "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E"
   1141           "473259');"
   1142       "CREATE TABLE models (model_id BLOB primary key, "
   1143           "last_download_timestamp INT, initial_sync_ended BOOLEAN default 0);"
   1144       "INSERT INTO 'models' VALUES(X'C2881000',694,1);"
   1145       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, "
   1146           "store_birthday TEXT, db_create_version TEXT, db_create_time INT, "
   1147           "next_id INT default -2, cache_guid TEXT, "
   1148           "notification_state BLOB);"
   1149       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   1150           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,"
   1151           "'9010788312004066376x-6609234393368420856x',X'C2881000');"));
   1152   ASSERT_TRUE(connection->CommitTransaction());
   1153 }
   1154 
   1155 void MigrationTest::SetUpVersion74Database(sql::Connection* connection) {
   1156   ASSERT_TRUE(connection->is_open());
   1157   ASSERT_TRUE(connection->BeginTransaction());
   1158   ASSERT_TRUE(connection->Execute(
   1159       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1160       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',74);"
   1161       "CREATE TABLE models (model_id BLOB primary key, last_download_timestamp"
   1162           " INT, initial_sync_ended BOOLEAN default 0);"
   1163       "INSERT INTO 'models' VALUES(X'C2881000',694,1);"
   1164       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthd"
   1165           "ay TEXT, db_create_version TEXT, db_create_time INT, next_id INT de"
   1166           "fault -2, cache_guid TEXT , notification_state BLOB, autofill_migra"
   1167           "tion_state INT default 0, bookmarks_added_during_autofill_migration"
   1168           " INT default 0, autofill_migration_time INT default 0, autofill_ent"
   1169           "ries_added_during_migration INT default 0, autofill_profiles_added_"
   1170           "during_migration INT default 0);"
   1171       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org'"
   1172           ",'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542"
   1173           ",'9010788312004066376x-6609234393368420856x',NULL,0,0,0,0,0);"
   1174       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,bas"
   1175           "e_version bigint default -1,server_version bigint default 0,mtime b"
   1176           "igint default 0,server_mtime bigint default 0,ctime bigint default "
   1177           "0,server_ctime bigint default 0,server_position_in_parent bigint de"
   1178           "fault 0,local_external_id bigint default 0,id varchar(255) default "
   1179           "'r',parent_id varchar(255) default 'r',server_parent_id varchar(255"
   1180           ") default 'r',prev_id varchar(255) default 'r',next_id varchar(255)"
   1181           " default 'r',is_unsynced bit default 0,is_unapplied_update bit defa"
   1182           "ult 0,is_del bit default 0,is_dir bit default 0,server_is_dir bit d"
   1183           "efault 0,server_is_del bit default 0,non_unique_name varchar,server"
   1184           "_non_unique_name varchar(255),unique_server_tag varchar,unique_clie"
   1185           "nt_tag varchar,specifics blob,server_specifics blob);"
   1186       "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
   1187           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'"
   1188           "');"
   1189       "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
   1190           ",-2097152,4,'s_ID_2','s_ID"
   1191           "_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,'Deleted Item','Deleted "
   1192           "Item',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652E6"
   1193           "36F6D2F12084141534741534741',X'C28810260A17687474703A2F2F7777772E67"
   1194           "6F6F676C652E636F6D2F32120B4153414447414447414447');"
   1195       "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
   1196           ",-3145728,3,'s_ID_4','s_ID"
   1197           "_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,'Welcome to Chromium','W"
   1198           "elcome to Chromium',NULL,NULL,X'C28810350A31687474703A2F2F7777772E6"
   1199           "76F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D652E"
   1200           "68746D6C1200',X'C28810350A31687474703A2F2F7777772E676F6F676C652E636"
   1201           "F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D652E68746D6C1200');"
   1202       "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
   1203           ",1048576,7,'s_ID_5','s_ID_"
   1204           "9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google','Google',NULL,NU"
   1205           "LL,X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D2F120841"
   1206           "47415347415347',X'C28810220A16687474703A2F2F7777772E676F6F676C652E6"
   1207           "36F6D2F12084147464447415347');"
   1208       "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
   1209           ",-4194304,6,'s_ID_6','s_ID"
   1210           "_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet','The Internet',NULL"
   1211           ",NULL,X'C2881000',X'C2881000');"
   1212       "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
   1213           ",1048576,0,'s_ID_7','r','r"
   1214           "','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome','google_chrom"
   1215           "e',NULL,NULL,NULL);"
   1216       "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
   1217           ",1048576,0,'s_ID_8','s_ID_"
   1218           "7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks','Bookmarks','google_chr"
   1219           "ome_bookmarks',NULL,X'C2881000',X'C2881000');"
   1220       "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
   1221           ",1048576,1,'s_ID_9','s_ID_"
   1222           "8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar','Bookmark Bar'"
   1223           ",'bookmark_bar',NULL,X'C2881000',X'C2881000');"
   1224       "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
   1225           ",2097152,2,'s_ID_10','s_I"
   1226           "D_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,'Other Bookmarks','Other Boo"
   1227           "kmarks','other_bookmarks',NULL,X'C2881000',X'C2881000');"
   1228       "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
   1229           ",-1048576,8,'s_ID_11','s_"
   1230           "ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,'Home (The Chromium Projec"
   1231           "ts)','Home (The Chromium Projects)',NULL,NULL,X'C28810220A186874747"
   1232           "03A2F2F6465762E6368726F6D69756D2E6F72672F1206414741545741',X'C28810"
   1233           "290A1D687474703A2F2F6465762E6368726F6D69756D2E6F72672F6F74686572120"
   1234           "84146414756415346');"
   1235       "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
   1236           ",0,9,'s_ID_12','s_ID_6','"
   1237           "s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bo"
   1238           "okmarks',NULL,NULL,X'C2881000',X'C2881000');"
   1239       "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
   1240           ",-917504,10,'s_ID_13','s_"
   1241           "ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,'ICANN | Internet Co"
   1242           "rporation for Assigned Names and Numbers','ICANN | Internet Corpora"
   1243           "tion for Assigned Names and Numbers',NULL,NULL,X'C28810240A15687474"
   1244           "703A2F2F7777772E6963616E6E2E636F6D2F120B504E474158463041414646',X'C"
   1245           "28810200A15687474703A2F2F7777772E6963616E6E2E636F6D2F12074441414641"
   1246           "5346');"
   1247       "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
   1248           ",1048576,11,'s_ID_14','s_"
   1249           "ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,'The WebKit Open Source Pr"
   1250           "oject','The WebKit Open Source Project',NULL,NULL,X'C288101A0A12687"
   1251           "474703A2F2F7765626B69742E6F72672F1204504E4758',X'C288101C0A13687474"
   1252           "703A2F2F7765626B69742E6F72672F781205504E473259');"
   1253       ));
   1254   ASSERT_TRUE(connection->CommitTransaction());
   1255 }
   1256 
   1257 void MigrationTest::SetUpVersion75Database(sql::Connection* connection) {
   1258   ASSERT_TRUE(connection->is_open());
   1259   ASSERT_TRUE(connection->BeginTransaction());
   1260   ASSERT_TRUE(connection->Execute(
   1261       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1262       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',75);"
   1263       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthd"
   1264           "ay TEXT, db_create_version TEXT, db_create_time INT, next_id INT de"
   1265           "fault -2, cache_guid TEXT , notification_state BLOB, autofill_migra"
   1266           "tion_state INT default 0,bookmarks_added_during_autofill_migration "
   1267           "INT default 0, autofill_migration_time INT default 0, autofill_entr"
   1268           "ies_added_during_migration INT default 0, autofill_profiles_added_d"
   1269           "uring_migration INT default 0);"
   1270        "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org"
   1271            "','c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-655"
   1272            "42,'9010788312004066376x-6609234393368420856x',NULL,0,0,0,0,0);"
   1273        "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, "
   1274            "initial_sync_ended BOOLEAN default 0);"
   1275        "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
   1276        "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,ba"
   1277            "se_version bigint default -1,server_version bigint default 0,mtime"
   1278            " bigint default 0,server_mtime bigint default 0,ctime bigint defau"
   1279            "lt 0,server_ctime bigint default 0,server_position_in_parent bigin"
   1280            "t default 0,local_external_id bigint default 0,id varchar(255) def"
   1281            "ault 'r',parent_id varchar(255) default 'r',server_parent_id varch"
   1282            "ar(255) default 'r',prev_id varchar(255) default 'r',next_id varch"
   1283            "ar(255) default 'r',is_unsynced bit default 0,is_unapplied_update "
   1284            "bit default 0,is_del bit default 0,is_dir bit default 0,server_is_"
   1285            "dir bit default 0,server_is_del bit default 0,non_unique_name varc"
   1286            "har,server_non_unique_name varchar(255),unique_server_tag varchar,"
   1287            "unique_client_tag varchar,specifics blob,server_specifics blob);"
   1288            "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
   1289               ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NUL"
   1290               "L,X'',X'');"
   1291            "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
   1292               ",-2097152,4,'s_ID_"
   1293               "2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,'Deleted Ite"
   1294               "m','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F7777772"
   1295               "E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A176874"
   1296               "74703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474"
   1297               "14447');"
   1298            "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
   1299               ",-3145728,3,'s_ID_"
   1300               "4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,'Welcome to "
   1301               "Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A316874747"
   1302               "03A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F65"
   1303               "6E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7"
   1304               "777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F7765"
   1305               "6C636F6D652E68746D6C1200');"
   1306            "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
   1307               ",1048576,7,'s_ID_5"
   1308               "','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google','Goo"
   1309               "gle',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C65"
   1310               "2E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F777"
   1311               "7772E676F6F676C652E636F6D2F12084147464447415347');"
   1312            "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
   1313               ",-4194304,6,'s_ID_"
   1314               "6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet','The In"
   1315               "ternet',NULL,NULL,X'C2881000',X'C2881000');"
   1316            "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
   1317               ",1048576,0,'s_ID_7"
   1318               "','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome','"
   1319               "google_chrome',NULL,NULL,NULL);"
   1320            "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
   1321               ",1048576,0,'s_ID_8"
   1322               "','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks','Bookmarks'"
   1323               ",'google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
   1324            "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
   1325               ",1048576,1,'s_ID_9"
   1326               "','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar','B"
   1327               "ookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
   1328            "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
   1329               ",2097152,2,'s_ID_"
   1330               "10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,'Other Bookmarks"
   1331               "','Other Bookmarks','other_bookmarks',NULL,X'C2881000',X'C28810"
   1332               "00');"
   1333            "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
   1334               ",-1048576,8,'s_ID"
   1335               "_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,'Home (The Chr"
   1336               "omium Projects)','Home (The Chromium Projects)',NULL,NULL,X'C28"
   1337               "810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F120641"
   1338               "4741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756"
   1339               "D2E6F72672F6F7468657212084146414756415346');"
   1340            "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
   1341               ",0,9,'s_ID_12','s"
   1342               "_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,'Extra Bookmark"
   1343               "s','Extra Bookmarks',NULL,NULL,X'C2881000',X'C2881000');"
   1344            "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
   1345               ",-917504,10,'s_ID"
   1346               "_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,'ICANN |"
   1347               " Internet Corporation for Assigned Names and Numbers','ICANN | "
   1348               "Internet Corporation for Assigned Names and Numbers',NULL,NULL,"
   1349               "X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504"
   1350               "E474158463041414646',X'C28810200A15687474703A2F2F7777772E696361"
   1351               "6E6E2E636F6D2F120744414146415346');"
   1352            "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
   1353               ",1048576,11,'s_ID"
   1354               "_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,'The WebKit Op"
   1355               "en Source Project','The WebKit Open Source Project',NULL,NULL,X"
   1356               "'C288101A0A12687474703A2F2F7765626B69742E6F72672F1204504E4758',"
   1357               "X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E473"
   1358               "259');"
   1359       ));
   1360   ASSERT_TRUE(connection->CommitTransaction());
   1361 }
   1362 
   1363 void MigrationTest::SetUpVersion76Database(sql::Connection* connection) {
   1364   ASSERT_TRUE(connection->is_open());
   1365   ASSERT_TRUE(connection->BeginTransaction());
   1366   ASSERT_TRUE(connection->Execute(
   1367       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1368       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',76);"
   1369       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   1370           "itial_sync_ended BOOLEAN default 0);"
   1371       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
   1372       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   1373           "_version bigint default -1,server_version bigint default 0,mtime big"
   1374           "int default 0,server_mtime bigint default 0,ctime bigint default 0,s"
   1375           "erver_ctime bigint default 0,server_position_in_parent bigint defaul"
   1376           "t 0,local_external_id bigint default 0,id varchar(255) default 'r',p"
   1377           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   1378           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   1379           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   1380           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   1381           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   1382           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   1383           "har,specifics blob,server_specifics blob);"
   1384       "INSERT INTO 'metas' VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS(1)
   1385           ",0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'')"
   1386           ";"
   1387       "INSERT INTO 'metas' VALUES(2,669,669," LEGACY_PROTO_TIME_VALS(2)
   1388           ",-2097152,4,'s_ID_2','s_ID_9"
   1389           "','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1,'Deleted Item','Deleted Ite"
   1390           "m',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6"
   1391           "D2F12084141534741534741',X'C28810260A17687474703A2F2F7777772E676F6F6"
   1392           "76C652E636F6D2F32120B4153414447414447414447');"
   1393       "INSERT INTO 'metas' VALUES(4,681,681," LEGACY_PROTO_TIME_VALS(4)
   1394           ",-3145728,3,'s_ID_4','s_ID_9"
   1395           "','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1,'Welcome to Chromium','Welc"
   1396           "ome to Chromium',NULL,NULL,X'C28810350A31687474703A2F2F7777772E676F6"
   1397           "F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D652E68746"
   1398           "D6C1200',X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6"
   1399           "368726F6D652F696E746C2F656E2F77656C636F6D652E68746D6C1200');"
   1400       "INSERT INTO 'metas' VALUES(5,677,677," LEGACY_PROTO_TIME_VALS(5)
   1401           ",1048576,7,'s_ID_5','s_ID_9'"
   1402           ",'s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google','Google',NULL,NULL,"
   1403           "X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D2F1208414741"
   1404           "5347415347',X'C28810220A16687474703A2F2F7777772E676F6F676C652E636F6D"
   1405           "2F12084147464447415347');"
   1406       "INSERT INTO 'metas' VALUES(6,694,694," LEGACY_PROTO_TIME_VALS(6)
   1407           ",-4194304,6,'s_ID_6','s_ID_9"
   1408           "','s_ID_9','r','r',0,0,0,1,1,0,'The Internet','The Internet',NULL,NU"
   1409           "LL,X'C2881000',X'C2881000');"
   1410       "INSERT INTO 'metas' VALUES(7,663,663," LEGACY_PROTO_TIME_VALS(7)
   1411           ",1048576,0,'s_ID_7','r','r',"
   1412           "'r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome','google_chrome',"
   1413           "NULL,NULL,NULL);"
   1414       "INSERT INTO 'metas' VALUES(8,664,664," LEGACY_PROTO_TIME_VALS(8)
   1415           ",1048576,0,'s_ID_8','s_ID_7'"
   1416           ",'s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks','Bookmarks','google_chrome"
   1417           "_bookmarks',NULL,X'C2881000',X'C2881000');"
   1418       "INSERT INTO 'metas' VALUES(9,665,665," LEGACY_PROTO_TIME_VALS(9)
   1419           ",1048576,1,'s_ID_9','s_ID_8'"
   1420           ",'s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar','Bookmark Bar','b"
   1421           "ookmark_bar',NULL,X'C2881000',X'C2881000');"
   1422       "INSERT INTO 'metas' VALUES(10,666,666," LEGACY_PROTO_TIME_VALS(10)
   1423           ",2097152,2,'s_ID_10','s_ID_"
   1424           "8','s_ID_8','s_ID_9','r',0,0,0,1,1,0,'Other Bookmarks','Other Bookma"
   1425           "rks','other_bookmarks',NULL,X'C2881000',X'C2881000');"
   1426       "INSERT INTO 'metas' VALUES(11,683,683," LEGACY_PROTO_TIME_VALS(11)
   1427           ",-1048576,8,'s_ID_11','s_ID"
   1428           "_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0,'Home (The Chromium Projects)"
   1429           "','Home (The Chromium Projects)',NULL,NULL,X'C28810220A18687474703A2"
   1430           "F2F6465762E6368726F6D69756D2E6F72672F1206414741545741',X'C28810290A1"
   1431           "D687474703A2F2F6465762E6368726F6D69756D2E6F72672F6F74686572120841464"
   1432           "14756415346');"
   1433       "INSERT INTO 'metas' VALUES(12,685,685," LEGACY_PROTO_TIME_VALS(12)
   1434           ",0,9,'s_ID_12','s_ID_6','s_"
   1435           "ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookm"
   1436           "arks',NULL,NULL,X'C2881000',X'C2881000');"
   1437       "INSERT INTO 'metas' VALUES(13,687,687," LEGACY_PROTO_TIME_VALS(13)
   1438           ",-917504,10,'s_ID_13','s_ID"
   1439           "_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0,'ICANN | Internet Corpo"
   1440           "ration for Assigned Names and Numbers','ICANN | Internet Corporation"
   1441           " for Assigned Names and Numbers',NULL,NULL,X'C28810240A15687474703A2"
   1442           "F2F7777772E6963616E6E2E636F6D2F120B504E474158463041414646',X'C288102"
   1443           "00A15687474703A2F2F7777772E6963616E6E2E636F6D2F120744414146415346');"
   1444       "INSERT INTO 'metas' VALUES(14,692,692," LEGACY_PROTO_TIME_VALS(14)
   1445           ",1048576,11,'s_ID_14','s_ID"
   1446           "_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0,'The WebKit Open Source Proje"
   1447           "ct','The WebKit Open Source Project',NULL,NULL,X'C288101A0A126874747"
   1448           "03A2F2F7765626B69742E6F72672F1204504E4758',X'C288101C0A13687474703A2"
   1449           "F2F7765626B69742E6F72672F781205504E473259');"
   1450       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   1451           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   1452           "ult -2, cache_guid TEXT , notification_state BLOB);"
   1453       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   1454           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'"
   1455           "9010788312004066376x-6609234393368420856x',NULL);"
   1456       ));
   1457   ASSERT_TRUE(connection->CommitTransaction());
   1458 }
   1459 
   1460 void MigrationTest::SetUpVersion77Database(sql::Connection* connection) {
   1461   ASSERT_TRUE(connection->is_open());
   1462   ASSERT_TRUE(connection->BeginTransaction());
   1463   ASSERT_TRUE(connection->Execute(
   1464       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1465       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',77);"
   1466       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   1467           "itial_sync_ended BOOLEAN default 0);"
   1468       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
   1469       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   1470           "_version bigint default -1,server_version bigint default 0,server_po"
   1471           "sition_in_parent bigint default 0,local_external_id bigint default 0"
   1472           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   1473           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   1474           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   1475           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   1476           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   1477           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   1478           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   1479           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   1480           "har,specifics blob,server_specifics blob);"
   1481       "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1)
   1482           ",'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'');"
   1483       "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
   1484           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   1485           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   1486           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   1487           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   1488           "14447414447414447');"
   1489       "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
   1490           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   1491           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   1492           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   1493           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   1494           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   1495           "E2F77656C636F6D652E68746D6C1200');"
   1496       "INSERT INTO 'metas' VALUES(5,677,677,1048576,7," META_PROTO_TIMES_VALS(5)
   1497           ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google','"
   1498           "Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652E"
   1499           "636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E67"
   1500           "6F6F676C652E636F6D2F12084147464447415347');"
   1501       "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
   1502           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   1503           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   1504           ");"
   1505       "INSERT INTO 'metas' VALUES(7,663,663,1048576,0," META_PROTO_TIMES_VALS(7)
   1506           ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Goo"
   1507           "gle Chrome','google_chrome',NULL,NULL,NULL);"
   1508       "INSERT INTO 'metas' VALUES(8,664,664,1048576,0," META_PROTO_TIMES_VALS(8)
   1509           ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks','Bookmar"
   1510           "ks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');"
   1511       "INSERT INTO 'metas' VALUES(9,665,665,1048576,1," META_PROTO_TIMES_VALS(9)
   1512           ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar'"
   1513           ",'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');"
   1514       "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
   1515           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   1516           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   1517           "LL,X'C2881000',X'C2881000');"
   1518       "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
   1519           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   1520           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   1521           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   1522           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   1523           "8726F6D69756D2E6F72672F6F7468657212084146414756415346');"
   1524       "INSERT INTO 'metas' VALUES(12,685,685,0,9," META_PROTO_TIMES_VALS(12)
   1525           ",'s_ID_12','s_ID_6','s_"
   1526           "ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookm"
   1527           "arks',NULL,NULL,X'C2881000',X'C2881000');"
   1528       "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
   1529           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   1530           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   1531           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   1532           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   1533           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   1534           "E6963616E6E2E636F6D2F120744414146415346');"
   1535       "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
   1536           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   1537           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   1538           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   1539           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   1540           "81205504E473259');"
   1541       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   1542           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   1543           "ult -2, cache_guid TEXT , notification_state BLOB);"
   1544       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   1545           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'"
   1546           "9010788312004066376x-6609234393368420856x',NULL);"
   1547       ));
   1548   ASSERT_TRUE(connection->CommitTransaction());
   1549 }
   1550 
   1551 void MigrationTest::SetUpVersion78Database(sql::Connection* connection) {
   1552   ASSERT_TRUE(connection->is_open());
   1553   ASSERT_TRUE(connection->BeginTransaction());
   1554   ASSERT_TRUE(connection->Execute(
   1555       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1556       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',78);"
   1557       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   1558           "itial_sync_ended BOOLEAN default 0);"
   1559       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
   1560       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   1561           "_version bigint default -1,server_version bigint default 0,server_po"
   1562           "sition_in_parent bigint default 0,local_external_id bigint default 0"
   1563           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   1564           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   1565           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   1566           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   1567           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   1568           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   1569           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   1570           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   1571           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   1572           ");"
   1573       "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
   1574           "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);"
   1575       "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
   1576           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   1577           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   1578           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   1579           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   1580           "14447414447414447',NULL);"
   1581       "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
   1582           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   1583           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   1584           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   1585           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   1586           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   1587           "E2F77656C636F6D652E68746D6C1200',NULL);"
   1588       "INSERT INTO 'metas' VALUES(5,677,677,1048576,7,"
   1589           META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
   1590           "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
   1591           "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
   1592           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
   1593           "ULL);"
   1594       "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
   1595           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   1596           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   1597           ",NULL);"
   1598       "INSERT INTO 'metas' VALUES(7,663,663,1048576,0,"
   1599           META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
   1600           "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL);"
   1601       "INSERT INTO 'metas' VALUES(8,664,664,1048576,0,"
   1602           META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
   1603           ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
   1604           "00',X'C2881000',NULL);"
   1605       "INSERT INTO 'metas' VALUES(9,665,665,1048576,1,"
   1606           META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
   1607           ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
   1608           "000',X'C2881000',NULL);"
   1609       "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
   1610           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   1611           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   1612           "LL,X'C2881000',X'C2881000',NULL);"
   1613       "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
   1614           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   1615           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   1616           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   1617           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   1618           "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);"
   1619       "INSERT INTO 'metas' VALUES(12,685,685,0,9,"
   1620           META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
   1621           "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
   1622           "2881000',X'C2881000',NULL);"
   1623       "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
   1624           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   1625           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   1626           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   1627           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   1628           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   1629           "E6963616E6E2E636F6D2F120744414146415346',NULL);"
   1630       "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
   1631           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   1632           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   1633           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   1634           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   1635           "81205504E473259',NULL);"
   1636       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   1637           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   1638           "ult -2, cache_guid TEXT , notification_state BLOB);"
   1639       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   1640           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542,'"
   1641           "9010788312004066376x-6609234393368420856x',NULL);"
   1642           ));
   1643   ASSERT_TRUE(connection->CommitTransaction());
   1644 }
   1645 
   1646 void MigrationTest::SetUpVersion79Database(sql::Connection* connection) {
   1647   ASSERT_TRUE(connection->is_open());
   1648   ASSERT_TRUE(connection->BeginTransaction());
   1649   ASSERT_TRUE(connection->Execute(
   1650       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1651       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',79);"
   1652       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   1653           "itial_sync_ended BOOLEAN default 0);"
   1654       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
   1655       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   1656           "_version bigint default -1,server_version bigint default 0,server_po"
   1657           "sition_in_parent bigint default 0,local_external_id bigint default 0"
   1658           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   1659           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   1660           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   1661           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   1662           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   1663           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   1664           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   1665           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   1666           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   1667           ");"
   1668       "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
   1669           "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);"
   1670       "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
   1671           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   1672           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   1673           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   1674           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   1675           "14447414447414447',NULL);"
   1676       "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
   1677           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   1678           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   1679           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   1680           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   1681           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   1682           "E2F77656C636F6D652E68746D6C1200',NULL);"
   1683       "INSERT INTO 'metas' VALUES(5,677,677,1048576,7,"
   1684           META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
   1685           "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
   1686           "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
   1687           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
   1688           "ULL);"
   1689       "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
   1690           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   1691           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   1692           ",NULL);"
   1693       "INSERT INTO 'metas' VALUES(7,663,663,1048576,0,"
   1694           META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
   1695           "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL);"
   1696       "INSERT INTO 'metas' VALUES(8,664,664,1048576,0,"
   1697           META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
   1698           ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
   1699           "00',X'C2881000',NULL);"
   1700       "INSERT INTO 'metas' VALUES(9,665,665,1048576,1,"
   1701           META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
   1702           ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
   1703           "000',X'C2881000',NULL);"
   1704       "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
   1705           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   1706           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   1707           "LL,X'C2881000',X'C2881000',NULL);"
   1708       "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
   1709           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   1710           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   1711           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   1712           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   1713           "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);"
   1714       "INSERT INTO 'metas' VALUES(12,685,685,0,9,"
   1715           META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
   1716           "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
   1717           "2881000',X'C2881000',NULL);"
   1718       "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
   1719           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   1720           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   1721           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   1722           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   1723           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   1724           "E6963616E6E2E636F6D2F120744414146415346',NULL);"
   1725       "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
   1726           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   1727           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   1728           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   1729           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   1730           "81205504E473259',NULL);"
   1731       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   1732           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   1733           "ult -2, cache_guid TEXT , notification_state BLOB);"
   1734       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   1735           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
   1736           "-131078,'9010788312004066376x-6609234393368420856x',NULL);"
   1737           ));
   1738   ASSERT_TRUE(connection->CommitTransaction());
   1739 }
   1740 
   1741 void MigrationTest::SetUpVersion80Database(sql::Connection* connection) {
   1742   ASSERT_TRUE(connection->is_open());
   1743   ASSERT_TRUE(connection->BeginTransaction());
   1744   ASSERT_TRUE(connection->Execute(
   1745       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1746       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',80);"
   1747       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   1748           "itial_sync_ended BOOLEAN default 0);"
   1749       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
   1750       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   1751           "_version bigint default -1,server_version bigint default 0,server_po"
   1752           "sition_in_parent bigint default 0,local_external_id bigint default 0"
   1753           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   1754           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   1755           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   1756           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   1757           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   1758           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   1759           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   1760           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   1761           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   1762           ");"
   1763       "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
   1764       "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);"
   1765       "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
   1766           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   1767           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   1768           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   1769           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   1770           "14447414447414447',NULL);"
   1771       "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
   1772           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   1773           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   1774           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   1775           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   1776           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   1777           "E2F77656C636F6D652E68746D6C1200',NULL);"
   1778       "INSERT INTO 'metas' VALUES(5,677,677,1048576,7,"
   1779           META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
   1780           "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
   1781           "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
   1782           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
   1783           "ULL);"
   1784       "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
   1785           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   1786           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   1787           ",NULL);"
   1788       "INSERT INTO 'metas' VALUES(7,663,663,1048576,0,"
   1789           META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
   1790           "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL);"
   1791       "INSERT INTO 'metas' VALUES(8,664,664,1048576,0,"
   1792           META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
   1793           ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
   1794           "00',X'C2881000',NULL);"
   1795       "INSERT INTO 'metas' VALUES(9,665,665,1048576,1,"
   1796           META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
   1797           ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
   1798           "000',X'C2881000',NULL);"
   1799       "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
   1800           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   1801           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   1802           "LL,X'C2881000',X'C2881000',NULL);"
   1803       "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
   1804           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   1805           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   1806           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   1807           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   1808           "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);"
   1809       "INSERT INTO 'metas' VALUES(12,685,685,0,9,"
   1810           META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
   1811           "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
   1812           "2881000',X'C2881000',NULL);"
   1813       "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
   1814           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   1815           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   1816           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   1817           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   1818           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   1819           "E6963616E6E2E636F6D2F120744414146415346',NULL);"
   1820       "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
   1821           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   1822           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   1823           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   1824           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   1825           "81205504E473259',NULL);"
   1826       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   1827           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   1828           "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
   1829           "blob);"
   1830       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   1831           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
   1832           "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"
   1833           ));
   1834   ASSERT_TRUE(connection->CommitTransaction());
   1835 }
   1836 
   1837 
   1838 // Helper definitions to create the version 81 DB tables.
   1839 namespace {
   1840 
   1841 const int V80_ROW_COUNT = 13;
   1842 const int64 V80_POSITIONS[V80_ROW_COUNT] = {
   1843   0,
   1844   -2097152,
   1845   -3145728,
   1846   1048576,
   1847   -4194304,
   1848   1048576,
   1849   1048576,
   1850   1048576,
   1851   2097152,
   1852   -1048576,
   1853   0,
   1854   -917504,
   1855   1048576
   1856 };
   1857 
   1858 std::string V81_Ordinal(int n) {
   1859   return Int64ToNodeOrdinal(V80_POSITIONS[n]).ToInternalValue();
   1860 }
   1861 
   1862 } //namespace
   1863 
   1864 // Unlike the earlier versions, the rows for version 81 are generated
   1865 // programmatically to accurately handle unprintable characters for the
   1866 // server_ordinal_in_parent field.
   1867 void MigrationTest::SetUpVersion81Database(sql::Connection* connection) {
   1868   ASSERT_TRUE(connection->is_open());
   1869   ASSERT_TRUE(connection->BeginTransaction());
   1870   ASSERT_TRUE(connection->Execute(
   1871       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1872       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',81);"
   1873       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   1874           "itial_sync_ended BOOLEAN default 0);"
   1875       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
   1876       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   1877           "_version bigint default -1,server_version bigint default 0,         "
   1878           "local_external_id bigint default 0"
   1879           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   1880           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   1881           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   1882           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   1883           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   1884           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   1885           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   1886           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   1887           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   1888           ", server_ordinal_in_parent blob);"
   1889       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   1890           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   1891           "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
   1892           "blob);"
   1893       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   1894           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
   1895           "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
   1896 
   1897       const char* insert_stmts[V80_ROW_COUNT] = {
   1898       "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
   1899           "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?);",
   1900       "INSERT INTO 'metas' VALUES(2,669,669,4,"
   1901           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   1902           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   1903           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   1904           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   1905           "14447414447414447',NULL,?);",
   1906       "INSERT INTO 'metas' VALUES(4,681,681,3,"
   1907           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   1908           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   1909           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   1910           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   1911           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   1912           "E2F77656C636F6D652E68746D6C1200',NULL,?);",
   1913       "INSERT INTO 'metas' VALUES(5,677,677,7,"
   1914           META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
   1915           "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
   1916           "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
   1917           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
   1918           "ULL,?);",
   1919       "INSERT INTO 'metas' VALUES(6,694,694,6,"
   1920           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   1921           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   1922           ",NULL,?);",
   1923       "INSERT INTO 'metas' VALUES(7,663,663,0,"
   1924           META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
   1925           "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?);",
   1926       "INSERT INTO 'metas' VALUES(8,664,664,0,"
   1927           META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
   1928           ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
   1929           "00',X'C2881000',NULL,?);",
   1930       "INSERT INTO 'metas' VALUES(9,665,665,1,"
   1931           META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
   1932           ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
   1933           "000',X'C2881000',NULL,?);",
   1934       "INSERT INTO 'metas' VALUES(10,666,666,2,"
   1935           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   1936           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   1937           "LL,X'C2881000',X'C2881000',NULL,?);",
   1938       "INSERT INTO 'metas' VALUES(11,683,683,8,"
   1939           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   1940           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   1941           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   1942           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   1943           "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?);",
   1944       "INSERT INTO 'metas' VALUES(12,685,685,9,"
   1945           META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
   1946           "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
   1947           "2881000',X'C2881000',NULL,?);",
   1948       "INSERT INTO 'metas' VALUES(13,687,687,10,"
   1949           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   1950           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   1951           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   1952           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   1953           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   1954           "E6963616E6E2E636F6D2F120744414146415346',NULL,?);",
   1955       "INSERT INTO 'metas' VALUES(14,692,692,11,"
   1956           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   1957           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   1958           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   1959           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   1960           "81205504E473259',NULL,?);" };
   1961 
   1962   for (int i = 0; i < V80_ROW_COUNT; i++) {
   1963     sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
   1964     std::string ord = V81_Ordinal(i);
   1965     s.BindBlob(0, ord.data(), ord.length());
   1966     ASSERT_TRUE(s.Run());
   1967     s.Reset(true);
   1968   }
   1969   ASSERT_TRUE(connection->CommitTransaction());
   1970 }
   1971 
   1972 void MigrationTest::SetUpVersion82Database(sql::Connection* connection) {
   1973   ASSERT_TRUE(connection->is_open());
   1974   ASSERT_TRUE(connection->BeginTransaction());
   1975   ASSERT_TRUE(connection->Execute(
   1976       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   1977       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',82);"
   1978       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   1979           "itial_sync_ended BOOLEAN default 0, transaction_version BIGINT "
   1980           "default 0);"
   1981       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1, 1);"
   1982       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   1983           "_version bigint default -1,server_version bigint default 0,         "
   1984           "local_external_id bigint default 0"
   1985           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   1986           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   1987           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   1988           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   1989           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   1990           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   1991           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   1992           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   1993           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   1994           ", server_ordinal_in_parent blob);"
   1995       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   1996           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   1997           "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
   1998           "blob);"
   1999       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   2000           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
   2001           "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
   2002 
   2003       const char* insert_stmts[V80_ROW_COUNT] = {
   2004       "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
   2005           "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?);",
   2006       "INSERT INTO 'metas' VALUES(2,669,669,4,"
   2007           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   2008           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   2009           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   2010           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   2011           "14447414447414447',NULL,?);",
   2012       "INSERT INTO 'metas' VALUES(4,681,681,3,"
   2013           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   2014           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   2015           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   2016           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   2017           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   2018           "E2F77656C636F6D652E68746D6C1200',NULL,?);",
   2019       "INSERT INTO 'metas' VALUES(5,677,677,7,"
   2020           META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
   2021           "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
   2022           "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
   2023           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
   2024           "ULL,?);",
   2025       "INSERT INTO 'metas' VALUES(6,694,694,6,"
   2026           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   2027           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   2028           ",NULL,?);",
   2029       "INSERT INTO 'metas' VALUES(7,663,663,0,"
   2030           META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
   2031           "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?);",
   2032       "INSERT INTO 'metas' VALUES(8,664,664,0,"
   2033           META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
   2034           ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
   2035           "00',X'C2881000',NULL,?);",
   2036       "INSERT INTO 'metas' VALUES(9,665,665,1,"
   2037           META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
   2038           ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
   2039           "000',X'C2881000',NULL,?);",
   2040       "INSERT INTO 'metas' VALUES(10,666,666,2,"
   2041           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   2042           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   2043           "LL,X'C2881000',X'C2881000',NULL,?);",
   2044       "INSERT INTO 'metas' VALUES(11,683,683,8,"
   2045           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   2046           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   2047           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   2048           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   2049           "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?);",
   2050       "INSERT INTO 'metas' VALUES(12,685,685,9,"
   2051           META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
   2052           "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
   2053           "2881000',X'C2881000',NULL,?);",
   2054       "INSERT INTO 'metas' VALUES(13,687,687,10,"
   2055           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   2056           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   2057           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   2058           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   2059           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   2060           "E6963616E6E2E636F6D2F120744414146415346',NULL,?);",
   2061       "INSERT INTO 'metas' VALUES(14,692,692,11,"
   2062           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   2063           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   2064           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   2065           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   2066           "81205504E473259',NULL,?);" };
   2067 
   2068   for (int i = 0; i < V80_ROW_COUNT; i++) {
   2069     sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
   2070     std::string ord = V81_Ordinal(i);
   2071     s.BindBlob(0, ord.data(), ord.length());
   2072     ASSERT_TRUE(s.Run());
   2073     s.Reset(true);
   2074   }
   2075   ASSERT_TRUE(connection->CommitTransaction());
   2076 }
   2077 
   2078 void MigrationTest::SetUpVersion83Database(sql::Connection* connection) {
   2079   ASSERT_TRUE(connection->is_open());
   2080   ASSERT_TRUE(connection->BeginTransaction());
   2081   ASSERT_TRUE(connection->Execute(
   2082       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   2083       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',83);"
   2084       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   2085           "itial_sync_ended BOOLEAN default 0, transaction_version BIGINT "
   2086           "default 0);"
   2087       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1, 1);"
   2088       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   2089           "_version bigint default -1,server_version bigint default 0,         "
   2090           "local_external_id bigint default 0"
   2091           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   2092           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   2093           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   2094           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   2095           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   2096           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   2097           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   2098           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   2099           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   2100           ", server_ordinal_in_parent blob, transaction_version bigint default "
   2101           "0);"
   2102       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   2103           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   2104           "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
   2105           "blob);"
   2106       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   2107           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
   2108           "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
   2109 
   2110       const char* insert_stmts[V80_ROW_COUNT] = {
   2111       "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
   2112           "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?,0);",
   2113       "INSERT INTO 'metas' VALUES(2,669,669,4,"
   2114           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   2115           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   2116           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   2117           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   2118           "14447414447414447',NULL,?,0);",
   2119       "INSERT INTO 'metas' VALUES(4,681,681,3,"
   2120           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   2121           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   2122           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   2123           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   2124           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   2125           "E2F77656C636F6D652E68746D6C1200',NULL,?,0);",
   2126       "INSERT INTO 'metas' VALUES(5,677,677,7,"
   2127           META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
   2128           "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
   2129           "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
   2130           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
   2131           "ULL,?,0);",
   2132       "INSERT INTO 'metas' VALUES(6,694,694,6,"
   2133           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   2134           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   2135           ",NULL,?,0);",
   2136       "INSERT INTO 'metas' VALUES(7,663,663,0,"
   2137           META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
   2138           "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?,0);"
   2139           "",
   2140       "INSERT INTO 'metas' VALUES(8,664,664,0,"
   2141           META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
   2142           ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
   2143           "00',X'C2881000',NULL,?,0);",
   2144       "INSERT INTO 'metas' VALUES(9,665,665,1,"
   2145           META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
   2146           ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
   2147           "000',X'C2881000',NULL,?,0);",
   2148       "INSERT INTO 'metas' VALUES(10,666,666,2,"
   2149           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   2150           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   2151           "LL,X'C2881000',X'C2881000',NULL,?,0);",
   2152       "INSERT INTO 'metas' VALUES(11,683,683,8,"
   2153           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   2154           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   2155           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   2156           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   2157           "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?,0);",
   2158       "INSERT INTO 'metas' VALUES(12,685,685,9,"
   2159           META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
   2160           "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
   2161           "2881000',X'C2881000',NULL,?,0);",
   2162       "INSERT INTO 'metas' VALUES(13,687,687,10,"
   2163           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   2164           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   2165           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   2166           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   2167           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   2168           "E6963616E6E2E636F6D2F120744414146415346',NULL,?,0);",
   2169       "INSERT INTO 'metas' VALUES(14,692,692,11,"
   2170           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   2171           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   2172           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   2173           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   2174           "81205504E473259',NULL,?,0);" };
   2175 
   2176   for (int i = 0; i < V80_ROW_COUNT; i++) {
   2177     sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
   2178     std::string ord = V81_Ordinal(i);
   2179     s.BindBlob(0, ord.data(), ord.length());
   2180     ASSERT_TRUE(s.Run());
   2181     s.Reset(true);
   2182   }
   2183   ASSERT_TRUE(connection->CommitTransaction());
   2184 }
   2185 
   2186 void MigrationTest::SetUpVersion84Database(sql::Connection* connection) {
   2187   ASSERT_TRUE(connection->is_open());
   2188   ASSERT_TRUE(connection->BeginTransaction());
   2189   ASSERT_TRUE(connection->Execute(
   2190       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   2191       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',84);"
   2192       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
   2193           "itial_sync_ended BOOLEAN default 0, transaction_version BIGINT "
   2194           "default 0);"
   2195       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1, 1);"
   2196       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   2197           "_version bigint default -1,server_version bigint default 0,         "
   2198           "local_external_id bigint default 0"
   2199           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   2200           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   2201           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   2202           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   2203           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   2204           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   2205           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   2206           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   2207           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   2208           ", server_ordinal_in_parent blob, transaction_version bigint default "
   2209           "0);"
   2210       "CREATE TABLE 'deleted_metas'"
   2211           "(metahandle bigint primary key ON CONFLICT FAIL,base"
   2212           "_version bigint default -1,server_version bigint default 0,         "
   2213           "local_external_id bigint default 0"
   2214           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   2215           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   2216           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   2217           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   2218           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   2219           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   2220           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   2221           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   2222           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   2223           ", server_ordinal_in_parent blob, transaction_version bigint default "
   2224           "0);"
   2225       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   2226           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   2227           "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
   2228           "blob);"
   2229       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   2230           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
   2231           "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
   2232 
   2233       const char* insert_stmts[V80_ROW_COUNT] = {
   2234       "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
   2235           "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?,0);",
   2236       "INSERT INTO 'metas' VALUES(2,669,669,4,"
   2237           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   2238           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   2239           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   2240           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   2241           "14447414447414447',NULL,?,0);",
   2242       "INSERT INTO 'metas' VALUES(4,681,681,3,"
   2243           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   2244           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   2245           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   2246           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   2247           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   2248           "E2F77656C636F6D652E68746D6C1200',NULL,?,0);",
   2249       "INSERT INTO 'metas' VALUES(5,677,677,7,"
   2250           META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
   2251           "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
   2252           "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
   2253           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
   2254           "ULL,?,0);",
   2255       "INSERT INTO 'metas' VALUES(6,694,694,6,"
   2256           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   2257           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   2258           ",NULL,?,0);",
   2259       "INSERT INTO 'metas' VALUES(7,663,663,0,"
   2260           META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
   2261           "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?,0);"
   2262           "",
   2263       "INSERT INTO 'metas' VALUES(8,664,664,0,"
   2264           META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
   2265           ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
   2266           "00',X'C2881000',NULL,?,0);",
   2267       "INSERT INTO 'metas' VALUES(9,665,665,1,"
   2268           META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
   2269           ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
   2270           "000',X'C2881000',NULL,?,0);",
   2271       "INSERT INTO 'metas' VALUES(10,666,666,2,"
   2272           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   2273           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   2274           "LL,X'C2881000',X'C2881000',NULL,?,0);",
   2275       "INSERT INTO 'metas' VALUES(11,683,683,8,"
   2276           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   2277           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   2278           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   2279           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   2280           "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?,0);",
   2281       "INSERT INTO 'metas' VALUES(12,685,685,9,"
   2282           META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
   2283           "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
   2284           "2881000',X'C2881000',NULL,?,0);",
   2285       "INSERT INTO 'metas' VALUES(13,687,687,10,"
   2286           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   2287           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   2288           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   2289           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   2290           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   2291           "E6963616E6E2E636F6D2F120744414146415346',NULL,?,0);",
   2292       "INSERT INTO 'metas' VALUES(14,692,692,11,"
   2293           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   2294           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   2295           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   2296           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   2297           "81205504E473259',NULL,?,0);" };
   2298 
   2299   for (int i = 0; i < V80_ROW_COUNT; i++) {
   2300     sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
   2301     std::string ord = V81_Ordinal(i);
   2302     s.BindBlob(0, ord.data(), ord.length());
   2303     ASSERT_TRUE(s.Run());
   2304     s.Reset(true);
   2305   }
   2306   ASSERT_TRUE(connection->CommitTransaction());
   2307 }
   2308 
   2309 void MigrationTest::SetUpVersion85Database(sql::Connection* connection) {
   2310   ASSERT_TRUE(connection->is_open());
   2311   ASSERT_TRUE(connection->BeginTransaction());
   2312   ASSERT_TRUE(connection->Execute(
   2313       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   2314       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',85);"
   2315       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, "
   2316           "transaction_version BIGINT default 0);"
   2317       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605', 1);"
   2318       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
   2319           "_version bigint default -1,server_version bigint default 0,         "
   2320           "local_external_id bigint default 0"
   2321           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   2322           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   2323           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   2324           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   2325           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   2326           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   2327           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   2328           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   2329           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   2330           ", server_ordinal_in_parent blob, transaction_version bigint default "
   2331           "0);"
   2332       "CREATE TABLE 'deleted_metas'"
   2333           "(metahandle bigint primary key ON CONFLICT FAIL,base"
   2334           "_version bigint default -1,server_version bigint default 0,         "
   2335           "local_external_id bigint default 0"
   2336           ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
   2337           "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   2338           "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
   2339           "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
   2340           "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   2341           "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
   2342           "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
   2343           "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
   2344           "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
   2345           ", server_ordinal_in_parent blob, transaction_version bigint default "
   2346           "0);"
   2347       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
   2348           "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
   2349           "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
   2350           "blob);"
   2351       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.org',"
   2352           "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
   2353           "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
   2354 
   2355       const char* insert_stmts[V80_ROW_COUNT] = {
   2356       "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
   2357           "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?,0);",
   2358       "INSERT INTO 'metas' VALUES(2,669,669,4,"
   2359           META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
   2360           "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
   2361           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
   2362           "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
   2363           "14447414447414447',NULL,?,0);",
   2364       "INSERT INTO 'metas' VALUES(4,681,681,3,"
   2365           META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
   2366           "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
   2367           ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
   2368           "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
   2369           "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
   2370           "E2F77656C636F6D652E68746D6C1200',NULL,?,0);",
   2371       "INSERT INTO 'metas' VALUES(5,677,677,7,"
   2372           META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
   2373           "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
   2374           "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
   2375           "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
   2376           "ULL,?,0);",
   2377       "INSERT INTO 'metas' VALUES(6,694,694,6,"
   2378           META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
   2379           ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
   2380           ",NULL,?,0);",
   2381       "INSERT INTO 'metas' VALUES(7,663,663,0,"
   2382           META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
   2383           "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?,0);"
   2384           "",
   2385       "INSERT INTO 'metas' VALUES(8,664,664,0,"
   2386           META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
   2387           ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
   2388           "00',X'C2881000',NULL,?,0);",
   2389       "INSERT INTO 'metas' VALUES(9,665,665,1,"
   2390           META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
   2391           ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
   2392           "000',X'C2881000',NULL,?,0);",
   2393       "INSERT INTO 'metas' VALUES(10,666,666,2,"
   2394           META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
   2395           "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
   2396           "LL,X'C2881000',X'C2881000',NULL,?,0);",
   2397       "INSERT INTO 'metas' VALUES(11,683,683,8,"
   2398           META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
   2399           ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
   2400           "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
   2401           "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
   2402           "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?,0);",
   2403       "INSERT INTO 'metas' VALUES(12,685,685,9,"
   2404           META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
   2405           "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
   2406           "2881000',X'C2881000',NULL,?,0);",
   2407       "INSERT INTO 'metas' VALUES(13,687,687,10,"
   2408           META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
   2409           "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
   2410           "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
   2411           "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
   2412           "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
   2413           "E6963616E6E2E636F6D2F120744414146415346',NULL,?,0);",
   2414       "INSERT INTO 'metas' VALUES(14,692,692,11,"
   2415           META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
   2416           ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
   2417           "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
   2418           "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
   2419           "81205504E473259',NULL,?,0);" };
   2420 
   2421   for (int i = 0; i < V80_ROW_COUNT; i++) {
   2422     sql::Statement s(connection->GetUniqueStatement(insert_stmts[i]));
   2423     std::string ord = V81_Ordinal(i);
   2424     s.BindBlob(0, ord.data(), ord.length());
   2425     ASSERT_TRUE(s.Run());
   2426     s.Reset(true);
   2427   }
   2428   ASSERT_TRUE(connection->CommitTransaction());
   2429 }
   2430 
   2431 void MigrationTest::SetUpVersion86Database(sql::Connection* connection) {
   2432   ASSERT_TRUE(connection->is_open());
   2433   ASSERT_TRUE(connection->BeginTransaction());
   2434   ASSERT_TRUE(connection->Execute(
   2435       "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
   2436       "INSERT INTO 'share_version' VALUES('nick (at) chromium.org',86);"
   2437       "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB,"
   2438          " transaction_version BIGINT default 0);"
   2439       "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
   2440       "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,b"
   2441          "ase_version bigint default -1,server_version bigint default 0,local_e"
   2442          "xternal_id bigint default 0,transaction_version bigint default 0,mtim"
   2443          "e bigint default 0,server_mtime bigint default 0,ctime bigint default"
   2444          " 0,server_ctime bigint default 0,id varchar(255) default 'r',parent_i"
   2445          "d varchar(255) default 'r',server_parent_id varchar(255) default 'r',"
   2446          "is_unsynced bit default 0,is_unapplied_update bit default 0,is_del bi"
   2447          "t default 0,is_dir bit default 0,server_is_dir bit default 0,server_i"
   2448          "s_del bit default 0,non_unique_name varchar,server_non_unique_name va"
   2449          "rchar(255),unique_server_tag varchar,unique_client_tag varchar,specif"
   2450          "ics blob,server_specifics blob,base_server_specifics blob,server_uniq"
   2451          "ue_position blob,unique_position blob,unique_bookmark_tag blob);"
   2452       "INSERT INTO 'metas' VALUES(1,-1,0,0,0,"
   2453          META_PROTO_TIMES_VALS(1)
   2454          ",'r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,"
   2455          "X'',X'',NULL,X'',X'',X'');"
   2456       "INSERT INTO 'metas' VALUES(6,694,694,6,0,"
   2457          META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9',0,0,0,1,1,0,'T"
   2458          "he Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000',NULL,X'"
   2459          "',X'',X'');"
   2460       "INSERT INTO 'metas' VALUES(7,663,663,0,0,"
   2461          META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r',0,0,0,1,1,0,'Google Chro"
   2462          "me','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,X'',X'',X'');"
   2463       "INSERT INTO 'metas' VALUES(8,664,664,0,0,"
   2464          META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7',0,0,0,1,1,0,'B"
   2465          "ookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',X'C2"
   2466          "881000',NULL,X'',X'',X'');"
   2467       "INSERT INTO 'metas' VALUES(9,665,665,1,0,"
   2468          META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8',0,0,0,1,1,0,'B"
   2469          "ookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C288100"
   2470          "0',NULL,X'',X'',X'');"
   2471       "INSERT INTO 'metas' VALUES(10,666,666,2,0,"
   2472          META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8',0,0,0,1,1,0,"
   2473          "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL,X'C2881000"
   2474          "',X'C2881000',NULL,X'',X'',X'');"
   2475       "INSERT INTO 'metas' VALUES(11,683,683,8,0,"
   2476          META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6',0,0,0,0,0,0,"
   2477          "'Home (The Chromium Projects)','Home (The Chromium Projects)',NULL,NU"
   2478          "LL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1206"
   2479          "414741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756D2E6"
   2480          "F72672F6F7468657212084146414756415346',NULL,X'',X'',X'');"
   2481       "INSERT INTO 'metas' VALUES(12,685,685,9,0,"
   2482          META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6',0,0,0,1,1,0,"
   2483          "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000',X'C2881000'"
   2484          ",NULL,X'',X'',X'');"
   2485       "INSERT INTO 'metas' VALUES(13,687,687,10,0,"
   2486          META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6',0,0,0,0,0,0"
   2487          ",'ICANN | Internet Corporation for Assigned Names and Numbers','ICANN"
   2488          " | Internet Corporation for Assigned Names and Numbers',NULL,NULL,X'C"
   2489          "28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504E47415846"
   2490          "3041414646',X'C28810200A15687474703A2F2F7777772E6963616E6E2E636F6D2F1"
   2491          "20744414146415346',NULL,X'',X'',X'');"
   2492       "INSERT INTO 'metas' VALUES(14,692,692,11,0,"
   2493          META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6',0,0,0,0,0,0"
   2494          ",'The WebKit Open Source Project','The WebKit Open Source Project',NU"
   2495          "LL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F72672F1204504E475"
   2496          "8',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E473259"
   2497          "',NULL,X'',X'',X'');"
   2498       "CREATE TABLE deleted_metas (metahandle bigint primary key ON CONFLICT"
   2499          " FAIL,base_version bigint default -1,server_version bigint default 0,"
   2500          "local_external_id bigint default 0,transaction_version bigint default"
   2501          " 0,mtime bigint default 0,server_mtime bigint default 0,ctime bigint "
   2502          "default 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
   2503          "arent_id varchar(255) default 'r',server_parent_id varchar(255) defau"
   2504          "lt 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
   2505          "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,s"
   2506          "erver_is_del bit default 0,non_unique_name varchar,server_non_unique_"
   2507          "name varchar(255),unique_server_tag varchar,unique_client_tag varchar"
   2508          ",specifics blob,server_specifics blob,base_server_specifics blob,serv"
   2509          "er_unique_position blob,unique_position blob,unique_bookmark_tag blob"
   2510          ");"
   2511       "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birt"
   2512          "hday TEXT, db_create_version TEXT, db_create_time INT, next_id INT de"
   2513          "fault -2, cache_guid TEXT, notification_state BLOB, bag_of_chips BLOB"
   2514          ");"
   2515       "INSERT INTO 'share_info' VALUES('nick (at) chromium.org','nick (at) chromium.or"
   2516          "g','c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-13107"
   2517          "8,'9010788312004066376x-6609234393368420856x',NULL,NULL);"));
   2518   ASSERT_TRUE(connection->CommitTransaction());
   2519 }
   2520 
   2521 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) {
   2522   sql::Connection connection;
   2523   ASSERT_TRUE(connection.OpenInMemory());
   2524 
   2525   SetUpVersion67Database(&connection);
   2526 
   2527   // Columns existing before version 67.
   2528   ASSERT_TRUE(connection.DoesColumnExist("metas", "name"));
   2529   ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name"));
   2530   ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name"));
   2531 
   2532   scoped_ptr<TestDirectoryBackingStore> dbs(
   2533       new TestDirectoryBackingStore(GetUsername(), &connection));
   2534 
   2535   ASSERT_FALSE(dbs->needs_column_refresh_);
   2536   ASSERT_TRUE(dbs->MigrateVersion67To68());
   2537   ASSERT_EQ(68, dbs->GetVersion());
   2538   ASSERT_TRUE(dbs->needs_column_refresh_);
   2539 }
   2540 
   2541 TEST_F(DirectoryBackingStoreTest, MigrateVersion68To69) {
   2542   sql::Connection connection;
   2543   ASSERT_TRUE(connection.OpenInMemory());
   2544   SetUpVersion68Database(&connection);
   2545 
   2546   {
   2547     scoped_ptr<TestDirectoryBackingStore> dbs(
   2548         new TestDirectoryBackingStore(GetUsername(), &connection));
   2549 
   2550     ASSERT_FALSE(dbs->needs_column_refresh_);
   2551     ASSERT_TRUE(dbs->MigrateVersion68To69());
   2552     ASSERT_EQ(69, dbs->GetVersion());
   2553     ASSERT_TRUE(dbs->needs_column_refresh_);
   2554   }
   2555 
   2556   ASSERT_TRUE(connection.DoesColumnExist("metas", "specifics"));
   2557   ASSERT_TRUE(connection.DoesColumnExist("metas", "server_specifics"));
   2558   sql::Statement s(connection.GetUniqueStatement("SELECT non_unique_name,"
   2559       "is_del, is_dir, id, specifics, server_specifics FROM metas "
   2560       "WHERE metahandle = 2"));
   2561   ASSERT_TRUE(s.Step());
   2562   ASSERT_EQ("Deleted Item", s.ColumnString(0));
   2563   ASSERT_TRUE(s.ColumnBool(1));
   2564   ASSERT_FALSE(s.ColumnBool(2));
   2565   ASSERT_EQ("s_ID_2", s.ColumnString(3));
   2566   sync_pb::EntitySpecifics specifics;
   2567   specifics.ParseFromArray(s.ColumnBlob(4), s.ColumnByteLength(4));
   2568   ASSERT_TRUE(specifics.has_bookmark());
   2569   ASSERT_EQ("http://www.google.com/", specifics.bookmark().url());
   2570   ASSERT_EQ("AASGASGA", specifics.bookmark().favicon());
   2571   specifics.ParseFromArray(s.ColumnBlob(5), s.ColumnByteLength(5));
   2572   ASSERT_TRUE(specifics.has_bookmark());
   2573   ASSERT_EQ("http://www.google.com/2", specifics.bookmark().url());
   2574   ASSERT_EQ("ASADGADGADG", specifics.bookmark().favicon());
   2575   ASSERT_FALSE(s.Step());
   2576 }
   2577 
   2578 TEST_F(DirectoryBackingStoreTest, MigrateVersion69To70) {
   2579   sql::Connection connection;
   2580   ASSERT_TRUE(connection.OpenInMemory());
   2581   SetUpVersion69Database(&connection);
   2582 
   2583   ASSERT_TRUE(connection.DoesColumnExist("metas", "singleton_tag"));
   2584   ASSERT_FALSE(connection.DoesColumnExist("metas", "unique_server_tag"));
   2585   ASSERT_FALSE(connection.DoesColumnExist("metas", "unique_client_tag"));
   2586 
   2587   {
   2588     scoped_ptr<TestDirectoryBackingStore> dbs(
   2589         new TestDirectoryBackingStore(GetUsername(), &connection));
   2590 
   2591     ASSERT_FALSE(dbs->needs_column_refresh_);
   2592     ASSERT_TRUE(dbs->MigrateVersion69To70());
   2593     ASSERT_EQ(70, dbs->GetVersion());
   2594     ASSERT_TRUE(dbs->needs_column_refresh_);
   2595   }
   2596 
   2597   EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag"));
   2598   EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag"));
   2599   sql::Statement s(connection.GetUniqueStatement("SELECT id"
   2600       " FROM metas WHERE unique_server_tag = 'google_chrome'"));
   2601   ASSERT_TRUE(s.Step());
   2602   EXPECT_EQ("s_ID_7", s.ColumnString(0));
   2603 }
   2604 
   2605 TEST_F(DirectoryBackingStoreTest, MigrateVersion70To71) {
   2606   sql::Connection connection;
   2607   ASSERT_TRUE(connection.OpenInMemory());
   2608   SetUpVersion70Database(&connection);
   2609 
   2610   ASSERT_TRUE(connection.DoesColumnExist("share_info", "last_sync_timestamp"));
   2611   ASSERT_TRUE(connection.DoesColumnExist("share_info", "initial_sync_ended"));
   2612   ASSERT_FALSE(connection.DoesTableExist("models"));
   2613 
   2614   {
   2615     scoped_ptr<TestDirectoryBackingStore> dbs(
   2616         new TestDirectoryBackingStore(GetUsername(), &connection));
   2617 
   2618     ASSERT_FALSE(dbs->needs_column_refresh_);
   2619     ASSERT_TRUE(dbs->MigrateVersion70To71());
   2620     ASSERT_EQ(71, dbs->GetVersion());
   2621     ASSERT_FALSE(dbs->needs_column_refresh_);
   2622   }
   2623 
   2624   ASSERT_FALSE(connection.DoesColumnExist("share_info", "last_sync_timestamp"));
   2625   ASSERT_FALSE(connection.DoesColumnExist("share_info", "initial_sync_ended"));
   2626   ASSERT_TRUE(connection.DoesTableExist("models"));
   2627   ASSERT_TRUE(connection.DoesColumnExist("models", "initial_sync_ended"));
   2628   ASSERT_TRUE(connection.DoesColumnExist("models", "last_download_timestamp"));
   2629   ASSERT_TRUE(connection.DoesColumnExist("models", "model_id"));
   2630 
   2631   sql::Statement s(connection.GetUniqueStatement("SELECT model_id, "
   2632       "initial_sync_ended, last_download_timestamp FROM models"));
   2633   ASSERT_TRUE(s.Step());
   2634   std::string model_id = s.ColumnString(0);
   2635   EXPECT_EQ("C2881000", base::HexEncode(model_id.data(), model_id.size()))
   2636       << "Model ID is expected to be the empty BookmarkSpecifics proto.";
   2637   EXPECT_TRUE(s.ColumnBool(1));
   2638   EXPECT_EQ(694, s.ColumnInt64(2));
   2639   ASSERT_FALSE(s.Step());
   2640 }
   2641 
   2642 
   2643 TEST_F(DirectoryBackingStoreTest, MigrateVersion71To72) {
   2644   sql::Connection connection;
   2645   ASSERT_TRUE(connection.OpenInMemory());
   2646   SetUpVersion71Database(&connection);
   2647 
   2648   ASSERT_TRUE(connection.DoesTableExist("extended_attributes"));
   2649 
   2650   {
   2651     scoped_ptr<TestDirectoryBackingStore> dbs(
   2652         new TestDirectoryBackingStore(GetUsername(), &connection));
   2653 
   2654     ASSERT_FALSE(dbs->needs_column_refresh_);
   2655     ASSERT_TRUE(dbs->MigrateVersion71To72());
   2656     ASSERT_EQ(72, dbs->GetVersion());
   2657     ASSERT_FALSE(dbs->needs_column_refresh_);
   2658   }
   2659 
   2660   ASSERT_FALSE(connection.DoesTableExist("extended_attributes"));
   2661 }
   2662 
   2663 TEST_F(DirectoryBackingStoreTest, MigrateVersion72To73) {
   2664   sql::Connection connection;
   2665   ASSERT_TRUE(connection.OpenInMemory());
   2666   SetUpVersion72Database(&connection);
   2667 
   2668   ASSERT_FALSE(connection.DoesColumnExist("share_info", "notification_state"));
   2669 
   2670   {
   2671     scoped_ptr<TestDirectoryBackingStore> dbs(
   2672         new TestDirectoryBackingStore(GetUsername(), &connection));
   2673 
   2674     ASSERT_FALSE(dbs->needs_column_refresh_);
   2675     ASSERT_TRUE(dbs->MigrateVersion72To73());
   2676     ASSERT_EQ(73, dbs->GetVersion());
   2677     ASSERT_FALSE(dbs->needs_column_refresh_);
   2678   }
   2679 
   2680   ASSERT_TRUE(connection.DoesColumnExist("share_info", "notification_state"));
   2681 }
   2682 
   2683 TEST_F(DirectoryBackingStoreTest, MigrateVersion73To74) {
   2684   sql::Connection connection;
   2685   ASSERT_TRUE(connection.OpenInMemory());
   2686   SetUpVersion73Database(&connection);
   2687 
   2688   ASSERT_FALSE(
   2689       connection.DoesColumnExist("share_info", "autofill_migration_state"));
   2690   ASSERT_FALSE(
   2691       connection.DoesColumnExist("share_info",
   2692           "bookmarks_added_during_autofill_migration"));
   2693   ASSERT_FALSE(
   2694       connection.DoesColumnExist("share_info", "autofill_migration_time"));
   2695   ASSERT_FALSE(
   2696       connection.DoesColumnExist("share_info",
   2697           "autofill_entries_added_during_migration"));
   2698 
   2699   ASSERT_FALSE(
   2700       connection.DoesColumnExist("share_info",
   2701           "autofill_profiles_added_during_migration"));
   2702 
   2703   {
   2704     scoped_ptr<TestDirectoryBackingStore> dbs(
   2705         new TestDirectoryBackingStore(GetUsername(), &connection));
   2706 
   2707     ASSERT_FALSE(dbs->needs_column_refresh_);
   2708     ASSERT_TRUE(dbs->MigrateVersion73To74());
   2709     ASSERT_EQ(74, dbs->GetVersion());
   2710     ASSERT_FALSE(dbs->needs_column_refresh_);
   2711   }
   2712 
   2713   ASSERT_TRUE(
   2714       connection.DoesColumnExist("share_info", "autofill_migration_state"));
   2715   ASSERT_TRUE(
   2716       connection.DoesColumnExist("share_info",
   2717           "bookmarks_added_during_autofill_migration"));
   2718   ASSERT_TRUE(
   2719       connection.DoesColumnExist("share_info", "autofill_migration_time"));
   2720   ASSERT_TRUE(
   2721       connection.DoesColumnExist("share_info",
   2722           "autofill_entries_added_during_migration"));
   2723 
   2724   ASSERT_TRUE(
   2725       connection.DoesColumnExist("share_info",
   2726           "autofill_profiles_added_during_migration"));
   2727 }
   2728 
   2729 TEST_F(DirectoryBackingStoreTest, MigrateVersion74To75) {
   2730   sql::Connection connection;
   2731   ASSERT_TRUE(connection.OpenInMemory());
   2732   SetUpVersion74Database(&connection);
   2733 
   2734   ASSERT_FALSE(connection.DoesColumnExist("models", "progress_marker"));
   2735   ASSERT_TRUE(connection.DoesColumnExist("models", "last_download_timestamp"));
   2736 
   2737   {
   2738     scoped_ptr<TestDirectoryBackingStore> dbs(
   2739         new TestDirectoryBackingStore(GetUsername(), &connection));
   2740 
   2741     ASSERT_FALSE(dbs->needs_column_refresh_);
   2742     ASSERT_TRUE(dbs->MigrateVersion74To75());
   2743     ASSERT_EQ(75, dbs->GetVersion());
   2744     ASSERT_FALSE(dbs->needs_column_refresh_);
   2745   }
   2746 
   2747   ASSERT_TRUE(connection.DoesColumnExist("models", "progress_marker"));
   2748   ASSERT_FALSE(connection.DoesColumnExist("models", "last_download_timestamp"));
   2749 }
   2750 
   2751 TEST_F(DirectoryBackingStoreTest, MigrateVersion75To76) {
   2752   sql::Connection connection;
   2753   ASSERT_TRUE(connection.OpenInMemory());
   2754   SetUpVersion75Database(&connection);
   2755 
   2756   ASSERT_TRUE(
   2757       connection.DoesColumnExist("share_info", "autofill_migration_state"));
   2758   ASSERT_TRUE(connection.DoesColumnExist("share_info",
   2759       "bookmarks_added_during_autofill_migration"));
   2760   ASSERT_TRUE(
   2761       connection.DoesColumnExist("share_info", "autofill_migration_time"));
   2762   ASSERT_TRUE(connection.DoesColumnExist("share_info",
   2763       "autofill_entries_added_during_migration"));
   2764   ASSERT_TRUE(connection.DoesColumnExist("share_info",
   2765       "autofill_profiles_added_during_migration"));
   2766 
   2767   scoped_ptr<TestDirectoryBackingStore> dbs(
   2768       new TestDirectoryBackingStore(GetUsername(), &connection));
   2769   ASSERT_FALSE(dbs->needs_column_refresh_);
   2770   ASSERT_TRUE(dbs->MigrateVersion75To76());
   2771   ASSERT_EQ(76, dbs->GetVersion());
   2772   ASSERT_TRUE(dbs->needs_column_refresh_);
   2773   // Cannot actual refresh columns due to version 76 not containing all
   2774   // necessary columns.
   2775 }
   2776 
   2777 TEST_F(DirectoryBackingStoreTest, MigrateVersion76To77) {
   2778   sql::Connection connection;
   2779   ASSERT_TRUE(connection.OpenInMemory());
   2780   SetUpVersion76Database(&connection);
   2781 
   2782   scoped_ptr<TestDirectoryBackingStore> dbs(
   2783       new TestDirectoryBackingStore(GetUsername(), &connection));
   2784   ASSERT_FALSE(dbs->needs_column_refresh_);
   2785 
   2786   EXPECT_EQ(GetExpectedLegacyMetaProtoTimes(INCLUDE_DELETED_ITEMS),
   2787             GetMetaProtoTimes(dbs->db_.get()));
   2788   // Since the proto times are expected to be in a legacy format, they may not
   2789   // be compatible with ProtoTimeToTime, so we don't call ExpectTimes().
   2790 
   2791   ASSERT_TRUE(dbs->MigrateVersion76To77());
   2792   ASSERT_EQ(77, dbs->GetVersion());
   2793 
   2794   EXPECT_EQ(GetExpectedMetaProtoTimes(INCLUDE_DELETED_ITEMS),
   2795             GetMetaProtoTimes(dbs->db_.get()));
   2796   // Cannot actually load entries due to version 77 not having all required
   2797   // columns.
   2798   ASSERT_FALSE(dbs->needs_column_refresh_);
   2799 }
   2800 
   2801 TEST_F(DirectoryBackingStoreTest, MigrateVersion77To78) {
   2802   sql::Connection connection;
   2803   ASSERT_TRUE(connection.OpenInMemory());
   2804   SetUpVersion77Database(&connection);
   2805 
   2806   ASSERT_FALSE(connection.DoesColumnExist("metas", "BASE_SERVER_SPECIFICS"));
   2807 
   2808   {
   2809     scoped_ptr<TestDirectoryBackingStore> dbs(
   2810         new TestDirectoryBackingStore(GetUsername(), &connection));
   2811     ASSERT_FALSE(dbs->needs_column_refresh_);
   2812     ASSERT_TRUE(dbs->MigrateVersion77To78());
   2813     ASSERT_EQ(78, dbs->GetVersion());
   2814 
   2815     ASSERT_FALSE(dbs->needs_column_refresh_);
   2816   }
   2817 
   2818   ASSERT_TRUE(connection.DoesColumnExist("metas", "base_server_specifics"));
   2819 }
   2820 
   2821 TEST_F(DirectoryBackingStoreTest, MigrateVersion78To79) {
   2822   const int kInitialNextId = -65542;
   2823 
   2824   sql::Connection connection;
   2825   ASSERT_TRUE(connection.OpenInMemory());
   2826   SetUpVersion78Database(&connection);
   2827 
   2828   // Double-check the original next_id is what we think it is.
   2829   sql::Statement s(connection.GetUniqueStatement(
   2830       "SELECT next_id FROM share_info"));
   2831   s.Step();
   2832   ASSERT_EQ(kInitialNextId, s.ColumnInt(0));
   2833 
   2834   scoped_ptr<TestDirectoryBackingStore> dbs(
   2835       new TestDirectoryBackingStore(GetUsername(), &connection));
   2836   ASSERT_FALSE(dbs->needs_column_refresh_);
   2837   ASSERT_TRUE(dbs->MigrateVersion78To79());
   2838   ASSERT_EQ(79, dbs->GetVersion());
   2839   ASSERT_FALSE(dbs->needs_column_refresh_);
   2840 
   2841   // Ensure the next_id has been incremented.
   2842   Directory::MetahandlesMap handles_map;
   2843   JournalIndex  delete_journals;;
   2844   STLValueDeleter<Directory::MetahandlesMap> deleter(&handles_map);
   2845   Directory::KernelLoadInfo load_info;
   2846 
   2847   s.Clear();
   2848   ASSERT_TRUE(dbs->Load(&handles_map, &delete_journals, &load_info));
   2849   EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536);
   2850 }
   2851 
   2852 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) {
   2853   sql::Connection connection;
   2854   ASSERT_TRUE(connection.OpenInMemory());
   2855   SetUpVersion79Database(&connection);
   2856 
   2857   scoped_ptr<TestDirectoryBackingStore> dbs(
   2858       new TestDirectoryBackingStore(GetUsername(), &connection));
   2859   ASSERT_FALSE(dbs->needs_column_refresh_);
   2860   ASSERT_TRUE(dbs->MigrateVersion79To80());
   2861   ASSERT_EQ(80, dbs->GetVersion());
   2862   ASSERT_FALSE(dbs->needs_column_refresh_);
   2863 
   2864   // Ensure the bag_of_chips has been set.
   2865   Directory::MetahandlesMap handles_map;
   2866   JournalIndex  delete_journals;;
   2867   STLValueDeleter<Directory::MetahandlesMap> deleter(&handles_map);
   2868   Directory::KernelLoadInfo load_info;
   2869 
   2870   ASSERT_TRUE(dbs->Load(&handles_map, &delete_journals, &load_info));
   2871   // Check that the initial value is the serialization of an empty ChipBag.
   2872   sync_pb::ChipBag chip_bag;
   2873   std::string serialized_chip_bag;
   2874   ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag));
   2875   EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips);
   2876 }
   2877 
   2878 TEST_F(DirectoryBackingStoreTest, MigrateVersion80To81) {
   2879   sql::Connection connection;
   2880   ASSERT_TRUE(connection.OpenInMemory());
   2881   SetUpVersion80Database(&connection);
   2882 
   2883   sql::Statement s(connection.GetUniqueStatement(
   2884       "SELECT metahandle, server_position_in_parent "
   2885       "FROM metas WHERE unique_server_tag = 'google_chrome'"));
   2886   ASSERT_TRUE(s.Step());
   2887   ASSERT_EQ(sql::COLUMN_TYPE_INTEGER, s.ColumnType(1));
   2888 
   2889   scoped_ptr<TestDirectoryBackingStore> dbs(
   2890       new TestDirectoryBackingStore(GetUsername(), &connection));
   2891   ASSERT_TRUE(dbs->MigrateVersion80To81());
   2892   ASSERT_EQ(81, dbs->GetVersion());
   2893 
   2894   // Test that ordinal values are preserved correctly.
   2895   sql::Statement new_s(connection.GetUniqueStatement(
   2896       "SELECT metahandle, server_ordinal_in_parent "
   2897       "FROM metas WHERE unique_server_tag = 'google_chrome'"));
   2898   ASSERT_TRUE(new_s.Step());
   2899   ASSERT_EQ(sql::COLUMN_TYPE_BLOB, new_s.ColumnType(1));
   2900 
   2901   std::string expected_ordinal = Int64ToNodeOrdinal(1048576).ToInternalValue();
   2902   std::string actual_ordinal;
   2903   new_s.ColumnBlobAsString(1, &actual_ordinal);
   2904   ASSERT_EQ(expected_ordinal, actual_ordinal);
   2905 }
   2906 
   2907 TEST_F(DirectoryBackingStoreTest, MigrateVersion81To82) {
   2908   sql::Connection connection;
   2909   ASSERT_TRUE(connection.OpenInMemory());
   2910   SetUpVersion81Database(&connection);
   2911   ASSERT_FALSE(connection.DoesColumnExist("models", "transaction_version"));
   2912 
   2913   scoped_ptr<TestDirectoryBackingStore> dbs(
   2914       new TestDirectoryBackingStore(GetUsername(), &connection));
   2915   ASSERT_FALSE(dbs->needs_column_refresh_);
   2916   ASSERT_TRUE(dbs->MigrateVersion81To82());
   2917   ASSERT_EQ(82, dbs->GetVersion());
   2918   ASSERT_FALSE(dbs->needs_column_refresh_);
   2919 
   2920   ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version"));
   2921 }
   2922 
   2923 TEST_F(DirectoryBackingStoreTest, MigrateVersion82To83) {
   2924   sql::Connection connection;
   2925   ASSERT_TRUE(connection.OpenInMemory());
   2926   SetUpVersion82Database(&connection);
   2927   ASSERT_FALSE(connection.DoesColumnExist("metas", "transaction_version"));
   2928 
   2929   scoped_ptr<TestDirectoryBackingStore> dbs(
   2930       new TestDirectoryBackingStore(GetUsername(), &connection));
   2931   ASSERT_TRUE(dbs->MigrateVersion82To83());
   2932   ASSERT_EQ(83, dbs->GetVersion());
   2933 
   2934   ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version"));
   2935 }
   2936 
   2937 TEST_F(DirectoryBackingStoreTest, MigrateVersion83To84) {
   2938   sql::Connection connection;
   2939   ASSERT_TRUE(connection.OpenInMemory());
   2940   SetUpVersion83Database(&connection);
   2941   ASSERT_FALSE(connection.DoesTableExist("deleted_metas"));
   2942 
   2943   scoped_ptr<TestDirectoryBackingStore> dbs(
   2944       new TestDirectoryBackingStore(GetUsername(), &connection));
   2945   ASSERT_TRUE(dbs->MigrateVersion83To84());
   2946   ASSERT_EQ(84, dbs->GetVersion());
   2947 
   2948   ASSERT_TRUE(connection.DoesTableExist("deleted_metas"));
   2949 }
   2950 
   2951 TEST_F(DirectoryBackingStoreTest, MigrateVersion84To85) {
   2952   sql::Connection connection;
   2953   ASSERT_TRUE(connection.OpenInMemory());
   2954   SetUpVersion84Database(&connection);
   2955   ASSERT_TRUE(connection.DoesColumnExist("models", "initial_sync_ended"));
   2956 
   2957   scoped_ptr<TestDirectoryBackingStore> dbs(
   2958       new TestDirectoryBackingStore(GetUsername(), &connection));
   2959   ASSERT_TRUE(dbs->MigrateVersion84To85());
   2960   ASSERT_EQ(85, dbs->GetVersion());
   2961   ASSERT_FALSE(connection.DoesColumnExist("models", "initial_sync_ended"));
   2962 }
   2963 
   2964 TEST_F(DirectoryBackingStoreTest, MigrateVersion85To86) {
   2965   sql::Connection connection;
   2966   ASSERT_TRUE(connection.OpenInMemory());
   2967   SetUpVersion85Database(&connection);
   2968   EXPECT_TRUE(connection.DoesColumnExist("metas", "next_id"));
   2969   EXPECT_TRUE(connection.DoesColumnExist("metas", "prev_id"));
   2970   EXPECT_TRUE(connection.DoesColumnExist("metas", "server_ordinal_in_parent"));
   2971   EXPECT_FALSE(connection.DoesColumnExist("metas", "unique_position"));
   2972   EXPECT_FALSE(connection.DoesColumnExist("metas", "server_unique_position"));
   2973   EXPECT_FALSE(connection.DoesColumnExist("metas", "unique_bookmark_tag"));
   2974 
   2975   scoped_ptr<TestDirectoryBackingStore> dbs(
   2976       new TestDirectoryBackingStore(GetUsername(), &connection));
   2977   ASSERT_TRUE(dbs->MigrateVersion85To86());
   2978   EXPECT_EQ(86, dbs->GetVersion());
   2979   EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_position"));
   2980   EXPECT_TRUE(connection.DoesColumnExist("metas", "server_unique_position"));
   2981   EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_bookmark_tag"));
   2982   ASSERT_TRUE(dbs->needs_column_refresh_);
   2983   ASSERT_TRUE(dbs->RefreshColumns());
   2984   EXPECT_FALSE(connection.DoesColumnExist("metas", "next_id"));
   2985   EXPECT_FALSE(connection.DoesColumnExist("metas", "prev_id"));
   2986   EXPECT_FALSE(connection.DoesColumnExist("metas", "server_ordinal_in_parent"));
   2987 
   2988   {
   2989     Directory::MetahandlesMap handles_map;
   2990     STLValueDeleter<Directory::MetahandlesMap> deleter(&handles_map);
   2991     dbs->LoadEntries(&handles_map);
   2992 
   2993     // Grab a bookmark and examine it.
   2994     Directory::MetahandlesMap::iterator i = handles_map.find(5);
   2995     ASSERT_FALSE(i == handles_map.end());
   2996     EntryKernel* bm = i->second;
   2997     ASSERT_EQ(bm->ref(ID).value(), "s_ID_5");
   2998 
   2999     EXPECT_TRUE(bm->ref(UNIQUE_POSITION).IsValid());
   3000     EXPECT_TRUE(bm->ref(SERVER_UNIQUE_POSITION).IsValid());
   3001     EXPECT_EQ(UniquePosition::kSuffixLength,
   3002               bm->ref(UNIQUE_BOOKMARK_TAG).length());
   3003 
   3004     // Grab a non-bookmark and examine it.
   3005     Directory::MetahandlesMap::iterator j = handles_map.find(1);
   3006 
   3007     ASSERT_FALSE(j == handles_map.end());
   3008     EntryKernel* root = j->second;
   3009     ASSERT_EQ(root->ref(ID).value(), "r");
   3010 
   3011     EXPECT_FALSE(root->ref(UNIQUE_POSITION).IsValid());
   3012     EXPECT_FALSE(root->ref(SERVER_UNIQUE_POSITION).IsValid());
   3013     EXPECT_TRUE(root->ref(UNIQUE_BOOKMARK_TAG).empty());
   3014 
   3015     // Make sure we didn't mistake the bookmark root node for a real bookmark.
   3016     Directory::MetahandlesMap::iterator k = handles_map.find(8);
   3017     ASSERT_FALSE(k == handles_map.end());
   3018     EntryKernel* bm_root = k->second;
   3019     ASSERT_EQ(bm_root->ref(ID).value(), "s_ID_8");
   3020     ASSERT_EQ(bm_root->ref(UNIQUE_SERVER_TAG), "google_chrome_bookmarks");
   3021 
   3022     EXPECT_FALSE(bm_root->ref(UNIQUE_POSITION).IsValid());
   3023     EXPECT_FALSE(bm_root->ref(SERVER_UNIQUE_POSITION).IsValid());
   3024     EXPECT_TRUE(bm_root->ref(UNIQUE_BOOKMARK_TAG).empty());
   3025 
   3026     // Make sure we didn't assign positions to server-created folders, either.
   3027     Directory::MetahandlesMap::iterator l = handles_map.find(10);
   3028     ASSERT_FALSE(l == handles_map.end());
   3029     EntryKernel* perm_folder = l->second;
   3030     ASSERT_EQ(perm_folder->ref(ID).value(), "s_ID_10");
   3031     ASSERT_EQ(perm_folder->ref(UNIQUE_SERVER_TAG), "other_bookmarks");
   3032 
   3033     EXPECT_FALSE(perm_folder->ref(UNIQUE_POSITION).IsValid());
   3034     EXPECT_FALSE(perm_folder->ref(SERVER_UNIQUE_POSITION).IsValid());
   3035     EXPECT_TRUE(perm_folder->ref(UNIQUE_BOOKMARK_TAG).empty());
   3036 
   3037     // Make sure that the syncable::Directory and the migration code agree on
   3038     // which items should or should not have unique position values.  This test
   3039     // may become obsolete if the directory's definition of that function
   3040     // changes, but, until then, this is a useful test.
   3041     for (Directory::MetahandlesMap::iterator it = handles_map.begin();
   3042          it != handles_map.end(); it++) {
   3043       SCOPED_TRACE(it->second->ref(ID));
   3044       if (it->second->ShouldMaintainPosition()) {
   3045         EXPECT_TRUE(it->second->ref(UNIQUE_POSITION).IsValid());
   3046         EXPECT_TRUE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
   3047         EXPECT_FALSE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
   3048       } else {
   3049         EXPECT_FALSE(it->second->ref(UNIQUE_POSITION).IsValid());
   3050         EXPECT_FALSE(it->second->ref(SERVER_UNIQUE_POSITION).IsValid());
   3051         EXPECT_TRUE(it->second->ref(UNIQUE_BOOKMARK_TAG).empty());
   3052       }
   3053     }
   3054   }
   3055 }
   3056 
   3057 TEST_F(DirectoryBackingStoreTest, DetectInvalidPosition) {
   3058   sql::Connection connection;
   3059   ASSERT_TRUE(connection.OpenInMemory());
   3060   SetUpVersion86Database(&connection);
   3061 
   3062   scoped_ptr<TestDirectoryBackingStore> dbs(
   3063       new TestDirectoryBackingStore(GetUsername(), &connection));
   3064   ASSERT_EQ(86, dbs->GetVersion());
   3065 
   3066   // Insert row with bad position.
   3067   sql::Statement s(connection.GetUniqueStatement(
   3068       "INSERT INTO metas "
   3069       "( id, metahandle, is_dir, ctime, mtime,"
   3070       "  unique_position, server_unique_position) "
   3071       "VALUES('c-invalid', 9999, 1, 0, 0, 'BAD_POS', 'BAD_POS')"));
   3072   ASSERT_TRUE(s.Run());
   3073 
   3074   // Trying to unpack this entry should signal that the DB is corrupted.
   3075   Directory::MetahandlesMap handles_map;
   3076   JournalIndex  delete_journals;;
   3077   STLValueDeleter<Directory::MetahandlesMap> deleter(&handles_map);
   3078   Directory::KernelLoadInfo kernel_load_info;
   3079   ASSERT_EQ(FAILED_DATABASE_CORRUPT,
   3080             dbs->Load(&handles_map, &delete_journals, &kernel_load_info));
   3081 }
   3082 
   3083 TEST_P(MigrationTest, ToCurrentVersion) {
   3084   sql::Connection connection;
   3085   ASSERT_TRUE(connection.OpenInMemory());
   3086   switch (GetParam()) {
   3087     case 67:
   3088       SetUpVersion67Database(&connection);
   3089       break;
   3090     case 68:
   3091       SetUpVersion68Database(&connection);
   3092       break;
   3093     case 69:
   3094       SetUpVersion69Database(&connection);
   3095       break;
   3096     case 70:
   3097       SetUpVersion70Database(&connection);
   3098       break;
   3099     case 71:
   3100       SetUpVersion71Database(&connection);
   3101       break;
   3102     case 72:
   3103       SetUpVersion72Database(&connection);
   3104       break;
   3105     case 73:
   3106       SetUpVersion73Database(&connection);
   3107       break;
   3108     case 74:
   3109       SetUpVersion74Database(&connection);
   3110       break;
   3111     case 75:
   3112       SetUpVersion75Database(&connection);
   3113       break;
   3114     case 76:
   3115       SetUpVersion76Database(&connection);
   3116       break;
   3117     case 77:
   3118       SetUpVersion77Database(&connection);
   3119       break;
   3120     case 78:
   3121       SetUpVersion78Database(&connection);
   3122       break;
   3123     case 79:
   3124       SetUpVersion79Database(&connection);
   3125       break;
   3126     case 80:
   3127       SetUpVersion80Database(&connection);
   3128       break;
   3129     case 81:
   3130       SetUpVersion81Database(&connection);
   3131       break;
   3132     case 82:
   3133       SetUpVersion82Database(&connection);
   3134       break;
   3135     case 83:
   3136       SetUpVersion83Database(&connection);
   3137       break;
   3138     case 84:
   3139       SetUpVersion84Database(&connection);
   3140       break;
   3141     case 85:
   3142       SetUpVersion85Database(&connection);
   3143       break;
   3144     case 86:
   3145       SetUpVersion86Database(&connection);
   3146       break;
   3147     default:
   3148       // If you see this error, it may mean that you've increased the
   3149       // database version number but you haven't finished adding unit tests
   3150       // for the database migration code.  You need to need to supply a
   3151       // SetUpVersionXXDatabase function with a dump of the test database
   3152       // at the old schema.  Here's one way to do that:
   3153       //   1. Start on a clean tree (with none of your pending schema changes).
   3154       //   2. Set a breakpoint in this function and run the unit test.
   3155       //   3. Allow this test to run to completion (step out of the call),
   3156       //      without allowing ~MigrationTest to execute.
   3157       //   4. Examine this->temp_dir_ to determine the location of the
   3158       //      test database (it is currently of the version you need).
   3159       //   5. Dump this using the sqlite3 command line tool:
   3160       //        > .output foo_dump.sql
   3161       //        > .dump
   3162       //   6. Replace the timestamp columns with META_PROTO_TIMES(x) (or
   3163       //      LEGACY_META_PROTO_TIMES(x) if before Version 77).
   3164       FAIL() << "Need to supply database dump for version " << GetParam();
   3165   }
   3166 
   3167   syncable::Directory::KernelLoadInfo dir_info;
   3168   Directory::MetahandlesMap handles_map;
   3169   JournalIndex  delete_journals;;
   3170   STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
   3171 
   3172   {
   3173     scoped_ptr<TestDirectoryBackingStore> dbs(
   3174         new TestDirectoryBackingStore(GetUsername(), &connection));
   3175     ASSERT_EQ(OPENED, dbs->Load(&handles_map, &delete_journals, &dir_info));
   3176     ASSERT_FALSE(dbs->needs_column_refresh_);
   3177     ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion());
   3178   }
   3179 
   3180   // Columns deleted in Version 67.
   3181   ASSERT_FALSE(connection.DoesColumnExist("metas", "name"));
   3182   ASSERT_FALSE(connection.DoesColumnExist("metas", "unsanitized_name"));
   3183   ASSERT_FALSE(connection.DoesColumnExist("metas", "server_name"));
   3184 
   3185   // Columns added in Version 68.
   3186   ASSERT_TRUE(connection.DoesColumnExist("metas", "specifics"));
   3187   ASSERT_TRUE(connection.DoesColumnExist("metas", "server_specifics"));
   3188 
   3189   // Columns deleted in Version 68.
   3190   ASSERT_FALSE(connection.DoesColumnExist("metas", "is_bookmark_object"));
   3191   ASSERT_FALSE(connection.DoesColumnExist("metas",
   3192                                           "server_is_bookmark_object"));
   3193   ASSERT_FALSE(connection.DoesColumnExist("metas", "bookmark_favicon"));
   3194   ASSERT_FALSE(connection.DoesColumnExist("metas", "bookmark_url"));
   3195   ASSERT_FALSE(connection.DoesColumnExist("metas", "server_bookmark_url"));
   3196 
   3197   // Renamed a column in Version 70
   3198   ASSERT_FALSE(connection.DoesColumnExist("metas", "singleton_tag"));
   3199   ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag"));
   3200   ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag"));
   3201 
   3202   // Removed extended attributes in Version 72.
   3203   ASSERT_FALSE(connection.DoesTableExist("extended_attributes"));
   3204 
   3205   // Columns added in Version 73.
   3206   ASSERT_TRUE(connection.DoesColumnExist("share_info", "notification_state"));
   3207 
   3208   // Column replaced in version 75.
   3209   ASSERT_TRUE(connection.DoesColumnExist("models", "progress_marker"));
   3210   ASSERT_FALSE(connection.DoesColumnExist("models", "last_download_timestamp"));
   3211 
   3212   // Columns removed in version 76.
   3213   ASSERT_FALSE(
   3214       connection.DoesColumnExist("share_info", "autofill_migration_state"));
   3215   ASSERT_FALSE(connection.DoesColumnExist("share_info",
   3216       "bookmarks_added_during_autofill_migration"));
   3217   ASSERT_FALSE(
   3218     connection.DoesColumnExist("share_info", "autofill_migration_time"));
   3219   ASSERT_FALSE(connection.DoesColumnExist("share_info",
   3220         "autofill_entries_added_during_migration"));
   3221   ASSERT_FALSE(connection.DoesColumnExist("share_info",
   3222         "autofill_profiles_added_during_migration"));
   3223 
   3224   // Column added in version 78.
   3225   ASSERT_TRUE(connection.DoesColumnExist("metas", "base_server_specifics"));
   3226 
   3227   // Column added in version 82.
   3228   ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version"));
   3229 
   3230   // Column added in version 83.
   3231   ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version"));
   3232 
   3233   // Table added in version 84.
   3234   ASSERT_TRUE(connection.DoesTableExist("deleted_metas"));
   3235 
   3236   // Column removed in version 85.
   3237   ASSERT_FALSE(connection.DoesColumnExist("models", "initial_sync_ended"));
   3238 
   3239   // Check download_progress state (v75 migration)
   3240   ASSERT_EQ(694,
   3241       dir_info.kernel_info.download_progress[BOOKMARKS]
   3242       .timestamp_token_for_migration());
   3243   ASSERT_FALSE(
   3244       dir_info.kernel_info.download_progress[BOOKMARKS]
   3245       .has_token());
   3246   ASSERT_EQ(32904,
   3247       dir_info.kernel_info.download_progress[BOOKMARKS]
   3248       .data_type_id());
   3249   ASSERT_FALSE(
   3250       dir_info.kernel_info.download_progress[THEMES]
   3251       .has_timestamp_token_for_migration());
   3252   ASSERT_TRUE(
   3253       dir_info.kernel_info.download_progress[THEMES]
   3254       .has_token());
   3255   ASSERT_TRUE(
   3256       dir_info.kernel_info.download_progress[THEMES]
   3257       .token().empty());
   3258   ASSERT_EQ(41210,
   3259       dir_info.kernel_info.download_progress[THEMES]
   3260       .data_type_id());
   3261 
   3262   // Check metas
   3263   EXPECT_EQ(GetExpectedMetaProtoTimes(DONT_INCLUDE_DELETED_ITEMS),
   3264             GetMetaProtoTimes(&connection));
   3265   ExpectTimes(handles_map, GetExpectedMetaTimes());
   3266 
   3267   Directory::MetahandlesMap::iterator it = handles_map.find(1);
   3268   ASSERT_TRUE(it != handles_map.end());
   3269   ASSERT_EQ(1, it->second->ref(META_HANDLE));
   3270   EXPECT_TRUE(it->second->ref(ID).IsRoot());
   3271 
   3272   it = handles_map.find(6);
   3273   ASSERT_EQ(6, it->second->ref(META_HANDLE));
   3274   EXPECT_TRUE(it->second->ref(IS_DIR));
   3275   EXPECT_TRUE(it->second->ref(SERVER_IS_DIR));
   3276   EXPECT_FALSE(
   3277       it->second->ref(SPECIFICS).bookmark().has_url());
   3278   EXPECT_FALSE(
   3279       it->second->ref(SERVER_SPECIFICS).bookmark().has_url());
   3280   EXPECT_FALSE(
   3281       it->second->ref(SPECIFICS).bookmark().has_favicon());
   3282   EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_favicon());
   3283 
   3284   it = handles_map.find(7);
   3285   ASSERT_EQ(7, it->second->ref(META_HANDLE));
   3286   EXPECT_EQ("google_chrome", it->second->ref(UNIQUE_SERVER_TAG));
   3287   EXPECT_FALSE(it->second->ref(SPECIFICS).has_bookmark());
   3288   EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
   3289 
   3290   it = handles_map.find(8);
   3291   ASSERT_EQ(8, it->second->ref(META_HANDLE));
   3292   EXPECT_EQ("google_chrome_bookmarks", it->second->ref(UNIQUE_SERVER_TAG));
   3293   EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
   3294   EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
   3295 
   3296   it = handles_map.find(9);
   3297   ASSERT_EQ(9, it->second->ref(META_HANDLE));
   3298   EXPECT_EQ("bookmark_bar", it->second->ref(UNIQUE_SERVER_TAG));
   3299   EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
   3300   EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
   3301 
   3302   it = handles_map.find(10);
   3303   ASSERT_EQ(10, it->second->ref(META_HANDLE));
   3304   EXPECT_FALSE(it->second->ref(IS_DEL));
   3305   EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
   3306   EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
   3307   EXPECT_FALSE(it->second->ref(SPECIFICS).bookmark().has_url());
   3308   EXPECT_FALSE(
   3309       it->second->ref(SPECIFICS).bookmark().has_favicon());
   3310   EXPECT_FALSE(
   3311       it->second->ref(SERVER_SPECIFICS).bookmark().has_url());
   3312   EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_favicon());
   3313   EXPECT_EQ("other_bookmarks", it->second->ref(UNIQUE_SERVER_TAG));
   3314   EXPECT_EQ("Other Bookmarks", it->second->ref(NON_UNIQUE_NAME));
   3315   EXPECT_EQ("Other Bookmarks", it->second->ref(SERVER_NON_UNIQUE_NAME));
   3316 
   3317   it = handles_map.find(11);
   3318   ASSERT_EQ(11, it->second->ref(META_HANDLE));
   3319   EXPECT_FALSE(it->second->ref(IS_DEL));
   3320   EXPECT_FALSE(it->second->ref(IS_DIR));
   3321   EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
   3322   EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
   3323   EXPECT_EQ("http://dev.chromium.org/",
   3324       it->second->ref(SPECIFICS).bookmark().url());
   3325   EXPECT_EQ("AGATWA",
   3326       it->second->ref(SPECIFICS).bookmark().favicon());
   3327   EXPECT_EQ("http://dev.chromium.org/other",
   3328       it->second->ref(SERVER_SPECIFICS).bookmark().url());
   3329   EXPECT_EQ("AFAGVASF",
   3330       it->second->ref(SERVER_SPECIFICS).bookmark().favicon());
   3331   EXPECT_EQ("", it->second->ref(UNIQUE_SERVER_TAG));
   3332   EXPECT_EQ("Home (The Chromium Projects)", it->second->ref(NON_UNIQUE_NAME));
   3333   EXPECT_EQ("Home (The Chromium Projects)",
   3334             it->second->ref(SERVER_NON_UNIQUE_NAME));
   3335 
   3336   it = handles_map.find(12);
   3337   ASSERT_EQ(12, it->second->ref(META_HANDLE));
   3338   EXPECT_FALSE(it->second->ref(IS_DEL));
   3339   EXPECT_TRUE(it->second->ref(IS_DIR));
   3340   EXPECT_EQ("Extra Bookmarks", it->second->ref(NON_UNIQUE_NAME));
   3341   EXPECT_EQ("Extra Bookmarks", it->second->ref(SERVER_NON_UNIQUE_NAME));
   3342   EXPECT_TRUE(it->second->ref(SPECIFICS).has_bookmark());
   3343   EXPECT_TRUE(it->second->ref(SERVER_SPECIFICS).has_bookmark());
   3344   EXPECT_FALSE(
   3345       it->second->ref(SPECIFICS).bookmark().has_url());
   3346   EXPECT_FALSE(
   3347       it->second->ref(SERVER_SPECIFICS).bookmark().has_url());
   3348   EXPECT_FALSE(
   3349       it->second->ref(SPECIFICS).bookmark().has_favicon());
   3350   EXPECT_FALSE(it->second->ref(SERVER_SPECIFICS).bookmark().has_favicon());
   3351 
   3352   it = handles_map.find(13);
   3353   ASSERT_EQ(13, it->second->ref(META_HANDLE));
   3354 
   3355   it = handles_map.find(14);
   3356   ASSERT_EQ(14, it->second->ref(META_HANDLE));
   3357 
   3358   ASSERT_EQ(static_cast<size_t>(10), handles_map.size());
   3359 }
   3360 
   3361 INSTANTIATE_TEST_CASE_P(DirectoryBackingStore, MigrationTest,
   3362                         testing::Range(67, kCurrentDBVersion + 1));
   3363 
   3364 TEST_F(DirectoryBackingStoreTest, ModelTypeIds) {
   3365   ModelTypeSet protocol_types = ProtocolTypes();
   3366   for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
   3367        iter.Inc()) {
   3368     std::string model_id =
   3369         TestDirectoryBackingStore::ModelTypeEnumToModelId(iter.Get());
   3370     EXPECT_EQ(iter.Get(),
   3371         TestDirectoryBackingStore::ModelIdToModelTypeEnum(model_id.data(),
   3372                                                           model_id.size()));
   3373   }
   3374 }
   3375 
   3376 namespace {
   3377 
   3378 class OnDiskDirectoryBackingStoreForTest : public OnDiskDirectoryBackingStore {
   3379  public:
   3380   OnDiskDirectoryBackingStoreForTest(const std::string& dir_name,
   3381                                      const base::FilePath& backing_filepath);
   3382   virtual ~OnDiskDirectoryBackingStoreForTest();
   3383   bool DidFailFirstOpenAttempt();
   3384 
   3385  protected:
   3386   virtual void ReportFirstTryOpenFailure() OVERRIDE;
   3387 
   3388  private:
   3389   bool first_open_failed_;
   3390 };
   3391 
   3392 OnDiskDirectoryBackingStoreForTest::OnDiskDirectoryBackingStoreForTest(
   3393     const std::string& dir_name,
   3394     const base::FilePath& backing_filepath) :
   3395   OnDiskDirectoryBackingStore(dir_name, backing_filepath),
   3396   first_open_failed_(false) { }
   3397 
   3398 OnDiskDirectoryBackingStoreForTest::~OnDiskDirectoryBackingStoreForTest() { }
   3399 
   3400 void OnDiskDirectoryBackingStoreForTest::ReportFirstTryOpenFailure() {
   3401   // Do nothing, just like we would in release-mode.  In debug mode, we DCHECK.
   3402   first_open_failed_ = true;
   3403 }
   3404 
   3405 bool OnDiskDirectoryBackingStoreForTest::DidFailFirstOpenAttempt() {
   3406   return first_open_failed_;
   3407 }
   3408 
   3409 }  // namespace
   3410 
   3411 // This is a whitebox test intended to exercise the code path where the on-disk
   3412 // directory load code decides to delete the current directory and start fresh.
   3413 //
   3414 // This is considered "minor" corruption because the database recreation is
   3415 // expected to succeed.  The alternative, where recreation does not succeed (ie.
   3416 // due to read-only file system), is not tested here.
   3417 TEST_F(DirectoryBackingStoreTest, MinorCorruption) {
   3418   {
   3419     scoped_ptr<OnDiskDirectoryBackingStore> dbs(
   3420         new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
   3421     EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
   3422   }
   3423 
   3424   // Corrupt the root node.
   3425   {
   3426     sql::Connection connection;
   3427     ASSERT_TRUE(connection.Open(GetDatabasePath()));
   3428     ASSERT_TRUE(connection.Execute(
   3429             "UPDATE metas SET parent_id='bogus' WHERE id = 'r';"));
   3430   }
   3431 
   3432   {
   3433     scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
   3434         new OnDiskDirectoryBackingStoreForTest(GetUsername(),
   3435                                                GetDatabasePath()));
   3436 
   3437     EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
   3438     EXPECT_TRUE(dbs->DidFailFirstOpenAttempt());
   3439   }
   3440 }
   3441 
   3442 TEST_F(DirectoryBackingStoreTest, DeleteEntries) {
   3443   sql::Connection connection;
   3444   ASSERT_TRUE(connection.OpenInMemory());
   3445 
   3446   SetUpCurrentDatabaseAndCheckVersion(&connection);
   3447   scoped_ptr<TestDirectoryBackingStore> dbs(
   3448       new TestDirectoryBackingStore(GetUsername(), &connection));
   3449   Directory::MetahandlesMap handles_map;
   3450   JournalIndex  delete_journals;
   3451   Directory::KernelLoadInfo kernel_load_info;
   3452   STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
   3453 
   3454   dbs->Load(&handles_map, &delete_journals, &kernel_load_info);
   3455   size_t initial_size = handles_map.size();
   3456   ASSERT_LT(0U, initial_size) << "Test requires handles_map to delete.";
   3457   int64 first_to_die = handles_map.begin()->second->ref(META_HANDLE);
   3458   MetahandleSet to_delete;
   3459   to_delete.insert(first_to_die);
   3460   EXPECT_TRUE(dbs->DeleteEntries(TestDirectoryBackingStore::METAS_TABLE,
   3461                                  to_delete));
   3462 
   3463   STLDeleteValues(&handles_map);
   3464   dbs->LoadEntries(&handles_map);
   3465 
   3466   EXPECT_EQ(initial_size - 1, handles_map.size());
   3467   bool delete_failed = false;
   3468   for (Directory::MetahandlesMap::iterator it = handles_map.begin();
   3469        it != handles_map.end(); ++it) {
   3470     if (it->first == first_to_die) {
   3471       delete_failed = true;
   3472       break;
   3473     }
   3474   }
   3475   EXPECT_FALSE(delete_failed);
   3476 
   3477   to_delete.clear();
   3478   for (Directory::MetahandlesMap::iterator it = handles_map.begin();
   3479        it != handles_map.end(); ++it) {
   3480     to_delete.insert(it->first);
   3481   }
   3482 
   3483   EXPECT_TRUE(dbs->DeleteEntries(TestDirectoryBackingStore::METAS_TABLE,
   3484                                  to_delete));
   3485 
   3486   STLDeleteValues(&handles_map);
   3487   dbs->LoadEntries(&handles_map);
   3488   EXPECT_EQ(0U, handles_map.size());
   3489 }
   3490 
   3491 TEST_F(DirectoryBackingStoreTest, GenerateCacheGUID) {
   3492   const std::string& guid1 = TestDirectoryBackingStore::GenerateCacheGUID();
   3493   const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID();
   3494   EXPECT_EQ(24U, guid1.size());
   3495   EXPECT_EQ(24U, guid2.size());
   3496   // In theory this test can fail, but it won't before the universe
   3497   // dies of heat death.
   3498   EXPECT_NE(guid1, guid2);
   3499 }
   3500 
   3501 }  // namespace syncable
   3502 }  // namespace syncer
   3503