Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: webkit/browser/appcache/appcache_database_unittest.cc

Issue 104593010: AppCache: Run a quick integrity check on the sqlite database when opening. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 base::FilePath mock_dir = temp_dir.path().AppendASCII("mock");
87 ASSERT_TRUE(base::CreateDirectory(mock_dir));
Scott Hess - ex-Googler 2013/12/13 23:15:46 Yeah, that's what I meant.
88
89 const base::FilePath kDbFile = mock_dir.AppendASCII("appcache.db");
90 const std::string kCorruptData("deadbeef");
91 EXPECT_EQ(static_cast<int>(kCorruptData.length()),
92 file_util::WriteFile(
93 kDbFile, kCorruptData.data(), kCorruptData.length()));
94 const base::FilePath kOtherFile = mock_dir.AppendASCII("other_file");
95 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3));
96
97 // See that the sql::Connection opens, but fails to pass the integrity check.
98 sql::Connection raw_db;
99 EXPECT_TRUE(raw_db.Open(kDbFile));
100 EXPECT_FALSE(raw_db.QuickIntegrityCheck());
101 raw_db.Close();
102
103 // Should delete the corrupt data and start over.
104 AppCacheDatabase db(kDbFile);
105 EXPECT_TRUE(db.LazyOpen(true));
106 EXPECT_FALSE(base::PathExists(kOtherFile));
107 EXPECT_TRUE(base::PathExists(kDbFile));
108 db.CloseConnection();
109
110 // See that the Connection now passes its integrity check.
111 EXPECT_TRUE(raw_db.Open(kDbFile));
112 EXPECT_TRUE(raw_db.QuickIntegrityCheck());
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
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
OLDNEW
« sql/connection_unittest.cc ('K') | « webkit/browser/appcache/appcache_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698