OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "sql/connection.h" | 9 #include "sql/connection.h" |
10 #include "sql/meta_table.h" | 10 #include "sql/meta_table.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 EXPECT_TRUE(base::DirectoryExists(kNestedDir)); | 66 EXPECT_TRUE(base::DirectoryExists(kNestedDir)); |
67 EXPECT_TRUE(base::PathExists(kOtherFile)); | 67 EXPECT_TRUE(base::PathExists(kOtherFile)); |
68 | 68 |
69 EXPECT_TRUE(db.DeleteExistingAndCreateNewDatabase()); | 69 EXPECT_TRUE(db.DeleteExistingAndCreateNewDatabase()); |
70 | 70 |
71 EXPECT_TRUE(base::PathExists(kDbFile)); | 71 EXPECT_TRUE(base::PathExists(kDbFile)); |
72 EXPECT_FALSE(base::DirectoryExists(kNestedDir)); | 72 EXPECT_FALSE(base::DirectoryExists(kNestedDir)); |
73 EXPECT_FALSE(base::PathExists(kOtherFile)); | 73 EXPECT_FALSE(base::PathExists(kOtherFile)); |
74 } | 74 } |
75 | 75 |
| 76 #ifdef NDEBUG |
| 77 // Only run in release builds because sql::Connection and familiy |
| 78 // crank up DLOG(FATAL)'ness and this test presents it with |
| 79 // intentionally bad data which causes debug builds to exit instead |
| 80 // of run to completion. In release builds, errors the are deliverd |
| 81 // to the consumer so we can test the error handling of the consumer. |
| 82 TEST(AppCacheDatabaseTest, QuickIntegrityCheck) { |
| 83 // Real files on disk for this test too, a corrupt database file. |
| 84 base::ScopedTempDir temp_dir; |
| 85 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 86 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); |
| 87 const std::string kCorruptData("deadbeef"); |
| 88 EXPECT_EQ(static_cast<int>(kCorruptData.length()), |
| 89 file_util::WriteFile( |
| 90 kDbFile, kCorruptData.data(), kCorruptData.length())); |
| 91 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); |
| 92 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); |
| 93 |
| 94 // See that the sql::Connection opens, but fails to pass the integrity check. |
| 95 sql::Connection raw_db; |
| 96 std::vector<std::string> messages; |
| 97 EXPECT_TRUE(raw_db.Open(kDbFile)); |
| 98 EXPECT_FALSE(raw_db.QuickIntegrityCheck(&messages)); |
| 99 raw_db.Close(); |
| 100 |
| 101 // Should delete the corrupt data and start over. |
| 102 AppCacheDatabase db(kDbFile); |
| 103 EXPECT_TRUE(db.LazyOpen(true)); |
| 104 EXPECT_FALSE(base::PathExists(kOtherFile)); |
| 105 EXPECT_TRUE(base::PathExists(kDbFile)); |
| 106 db.CloseConnection(); |
| 107 |
| 108 // See that the Connection now passes its integrity check. |
| 109 EXPECT_TRUE(raw_db.Open(kDbFile)); |
| 110 EXPECT_TRUE(raw_db.QuickIntegrityCheck(&messages)); |
| 111 ASSERT_EQ(1u, messages.size()); |
| 112 EXPECT_EQ(std::string("ok"), messages[0]); |
| 113 } |
| 114 #endif // NDEBUG |
| 115 |
76 TEST(AppCacheDatabaseTest, ExperimentalFlags) { | 116 TEST(AppCacheDatabaseTest, ExperimentalFlags) { |
77 const char kExperimentFlagsKey[] = "ExperimentFlags"; | 117 const char kExperimentFlagsKey[] = "ExperimentFlags"; |
78 std::string kInjectedFlags("exp1,exp2"); | 118 std::string kInjectedFlags("exp1,exp2"); |
79 | 119 |
80 // Real files on disk for this test. | 120 // Real files on disk for this test. |
81 base::ScopedTempDir temp_dir; | 121 base::ScopedTempDir temp_dir; |
82 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 122 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
83 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); | 123 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); |
84 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); | 124 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); |
85 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); | 125 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); |
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); | 1167 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); |
1128 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); | 1168 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); |
1129 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); | 1169 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); |
1130 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); | 1170 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); |
1131 EXPECT_FALSE(whitelists[i].is_pattern); | 1171 EXPECT_FALSE(whitelists[i].is_pattern); |
1132 } | 1172 } |
1133 } | 1173 } |
1134 #endif // !APPCACHE_USE_SIMPLE_CACHE | 1174 #endif // !APPCACHE_USE_SIMPLE_CACHE |
1135 | 1175 |
1136 } // namespace appcache | 1176 } // namespace appcache |
OLD | NEW |