| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST(AppCacheDatabaseTest, ReCreate) { | 52 TEST(AppCacheDatabaseTest, ReCreate) { |
| 53 // Real files on disk for this test. | 53 // Real files on disk for this test. |
| 54 base::ScopedTempDir temp_dir; | 54 base::ScopedTempDir temp_dir; |
| 55 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 55 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 56 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); | 56 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); |
| 57 const base::FilePath kNestedDir = temp_dir.path().AppendASCII("nested"); | 57 const base::FilePath kNestedDir = temp_dir.path().AppendASCII("nested"); |
| 58 const base::FilePath kOtherFile = kNestedDir.AppendASCII("other_file"); | 58 const base::FilePath kOtherFile = kNestedDir.AppendASCII("other_file"); |
| 59 EXPECT_TRUE(base::CreateDirectory(kNestedDir)); | 59 EXPECT_TRUE(base::CreateDirectory(kNestedDir)); |
| 60 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); | 60 EXPECT_EQ(3, base::WriteFile(kOtherFile, "foo", 3)); |
| 61 | 61 |
| 62 AppCacheDatabase db(kDbFile); | 62 AppCacheDatabase db(kDbFile); |
| 63 EXPECT_FALSE(db.LazyOpen(false)); | 63 EXPECT_FALSE(db.LazyOpen(false)); |
| 64 EXPECT_TRUE(db.LazyOpen(true)); | 64 EXPECT_TRUE(db.LazyOpen(true)); |
| 65 | 65 |
| 66 EXPECT_TRUE(base::PathExists(kDbFile)); | 66 EXPECT_TRUE(base::PathExists(kDbFile)); |
| 67 EXPECT_TRUE(base::DirectoryExists(kNestedDir)); | 67 EXPECT_TRUE(base::DirectoryExists(kNestedDir)); |
| 68 EXPECT_TRUE(base::PathExists(kOtherFile)); | 68 EXPECT_TRUE(base::PathExists(kOtherFile)); |
| 69 | 69 |
| 70 EXPECT_TRUE(db.DeleteExistingAndCreateNewDatabase()); | 70 EXPECT_TRUE(db.DeleteExistingAndCreateNewDatabase()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 // TODO: crbug/328576 | 83 // TODO: crbug/328576 |
| 84 TEST(AppCacheDatabaseTest, QuickIntegrityCheck) { | 84 TEST(AppCacheDatabaseTest, QuickIntegrityCheck) { |
| 85 // Real files on disk for this test too, a corrupt database file. | 85 // Real files on disk for this test too, a corrupt database file. |
| 86 base::ScopedTempDir temp_dir; | 86 base::ScopedTempDir temp_dir; |
| 87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 88 base::FilePath mock_dir = temp_dir.path().AppendASCII("mock"); | 88 base::FilePath mock_dir = temp_dir.path().AppendASCII("mock"); |
| 89 ASSERT_TRUE(base::CreateDirectory(mock_dir)); | 89 ASSERT_TRUE(base::CreateDirectory(mock_dir)); |
| 90 | 90 |
| 91 const base::FilePath kDbFile = mock_dir.AppendASCII("appcache.db"); | 91 const base::FilePath kDbFile = mock_dir.AppendASCII("appcache.db"); |
| 92 const base::FilePath kOtherFile = mock_dir.AppendASCII("other_file"); | 92 const base::FilePath kOtherFile = mock_dir.AppendASCII("other_file"); |
| 93 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); | 93 EXPECT_EQ(3, base::WriteFile(kOtherFile, "foo", 3)); |
| 94 | 94 |
| 95 // First create a valid db file. | 95 // First create a valid db file. |
| 96 AppCacheDatabase db(kDbFile); | 96 AppCacheDatabase db(kDbFile); |
| 97 EXPECT_TRUE(db.LazyOpen(true)); | 97 EXPECT_TRUE(db.LazyOpen(true)); |
| 98 EXPECT_TRUE(base::PathExists(kOtherFile)); | 98 EXPECT_TRUE(base::PathExists(kOtherFile)); |
| 99 EXPECT_TRUE(base::PathExists(kDbFile)); | 99 EXPECT_TRUE(base::PathExists(kDbFile)); |
| 100 db.CloseConnection(); | 100 db.CloseConnection(); |
| 101 | 101 |
| 102 // Break it. | 102 // Break it. |
| 103 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); | 103 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 TEST(AppCacheDatabaseTest, ExperimentalFlags) { | 144 TEST(AppCacheDatabaseTest, ExperimentalFlags) { |
| 145 const char kExperimentFlagsKey[] = "ExperimentFlags"; | 145 const char kExperimentFlagsKey[] = "ExperimentFlags"; |
| 146 std::string kInjectedFlags("exp1,exp2"); | 146 std::string kInjectedFlags("exp1,exp2"); |
| 147 | 147 |
| 148 // Real files on disk for this test. | 148 // Real files on disk for this test. |
| 149 base::ScopedTempDir temp_dir; | 149 base::ScopedTempDir temp_dir; |
| 150 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 150 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 151 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); | 151 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); |
| 152 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); | 152 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); |
| 153 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); | 153 EXPECT_EQ(3, base::WriteFile(kOtherFile, "foo", 3)); |
| 154 EXPECT_TRUE(base::PathExists(kOtherFile)); | 154 EXPECT_TRUE(base::PathExists(kOtherFile)); |
| 155 | 155 |
| 156 AppCacheDatabase db(kDbFile); | 156 AppCacheDatabase db(kDbFile); |
| 157 EXPECT_TRUE(db.LazyOpen(true)); | 157 EXPECT_TRUE(db.LazyOpen(true)); |
| 158 | 158 |
| 159 // Inject a non empty flags value, and verify it got there. | 159 // Inject a non empty flags value, and verify it got there. |
| 160 EXPECT_TRUE(db.meta_table_->SetValue(kExperimentFlagsKey, kInjectedFlags)); | 160 EXPECT_TRUE(db.meta_table_->SetValue(kExperimentFlagsKey, kInjectedFlags)); |
| 161 std::string flags; | 161 std::string flags; |
| 162 EXPECT_TRUE(db.meta_table_->GetValue(kExperimentFlagsKey, &flags)); | 162 EXPECT_TRUE(db.meta_table_->GetValue(kExperimentFlagsKey, &flags)); |
| 163 EXPECT_EQ(kInjectedFlags, flags); | 163 EXPECT_EQ(kInjectedFlags, flags); |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); | 1195 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); |
| 1196 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); | 1196 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); |
| 1197 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); | 1197 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); |
| 1198 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); | 1198 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); |
| 1199 EXPECT_FALSE(whitelists[i].is_pattern); | 1199 EXPECT_FALSE(whitelists[i].is_pattern); |
| 1200 } | 1200 } |
| 1201 } | 1201 } |
| 1202 #endif // !APPCACHE_USE_SIMPLE_CACHE | 1202 #endif // !APPCACHE_USE_SIMPLE_CACHE |
| 1203 | 1203 |
| 1204 } // namespace appcache | 1204 } // namespace appcache |
| OLD | NEW |