| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 102   // Break it. | 102   // Break it. | 
| 103   ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); | 103   ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); | 
| 104 | 104 | 
| 105   // Reopening will notice the corruption and delete/recreate the directory. | 105   // Reopening will notice the corruption and delete/recreate the directory. | 
| 106   { | 106   { | 
| 107     sql::ScopedErrorIgnorer ignore_errors; | 107     sql::ScopedErrorIgnorer ignore_errors; | 
| 108     ignore_errors.IgnoreError(SQLITE_CORRUPT); | 108     ignore_errors.IgnoreError(SQLITE_CORRUPT); | 
| 109     EXPECT_TRUE(db.LazyOpen(true)); | 109     EXPECT_TRUE(db.LazyOpen(true)); | 
| 110     EXPECT_FALSE(base::PathExists(kOtherFile)); | 110     EXPECT_FALSE(base::PathExists(kOtherFile)); | 
| 111     EXPECT_TRUE(base::PathExists(kDbFile)); | 111     EXPECT_TRUE(base::PathExists(kDbFile)); | 
| 112     ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); | 112     EXPECT_TRUE(ignore_errors.CheckIgnoredErrors()); | 
| 113   } | 113   } | 
| 114 } | 114 } | 
| 115 #endif  // NDEBUG | 115 #endif  // NDEBUG | 
| 116 | 116 | 
|  | 117 TEST(AppCacheDatabaseTest, WasCorrutionDetected) { | 
|  | 118   // Real files on disk for this test too, a corrupt database file. | 
|  | 119   base::ScopedTempDir temp_dir; | 
|  | 120   ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 
|  | 121   const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); | 
|  | 122 | 
|  | 123   // First create a valid db file. | 
|  | 124   AppCacheDatabase db(kDbFile); | 
|  | 125   EXPECT_TRUE(db.LazyOpen(true)); | 
|  | 126   EXPECT_TRUE(base::PathExists(kDbFile)); | 
|  | 127   EXPECT_FALSE(db.was_corruption_detected()); | 
|  | 128 | 
|  | 129   // Break it. | 
|  | 130   ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); | 
|  | 131 | 
|  | 132   // See the the corruption is detected and reported. | 
|  | 133   { | 
|  | 134     sql::ScopedErrorIgnorer ignore_errors; | 
|  | 135     ignore_errors.IgnoreError(SQLITE_CORRUPT); | 
|  | 136     std::map<GURL, int64> usage_map; | 
|  | 137     EXPECT_FALSE(db.GetAllOriginUsage(&usage_map)); | 
|  | 138     EXPECT_TRUE(db.was_corruption_detected()); | 
|  | 139     EXPECT_TRUE(base::PathExists(kDbFile)); | 
|  | 140     EXPECT_TRUE(ignore_errors.CheckIgnoredErrors()); | 
|  | 141   } | 
|  | 142 } | 
|  | 143 | 
| 117 TEST(AppCacheDatabaseTest, ExperimentalFlags) { | 144 TEST(AppCacheDatabaseTest, ExperimentalFlags) { | 
| 118   const char kExperimentFlagsKey[] = "ExperimentFlags"; | 145   const char kExperimentFlagsKey[] = "ExperimentFlags"; | 
| 119   std::string kInjectedFlags("exp1,exp2"); | 146   std::string kInjectedFlags("exp1,exp2"); | 
| 120 | 147 | 
| 121   // Real files on disk for this test. | 148   // Real files on disk for this test. | 
| 122   base::ScopedTempDir temp_dir; | 149   base::ScopedTempDir temp_dir; | 
| 123   ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 150   ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 
| 124   const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); | 151   const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); | 
| 125   const base::FilePath kOtherFile =  temp_dir.path().AppendASCII("other_file"); | 152   const base::FilePath kOtherFile =  temp_dir.path().AppendASCII("other_file"); | 
| 126   EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); | 153   EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); | 
| (...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1168     EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); | 1195     EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); | 
| 1169     EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); | 1196     EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); | 
| 1170     EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); | 1197     EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); | 
| 1171     EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); | 1198     EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); | 
| 1172     EXPECT_FALSE(whitelists[i].is_pattern); | 1199     EXPECT_FALSE(whitelists[i].is_pattern); | 
| 1173   } | 1200   } | 
| 1174 } | 1201 } | 
| 1175 #endif  // !APPCACHE_USE_SIMPLE_CACHE | 1202 #endif  // !APPCACHE_USE_SIMPLE_CACHE | 
| 1176 | 1203 | 
| 1177 }  // namespace appcache | 1204 }  // namespace appcache | 
| OLD | NEW | 
|---|