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

Side by Side Diff: content/browser/indexed_db/indexed_db_backing_store_unittest.cc

Issue 2773823002: Use a two-part data format version in IndexedDB metadata. (Closed)
Patch Set: jsbell, cmumford Created 3 years, 8 months 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
OLDNEW
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 "content/browser/indexed_db/indexed_db_backing_store.h" 5 #include "content/browser/indexed_db/indexed_db_backing_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 12 matching lines...) Expand all
23 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" 23 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
24 #include "content/browser/indexed_db/indexed_db_value.h" 24 #include "content/browser/indexed_db/indexed_db_value.h"
25 #include "content/browser/indexed_db/leveldb/leveldb_factory.h" 25 #include "content/browser/indexed_db/leveldb/leveldb_factory.h"
26 #include "content/browser/quota/mock_quota_manager_proxy.h" 26 #include "content/browser/quota/mock_quota_manager_proxy.h"
27 #include "content/public/test/mock_special_storage_policy.h" 27 #include "content/public/test/mock_special_storage_policy.h"
28 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "net/url_request/url_request_test_util.h" 29 #include "net/url_request/url_request_test_util.h"
30 #include "storage/browser/blob/blob_data_handle.h" 30 #include "storage/browser/blob/blob_data_handle.h"
31 #include "storage/browser/quota/special_storage_policy.h" 31 #include "storage/browser/quota/special_storage_policy.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
33 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" 34 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
34 35
35 using base::ASCIIToUTF16; 36 using base::ASCIIToUTF16;
36 using url::Origin; 37 using url::Origin;
37 38
38 namespace content { 39 namespace content {
39 40
40 namespace { 41 namespace {
41 static const size_t kDefaultMaxOpenIteratorsPerDatabase = 50; 42 static const size_t kDefaultMaxOpenIteratorsPerDatabase = 50;
42 43
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 private: 75 private:
75 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); 76 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory);
76 }; 77 };
77 78
78 class TestableIndexedDBBackingStore : public IndexedDBBackingStore { 79 class TestableIndexedDBBackingStore : public IndexedDBBackingStore {
79 public: 80 public:
80 static scoped_refptr<TestableIndexedDBBackingStore> Open( 81 static scoped_refptr<TestableIndexedDBBackingStore> Open(
81 IndexedDBFactory* indexed_db_factory, 82 IndexedDBFactory* indexed_db_factory,
82 const Origin& origin, 83 const Origin& origin,
83 const base::FilePath& path_base, 84 const base::FilePath& path_base,
85 const IndexedDBDataFormatVersion& data_format_version,
84 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 86 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
85 LevelDBFactory* leveldb_factory, 87 LevelDBFactory* leveldb_factory,
86 base::SequencedTaskRunner* task_runner, 88 base::SequencedTaskRunner* task_runner,
87 leveldb::Status* status) { 89 leveldb::Status* status) {
88 DCHECK(!path_base.empty()); 90 DCHECK(!path_base.empty());
89 91
90 std::unique_ptr<LevelDBComparator> comparator = 92 std::unique_ptr<LevelDBComparator> comparator =
91 base::MakeUnique<Comparator>(); 93 base::MakeUnique<Comparator>();
92 94
93 if (!base::CreateDirectory(path_base)) { 95 if (!base::CreateDirectory(path_base)) {
94 *status = leveldb::Status::IOError("Unable to create base dir"); 96 *status = leveldb::Status::IOError("Unable to create base dir");
95 return scoped_refptr<TestableIndexedDBBackingStore>(); 97 return scoped_refptr<TestableIndexedDBBackingStore>();
96 } 98 }
97 99
98 const base::FilePath file_path = path_base.AppendASCII("test_db_path"); 100 const base::FilePath file_path =
99 const base::FilePath blob_path = path_base.AppendASCII("test_blob_path"); 101 path_base.Append(IndexedDBContextImpl::GetLevelDBFileName(origin));
102 const base::FilePath blob_path =
103 path_base.Append(IndexedDBContextImpl::GetBlobStoreFileName(origin));
100 104
101 std::unique_ptr<LevelDBDatabase> db; 105 std::unique_ptr<LevelDBDatabase> db;
102 bool is_disk_full = false; 106 bool is_disk_full = false;
103 *status = leveldb_factory->OpenLevelDB( 107 *status = leveldb_factory->OpenLevelDB(
104 file_path, comparator.get(), &db, &is_disk_full); 108 file_path, comparator.get(), &db, &is_disk_full);
105 109
106 if (!db || !status->ok()) 110 if (!db || !status->ok())
107 return scoped_refptr<TestableIndexedDBBackingStore>(); 111 return scoped_refptr<TestableIndexedDBBackingStore>();
108 112
109 scoped_refptr<TestableIndexedDBBackingStore> backing_store( 113 scoped_refptr<TestableIndexedDBBackingStore> backing_store(
110 new TestableIndexedDBBackingStore(indexed_db_factory, origin, blob_path, 114 new TestableIndexedDBBackingStore(indexed_db_factory, origin, blob_path,
115 data_format_version,
111 request_context_getter, std::move(db), 116 request_context_getter, std::move(db),
112 std::move(comparator), task_runner)); 117 std::move(comparator), task_runner));
113 118
114 *status = backing_store->SetUpMetadata(); 119 *status = backing_store->SetUpMetadata();
115 if (!status->ok()) 120 if (!status->ok())
116 return scoped_refptr<TestableIndexedDBBackingStore>(); 121 return scoped_refptr<TestableIndexedDBBackingStore>();
117 122
118 return backing_store; 123 return backing_store;
119 } 124 }
120 125
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // Timers don't play nicely with unit tests. 167 // Timers don't play nicely with unit tests.
163 void StartJournalCleaningTimer() override { 168 void StartJournalCleaningTimer() override {
164 CleanPrimaryJournalIgnoreReturn(); 169 CleanPrimaryJournalIgnoreReturn();
165 } 170 }
166 171
167 private: 172 private:
168 TestableIndexedDBBackingStore( 173 TestableIndexedDBBackingStore(
169 IndexedDBFactory* indexed_db_factory, 174 IndexedDBFactory* indexed_db_factory,
170 const Origin& origin, 175 const Origin& origin,
171 const base::FilePath& blob_path, 176 const base::FilePath& blob_path,
177 const IndexedDBDataFormatVersion& data_format_version,
172 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 178 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
173 std::unique_ptr<LevelDBDatabase> db, 179 std::unique_ptr<LevelDBDatabase> db,
174 std::unique_ptr<LevelDBComparator> comparator, 180 std::unique_ptr<LevelDBComparator> comparator,
175 base::SequencedTaskRunner* task_runner) 181 base::SequencedTaskRunner* task_runner)
176 : IndexedDBBackingStore(indexed_db_factory, 182 : IndexedDBBackingStore(indexed_db_factory,
177 origin, 183 origin,
178 blob_path, 184 blob_path,
185 data_format_version,
179 request_context_getter, 186 request_context_getter,
180 std::move(db), 187 std::move(db),
181 std::move(comparator), 188 std::move(comparator),
182 task_runner), 189 task_runner),
183 database_id_(0) {} 190 database_id_(0) {}
184 191
185 int64_t database_id_; 192 int64_t database_id_;
186 std::vector<Transaction::WriteDescriptor> writes_; 193 std::vector<Transaction::WriteDescriptor> writes_;
187 194
188 // This is modified in an overridden virtual function that is properly const 195 // This is modified in an overridden virtual function that is properly const
189 // in the real implementation, therefore must be mutable here. 196 // in the real implementation, therefore must be mutable here.
190 mutable std::vector<int64_t> removals_; 197 mutable std::vector<int64_t> removals_;
191 198
192 DISALLOW_COPY_AND_ASSIGN(TestableIndexedDBBackingStore); 199 DISALLOW_COPY_AND_ASSIGN(TestableIndexedDBBackingStore);
193 }; 200 };
194 201
195 class TestIDBFactory : public IndexedDBFactoryImpl { 202 class TestIDBFactory : public IndexedDBFactoryImpl {
196 public: 203 public:
197 explicit TestIDBFactory(IndexedDBContextImpl* idb_context) 204 explicit TestIDBFactory(IndexedDBContextImpl* idb_context)
198 : IndexedDBFactoryImpl(idb_context) {} 205 : IndexedDBFactoryImpl(idb_context) {}
199 206
200 scoped_refptr<TestableIndexedDBBackingStore> OpenBackingStoreForTest( 207 scoped_refptr<TestableIndexedDBBackingStore> OpenBackingStoreForTest(
201 const Origin& origin, 208 const Origin& origin,
202 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) { 209 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
203 IndexedDBDataLossInfo data_loss_info; 210 IndexedDBDataLossInfo data_loss_info;
204 bool disk_full; 211 bool disk_full;
205 leveldb::Status status; 212 leveldb::Status status;
206 scoped_refptr<IndexedDBBackingStore> backing_store = OpenBackingStore( 213 scoped_refptr<IndexedDBBackingStore> backing_store = OpenBackingStore(
207 origin, context()->data_path(), url_request_context_getter, 214 origin, context()->data_path(), IndexedDBDataFormatVersion(),
208 &data_loss_info, &disk_full, &status); 215 url_request_context_getter, &data_loss_info, &disk_full, &status);
209 scoped_refptr<TestableIndexedDBBackingStore> testable_store = 216 scoped_refptr<TestableIndexedDBBackingStore> testable_store =
210 static_cast<TestableIndexedDBBackingStore*>(backing_store.get()); 217 static_cast<TestableIndexedDBBackingStore*>(backing_store.get());
211 return testable_store; 218 return testable_store;
212 } 219 }
213 220
214 protected: 221 protected:
215 ~TestIDBFactory() override {} 222 ~TestIDBFactory() override {}
216 223
217 scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( 224 scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
218 const Origin& origin, 225 const Origin& origin,
219 const base::FilePath& data_directory, 226 const base::FilePath& data_directory,
227 const IndexedDBDataFormatVersion& data_format_version,
220 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 228 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
221 IndexedDBDataLossInfo* data_loss_info, 229 IndexedDBDataLossInfo* data_loss_info,
222 bool* disk_full, 230 bool* disk_full,
223 bool first_time, 231 bool first_time,
224 leveldb::Status* status) override { 232 leveldb::Status* status) override {
225 DefaultLevelDBFactory leveldb_factory; 233 DefaultLevelDBFactory leveldb_factory;
226 return TestableIndexedDBBackingStore::Open( 234 return TestableIndexedDBBackingStore::Open(
227 this, origin, data_directory, request_context_getter, &leveldb_factory, 235 this, origin, data_directory, data_format_version,
228 context()->TaskRunner(), status); 236 request_context_getter, &leveldb_factory, context()->TaskRunner(),
237 status);
229 } 238 }
230 239
231 private: 240 private:
232 DISALLOW_COPY_AND_ASSIGN(TestIDBFactory); 241 DISALLOW_COPY_AND_ASSIGN(TestIDBFactory);
233 }; 242 };
234 243
235 class IndexedDBBackingStoreTest : public testing::Test { 244 class IndexedDBBackingStoreTest : public testing::Test {
236 public: 245 public:
237 IndexedDBBackingStoreTest() {} 246 IndexedDBBackingStoreTest() {}
238 void SetUp() override { 247 void SetUp() override {
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 1158
1150 // Dictionary, message key and more. 1159 // Dictionary, message key and more.
1151 ASSERT_TRUE(WriteFile(info_path, "{\"message\":\"foo\",\"bar\":5}")); 1160 ASSERT_TRUE(WriteFile(info_path, "{\"message\":\"foo\",\"bar\":5}"));
1152 EXPECT_TRUE( 1161 EXPECT_TRUE(
1153 IndexedDBBackingStore::ReadCorruptionInfo(path_base, origin, &message)); 1162 IndexedDBBackingStore::ReadCorruptionInfo(path_base, origin, &message));
1154 EXPECT_FALSE(PathExists(info_path)); 1163 EXPECT_FALSE(PathExists(info_path));
1155 EXPECT_EQ("foo", message); 1164 EXPECT_EQ("foo", message);
1156 } 1165 }
1157 1166
1158 } // namespace content 1167 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698