| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <cerrno> | 5 #include <cerrno> |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 using content::LevelDBSnapshot; | 22 using content::LevelDBSnapshot; |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class TaskRunner; | 25 class TaskRunner; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class IndexedDBFactory; | 29 class IndexedDBFactory; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace net { |
| 33 class URLRequestContext; |
| 34 } |
| 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 class BustedLevelDBDatabase : public LevelDBDatabase { | 38 class BustedLevelDBDatabase : public LevelDBDatabase { |
| 35 public: | 39 public: |
| 36 static scoped_ptr<LevelDBDatabase> Open( | 40 static scoped_ptr<LevelDBDatabase> Open( |
| 37 const base::FilePath& file_name, | 41 const base::FilePath& file_name, |
| 38 const LevelDBComparator* /*comparator*/) { | 42 const LevelDBComparator* /*comparator*/) { |
| 39 return scoped_ptr<LevelDBDatabase>(new BustedLevelDBDatabase); | 43 return scoped_ptr<LevelDBDatabase>(new BustedLevelDBDatabase); |
| 40 } | 44 } |
| 41 virtual leveldb::Status Get(const base::StringPiece& key, | 45 virtual leveldb::Status Get(const base::StringPiece& key, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 68 private: | 72 private: |
| 69 bool destroy_called_; | 73 bool destroy_called_; |
| 70 }; | 74 }; |
| 71 | 75 |
| 72 TEST(IndexedDBIOErrorTest, CleanUpTest) { | 76 TEST(IndexedDBIOErrorTest, CleanUpTest) { |
| 73 content::IndexedDBFactory* factory = NULL; | 77 content::IndexedDBFactory* factory = NULL; |
| 74 const GURL origin("http://localhost:81"); | 78 const GURL origin("http://localhost:81"); |
| 75 base::ScopedTempDir temp_directory; | 79 base::ScopedTempDir temp_directory; |
| 76 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 80 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 77 const base::FilePath path = temp_directory.path(); | 81 const base::FilePath path = temp_directory.path(); |
| 82 net::URLRequestContext* request_context = NULL; |
| 78 MockLevelDBFactory mock_leveldb_factory; | 83 MockLevelDBFactory mock_leveldb_factory; |
| 79 blink::WebIDBDataLoss data_loss = | 84 blink::WebIDBDataLoss data_loss = |
| 80 blink::WebIDBDataLossNone; | 85 blink::WebIDBDataLossNone; |
| 81 std::string data_loss_message; | 86 std::string data_loss_message; |
| 82 bool disk_full = false; | 87 bool disk_full = false; |
| 83 base::TaskRunner* task_runner = NULL; | 88 base::TaskRunner* task_runner = NULL; |
| 84 scoped_refptr<IndexedDBBackingStore> backing_store = | 89 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 85 IndexedDBBackingStore::Open(factory, | 90 IndexedDBBackingStore::Open(factory, |
| 86 origin, | 91 origin, |
| 87 path, | 92 path, |
| 93 request_context, |
| 88 &data_loss, | 94 &data_loss, |
| 89 &data_loss_message, | 95 &data_loss_message, |
| 90 &disk_full, | 96 &disk_full, |
| 91 &mock_leveldb_factory, | 97 &mock_leveldb_factory, |
| 92 task_runner); | 98 task_runner); |
| 93 } | 99 } |
| 94 | 100 |
| 95 // TODO(dgrogan): Remove expect_destroy if we end up not using it again. It is | 101 // TODO(dgrogan): Remove expect_destroy if we end up not using it again. It is |
| 96 // currently set to false in all 4 calls below. | 102 // currently set to false in all 4 calls below. |
| 97 template <class T> | 103 template <class T> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 121 | 127 |
| 122 private: | 128 private: |
| 123 T error_; | 129 T error_; |
| 124 bool expect_destroy_; | 130 bool expect_destroy_; |
| 125 bool destroy_called_; | 131 bool destroy_called_; |
| 126 }; | 132 }; |
| 127 | 133 |
| 128 TEST(IndexedDBNonRecoverableIOErrorTest, NuancedCleanupTest) { | 134 TEST(IndexedDBNonRecoverableIOErrorTest, NuancedCleanupTest) { |
| 129 content::IndexedDBFactory* factory = NULL; | 135 content::IndexedDBFactory* factory = NULL; |
| 130 const GURL origin("http://localhost:81"); | 136 const GURL origin("http://localhost:81"); |
| 137 net::URLRequestContext* request_context = NULL; |
| 131 base::ScopedTempDir temp_directory; | 138 base::ScopedTempDir temp_directory; |
| 132 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 139 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 133 const base::FilePath path = temp_directory.path(); | 140 const base::FilePath path = temp_directory.path(); |
| 134 blink::WebIDBDataLoss data_loss = | 141 blink::WebIDBDataLoss data_loss = |
| 135 blink::WebIDBDataLossNone; | 142 blink::WebIDBDataLossNone; |
| 136 std::string data_loss_reason; | 143 std::string data_loss_reason; |
| 137 bool disk_full = false; | 144 bool disk_full = false; |
| 138 base::TaskRunner* task_runner = NULL; | 145 base::TaskRunner* task_runner = NULL; |
| 139 | 146 |
| 140 MockErrorLevelDBFactory<int> mock_leveldb_factory(ENOSPC, false); | 147 MockErrorLevelDBFactory<int> mock_leveldb_factory(ENOSPC, false); |
| 141 scoped_refptr<IndexedDBBackingStore> backing_store = | 148 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 142 IndexedDBBackingStore::Open(factory, | 149 IndexedDBBackingStore::Open(factory, |
| 143 origin, | 150 origin, |
| 144 path, | 151 path, |
| 152 request_context, |
| 145 &data_loss, | 153 &data_loss, |
| 146 &data_loss_reason, | 154 &data_loss_reason, |
| 147 &disk_full, | 155 &disk_full, |
| 148 &mock_leveldb_factory, | 156 &mock_leveldb_factory, |
| 149 task_runner); | 157 task_runner); |
| 150 | 158 |
| 151 MockErrorLevelDBFactory<base::File::Error> mock_leveldb_factory2( | 159 MockErrorLevelDBFactory<base::File::Error> mock_leveldb_factory2( |
| 152 base::File::FILE_ERROR_NO_MEMORY, false); | 160 base::File::FILE_ERROR_NO_MEMORY, false); |
| 153 scoped_refptr<IndexedDBBackingStore> backing_store2 = | 161 scoped_refptr<IndexedDBBackingStore> backing_store2 = |
| 154 IndexedDBBackingStore::Open(factory, | 162 IndexedDBBackingStore::Open(factory, |
| 155 origin, | 163 origin, |
| 156 path, | 164 path, |
| 165 request_context, |
| 157 &data_loss, | 166 &data_loss, |
| 158 &data_loss_reason, | 167 &data_loss_reason, |
| 159 &disk_full, | 168 &disk_full, |
| 160 &mock_leveldb_factory2, | 169 &mock_leveldb_factory2, |
| 161 task_runner); | 170 task_runner); |
| 162 | 171 |
| 163 MockErrorLevelDBFactory<int> mock_leveldb_factory3(EIO, false); | 172 MockErrorLevelDBFactory<int> mock_leveldb_factory3(EIO, false); |
| 164 scoped_refptr<IndexedDBBackingStore> backing_store3 = | 173 scoped_refptr<IndexedDBBackingStore> backing_store3 = |
| 165 IndexedDBBackingStore::Open(factory, | 174 IndexedDBBackingStore::Open(factory, |
| 166 origin, | 175 origin, |
| 167 path, | 176 path, |
| 177 request_context, |
| 168 &data_loss, | 178 &data_loss, |
| 169 &data_loss_reason, | 179 &data_loss_reason, |
| 170 &disk_full, | 180 &disk_full, |
| 171 &mock_leveldb_factory3, | 181 &mock_leveldb_factory3, |
| 172 task_runner); | 182 task_runner); |
| 173 | 183 |
| 174 MockErrorLevelDBFactory<base::File::Error> mock_leveldb_factory4( | 184 MockErrorLevelDBFactory<base::File::Error> mock_leveldb_factory4( |
| 175 base::File::FILE_ERROR_FAILED, false); | 185 base::File::FILE_ERROR_FAILED, false); |
| 176 scoped_refptr<IndexedDBBackingStore> backing_store4 = | 186 scoped_refptr<IndexedDBBackingStore> backing_store4 = |
| 177 IndexedDBBackingStore::Open(factory, | 187 IndexedDBBackingStore::Open(factory, |
| 178 origin, | 188 origin, |
| 179 path, | 189 path, |
| 190 request_context, |
| 180 &data_loss, | 191 &data_loss, |
| 181 &data_loss_reason, | 192 &data_loss_reason, |
| 182 &disk_full, | 193 &disk_full, |
| 183 &mock_leveldb_factory4, | 194 &mock_leveldb_factory4, |
| 184 task_runner); | 195 task_runner); |
| 185 } | 196 } |
| 186 | 197 |
| 187 } // namespace | 198 } // namespace |
| OLD | NEW |