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" |
11 #include "sql/statement.h" | 11 #include "sql/statement.h" |
12 #include "sql/test/scoped_error_ignorer.h" | 12 #include "sql/test/scoped_error_ignorer.h" |
| 13 #include "sql/test/test_helpers.h" |
13 #include "sql/transaction.h" | 14 #include "sql/transaction.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/sqlite/sqlite3.h" | 16 #include "third_party/sqlite/sqlite3.h" |
16 #include "webkit/browser/appcache/appcache_database.h" | 17 #include "webkit/browser/appcache/appcache_database.h" |
17 #include "webkit/browser/appcache/appcache_entry.h" | 18 #include "webkit/browser/appcache/appcache_entry.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const base::Time kZeroTime; | 22 const base::Time kZeroTime; |
22 | 23 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 EXPECT_TRUE(base::DirectoryExists(kNestedDir)); | 67 EXPECT_TRUE(base::DirectoryExists(kNestedDir)); |
67 EXPECT_TRUE(base::PathExists(kOtherFile)); | 68 EXPECT_TRUE(base::PathExists(kOtherFile)); |
68 | 69 |
69 EXPECT_TRUE(db.DeleteExistingAndCreateNewDatabase()); | 70 EXPECT_TRUE(db.DeleteExistingAndCreateNewDatabase()); |
70 | 71 |
71 EXPECT_TRUE(base::PathExists(kDbFile)); | 72 EXPECT_TRUE(base::PathExists(kDbFile)); |
72 EXPECT_FALSE(base::DirectoryExists(kNestedDir)); | 73 EXPECT_FALSE(base::DirectoryExists(kNestedDir)); |
73 EXPECT_FALSE(base::PathExists(kOtherFile)); | 74 EXPECT_FALSE(base::PathExists(kOtherFile)); |
74 } | 75 } |
75 | 76 |
| 77 #ifdef NDEBUG |
| 78 // Only run in release builds because sql::Connection and familiy |
| 79 // crank up DLOG(FATAL)'ness and this test presents it with |
| 80 // intentionally bad data which causes debug builds to exit instead |
| 81 // of run to completion. In release builds, errors the are delivered |
| 82 // to the consumer so we can test the error handling of the consumer. |
| 83 // TODO: crbug/328576 |
| 84 TEST(AppCacheDatabaseTest, QuickIntegrityCheck) { |
| 85 // Real files on disk for this test too, a corrupt database file. |
| 86 base::ScopedTempDir temp_dir; |
| 87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 88 base::FilePath mock_dir = temp_dir.path().AppendASCII("mock"); |
| 89 ASSERT_TRUE(base::CreateDirectory(mock_dir)); |
| 90 |
| 91 const base::FilePath kDbFile = mock_dir.AppendASCII("appcache.db"); |
| 92 const base::FilePath kOtherFile = mock_dir.AppendASCII("other_file"); |
| 93 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); |
| 94 |
| 95 // First create a valid db file. |
| 96 AppCacheDatabase db(kDbFile); |
| 97 EXPECT_TRUE(db.LazyOpen(true)); |
| 98 EXPECT_TRUE(base::PathExists(kOtherFile)); |
| 99 EXPECT_TRUE(base::PathExists(kDbFile)); |
| 100 db.CloseConnection(); |
| 101 |
| 102 // Break it. |
| 103 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); |
| 104 |
| 105 // Reopening will notice the corruption and delete/recreate the directory. |
| 106 { |
| 107 sql::ScopedErrorIgnorer ignore_errors; |
| 108 ignore_errors.IgnoreError(SQLITE_CORRUPT); |
| 109 EXPECT_TRUE(db.LazyOpen(true)); |
| 110 EXPECT_FALSE(base::PathExists(kOtherFile)); |
| 111 EXPECT_TRUE(base::PathExists(kDbFile)); |
| 112 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); |
| 113 } |
| 114 } |
| 115 #endif // NDEBUG |
| 116 |
76 TEST(AppCacheDatabaseTest, ExperimentalFlags) { | 117 TEST(AppCacheDatabaseTest, ExperimentalFlags) { |
77 const char kExperimentFlagsKey[] = "ExperimentFlags"; | 118 const char kExperimentFlagsKey[] = "ExperimentFlags"; |
78 std::string kInjectedFlags("exp1,exp2"); | 119 std::string kInjectedFlags("exp1,exp2"); |
79 | 120 |
80 // Real files on disk for this test. | 121 // Real files on disk for this test. |
81 base::ScopedTempDir temp_dir; | 122 base::ScopedTempDir temp_dir; |
82 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 123 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
83 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); | 124 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); |
84 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); | 125 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); |
85 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); | 126 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); | 1168 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); |
1128 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); | 1169 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); |
1129 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); | 1170 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); |
1130 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); | 1171 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); |
1131 EXPECT_FALSE(whitelists[i].is_pattern); | 1172 EXPECT_FALSE(whitelists[i].is_pattern); |
1132 } | 1173 } |
1133 } | 1174 } |
1134 #endif // !APPCACHE_USE_SIMPLE_CACHE | 1175 #endif // !APPCACHE_USE_SIMPLE_CACHE |
1135 | 1176 |
1136 } // namespace appcache | 1177 } // namespace appcache |
OLD | NEW |