Chromium Code Reviews| 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. | |
|
Scott Hess - ex-Googler
2013/12/13 20:03:45
Does sql::ScopedErrorIgnorer not handle this? The
michaeln
2013/12/13 22:46:05
It does not, other DLOG(FATAL)'s get hit given the
Scott Hess - ex-Googler
2013/12/13 23:15:46
I think CorruptSizeInHeader() will let it get thro
michaeln
2013/12/13 23:57:01
The test is modifed to use that helper, but... it
| |
| 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 EXPECT_TRUE(raw_db.Open(kDbFile)); | |
| 97 EXPECT_FALSE(raw_db.QuickIntegrityCheck()); | |
| 98 raw_db.Close(); | |
| 99 | |
| 100 // Should delete the corrupt data and start over. | |
| 101 AppCacheDatabase db(kDbFile); | |
| 102 EXPECT_TRUE(db.LazyOpen(true)); | |
| 103 EXPECT_FALSE(base::PathExists(kOtherFile)); | |
| 104 EXPECT_TRUE(base::PathExists(kDbFile)); | |
|
Scott Hess - ex-Googler
2013/12/13 20:03:45
If I understand things correctly, the AppCacheData
michaeln
2013/12/13 22:46:05
Done.
| |
| 105 db.CloseConnection(); | |
| 106 | |
| 107 // See that the Connection now passes its integrity check. | |
| 108 EXPECT_TRUE(raw_db.Open(kDbFile)); | |
| 109 EXPECT_TRUE(raw_db.QuickIntegrityCheck()); | |
| 110 } | |
| 111 #endif // NDEBUG | |
| 112 | |
| 76 TEST(AppCacheDatabaseTest, ExperimentalFlags) { | 113 TEST(AppCacheDatabaseTest, ExperimentalFlags) { |
| 77 const char kExperimentFlagsKey[] = "ExperimentFlags"; | 114 const char kExperimentFlagsKey[] = "ExperimentFlags"; |
| 78 std::string kInjectedFlags("exp1,exp2"); | 115 std::string kInjectedFlags("exp1,exp2"); |
| 79 | 116 |
| 80 // Real files on disk for this test. | 117 // Real files on disk for this test. |
| 81 base::ScopedTempDir temp_dir; | 118 base::ScopedTempDir temp_dir; |
| 82 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 119 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 83 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); | 120 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); |
| 84 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); | 121 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); |
| 85 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); | 122 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); | 1164 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); |
| 1128 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); | 1165 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); |
| 1129 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); | 1166 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); |
| 1130 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); | 1167 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); |
| 1131 EXPECT_FALSE(whitelists[i].is_pattern); | 1168 EXPECT_FALSE(whitelists[i].is_pattern); |
| 1132 } | 1169 } |
| 1133 } | 1170 } |
| 1134 #endif // !APPCACHE_USE_SIMPLE_CACHE | 1171 #endif // !APPCACHE_USE_SIMPLE_CACHE |
| 1135 | 1172 |
| 1136 } // namespace appcache | 1173 } // namespace appcache |
| OLD | NEW |