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 "components/sync/syncable/directory_backing_store.h" | 5 #include "components/sync/syncable/directory_backing_store.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "components/sync/base/node_ordinal.h" | 18 #include "components/sync/base/node_ordinal.h" |
19 #include "components/sync/base/time.h" | 19 #include "components/sync/base/time.h" |
20 #include "components/sync/protocol/bookmark_specifics.pb.h" | 20 #include "components/sync/protocol/bookmark_specifics.pb.h" |
21 #include "components/sync/protocol/sync.pb.h" | 21 #include "components/sync/protocol/sync.pb.h" |
22 #include "components/sync/syncable/on_disk_directory_backing_store.h" | 22 #include "components/sync/syncable/on_disk_directory_backing_store.h" |
23 #include "components/sync/test/directory_backing_store_corruption_testing.h" | |
24 #include "components/sync/test/test_directory_backing_store.h" | 23 #include "components/sync/test/test_directory_backing_store.h" |
25 #include "sql/test/test_helpers.h" | 24 #include "sql/test/test_helpers.h" |
26 #include "testing/gtest/include/gtest/gtest-param-test.h" | 25 #include "testing/gtest/include/gtest/gtest-param-test.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
28 | 27 |
29 namespace syncer { | 28 namespace syncer { |
30 namespace syncable { | 29 namespace syncable { |
31 namespace { | 30 namespace { |
32 | 31 |
33 // A handler that simply sets |catastrophic_error_handler_was_called| to true. | 32 // A handler that simply sets |catastrophic_error_handler_was_called| to true. |
(...skipping 4254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4288 base::Bind(&CatastrophicErrorHandler, &was_called); | 4287 base::Bind(&CatastrophicErrorHandler, &was_called); |
4289 // Create a DB with many entries. | 4288 // Create a DB with many entries. |
4290 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs( | 4289 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs( |
4291 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath())); | 4290 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath())); |
4292 dbs->SetCatastrophicErrorHandler(handler); | 4291 dbs->SetCatastrophicErrorHandler(handler); |
4293 ASSERT_TRUE(dbs->db_->has_error_callback()); | 4292 ASSERT_TRUE(dbs->db_->has_error_callback()); |
4294 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); | 4293 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); |
4295 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt()); | 4294 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt()); |
4296 Directory::SaveChangesSnapshot snapshot; | 4295 Directory::SaveChangesSnapshot snapshot; |
4297 const std::string suffix(400, 'o'); | 4296 const std::string suffix(400, 'o'); |
4298 for (int i = 0; i < corruption_testing::kNumEntriesRequiredForCorruption; | 4297 for (size_t i = 0; i < 100; ++i) { |
4299 ++i) { | |
4300 snapshot.dirty_metas.insert(CreateEntry(i, suffix)); | 4298 snapshot.dirty_metas.insert(CreateEntry(i, suffix)); |
4301 } | 4299 } |
4302 ASSERT_TRUE(dbs->SaveChanges(snapshot)); | 4300 ASSERT_TRUE(dbs->SaveChanges(snapshot)); |
4303 // Corrupt it. | 4301 // Corrupt the database on disk. |
4304 ASSERT_TRUE(corruption_testing::CorruptDatabase(GetDatabasePath())); | 4302 ASSERT_TRUE(sql::test::CorruptSizeInHeaderWithLock(GetDatabasePath())); |
4305 // Attempt to save all those entries again. See that it fails (because of the | 4303 // Attempt to save all those entries again. See that it fails (because of the |
4306 // corruption). | 4304 // corruption). |
4307 // | |
4308 // If this test fails because SaveChanges returned true, it may mean you need | |
4309 // to increase the number of entries written to the DB. See also | |
4310 // |kNumEntriesRequiredForCorruption|. | |
4311 ASSERT_FALSE(dbs->SaveChanges(snapshot)); | 4305 ASSERT_FALSE(dbs->SaveChanges(snapshot)); |
4312 // At this point the handler has been posted but not executed. | 4306 // At this point the handler has been posted but not executed. |
4313 ASSERT_FALSE(was_called); | 4307 ASSERT_FALSE(was_called); |
4314 // Pump the message loop and see that it is executed. | 4308 // Pump the message loop and see that it is executed. |
4315 base::RunLoop().RunUntilIdle(); | 4309 base::RunLoop().RunUntilIdle(); |
4316 ASSERT_TRUE(was_called); | 4310 ASSERT_TRUE(was_called); |
4317 } | 4311 } |
4318 | 4312 |
4319 } // namespace syncable | 4313 } // namespace syncable |
4320 } // namespace syncer | 4314 } // namespace syncer |
OLD | NEW |