OLD | NEW |
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 <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.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_expecter.h" |
25 #include "sql/test/test_helpers.h" | 25 #include "sql/test/test_helpers.h" |
26 #include "sync/base/sync_export.h" | 26 #include "sync/base/sync_export.h" |
27 #include "sync/internal_api/public/base/node_ordinal.h" | 27 #include "sync/internal_api/public/base/node_ordinal.h" |
28 #include "sync/protocol/bookmark_specifics.pb.h" | 28 #include "sync/protocol/bookmark_specifics.pb.h" |
29 #include "sync/protocol/sync.pb.h" | 29 #include "sync/protocol/sync.pb.h" |
30 #include "sync/syncable/directory.h" | 30 #include "sync/syncable/directory.h" |
31 #include "sync/syncable/on_disk_directory_backing_store.h" | 31 #include "sync/syncable/on_disk_directory_backing_store.h" |
32 #include "sync/syncable/syncable-inl.h" | 32 #include "sync/syncable/syncable-inl.h" |
33 #include "sync/test/directory_backing_store_corruption_testing.h" | 33 #include "sync/test/directory_backing_store_corruption_testing.h" |
34 #include "sync/test/test_directory_backing_store.h" | 34 #include "sync/test/test_directory_backing_store.h" |
(...skipping 4179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4214 ASSERT_TRUE(sql::test::CorruptSizeInHeader(GetDatabasePath())); | 4214 ASSERT_TRUE(sql::test::CorruptSizeInHeader(GetDatabasePath())); |
4215 | 4215 |
4216 { | 4216 { |
4217 std::unique_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 // ScopedErrorExpecter to ensure we don't crash in debug builds. |
4225 sql::ScopedErrorIgnorer error_ignorer; | 4225 sql::test::ScopedErrorExpecter expecter; |
4226 error_ignorer.IgnoreError(SQLITE_CORRUPT); | 4226 expecter.ExpectError(SQLITE_CORRUPT); |
4227 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); | 4227 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); |
4228 ASSERT_TRUE(error_ignorer.CheckIgnoredErrors()); | 4228 ASSERT_TRUE(expecter.SawExpectedErrors()); |
4229 } | 4229 } |
4230 // See that the first open failed as expected. | 4230 // See that the first open failed as expected. |
4231 ASSERT_TRUE(dbs->DidFailFirstOpenAttempt()); | 4231 ASSERT_TRUE(dbs->DidFailFirstOpenAttempt()); |
4232 } | 4232 } |
4233 | 4233 |
4234 // At this point the handler has been posted but not executed. | 4234 // At this point the handler has been posted but not executed. |
4235 ASSERT_FALSE(was_called); | 4235 ASSERT_FALSE(was_called); |
4236 // Pump the message loop and see that it is executed. | 4236 // Pump the message loop and see that it is executed. |
4237 base::RunLoop().RunUntilIdle(); | 4237 base::RunLoop().RunUntilIdle(); |
4238 ASSERT_TRUE(was_called); | 4238 ASSERT_TRUE(was_called); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |