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

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

Issue 1866243002: Convert //sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/syncable/directory_backing_store.h" 5 #include "sync/syncable/directory_backing_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory>
11 #include <string> 12 #include <string>
12 13
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "sql/connection.h" 22 #include "sql/connection.h"
23 #include "sql/statement.h" 23 #include "sql/statement.h"
24 #include "sql/test/scoped_error_ignorer.h" 24 #include "sql/test/scoped_error_ignorer.h"
25 #include "sql/test/test_helpers.h" 25 #include "sql/test/test_helpers.h"
(...skipping 13 matching lines...) Expand all
39 namespace syncer { 39 namespace syncer {
40 namespace syncable { 40 namespace syncable {
41 namespace { 41 namespace {
42 42
43 // A handler that simply sets |catastrophic_error_handler_was_called| to true. 43 // A handler that simply sets |catastrophic_error_handler_was_called| to true.
44 void CatastrophicErrorHandler(bool* catastrophic_error_handler_was_called) { 44 void CatastrophicErrorHandler(bool* catastrophic_error_handler_was_called) {
45 *catastrophic_error_handler_was_called = true; 45 *catastrophic_error_handler_was_called = true;
46 } 46 }
47 47
48 // Create a dirty EntryKernel with an ID derived from |id| + |id_suffix|. 48 // Create a dirty EntryKernel with an ID derived from |id| + |id_suffix|.
49 scoped_ptr<EntryKernel> CreateEntry(int id, const std::string &id_suffix) { 49 std::unique_ptr<EntryKernel> CreateEntry(int id, const std::string& id_suffix) {
50 scoped_ptr<EntryKernel> entry(new EntryKernel()); 50 std::unique_ptr<EntryKernel> entry(new EntryKernel());
51 std::string id_string = base::Int64ToString(id) + id_suffix; 51 std::string id_string = base::Int64ToString(id) + id_suffix;
52 entry->put(ID, Id::CreateFromClientString(id_string)); 52 entry->put(ID, Id::CreateFromClientString(id_string));
53 entry->put(META_HANDLE, id); 53 entry->put(META_HANDLE, id);
54 entry->mark_dirty(NULL); 54 entry->mark_dirty(NULL);
55 return entry; 55 return entry;
56 } 56 }
57 57
58 } // namespace 58 } // namespace
59 59
60 SYNC_EXPORT extern const int32_t kCurrentPageSizeKB; 60 SYNC_EXPORT extern const int32_t kCurrentPageSizeKB;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void SetUpVersion84Database(sql::Connection* connection); 103 void SetUpVersion84Database(sql::Connection* connection);
104 void SetUpVersion85Database(sql::Connection* connection); 104 void SetUpVersion85Database(sql::Connection* connection);
105 void SetUpVersion86Database(sql::Connection* connection); 105 void SetUpVersion86Database(sql::Connection* connection);
106 void SetUpVersion87Database(sql::Connection* connection); 106 void SetUpVersion87Database(sql::Connection* connection);
107 void SetUpVersion88Database(sql::Connection* connection); 107 void SetUpVersion88Database(sql::Connection* connection);
108 void SetUpVersion89Database(sql::Connection* connection); 108 void SetUpVersion89Database(sql::Connection* connection);
109 void SetUpVersion90Database(sql::Connection* connection); 109 void SetUpVersion90Database(sql::Connection* connection);
110 110
111 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { 111 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) {
112 SetUpVersion90Database(connection); // Prepopulates data. 112 SetUpVersion90Database(connection); // Prepopulates data.
113 scoped_ptr<TestDirectoryBackingStore> dbs( 113 std::unique_ptr<TestDirectoryBackingStore> dbs(
114 new TestDirectoryBackingStore(GetUsername(), connection)); 114 new TestDirectoryBackingStore(GetUsername(), connection));
115 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); 115 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion());
116 116
117 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 117 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
118 ASSERT_FALSE(dbs->needs_column_refresh()); 118 ASSERT_FALSE(dbs->needs_column_refresh());
119 } 119 }
120 120
121 private: 121 private:
122 base::MessageLoop message_loop_; 122 base::MessageLoop message_loop_;
123 base::ScopedTempDir temp_dir_; 123 base::ScopedTempDir temp_dir_;
(...skipping 2882 matching lines...) Expand 10 before | Expand all | Expand 10 after
3006 sql::Connection connection; 3006 sql::Connection connection;
3007 ASSERT_TRUE(connection.OpenInMemory()); 3007 ASSERT_TRUE(connection.OpenInMemory());
3008 3008
3009 SetUpVersion67Database(&connection); 3009 SetUpVersion67Database(&connection);
3010 3010
3011 // Columns existing before version 67. 3011 // Columns existing before version 67.
3012 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); 3012 ASSERT_TRUE(connection.DoesColumnExist("metas", "name"));
3013 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); 3013 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name"));
3014 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); 3014 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name"));
3015 3015
3016 scoped_ptr<TestDirectoryBackingStore> dbs( 3016 std::unique_ptr<TestDirectoryBackingStore> dbs(
3017 new TestDirectoryBackingStore(GetUsername(), &connection)); 3017 new TestDirectoryBackingStore(GetUsername(), &connection));
3018 3018
3019 ASSERT_FALSE(dbs->needs_column_refresh()); 3019 ASSERT_FALSE(dbs->needs_column_refresh());
3020 ASSERT_TRUE(dbs->MigrateVersion67To68()); 3020 ASSERT_TRUE(dbs->MigrateVersion67To68());
3021 ASSERT_EQ(68, dbs->GetVersion()); 3021 ASSERT_EQ(68, dbs->GetVersion());
3022 ASSERT_TRUE(dbs->needs_column_refresh()); 3022 ASSERT_TRUE(dbs->needs_column_refresh());
3023 } 3023 }
3024 3024
3025 TEST_F(DirectoryBackingStoreTest, MigrateVersion68To69) { 3025 TEST_F(DirectoryBackingStoreTest, MigrateVersion68To69) {
3026 sql::Connection connection; 3026 sql::Connection connection;
3027 ASSERT_TRUE(connection.OpenInMemory()); 3027 ASSERT_TRUE(connection.OpenInMemory());
3028 SetUpVersion68Database(&connection); 3028 SetUpVersion68Database(&connection);
3029 3029
3030 { 3030 {
3031 scoped_ptr<TestDirectoryBackingStore> dbs( 3031 std::unique_ptr<TestDirectoryBackingStore> dbs(
3032 new TestDirectoryBackingStore(GetUsername(), &connection)); 3032 new TestDirectoryBackingStore(GetUsername(), &connection));
3033 3033
3034 ASSERT_FALSE(dbs->needs_column_refresh()); 3034 ASSERT_FALSE(dbs->needs_column_refresh());
3035 ASSERT_TRUE(dbs->MigrateVersion68To69()); 3035 ASSERT_TRUE(dbs->MigrateVersion68To69());
3036 ASSERT_EQ(69, dbs->GetVersion()); 3036 ASSERT_EQ(69, dbs->GetVersion());
3037 ASSERT_TRUE(dbs->needs_column_refresh()); 3037 ASSERT_TRUE(dbs->needs_column_refresh());
3038 } 3038 }
3039 3039
3040 ASSERT_TRUE(connection.DoesColumnExist("metas", "specifics")); 3040 ASSERT_TRUE(connection.DoesColumnExist("metas", "specifics"));
3041 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_specifics")); 3041 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_specifics"));
(...skipping 20 matching lines...) Expand all
3062 TEST_F(DirectoryBackingStoreTest, MigrateVersion69To70) { 3062 TEST_F(DirectoryBackingStoreTest, MigrateVersion69To70) {
3063 sql::Connection connection; 3063 sql::Connection connection;
3064 ASSERT_TRUE(connection.OpenInMemory()); 3064 ASSERT_TRUE(connection.OpenInMemory());
3065 SetUpVersion69Database(&connection); 3065 SetUpVersion69Database(&connection);
3066 3066
3067 ASSERT_TRUE(connection.DoesColumnExist("metas", "singleton_tag")); 3067 ASSERT_TRUE(connection.DoesColumnExist("metas", "singleton_tag"));
3068 ASSERT_FALSE(connection.DoesColumnExist("metas", "unique_server_tag")); 3068 ASSERT_FALSE(connection.DoesColumnExist("metas", "unique_server_tag"));
3069 ASSERT_FALSE(connection.DoesColumnExist("metas", "unique_client_tag")); 3069 ASSERT_FALSE(connection.DoesColumnExist("metas", "unique_client_tag"));
3070 3070
3071 { 3071 {
3072 scoped_ptr<TestDirectoryBackingStore> dbs( 3072 std::unique_ptr<TestDirectoryBackingStore> dbs(
3073 new TestDirectoryBackingStore(GetUsername(), &connection)); 3073 new TestDirectoryBackingStore(GetUsername(), &connection));
3074 3074
3075 ASSERT_FALSE(dbs->needs_column_refresh()); 3075 ASSERT_FALSE(dbs->needs_column_refresh());
3076 ASSERT_TRUE(dbs->MigrateVersion69To70()); 3076 ASSERT_TRUE(dbs->MigrateVersion69To70());
3077 ASSERT_EQ(70, dbs->GetVersion()); 3077 ASSERT_EQ(70, dbs->GetVersion());
3078 ASSERT_TRUE(dbs->needs_column_refresh()); 3078 ASSERT_TRUE(dbs->needs_column_refresh());
3079 } 3079 }
3080 3080
3081 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag")); 3081 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag"));
3082 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag")); 3082 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag"));
3083 sql::Statement s(connection.GetUniqueStatement("SELECT id" 3083 sql::Statement s(connection.GetUniqueStatement("SELECT id"
3084 " FROM metas WHERE unique_server_tag = 'google_chrome'")); 3084 " FROM metas WHERE unique_server_tag = 'google_chrome'"));
3085 ASSERT_TRUE(s.Step()); 3085 ASSERT_TRUE(s.Step());
3086 EXPECT_EQ("s_ID_7", s.ColumnString(0)); 3086 EXPECT_EQ("s_ID_7", s.ColumnString(0));
3087 } 3087 }
3088 3088
3089 TEST_F(DirectoryBackingStoreTest, MigrateVersion70To71) { 3089 TEST_F(DirectoryBackingStoreTest, MigrateVersion70To71) {
3090 sql::Connection connection; 3090 sql::Connection connection;
3091 ASSERT_TRUE(connection.OpenInMemory()); 3091 ASSERT_TRUE(connection.OpenInMemory());
3092 SetUpVersion70Database(&connection); 3092 SetUpVersion70Database(&connection);
3093 3093
3094 ASSERT_TRUE(connection.DoesColumnExist("share_info", "last_sync_timestamp")); 3094 ASSERT_TRUE(connection.DoesColumnExist("share_info", "last_sync_timestamp"));
3095 ASSERT_TRUE(connection.DoesColumnExist("share_info", "initial_sync_ended")); 3095 ASSERT_TRUE(connection.DoesColumnExist("share_info", "initial_sync_ended"));
3096 ASSERT_FALSE(connection.DoesTableExist("models")); 3096 ASSERT_FALSE(connection.DoesTableExist("models"));
3097 3097
3098 { 3098 {
3099 scoped_ptr<TestDirectoryBackingStore> dbs( 3099 std::unique_ptr<TestDirectoryBackingStore> dbs(
3100 new TestDirectoryBackingStore(GetUsername(), &connection)); 3100 new TestDirectoryBackingStore(GetUsername(), &connection));
3101 3101
3102 ASSERT_FALSE(dbs->needs_column_refresh()); 3102 ASSERT_FALSE(dbs->needs_column_refresh());
3103 ASSERT_TRUE(dbs->MigrateVersion70To71()); 3103 ASSERT_TRUE(dbs->MigrateVersion70To71());
3104 ASSERT_EQ(71, dbs->GetVersion()); 3104 ASSERT_EQ(71, dbs->GetVersion());
3105 ASSERT_FALSE(dbs->needs_column_refresh()); 3105 ASSERT_FALSE(dbs->needs_column_refresh());
3106 } 3106 }
3107 3107
3108 ASSERT_FALSE(connection.DoesColumnExist("share_info", "last_sync_timestamp")); 3108 ASSERT_FALSE(connection.DoesColumnExist("share_info", "last_sync_timestamp"));
3109 ASSERT_FALSE(connection.DoesColumnExist("share_info", "initial_sync_ended")); 3109 ASSERT_FALSE(connection.DoesColumnExist("share_info", "initial_sync_ended"));
(...skipping 15 matching lines...) Expand all
3125 3125
3126 3126
3127 TEST_F(DirectoryBackingStoreTest, MigrateVersion71To72) { 3127 TEST_F(DirectoryBackingStoreTest, MigrateVersion71To72) {
3128 sql::Connection connection; 3128 sql::Connection connection;
3129 ASSERT_TRUE(connection.OpenInMemory()); 3129 ASSERT_TRUE(connection.OpenInMemory());
3130 SetUpVersion71Database(&connection); 3130 SetUpVersion71Database(&connection);
3131 3131
3132 ASSERT_TRUE(connection.DoesTableExist("extended_attributes")); 3132 ASSERT_TRUE(connection.DoesTableExist("extended_attributes"));
3133 3133
3134 { 3134 {
3135 scoped_ptr<TestDirectoryBackingStore> dbs( 3135 std::unique_ptr<TestDirectoryBackingStore> dbs(
3136 new TestDirectoryBackingStore(GetUsername(), &connection)); 3136 new TestDirectoryBackingStore(GetUsername(), &connection));
3137 3137
3138 ASSERT_FALSE(dbs->needs_column_refresh()); 3138 ASSERT_FALSE(dbs->needs_column_refresh());
3139 ASSERT_TRUE(dbs->MigrateVersion71To72()); 3139 ASSERT_TRUE(dbs->MigrateVersion71To72());
3140 ASSERT_EQ(72, dbs->GetVersion()); 3140 ASSERT_EQ(72, dbs->GetVersion());
3141 ASSERT_FALSE(dbs->needs_column_refresh()); 3141 ASSERT_FALSE(dbs->needs_column_refresh());
3142 } 3142 }
3143 3143
3144 ASSERT_FALSE(connection.DoesTableExist("extended_attributes")); 3144 ASSERT_FALSE(connection.DoesTableExist("extended_attributes"));
3145 } 3145 }
3146 3146
3147 TEST_F(DirectoryBackingStoreTest, MigrateVersion72To73) { 3147 TEST_F(DirectoryBackingStoreTest, MigrateVersion72To73) {
3148 sql::Connection connection; 3148 sql::Connection connection;
3149 ASSERT_TRUE(connection.OpenInMemory()); 3149 ASSERT_TRUE(connection.OpenInMemory());
3150 SetUpVersion72Database(&connection); 3150 SetUpVersion72Database(&connection);
3151 3151
3152 ASSERT_FALSE(connection.DoesColumnExist("share_info", "notification_state")); 3152 ASSERT_FALSE(connection.DoesColumnExist("share_info", "notification_state"));
3153 3153
3154 { 3154 {
3155 scoped_ptr<TestDirectoryBackingStore> dbs( 3155 std::unique_ptr<TestDirectoryBackingStore> dbs(
3156 new TestDirectoryBackingStore(GetUsername(), &connection)); 3156 new TestDirectoryBackingStore(GetUsername(), &connection));
3157 3157
3158 ASSERT_FALSE(dbs->needs_column_refresh()); 3158 ASSERT_FALSE(dbs->needs_column_refresh());
3159 ASSERT_TRUE(dbs->MigrateVersion72To73()); 3159 ASSERT_TRUE(dbs->MigrateVersion72To73());
3160 ASSERT_EQ(73, dbs->GetVersion()); 3160 ASSERT_EQ(73, dbs->GetVersion());
3161 ASSERT_FALSE(dbs->needs_column_refresh()); 3161 ASSERT_FALSE(dbs->needs_column_refresh());
3162 } 3162 }
3163 3163
3164 ASSERT_TRUE(connection.DoesColumnExist("share_info", "notification_state")); 3164 ASSERT_TRUE(connection.DoesColumnExist("share_info", "notification_state"));
3165 } 3165 }
(...skipping 12 matching lines...) Expand all
3178 connection.DoesColumnExist("share_info", "autofill_migration_time")); 3178 connection.DoesColumnExist("share_info", "autofill_migration_time"));
3179 ASSERT_FALSE( 3179 ASSERT_FALSE(
3180 connection.DoesColumnExist("share_info", 3180 connection.DoesColumnExist("share_info",
3181 "autofill_entries_added_during_migration")); 3181 "autofill_entries_added_during_migration"));
3182 3182
3183 ASSERT_FALSE( 3183 ASSERT_FALSE(
3184 connection.DoesColumnExist("share_info", 3184 connection.DoesColumnExist("share_info",
3185 "autofill_profiles_added_during_migration")); 3185 "autofill_profiles_added_during_migration"));
3186 3186
3187 { 3187 {
3188 scoped_ptr<TestDirectoryBackingStore> dbs( 3188 std::unique_ptr<TestDirectoryBackingStore> dbs(
3189 new TestDirectoryBackingStore(GetUsername(), &connection)); 3189 new TestDirectoryBackingStore(GetUsername(), &connection));
3190 3190
3191 ASSERT_FALSE(dbs->needs_column_refresh()); 3191 ASSERT_FALSE(dbs->needs_column_refresh());
3192 ASSERT_TRUE(dbs->MigrateVersion73To74()); 3192 ASSERT_TRUE(dbs->MigrateVersion73To74());
3193 ASSERT_EQ(74, dbs->GetVersion()); 3193 ASSERT_EQ(74, dbs->GetVersion());
3194 ASSERT_FALSE(dbs->needs_column_refresh()); 3194 ASSERT_FALSE(dbs->needs_column_refresh());
3195 } 3195 }
3196 3196
3197 ASSERT_TRUE( 3197 ASSERT_TRUE(
3198 connection.DoesColumnExist("share_info", "autofill_migration_state")); 3198 connection.DoesColumnExist("share_info", "autofill_migration_state"));
(...skipping 13 matching lines...) Expand all
3212 3212
3213 TEST_F(DirectoryBackingStoreTest, MigrateVersion74To75) { 3213 TEST_F(DirectoryBackingStoreTest, MigrateVersion74To75) {
3214 sql::Connection connection; 3214 sql::Connection connection;
3215 ASSERT_TRUE(connection.OpenInMemory()); 3215 ASSERT_TRUE(connection.OpenInMemory());
3216 SetUpVersion74Database(&connection); 3216 SetUpVersion74Database(&connection);
3217 3217
3218 ASSERT_FALSE(connection.DoesColumnExist("models", "progress_marker")); 3218 ASSERT_FALSE(connection.DoesColumnExist("models", "progress_marker"));
3219 ASSERT_TRUE(connection.DoesColumnExist("models", "last_download_timestamp")); 3219 ASSERT_TRUE(connection.DoesColumnExist("models", "last_download_timestamp"));
3220 3220
3221 { 3221 {
3222 scoped_ptr<TestDirectoryBackingStore> dbs( 3222 std::unique_ptr<TestDirectoryBackingStore> dbs(
3223 new TestDirectoryBackingStore(GetUsername(), &connection)); 3223 new TestDirectoryBackingStore(GetUsername(), &connection));
3224 3224
3225 ASSERT_FALSE(dbs->needs_column_refresh()); 3225 ASSERT_FALSE(dbs->needs_column_refresh());
3226 ASSERT_TRUE(dbs->MigrateVersion74To75()); 3226 ASSERT_TRUE(dbs->MigrateVersion74To75());
3227 ASSERT_EQ(75, dbs->GetVersion()); 3227 ASSERT_EQ(75, dbs->GetVersion());
3228 ASSERT_FALSE(dbs->needs_column_refresh()); 3228 ASSERT_FALSE(dbs->needs_column_refresh());
3229 } 3229 }
3230 3230
3231 ASSERT_TRUE(connection.DoesColumnExist("models", "progress_marker")); 3231 ASSERT_TRUE(connection.DoesColumnExist("models", "progress_marker"));
3232 ASSERT_FALSE(connection.DoesColumnExist("models", "last_download_timestamp")); 3232 ASSERT_FALSE(connection.DoesColumnExist("models", "last_download_timestamp"));
3233 } 3233 }
3234 3234
3235 TEST_F(DirectoryBackingStoreTest, MigrateVersion75To76) { 3235 TEST_F(DirectoryBackingStoreTest, MigrateVersion75To76) {
3236 sql::Connection connection; 3236 sql::Connection connection;
3237 ASSERT_TRUE(connection.OpenInMemory()); 3237 ASSERT_TRUE(connection.OpenInMemory());
3238 SetUpVersion75Database(&connection); 3238 SetUpVersion75Database(&connection);
3239 3239
3240 ASSERT_TRUE( 3240 ASSERT_TRUE(
3241 connection.DoesColumnExist("share_info", "autofill_migration_state")); 3241 connection.DoesColumnExist("share_info", "autofill_migration_state"));
3242 ASSERT_TRUE(connection.DoesColumnExist("share_info", 3242 ASSERT_TRUE(connection.DoesColumnExist("share_info",
3243 "bookmarks_added_during_autofill_migration")); 3243 "bookmarks_added_during_autofill_migration"));
3244 ASSERT_TRUE( 3244 ASSERT_TRUE(
3245 connection.DoesColumnExist("share_info", "autofill_migration_time")); 3245 connection.DoesColumnExist("share_info", "autofill_migration_time"));
3246 ASSERT_TRUE(connection.DoesColumnExist("share_info", 3246 ASSERT_TRUE(connection.DoesColumnExist("share_info",
3247 "autofill_entries_added_during_migration")); 3247 "autofill_entries_added_during_migration"));
3248 ASSERT_TRUE(connection.DoesColumnExist("share_info", 3248 ASSERT_TRUE(connection.DoesColumnExist("share_info",
3249 "autofill_profiles_added_during_migration")); 3249 "autofill_profiles_added_during_migration"));
3250 3250
3251 scoped_ptr<TestDirectoryBackingStore> dbs( 3251 std::unique_ptr<TestDirectoryBackingStore> dbs(
3252 new TestDirectoryBackingStore(GetUsername(), &connection)); 3252 new TestDirectoryBackingStore(GetUsername(), &connection));
3253 ASSERT_FALSE(dbs->needs_column_refresh()); 3253 ASSERT_FALSE(dbs->needs_column_refresh());
3254 ASSERT_TRUE(dbs->MigrateVersion75To76()); 3254 ASSERT_TRUE(dbs->MigrateVersion75To76());
3255 ASSERT_EQ(76, dbs->GetVersion()); 3255 ASSERT_EQ(76, dbs->GetVersion());
3256 ASSERT_TRUE(dbs->needs_column_refresh()); 3256 ASSERT_TRUE(dbs->needs_column_refresh());
3257 // Cannot actual refresh columns due to version 76 not containing all 3257 // Cannot actual refresh columns due to version 76 not containing all
3258 // necessary columns. 3258 // necessary columns.
3259 } 3259 }
3260 3260
3261 TEST_F(DirectoryBackingStoreTest, MigrateVersion76To77) { 3261 TEST_F(DirectoryBackingStoreTest, MigrateVersion76To77) {
3262 sql::Connection connection; 3262 sql::Connection connection;
3263 ASSERT_TRUE(connection.OpenInMemory()); 3263 ASSERT_TRUE(connection.OpenInMemory());
3264 SetUpVersion76Database(&connection); 3264 SetUpVersion76Database(&connection);
3265 3265
3266 scoped_ptr<TestDirectoryBackingStore> dbs( 3266 std::unique_ptr<TestDirectoryBackingStore> dbs(
3267 new TestDirectoryBackingStore(GetUsername(), &connection)); 3267 new TestDirectoryBackingStore(GetUsername(), &connection));
3268 ASSERT_FALSE(dbs->needs_column_refresh()); 3268 ASSERT_FALSE(dbs->needs_column_refresh());
3269 3269
3270 EXPECT_EQ(GetExpectedLegacyMetaProtoTimes(INCLUDE_DELETED_ITEMS), 3270 EXPECT_EQ(GetExpectedLegacyMetaProtoTimes(INCLUDE_DELETED_ITEMS),
3271 GetMetaProtoTimes(&connection)); 3271 GetMetaProtoTimes(&connection));
3272 // Since the proto times are expected to be in a legacy format, they may not 3272 // Since the proto times are expected to be in a legacy format, they may not
3273 // be compatible with ProtoTimeToTime, so we don't call ExpectTimes(). 3273 // be compatible with ProtoTimeToTime, so we don't call ExpectTimes().
3274 3274
3275 ASSERT_TRUE(dbs->MigrateVersion76To77()); 3275 ASSERT_TRUE(dbs->MigrateVersion76To77());
3276 ASSERT_EQ(77, dbs->GetVersion()); 3276 ASSERT_EQ(77, dbs->GetVersion());
3277 3277
3278 EXPECT_EQ(GetExpectedMetaProtoTimes(INCLUDE_DELETED_ITEMS), 3278 EXPECT_EQ(GetExpectedMetaProtoTimes(INCLUDE_DELETED_ITEMS),
3279 GetMetaProtoTimes(&connection)); 3279 GetMetaProtoTimes(&connection));
3280 // Cannot actually load entries due to version 77 not having all required 3280 // Cannot actually load entries due to version 77 not having all required
3281 // columns. 3281 // columns.
3282 ASSERT_FALSE(dbs->needs_column_refresh()); 3282 ASSERT_FALSE(dbs->needs_column_refresh());
3283 } 3283 }
3284 3284
3285 TEST_F(DirectoryBackingStoreTest, MigrateVersion77To78) { 3285 TEST_F(DirectoryBackingStoreTest, MigrateVersion77To78) {
3286 sql::Connection connection; 3286 sql::Connection connection;
3287 ASSERT_TRUE(connection.OpenInMemory()); 3287 ASSERT_TRUE(connection.OpenInMemory());
3288 SetUpVersion77Database(&connection); 3288 SetUpVersion77Database(&connection);
3289 3289
3290 ASSERT_FALSE(connection.DoesColumnExist("metas", "BASE_SERVER_SPECIFICS")); 3290 ASSERT_FALSE(connection.DoesColumnExist("metas", "BASE_SERVER_SPECIFICS"));
3291 3291
3292 { 3292 {
3293 scoped_ptr<TestDirectoryBackingStore> dbs( 3293 std::unique_ptr<TestDirectoryBackingStore> dbs(
3294 new TestDirectoryBackingStore(GetUsername(), &connection)); 3294 new TestDirectoryBackingStore(GetUsername(), &connection));
3295 ASSERT_FALSE(dbs->needs_column_refresh()); 3295 ASSERT_FALSE(dbs->needs_column_refresh());
3296 ASSERT_TRUE(dbs->MigrateVersion77To78()); 3296 ASSERT_TRUE(dbs->MigrateVersion77To78());
3297 ASSERT_EQ(78, dbs->GetVersion()); 3297 ASSERT_EQ(78, dbs->GetVersion());
3298 3298
3299 ASSERT_FALSE(dbs->needs_column_refresh()); 3299 ASSERT_FALSE(dbs->needs_column_refresh());
3300 } 3300 }
3301 3301
3302 ASSERT_TRUE(connection.DoesColumnExist("metas", "base_server_specifics")); 3302 ASSERT_TRUE(connection.DoesColumnExist("metas", "base_server_specifics"));
3303 } 3303 }
3304 3304
3305 TEST_F(DirectoryBackingStoreTest, MigrateVersion78To79) { 3305 TEST_F(DirectoryBackingStoreTest, MigrateVersion78To79) {
3306 sql::Connection connection; 3306 sql::Connection connection;
3307 ASSERT_TRUE(connection.OpenInMemory()); 3307 ASSERT_TRUE(connection.OpenInMemory());
3308 SetUpVersion78Database(&connection); 3308 SetUpVersion78Database(&connection);
3309 3309
3310 scoped_ptr<TestDirectoryBackingStore> dbs( 3310 std::unique_ptr<TestDirectoryBackingStore> dbs(
3311 new TestDirectoryBackingStore(GetUsername(), &connection)); 3311 new TestDirectoryBackingStore(GetUsername(), &connection));
3312 ASSERT_FALSE(dbs->needs_column_refresh()); 3312 ASSERT_FALSE(dbs->needs_column_refresh());
3313 ASSERT_TRUE(dbs->MigrateVersion78To79()); 3313 ASSERT_TRUE(dbs->MigrateVersion78To79());
3314 ASSERT_EQ(79, dbs->GetVersion()); 3314 ASSERT_EQ(79, dbs->GetVersion());
3315 ASSERT_FALSE(dbs->needs_column_refresh()); 3315 ASSERT_FALSE(dbs->needs_column_refresh());
3316 } 3316 }
3317 3317
3318 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) { 3318 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) {
3319 sql::Connection connection; 3319 sql::Connection connection;
3320 ASSERT_TRUE(connection.OpenInMemory()); 3320 ASSERT_TRUE(connection.OpenInMemory());
3321 SetUpVersion79Database(&connection); 3321 SetUpVersion79Database(&connection);
3322 3322
3323 scoped_ptr<TestDirectoryBackingStore> dbs( 3323 std::unique_ptr<TestDirectoryBackingStore> dbs(
3324 new TestDirectoryBackingStore(GetUsername(), &connection)); 3324 new TestDirectoryBackingStore(GetUsername(), &connection));
3325 ASSERT_FALSE(dbs->needs_column_refresh()); 3325 ASSERT_FALSE(dbs->needs_column_refresh());
3326 ASSERT_TRUE(dbs->MigrateVersion79To80()); 3326 ASSERT_TRUE(dbs->MigrateVersion79To80());
3327 ASSERT_EQ(80, dbs->GetVersion()); 3327 ASSERT_EQ(80, dbs->GetVersion());
3328 ASSERT_FALSE(dbs->needs_column_refresh()); 3328 ASSERT_FALSE(dbs->needs_column_refresh());
3329 3329
3330 // Ensure the bag_of_chips has been set. 3330 // Ensure the bag_of_chips has been set.
3331 Directory::MetahandlesMap handles_map; 3331 Directory::MetahandlesMap handles_map;
3332 JournalIndex delete_journals; 3332 JournalIndex delete_journals;
3333 MetahandleSet metahandles_to_purge; 3333 MetahandleSet metahandles_to_purge;
(...skipping 13 matching lines...) Expand all
3347 sql::Connection connection; 3347 sql::Connection connection;
3348 ASSERT_TRUE(connection.OpenInMemory()); 3348 ASSERT_TRUE(connection.OpenInMemory());
3349 SetUpVersion80Database(&connection); 3349 SetUpVersion80Database(&connection);
3350 3350
3351 sql::Statement s(connection.GetUniqueStatement( 3351 sql::Statement s(connection.GetUniqueStatement(
3352 "SELECT metahandle, server_position_in_parent " 3352 "SELECT metahandle, server_position_in_parent "
3353 "FROM metas WHERE unique_server_tag = 'google_chrome'")); 3353 "FROM metas WHERE unique_server_tag = 'google_chrome'"));
3354 ASSERT_TRUE(s.Step()); 3354 ASSERT_TRUE(s.Step());
3355 ASSERT_EQ(sql::COLUMN_TYPE_INTEGER, s.ColumnType(1)); 3355 ASSERT_EQ(sql::COLUMN_TYPE_INTEGER, s.ColumnType(1));
3356 3356
3357 scoped_ptr<TestDirectoryBackingStore> dbs( 3357 std::unique_ptr<TestDirectoryBackingStore> dbs(
3358 new TestDirectoryBackingStore(GetUsername(), &connection)); 3358 new TestDirectoryBackingStore(GetUsername(), &connection));
3359 ASSERT_TRUE(dbs->MigrateVersion80To81()); 3359 ASSERT_TRUE(dbs->MigrateVersion80To81());
3360 ASSERT_EQ(81, dbs->GetVersion()); 3360 ASSERT_EQ(81, dbs->GetVersion());
3361 3361
3362 // Test that ordinal values are preserved correctly. 3362 // Test that ordinal values are preserved correctly.
3363 sql::Statement new_s(connection.GetUniqueStatement( 3363 sql::Statement new_s(connection.GetUniqueStatement(
3364 "SELECT metahandle, server_ordinal_in_parent " 3364 "SELECT metahandle, server_ordinal_in_parent "
3365 "FROM metas WHERE unique_server_tag = 'google_chrome'")); 3365 "FROM metas WHERE unique_server_tag = 'google_chrome'"));
3366 ASSERT_TRUE(new_s.Step()); 3366 ASSERT_TRUE(new_s.Step());
3367 ASSERT_EQ(sql::COLUMN_TYPE_BLOB, new_s.ColumnType(1)); 3367 ASSERT_EQ(sql::COLUMN_TYPE_BLOB, new_s.ColumnType(1));
3368 3368
3369 std::string expected_ordinal = Int64ToNodeOrdinal(1048576).ToInternalValue(); 3369 std::string expected_ordinal = Int64ToNodeOrdinal(1048576).ToInternalValue();
3370 std::string actual_ordinal; 3370 std::string actual_ordinal;
3371 new_s.ColumnBlobAsString(1, &actual_ordinal); 3371 new_s.ColumnBlobAsString(1, &actual_ordinal);
3372 ASSERT_EQ(expected_ordinal, actual_ordinal); 3372 ASSERT_EQ(expected_ordinal, actual_ordinal);
3373 } 3373 }
3374 3374
3375 TEST_F(DirectoryBackingStoreTest, MigrateVersion81To82) { 3375 TEST_F(DirectoryBackingStoreTest, MigrateVersion81To82) {
3376 sql::Connection connection; 3376 sql::Connection connection;
3377 ASSERT_TRUE(connection.OpenInMemory()); 3377 ASSERT_TRUE(connection.OpenInMemory());
3378 SetUpVersion81Database(&connection); 3378 SetUpVersion81Database(&connection);
3379 ASSERT_FALSE(connection.DoesColumnExist("models", "transaction_version")); 3379 ASSERT_FALSE(connection.DoesColumnExist("models", "transaction_version"));
3380 3380
3381 scoped_ptr<TestDirectoryBackingStore> dbs( 3381 std::unique_ptr<TestDirectoryBackingStore> dbs(
3382 new TestDirectoryBackingStore(GetUsername(), &connection)); 3382 new TestDirectoryBackingStore(GetUsername(), &connection));
3383 ASSERT_FALSE(dbs->needs_column_refresh()); 3383 ASSERT_FALSE(dbs->needs_column_refresh());
3384 ASSERT_TRUE(dbs->MigrateVersion81To82()); 3384 ASSERT_TRUE(dbs->MigrateVersion81To82());
3385 ASSERT_EQ(82, dbs->GetVersion()); 3385 ASSERT_EQ(82, dbs->GetVersion());
3386 ASSERT_FALSE(dbs->needs_column_refresh()); 3386 ASSERT_FALSE(dbs->needs_column_refresh());
3387 3387
3388 ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version")); 3388 ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version"));
3389 } 3389 }
3390 3390
3391 TEST_F(DirectoryBackingStoreTest, MigrateVersion82To83) { 3391 TEST_F(DirectoryBackingStoreTest, MigrateVersion82To83) {
3392 sql::Connection connection; 3392 sql::Connection connection;
3393 ASSERT_TRUE(connection.OpenInMemory()); 3393 ASSERT_TRUE(connection.OpenInMemory());
3394 SetUpVersion82Database(&connection); 3394 SetUpVersion82Database(&connection);
3395 ASSERT_FALSE(connection.DoesColumnExist("metas", "transaction_version")); 3395 ASSERT_FALSE(connection.DoesColumnExist("metas", "transaction_version"));
3396 3396
3397 scoped_ptr<TestDirectoryBackingStore> dbs( 3397 std::unique_ptr<TestDirectoryBackingStore> dbs(
3398 new TestDirectoryBackingStore(GetUsername(), &connection)); 3398 new TestDirectoryBackingStore(GetUsername(), &connection));
3399 ASSERT_TRUE(dbs->MigrateVersion82To83()); 3399 ASSERT_TRUE(dbs->MigrateVersion82To83());
3400 ASSERT_EQ(83, dbs->GetVersion()); 3400 ASSERT_EQ(83, dbs->GetVersion());
3401 3401
3402 ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version")); 3402 ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version"));
3403 } 3403 }
3404 3404
3405 TEST_F(DirectoryBackingStoreTest, MigrateVersion83To84) { 3405 TEST_F(DirectoryBackingStoreTest, MigrateVersion83To84) {
3406 sql::Connection connection; 3406 sql::Connection connection;
3407 ASSERT_TRUE(connection.OpenInMemory()); 3407 ASSERT_TRUE(connection.OpenInMemory());
3408 SetUpVersion83Database(&connection); 3408 SetUpVersion83Database(&connection);
3409 ASSERT_FALSE(connection.DoesTableExist("deleted_metas")); 3409 ASSERT_FALSE(connection.DoesTableExist("deleted_metas"));
3410 3410
3411 scoped_ptr<TestDirectoryBackingStore> dbs( 3411 std::unique_ptr<TestDirectoryBackingStore> dbs(
3412 new TestDirectoryBackingStore(GetUsername(), &connection)); 3412 new TestDirectoryBackingStore(GetUsername(), &connection));
3413 ASSERT_TRUE(dbs->MigrateVersion83To84()); 3413 ASSERT_TRUE(dbs->MigrateVersion83To84());
3414 ASSERT_EQ(84, dbs->GetVersion()); 3414 ASSERT_EQ(84, dbs->GetVersion());
3415 3415
3416 ASSERT_TRUE(connection.DoesTableExist("deleted_metas")); 3416 ASSERT_TRUE(connection.DoesTableExist("deleted_metas"));
3417 } 3417 }
3418 3418
3419 TEST_F(DirectoryBackingStoreTest, MigrateVersion84To85) { 3419 TEST_F(DirectoryBackingStoreTest, MigrateVersion84To85) {
3420 sql::Connection connection; 3420 sql::Connection connection;
3421 ASSERT_TRUE(connection.OpenInMemory()); 3421 ASSERT_TRUE(connection.OpenInMemory());
3422 SetUpVersion84Database(&connection); 3422 SetUpVersion84Database(&connection);
3423 ASSERT_TRUE(connection.DoesColumnExist("models", "initial_sync_ended")); 3423 ASSERT_TRUE(connection.DoesColumnExist("models", "initial_sync_ended"));
3424 3424
3425 scoped_ptr<TestDirectoryBackingStore> dbs( 3425 std::unique_ptr<TestDirectoryBackingStore> dbs(
3426 new TestDirectoryBackingStore(GetUsername(), &connection)); 3426 new TestDirectoryBackingStore(GetUsername(), &connection));
3427 ASSERT_TRUE(dbs->MigrateVersion84To85()); 3427 ASSERT_TRUE(dbs->MigrateVersion84To85());
3428 ASSERT_EQ(85, dbs->GetVersion()); 3428 ASSERT_EQ(85, dbs->GetVersion());
3429 ASSERT_FALSE(connection.DoesColumnExist("models", "initial_sync_ended")); 3429 ASSERT_FALSE(connection.DoesColumnExist("models", "initial_sync_ended"));
3430 } 3430 }
3431 3431
3432 TEST_F(DirectoryBackingStoreTest, MigrateVersion85To86) { 3432 TEST_F(DirectoryBackingStoreTest, MigrateVersion85To86) {
3433 sql::Connection connection; 3433 sql::Connection connection;
3434 ASSERT_TRUE(connection.OpenInMemory()); 3434 ASSERT_TRUE(connection.OpenInMemory());
3435 SetUpVersion85Database(&connection); 3435 SetUpVersion85Database(&connection);
3436 EXPECT_TRUE(connection.DoesColumnExist("metas", "next_id")); 3436 EXPECT_TRUE(connection.DoesColumnExist("metas", "next_id"));
3437 EXPECT_TRUE(connection.DoesColumnExist("metas", "prev_id")); 3437 EXPECT_TRUE(connection.DoesColumnExist("metas", "prev_id"));
3438 EXPECT_TRUE(connection.DoesColumnExist("metas", "server_ordinal_in_parent")); 3438 EXPECT_TRUE(connection.DoesColumnExist("metas", "server_ordinal_in_parent"));
3439 EXPECT_FALSE(connection.DoesColumnExist("metas", "unique_position")); 3439 EXPECT_FALSE(connection.DoesColumnExist("metas", "unique_position"));
3440 EXPECT_FALSE(connection.DoesColumnExist("metas", "server_unique_position")); 3440 EXPECT_FALSE(connection.DoesColumnExist("metas", "server_unique_position"));
3441 EXPECT_FALSE(connection.DoesColumnExist("metas", "unique_bookmark_tag")); 3441 EXPECT_FALSE(connection.DoesColumnExist("metas", "unique_bookmark_tag"));
3442 3442
3443 scoped_ptr<TestDirectoryBackingStore> dbs( 3443 std::unique_ptr<TestDirectoryBackingStore> dbs(
3444 new TestDirectoryBackingStore(GetUsername(), &connection)); 3444 new TestDirectoryBackingStore(GetUsername(), &connection));
3445 ASSERT_TRUE(dbs->MigrateVersion85To86()); 3445 ASSERT_TRUE(dbs->MigrateVersion85To86());
3446 EXPECT_EQ(86, dbs->GetVersion()); 3446 EXPECT_EQ(86, dbs->GetVersion());
3447 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_position")); 3447 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_position"));
3448 EXPECT_TRUE(connection.DoesColumnExist("metas", "server_unique_position")); 3448 EXPECT_TRUE(connection.DoesColumnExist("metas", "server_unique_position"));
3449 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_bookmark_tag")); 3449 EXPECT_TRUE(connection.DoesColumnExist("metas", "unique_bookmark_tag"));
3450 ASSERT_TRUE(dbs->needs_column_refresh()); 3450 ASSERT_TRUE(dbs->needs_column_refresh());
3451 } 3451 }
3452 3452
3453 TEST_F(DirectoryBackingStoreTest, MigrateVersion86To87) { 3453 TEST_F(DirectoryBackingStoreTest, MigrateVersion86To87) {
3454 sql::Connection connection; 3454 sql::Connection connection;
3455 EXPECT_TRUE(connection.OpenInMemory()); 3455 EXPECT_TRUE(connection.OpenInMemory());
3456 SetUpVersion86Database(&connection); 3456 SetUpVersion86Database(&connection);
3457 EXPECT_FALSE(connection.DoesColumnExist("metas", "attachment_metadata")); 3457 EXPECT_FALSE(connection.DoesColumnExist("metas", "attachment_metadata"));
3458 3458
3459 scoped_ptr<TestDirectoryBackingStore> dbs( 3459 std::unique_ptr<TestDirectoryBackingStore> dbs(
3460 new TestDirectoryBackingStore(GetUsername(), &connection)); 3460 new TestDirectoryBackingStore(GetUsername(), &connection));
3461 EXPECT_TRUE(dbs->MigrateVersion86To87()); 3461 EXPECT_TRUE(dbs->MigrateVersion86To87());
3462 EXPECT_EQ(87, dbs->GetVersion()); 3462 EXPECT_EQ(87, dbs->GetVersion());
3463 EXPECT_TRUE(connection.DoesColumnExist("metas", "attachment_metadata")); 3463 EXPECT_TRUE(connection.DoesColumnExist("metas", "attachment_metadata"));
3464 EXPECT_TRUE(dbs->needs_column_refresh()); 3464 EXPECT_TRUE(dbs->needs_column_refresh());
3465 } 3465 }
3466 3466
3467 TEST_F(DirectoryBackingStoreTest, MigrateVersion87To88) { 3467 TEST_F(DirectoryBackingStoreTest, MigrateVersion87To88) {
3468 sql::Connection connection; 3468 sql::Connection connection;
3469 ASSERT_TRUE(connection.OpenInMemory()); 3469 ASSERT_TRUE(connection.OpenInMemory());
3470 SetUpVersion87Database(&connection); 3470 SetUpVersion87Database(&connection);
3471 3471
3472 scoped_ptr<TestDirectoryBackingStore> dbs( 3472 std::unique_ptr<TestDirectoryBackingStore> dbs(
3473 new TestDirectoryBackingStore(GetUsername(), &connection)); 3473 new TestDirectoryBackingStore(GetUsername(), &connection));
3474 ASSERT_TRUE(dbs->MigrateVersion87To88()); 3474 ASSERT_TRUE(dbs->MigrateVersion87To88());
3475 ASSERT_EQ(88, dbs->GetVersion()); 3475 ASSERT_EQ(88, dbs->GetVersion());
3476 ASSERT_TRUE(connection.DoesColumnExist("models", "context")); 3476 ASSERT_TRUE(connection.DoesColumnExist("models", "context"));
3477 } 3477 }
3478 3478
3479 TEST_F(DirectoryBackingStoreTest, MigrateVersion88To89) { 3479 TEST_F(DirectoryBackingStoreTest, MigrateVersion88To89) {
3480 sql::Connection connection; 3480 sql::Connection connection;
3481 ASSERT_TRUE(connection.OpenInMemory()); 3481 ASSERT_TRUE(connection.OpenInMemory());
3482 SetUpVersion88Database(&connection); 3482 SetUpVersion88Database(&connection);
3483 ASSERT_FALSE( 3483 ASSERT_FALSE(
3484 connection.DoesColumnExist("metas", "server_attachment_metadata")); 3484 connection.DoesColumnExist("metas", "server_attachment_metadata"));
3485 3485
3486 scoped_ptr<TestDirectoryBackingStore> dbs( 3486 std::unique_ptr<TestDirectoryBackingStore> dbs(
3487 new TestDirectoryBackingStore(GetUsername(), &connection)); 3487 new TestDirectoryBackingStore(GetUsername(), &connection));
3488 ASSERT_TRUE(dbs->MigrateVersion88To89()); 3488 ASSERT_TRUE(dbs->MigrateVersion88To89());
3489 ASSERT_EQ(89, dbs->GetVersion()); 3489 ASSERT_EQ(89, dbs->GetVersion());
3490 EXPECT_TRUE( 3490 EXPECT_TRUE(
3491 connection.DoesColumnExist("metas", "server_attachment_metadata")); 3491 connection.DoesColumnExist("metas", "server_attachment_metadata"));
3492 EXPECT_TRUE(dbs->needs_column_refresh()); 3492 EXPECT_TRUE(dbs->needs_column_refresh());
3493 } 3493 }
3494 3494
3495 TEST_F(DirectoryBackingStoreTest, MigrateVersion89To90) { 3495 TEST_F(DirectoryBackingStoreTest, MigrateVersion89To90) {
3496 sql::Connection connection; 3496 sql::Connection connection;
3497 ASSERT_TRUE(connection.OpenInMemory()); 3497 ASSERT_TRUE(connection.OpenInMemory());
3498 SetUpVersion89Database(&connection); 3498 SetUpVersion89Database(&connection);
3499 ASSERT_TRUE(connection.DoesColumnExist("share_info", "db_create_version")); 3499 ASSERT_TRUE(connection.DoesColumnExist("share_info", "db_create_version"));
3500 ASSERT_TRUE(connection.DoesColumnExist("share_info", "db_create_time")); 3500 ASSERT_TRUE(connection.DoesColumnExist("share_info", "db_create_time"));
3501 ASSERT_TRUE(connection.DoesColumnExist("share_info", "next_id")); 3501 ASSERT_TRUE(connection.DoesColumnExist("share_info", "next_id"));
3502 ASSERT_TRUE(connection.DoesColumnExist("share_info", "notification_state")); 3502 ASSERT_TRUE(connection.DoesColumnExist("share_info", "notification_state"));
3503 3503
3504 scoped_ptr<TestDirectoryBackingStore> dbs( 3504 std::unique_ptr<TestDirectoryBackingStore> dbs(
3505 new TestDirectoryBackingStore(GetUsername(), &connection)); 3505 new TestDirectoryBackingStore(GetUsername(), &connection));
3506 ASSERT_TRUE(dbs->MigrateVersion89To90()); 3506 ASSERT_TRUE(dbs->MigrateVersion89To90());
3507 ASSERT_EQ(90, dbs->GetVersion()); 3507 ASSERT_EQ(90, dbs->GetVersion());
3508 EXPECT_TRUE(dbs->needs_column_refresh()); 3508 EXPECT_TRUE(dbs->needs_column_refresh());
3509 3509
3510 ASSERT_TRUE(dbs->RefreshColumns()); 3510 ASSERT_TRUE(dbs->RefreshColumns());
3511 EXPECT_FALSE(dbs->needs_column_refresh()); 3511 EXPECT_FALSE(dbs->needs_column_refresh());
3512 3512
3513 ASSERT_FALSE(connection.DoesColumnExist("share_info", "db_create_version")); 3513 ASSERT_FALSE(connection.DoesColumnExist("share_info", "db_create_version"));
3514 ASSERT_FALSE(connection.DoesColumnExist("share_info", "db_create_time")); 3514 ASSERT_FALSE(connection.DoesColumnExist("share_info", "db_create_time"));
(...skipping 17 matching lines...) Expand all
3532 // > .dump 3532 // > .dump
3533 // 5. Replace the timestamp columns with META_PROTO_TIMES(x) (or 3533 // 5. Replace the timestamp columns with META_PROTO_TIMES(x) (or
3534 // LEGACY_META_PROTO_TIMES(x) if before Version 77). Use this dump to write 3534 // LEGACY_META_PROTO_TIMES(x) if before Version 77). Use this dump to write
3535 // a SetupVersionYDatabase method. 3535 // a SetupVersionYDatabase method.
3536 TEST_F(DirectoryBackingStoreTest, MigrateToLatestAndDump) { 3536 TEST_F(DirectoryBackingStoreTest, MigrateToLatestAndDump) {
3537 { 3537 {
3538 sql::Connection connection; 3538 sql::Connection connection;
3539 ASSERT_TRUE(connection.Open(GetDatabasePath())); 3539 ASSERT_TRUE(connection.Open(GetDatabasePath()));
3540 SetUpVersion89Database(&connection); // Update this. 3540 SetUpVersion89Database(&connection); // Update this.
3541 3541
3542 scoped_ptr<TestDirectoryBackingStore> dbs( 3542 std::unique_ptr<TestDirectoryBackingStore> dbs(
3543 new TestDirectoryBackingStore(GetUsername(), &connection)); 3543 new TestDirectoryBackingStore(GetUsername(), &connection));
3544 ASSERT_TRUE(dbs->MigrateVersion89To90()); // Update this. 3544 ASSERT_TRUE(dbs->MigrateVersion89To90()); // Update this.
3545 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 3545 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
3546 EXPECT_EQ(90, dbs->GetVersion()); // Update this. 3546 EXPECT_EQ(90, dbs->GetVersion()); // Update this.
3547 ASSERT_FALSE(dbs->needs_column_refresh()); 3547 ASSERT_FALSE(dbs->needs_column_refresh());
3548 } 3548 }
3549 // Set breakpoint here. 3549 // Set breakpoint here.
3550 } 3550 }
3551 3551
3552 TEST_F(DirectoryBackingStoreTest, DetectInvalidPosition) { 3552 TEST_F(DirectoryBackingStoreTest, DetectInvalidPosition) {
3553 sql::Connection connection; 3553 sql::Connection connection;
3554 ASSERT_TRUE(connection.OpenInMemory()); 3554 ASSERT_TRUE(connection.OpenInMemory());
3555 SetUpVersion86Database(&connection); 3555 SetUpVersion86Database(&connection);
3556 3556
3557 scoped_ptr<TestDirectoryBackingStore> dbs( 3557 std::unique_ptr<TestDirectoryBackingStore> dbs(
3558 new TestDirectoryBackingStore(GetUsername(), &connection)); 3558 new TestDirectoryBackingStore(GetUsername(), &connection));
3559 ASSERT_EQ(86, dbs->GetVersion()); 3559 ASSERT_EQ(86, dbs->GetVersion());
3560 3560
3561 // Insert row with bad position. 3561 // Insert row with bad position.
3562 sql::Statement s(connection.GetUniqueStatement( 3562 sql::Statement s(connection.GetUniqueStatement(
3563 "INSERT INTO metas " 3563 "INSERT INTO metas "
3564 "( id, metahandle, is_dir, ctime, mtime," 3564 "( id, metahandle, is_dir, ctime, mtime,"
3565 " unique_position, server_unique_position) " 3565 " unique_position, server_unique_position) "
3566 "VALUES('c-invalid', 9999, 1, 0, 0, 'BAD_POS', 'BAD_POS')")); 3566 "VALUES('c-invalid', 9999, 1, 0, 0, 'BAD_POS', 'BAD_POS')"));
3567 ASSERT_TRUE(s.Run()); 3567 ASSERT_TRUE(s.Run());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3665 } 3665 }
3666 connection.Close(); 3666 connection.Close();
3667 3667
3668 syncable::Directory::KernelLoadInfo dir_info; 3668 syncable::Directory::KernelLoadInfo dir_info;
3669 Directory::MetahandlesMap handles_map; 3669 Directory::MetahandlesMap handles_map;
3670 JournalIndex delete_journals; 3670 JournalIndex delete_journals;
3671 MetahandleSet metahandles_to_purge; 3671 MetahandleSet metahandles_to_purge;
3672 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map); 3672 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
3673 3673
3674 { 3674 {
3675 scoped_ptr<OnDiskDirectoryBackingStore> dbs( 3675 std::unique_ptr<OnDiskDirectoryBackingStore> dbs(
3676 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath())); 3676 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
3677 ASSERT_EQ(OPENED, dbs->Load(&handles_map, &delete_journals, 3677 ASSERT_EQ(OPENED, dbs->Load(&handles_map, &delete_journals,
3678 &metahandles_to_purge, &dir_info)); 3678 &metahandles_to_purge, &dir_info));
3679 if (!metahandles_to_purge.empty()) 3679 if (!metahandles_to_purge.empty())
3680 dbs->DeleteEntries(DirectoryBackingStore::METAS_TABLE, 3680 dbs->DeleteEntries(DirectoryBackingStore::METAS_TABLE,
3681 metahandles_to_purge); 3681 metahandles_to_purge);
3682 ASSERT_FALSE(dbs->needs_column_refresh()); 3682 ASSERT_FALSE(dbs->needs_column_refresh());
3683 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); 3683 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion());
3684 int pageSize = 0; 3684 int pageSize = 0;
3685 ASSERT_TRUE(dbs->GetDatabasePageSize(&pageSize)); 3685 ASSERT_TRUE(dbs->GetDatabasePageSize(&pageSize));
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
4015 } // namespace 4015 } // namespace
4016 4016
4017 // This is a whitebox test intended to exercise the code path where the on-disk 4017 // This is a whitebox test intended to exercise the code path where the on-disk
4018 // directory load code decides to delete the current directory and start fresh. 4018 // directory load code decides to delete the current directory and start fresh.
4019 // 4019 //
4020 // This is considered "minor" corruption because the database recreation is 4020 // This is considered "minor" corruption because the database recreation is
4021 // expected to succeed. The alternative, where recreation does not succeed (ie. 4021 // expected to succeed. The alternative, where recreation does not succeed (ie.
4022 // due to read-only file system), is not tested here. 4022 // due to read-only file system), is not tested here.
4023 TEST_F(DirectoryBackingStoreTest, MinorCorruption) { 4023 TEST_F(DirectoryBackingStoreTest, MinorCorruption) {
4024 { 4024 {
4025 scoped_ptr<OnDiskDirectoryBackingStore> dbs( 4025 std::unique_ptr<OnDiskDirectoryBackingStore> dbs(
4026 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath())); 4026 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
4027 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4027 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4028 } 4028 }
4029 4029
4030 // Corrupt the root node. 4030 // Corrupt the root node.
4031 { 4031 {
4032 sql::Connection connection; 4032 sql::Connection connection;
4033 ASSERT_TRUE(connection.Open(GetDatabasePath())); 4033 ASSERT_TRUE(connection.Open(GetDatabasePath()));
4034 ASSERT_TRUE(connection.Execute( 4034 ASSERT_TRUE(connection.Execute(
4035 "UPDATE metas SET parent_id='bogus' WHERE id = 'r';")); 4035 "UPDATE metas SET parent_id='bogus' WHERE id = 'r';"));
4036 } 4036 }
4037 4037
4038 { 4038 {
4039 scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs( 4039 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4040 new OnDiskDirectoryBackingStoreForTest(GetUsername(), 4040 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4041 GetDatabasePath())); 4041 GetDatabasePath()));
4042 4042
4043 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4043 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4044 EXPECT_TRUE(dbs->DidFailFirstOpenAttempt()); 4044 EXPECT_TRUE(dbs->DidFailFirstOpenAttempt());
4045 } 4045 }
4046 } 4046 }
4047 4047
4048 TEST_F(DirectoryBackingStoreTest, MinorCorruptionAndUpgrade) { 4048 TEST_F(DirectoryBackingStoreTest, MinorCorruptionAndUpgrade) {
4049 { 4049 {
4050 scoped_ptr<OnDiskDirectoryBackingStore> dbs( 4050 std::unique_ptr<OnDiskDirectoryBackingStore> dbs(
4051 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath())); 4051 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
4052 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4052 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4053 } 4053 }
4054 4054
4055 // Make the node look outdated with an invalid version. 4055 // Make the node look outdated with an invalid version.
4056 { 4056 {
4057 sql::Connection connection; 4057 sql::Connection connection;
4058 ASSERT_TRUE(connection.Open(GetDatabasePath())); 4058 ASSERT_TRUE(connection.Open(GetDatabasePath()));
4059 ASSERT_TRUE(connection.Execute("UPDATE share_version SET data = 0;")); 4059 ASSERT_TRUE(connection.Execute("UPDATE share_version SET data = 0;"));
4060 ASSERT_TRUE(connection.Execute("PRAGMA page_size=4096;")); 4060 ASSERT_TRUE(connection.Execute("PRAGMA page_size=4096;"));
4061 ASSERT_TRUE(connection.Execute("VACUUM;")); 4061 ASSERT_TRUE(connection.Execute("VACUUM;"));
4062 } 4062 }
4063 4063
4064 { 4064 {
4065 scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs( 4065 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4066 new OnDiskDirectoryBackingStoreForTest(GetUsername(), 4066 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4067 GetDatabasePath())); 4067 GetDatabasePath()));
4068 dbs->SetCatastrophicErrorHandler(base::Bind(&base::DoNothing)); 4068 dbs->SetCatastrophicErrorHandler(base::Bind(&base::DoNothing));
4069 4069
4070 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4070 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4071 EXPECT_TRUE(dbs->DidFailFirstOpenAttempt()); 4071 EXPECT_TRUE(dbs->DidFailFirstOpenAttempt());
4072 4072
4073 int page_size = 0; 4073 int page_size = 0;
4074 ASSERT_TRUE(dbs->GetDatabasePageSize(&page_size)); 4074 ASSERT_TRUE(dbs->GetDatabasePageSize(&page_size));
4075 EXPECT_EQ(kCurrentPageSizeKB, page_size); 4075 EXPECT_EQ(kCurrentPageSizeKB, page_size);
4076 } 4076 }
4077 } 4077 }
4078 4078
4079 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { 4079 TEST_F(DirectoryBackingStoreTest, DeleteEntries) {
4080 sql::Connection connection; 4080 sql::Connection connection;
4081 ASSERT_TRUE(connection.OpenInMemory()); 4081 ASSERT_TRUE(connection.OpenInMemory());
4082 4082
4083 SetUpCurrentDatabaseAndCheckVersion(&connection); 4083 SetUpCurrentDatabaseAndCheckVersion(&connection);
4084 scoped_ptr<TestDirectoryBackingStore> dbs( 4084 std::unique_ptr<TestDirectoryBackingStore> dbs(
4085 new TestDirectoryBackingStore(GetUsername(), &connection)); 4085 new TestDirectoryBackingStore(GetUsername(), &connection));
4086 Directory::MetahandlesMap handles_map; 4086 Directory::MetahandlesMap handles_map;
4087 JournalIndex delete_journals; 4087 JournalIndex delete_journals;
4088 MetahandleSet metahandles_to_purge; 4088 MetahandleSet metahandles_to_purge;
4089 Directory::KernelLoadInfo kernel_load_info; 4089 Directory::KernelLoadInfo kernel_load_info;
4090 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map); 4090 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
4091 4091
4092 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge, 4092 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge,
4093 &kernel_load_info); 4093 &kernel_load_info);
4094 size_t initial_size = handles_map.size(); 4094 size_t initial_size = handles_map.size();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4135 // In theory this test can fail, but it won't before the universe 4135 // In theory this test can fail, but it won't before the universe
4136 // dies of heat death. 4136 // dies of heat death.
4137 EXPECT_NE(guid1, guid2); 4137 EXPECT_NE(guid1, guid2);
4138 } 4138 }
4139 4139
4140 TEST_F(DirectoryBackingStoreTest, IncreaseDatabasePageSizeFrom4KTo32K) { 4140 TEST_F(DirectoryBackingStoreTest, IncreaseDatabasePageSizeFrom4KTo32K) {
4141 sql::Connection connection; 4141 sql::Connection connection;
4142 ASSERT_TRUE(connection.Open(GetDatabasePath())); 4142 ASSERT_TRUE(connection.Open(GetDatabasePath()));
4143 4143
4144 SetUpCurrentDatabaseAndCheckVersion(&connection); 4144 SetUpCurrentDatabaseAndCheckVersion(&connection);
4145 scoped_ptr<TestDirectoryBackingStore> dbs( 4145 std::unique_ptr<TestDirectoryBackingStore> dbs(
4146 new TestDirectoryBackingStore(GetUsername(), &connection)); 4146 new TestDirectoryBackingStore(GetUsername(), &connection));
4147 Directory::MetahandlesMap handles_map; 4147 Directory::MetahandlesMap handles_map;
4148 JournalIndex delete_journals; 4148 JournalIndex delete_journals;
4149 MetahandleSet metahandles_to_purge; 4149 MetahandleSet metahandles_to_purge;
4150 Directory::KernelLoadInfo kernel_load_info; 4150 Directory::KernelLoadInfo kernel_load_info;
4151 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map); 4151 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
4152 4152
4153 DirOpenResult open_result = dbs->Load( 4153 DirOpenResult open_result = dbs->Load(
4154 &handles_map, &delete_journals, &metahandles_to_purge, &kernel_load_info); 4154 &handles_map, &delete_journals, &metahandles_to_purge, &kernel_load_info);
4155 EXPECT_EQ(open_result, OPENED); 4155 EXPECT_EQ(open_result, OPENED);
4156 4156
4157 // Set up database's page size to 4096 4157 // Set up database's page size to 4096
4158 EXPECT_TRUE(dbs->db_->Execute("PRAGMA page_size=4096;")); 4158 EXPECT_TRUE(dbs->db_->Execute("PRAGMA page_size=4096;"));
4159 EXPECT_TRUE(dbs->Vacuum()); 4159 EXPECT_TRUE(dbs->Vacuum());
4160 4160
4161 // Check if update is successful. 4161 // Check if update is successful.
4162 int pageSize = 0; 4162 int pageSize = 0;
4163 EXPECT_TRUE(dbs->GetDatabasePageSize(&pageSize)); 4163 EXPECT_TRUE(dbs->GetDatabasePageSize(&pageSize));
4164 EXPECT_NE(kCurrentPageSizeKB, pageSize); 4164 EXPECT_NE(kCurrentPageSizeKB, pageSize);
4165 EXPECT_TRUE(dbs->UpdatePageSizeIfNecessary()); 4165 EXPECT_TRUE(dbs->UpdatePageSizeIfNecessary());
4166 pageSize = 0; 4166 pageSize = 0;
4167 EXPECT_TRUE(dbs->GetDatabasePageSize(&pageSize)); 4167 EXPECT_TRUE(dbs->GetDatabasePageSize(&pageSize));
4168 EXPECT_EQ(kCurrentPageSizeKB, pageSize); 4168 EXPECT_EQ(kCurrentPageSizeKB, pageSize);
4169 } 4169 }
4170 4170
4171 // See that a catastrophic error handler remains set across instances of the 4171 // See that a catastrophic error handler remains set across instances of the
4172 // underlying sql:Connection. 4172 // underlying sql:Connection.
4173 TEST_F(DirectoryBackingStoreTest, CatastrophicErrorHandler_KeptAcrossReset) { 4173 TEST_F(DirectoryBackingStoreTest, CatastrophicErrorHandler_KeptAcrossReset) {
4174 scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs( 4174 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4175 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath())); 4175 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath()));
4176 // See that by default there is no catastrophic error handler. 4176 // See that by default there is no catastrophic error handler.
4177 ASSERT_FALSE(dbs->db_->has_error_callback()); 4177 ASSERT_FALSE(dbs->db_->has_error_callback());
4178 // Set one and see that it was set. 4178 // Set one and see that it was set.
4179 dbs->SetCatastrophicErrorHandler( 4179 dbs->SetCatastrophicErrorHandler(
4180 base::Bind(&CatastrophicErrorHandler, nullptr)); 4180 base::Bind(&CatastrophicErrorHandler, nullptr));
4181 ASSERT_TRUE(dbs->db_->has_error_callback()); 4181 ASSERT_TRUE(dbs->db_->has_error_callback());
4182 // Recreate the Connection and see that the handler remains set. 4182 // Recreate the Connection and see that the handler remains set.
4183 dbs->ResetAndCreateConnection(); 4183 dbs->ResetAndCreateConnection();
4184 ASSERT_TRUE(dbs->db_->has_error_callback()); 4184 ASSERT_TRUE(dbs->db_->has_error_callback());
4185 } 4185 }
4186 4186
4187 // Verify that database corruption encountered during Load will trigger the 4187 // Verify that database corruption encountered during Load will trigger the
4188 // catastrohpic error handler. 4188 // catastrohpic error handler.
4189 TEST_F(DirectoryBackingStoreTest, 4189 TEST_F(DirectoryBackingStoreTest,
4190 CatastrophicErrorHandler_InvocationDuringLoad) { 4190 CatastrophicErrorHandler_InvocationDuringLoad) {
4191 bool was_called = false; 4191 bool was_called = false;
4192 const base::Closure handler = 4192 const base::Closure handler =
4193 base::Bind(&CatastrophicErrorHandler, &was_called); 4193 base::Bind(&CatastrophicErrorHandler, &was_called);
4194 { 4194 {
4195 scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs( 4195 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4196 new OnDiskDirectoryBackingStoreForTest(GetUsername(), 4196 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4197 GetDatabasePath())); 4197 GetDatabasePath()));
4198 dbs->SetCatastrophicErrorHandler(handler); 4198 dbs->SetCatastrophicErrorHandler(handler);
4199 ASSERT_TRUE(dbs->db_->has_error_callback()); 4199 ASSERT_TRUE(dbs->db_->has_error_callback());
4200 // Load the DB, and save one entry. 4200 // Load the DB, and save one entry.
4201 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4201 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4202 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt()); 4202 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt());
4203 Directory::SaveChangesSnapshot snapshot; 4203 Directory::SaveChangesSnapshot snapshot;
4204 snapshot.dirty_metas.insert(CreateEntry(2, "").release()); 4204 snapshot.dirty_metas.insert(CreateEntry(2, "").release());
4205 ASSERT_TRUE(dbs->SaveChanges(snapshot)); 4205 ASSERT_TRUE(dbs->SaveChanges(snapshot));
4206 } 4206 }
4207 4207
4208 base::RunLoop().RunUntilIdle(); 4208 base::RunLoop().RunUntilIdle();
4209 // No catastrophic errors have happened. See that it hasn't be called yet. 4209 // No catastrophic errors have happened. See that it hasn't be called yet.
4210 ASSERT_FALSE(was_called); 4210 ASSERT_FALSE(was_called);
4211 4211
4212 // Corrupt the DB. Some forms of corruption (like this one) will be detected 4212 // Corrupt the DB. Some forms of corruption (like this one) will be detected
4213 // upon loading the Sync DB. 4213 // upon loading the Sync DB.
4214 ASSERT_TRUE(sql::test::CorruptSizeInHeader(GetDatabasePath())); 4214 ASSERT_TRUE(sql::test::CorruptSizeInHeader(GetDatabasePath()));
4215 4215
4216 { 4216 {
4217 scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs( 4217 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4218 new OnDiskDirectoryBackingStoreForTest(GetUsername(), 4218 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4219 GetDatabasePath())); 4219 GetDatabasePath()));
4220 dbs->SetCatastrophicErrorHandler(handler); 4220 dbs->SetCatastrophicErrorHandler(handler);
4221 ASSERT_TRUE(dbs->db_->has_error_callback()); 4221 ASSERT_TRUE(dbs->db_->has_error_callback());
4222 { 4222 {
4223 // The corruption will be detected when we attempt to load the data. Use a 4223 // The corruption will be detected when we attempt to load the data. Use a
4224 // ScopedErrorIgnorer to ensure we don't crash in debug builds. 4224 // ScopedErrorIgnorer to ensure we don't crash in debug builds.
4225 sql::ScopedErrorIgnorer error_ignorer; 4225 sql::ScopedErrorIgnorer error_ignorer;
4226 error_ignorer.IgnoreError(SQLITE_CORRUPT); 4226 error_ignorer.IgnoreError(SQLITE_CORRUPT);
4227 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4227 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
(...skipping 11 matching lines...) Expand all
4239 } 4239 }
4240 4240
4241 // Verify that database corruption encountered during SaveChanges will trigger 4241 // Verify that database corruption encountered during SaveChanges will trigger
4242 // the catastrohpic error handler. 4242 // the catastrohpic error handler.
4243 TEST_F(DirectoryBackingStoreTest, 4243 TEST_F(DirectoryBackingStoreTest,
4244 CatastrophicErrorHandler_InvocationDuringSaveChanges) { 4244 CatastrophicErrorHandler_InvocationDuringSaveChanges) {
4245 bool was_called = false; 4245 bool was_called = false;
4246 const base::Closure handler = 4246 const base::Closure handler =
4247 base::Bind(&CatastrophicErrorHandler, &was_called); 4247 base::Bind(&CatastrophicErrorHandler, &was_called);
4248 // Create a DB with many entries. 4248 // Create a DB with many entries.
4249 scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs( 4249 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4250 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath())); 4250 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath()));
4251 dbs->SetCatastrophicErrorHandler(handler); 4251 dbs->SetCatastrophicErrorHandler(handler);
4252 ASSERT_TRUE(dbs->db_->has_error_callback()); 4252 ASSERT_TRUE(dbs->db_->has_error_callback());
4253 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4253 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4254 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt()); 4254 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt());
4255 Directory::SaveChangesSnapshot snapshot; 4255 Directory::SaveChangesSnapshot snapshot;
4256 const std::string suffix(400, 'o'); 4256 const std::string suffix(400, 'o');
4257 for (int i = 0; i < corruption_testing::kNumEntriesRequiredForCorruption; 4257 for (int i = 0; i < corruption_testing::kNumEntriesRequiredForCorruption;
4258 ++i) { 4258 ++i) {
4259 scoped_ptr<EntryKernel> large_entry = CreateEntry(i, suffix); 4259 std::unique_ptr<EntryKernel> large_entry = CreateEntry(i, suffix);
4260 snapshot.dirty_metas.insert(large_entry.release()); 4260 snapshot.dirty_metas.insert(large_entry.release());
4261 } 4261 }
4262 ASSERT_TRUE(dbs->SaveChanges(snapshot)); 4262 ASSERT_TRUE(dbs->SaveChanges(snapshot));
4263 // Corrupt it. 4263 // Corrupt it.
4264 ASSERT_TRUE(corruption_testing::CorruptDatabase(GetDatabasePath())); 4264 ASSERT_TRUE(corruption_testing::CorruptDatabase(GetDatabasePath()));
4265 // Attempt to save all those entries again. See that it fails (because of the 4265 // Attempt to save all those entries again. See that it fails (because of the
4266 // corruption). 4266 // corruption).
4267 // 4267 //
4268 // If this test fails because SaveChanges returned true, it may mean you need 4268 // If this test fails because SaveChanges returned true, it may mean you need
4269 // to increase the number of entries written to the DB. See also 4269 // to increase the number of entries written to the DB. See also
4270 // |kNumEntriesRequiredForCorruption|. 4270 // |kNumEntriesRequiredForCorruption|.
4271 ASSERT_FALSE(dbs->SaveChanges(snapshot)); 4271 ASSERT_FALSE(dbs->SaveChanges(snapshot));
4272 // At this point the handler has been posted but not executed. 4272 // At this point the handler has been posted but not executed.
4273 ASSERT_FALSE(was_called); 4273 ASSERT_FALSE(was_called);
4274 // Pump the message loop and see that it is executed. 4274 // Pump the message loop and see that it is executed.
4275 base::RunLoop().RunUntilIdle(); 4275 base::RunLoop().RunUntilIdle();
4276 ASSERT_TRUE(was_called); 4276 ASSERT_TRUE(was_called);
4277 } 4277 }
4278 4278
4279 } // namespace syncable 4279 } // namespace syncable
4280 } // namespace syncer 4280 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698