OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/sql/connection.h" | 9 #include "app/sql/connection.h" |
10 #include "app/sql/statement.h" | 10 #include "app/sql/statement.h" |
11 #include "app/sql/transaction.h" | 11 #include "app/sql/transaction.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" |
13 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
14 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
15 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" |
16 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 17 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
17 #include "chrome/browser/sync/protocol/sync.pb.h" | 18 #include "chrome/browser/sync/protocol/sync.pb.h" |
18 #include "chrome/browser/sync/syncable/directory_backing_store.h" | 19 #include "chrome/browser/sync/syncable/directory_backing_store.h" |
19 #include "chrome/browser/sync/syncable/directory_manager.h" | 20 #include "chrome/browser/sync/syncable/directory_manager.h" |
20 #include "chrome/browser/sync/syncable/syncable-inl.h" | 21 #include "chrome/browser/sync/syncable/syncable-inl.h" |
21 #include "chrome/browser/sync/syncable/syncable.h" | 22 #include "chrome/browser/sync/syncable/syncable.h" |
22 #include "chrome/common/sqlite_utils.h" | 23 #include "chrome/common/sqlite_utils.h" |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 | 864 |
864 TEST_F(DirectoryBackingStoreTest, ModelTypeIds) { | 865 TEST_F(DirectoryBackingStoreTest, ModelTypeIds) { |
865 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 866 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
866 std::string model_id = | 867 std::string model_id = |
867 DirectoryBackingStore::ModelTypeEnumToModelId(ModelTypeFromInt(i)); | 868 DirectoryBackingStore::ModelTypeEnumToModelId(ModelTypeFromInt(i)); |
868 EXPECT_EQ(i, | 869 EXPECT_EQ(i, |
869 DirectoryBackingStore::ModelIdToModelTypeEnum(model_id)); | 870 DirectoryBackingStore::ModelIdToModelTypeEnum(model_id)); |
870 } | 871 } |
871 } | 872 } |
872 | 873 |
| 874 TEST_F(DirectoryBackingStoreTest, Corruption) { |
| 875 { |
| 876 scoped_ptr<DirectoryBackingStore> dbs( |
| 877 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); |
| 878 EXPECT_TRUE(dbs->BeginLoad()); |
| 879 } |
| 880 std::string bad_data("BAD DATA"); |
| 881 EXPECT_TRUE(file_util::WriteFile(GetDatabasePath(), bad_data.data(), |
| 882 bad_data.size())); |
| 883 { |
| 884 scoped_ptr<DirectoryBackingStore> dbs( |
| 885 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); |
| 886 |
| 887 // In release mode, we expect the sync database to nuke itself and start |
| 888 // over if it detects invalid/corrupted data. |
| 889 #if defined(NDEBUG) |
| 890 EXPECT_TRUE(dbs->BeginLoad()); |
| 891 #else |
| 892 EXPECT_DEATH(dbs->BeginLoad(), "sqlite error"); |
| 893 #endif |
| 894 } |
| 895 } |
| 896 |
873 } // namespace syncable | 897 } // namespace syncable |
OLD | NEW |