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 "content/browser/indexed_db/indexed_db_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
6 | 6 |
7 #include "base/callback.h" | |
8 #include "base/file_util.h" | |
9 #include "base/files/scoped_temp_dir.h" | |
7 #include "base/logging.h" | 10 #include "base/logging.h" |
8 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/task_runner.h" | |
14 #include "base/test/test_simple_task_runner.h" | |
15 #include "content/browser/indexed_db/indexed_db_context_impl.h" | |
10 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 16 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
11 #include "content/browser/indexed_db/indexed_db_value.h" | 17 #include "content/browser/indexed_db/indexed_db_value.h" |
18 #include "content/public/test/mock_special_storage_policy.h" | |
19 #include "net/url_request/url_request_test_util.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/WebKit/public/platform/WebIDBTypes.h" | 21 #include "third_party/WebKit/public/platform/WebIDBTypes.h" |
22 #include "webkit/browser/blob/blob_data_handle.h" | |
23 #include "webkit/browser/quota/special_storage_policy.h" | |
14 | 24 |
15 using base::ASCIIToUTF16; | 25 using base::ASCIIToUTF16; |
16 | 26 |
17 namespace content { | 27 namespace content { |
18 | 28 |
19 namespace { | 29 namespace { |
20 | 30 |
31 class Comparator : public LevelDBComparator { | |
32 public: | |
33 virtual int Compare(const base::StringPiece& a, | |
34 const base::StringPiece& b) const OVERRIDE { | |
35 return content::Compare(a, b, false /*index_keys*/); | |
36 } | |
37 virtual const char* Name() const OVERRIDE { return "idb_cmp1"; } | |
38 }; | |
39 | |
40 class DefaultLevelDBFactory : public LevelDBFactory { | |
41 public: | |
42 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, | |
43 const LevelDBComparator* comparator, | |
44 scoped_ptr<LevelDBDatabase>* db, | |
45 bool* is_disk_full) OVERRIDE { | |
46 return LevelDBDatabase::Open(file_name, comparator, db, is_disk_full); | |
47 } | |
48 virtual leveldb::Status DestroyLevelDB( | |
49 const base::FilePath& file_name) OVERRIDE { | |
50 return LevelDBDatabase::Destroy(file_name); | |
51 } | |
52 }; | |
53 | |
54 class TestableIndexedDBBackingStore : public IndexedDBBackingStore { | |
55 public: | |
56 static scoped_refptr<TestableIndexedDBBackingStore> Open( | |
57 IndexedDBFactory* indexed_db_factory, | |
58 const GURL& origin_url, | |
59 const base::FilePath& path_base, | |
60 net::URLRequestContext* request_context, | |
61 LevelDBFactory* leveldb_factory, | |
62 base::TaskRunner* task_runner) { | |
63 DCHECK(!path_base.empty()); | |
64 | |
65 scoped_ptr<LevelDBComparator> comparator(new Comparator()); | |
66 | |
67 if (!base::CreateDirectory(path_base)) | |
68 return scoped_refptr<TestableIndexedDBBackingStore>(); | |
69 | |
70 const base::FilePath file_path = path_base.Append("test_db_path"); | |
71 const base::FilePath blob_path = path_base.Append("test_blob_path"); | |
72 | |
73 scoped_ptr<LevelDBDatabase> db; | |
74 bool is_disk_full = false; | |
75 leveldb::Status status = leveldb_factory->OpenLevelDB( | |
76 file_path, comparator.get(), &db, &is_disk_full); | |
77 | |
78 if (!db || !status.ok()) | |
79 return scoped_refptr<TestableIndexedDBBackingStore>(); | |
80 | |
81 scoped_refptr<TestableIndexedDBBackingStore> backing_store( | |
82 new TestableIndexedDBBackingStore(indexed_db_factory, | |
83 origin_url, | |
84 blob_path, | |
85 request_context, | |
86 db.Pass(), | |
87 comparator.Pass(), | |
88 task_runner)); | |
89 | |
90 if (!backing_store->SetUpMetadata()) | |
91 return scoped_refptr<TestableIndexedDBBackingStore>(); | |
92 | |
93 return backing_store; | |
94 } | |
95 | |
96 const std::vector<IndexedDBBackingStore::Transaction::WriteDescriptor>& | |
97 writes() const { | |
98 return writes_; | |
99 } | |
100 const std::vector<int64> removals() const { return removals_; } | |
101 | |
102 protected: | |
103 bool WriteBlobFile( | |
104 int64 database_id, | |
105 const Transaction::WriteDescriptor& descriptor, | |
106 Transaction::ChainedBlobWriter* chained_blob_writer) OVERRIDE { | |
107 if (KeyPrefix::IsValidDatabaseId(database_id_)) { | |
108 if (database_id_ != database_id) { | |
109 return false; | |
110 } | |
111 } else { | |
112 database_id_ = database_id; | |
113 } | |
114 writes_.push_back(descriptor); | |
115 task_runner()->PostTask( | |
116 FROM_HERE, | |
117 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, | |
118 chained_blob_writer, | |
119 true, | |
120 1)); | |
121 return true; | |
122 } | |
123 | |
124 bool RemoveBlobFile(int64 database_id, int64 key) OVERRIDE { | |
125 if (database_id_ != database_id || | |
126 !KeyPrefix::IsValidDatabaseId(database_id)) { | |
127 return false; | |
128 } | |
129 removals_.push_back(key); | |
130 return true; | |
131 } | |
132 | |
133 // Timers don't play nicely with unit tests. | |
134 void StartJournalCleaningTimer() OVERRIDE { | |
135 CleanPrimaryJournalIgnoreReturn(); | |
136 } | |
137 | |
138 private: | |
139 TestableIndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, | |
140 const GURL& origin_url, | |
141 const base::FilePath& blob_path, | |
142 net::URLRequestContext* request_context, | |
143 scoped_ptr<LevelDBDatabase> db, | |
144 scoped_ptr<LevelDBComparator> comparator, | |
145 base::TaskRunner* task_runner) | |
146 : IndexedDBBackingStore(indexed_db_factory, | |
147 origin_url, | |
148 blob_path, | |
149 request_context, | |
150 db.Pass(), | |
151 comparator.Pass(), | |
152 task_runner), | |
153 database_id_(0) {} | |
154 | |
155 int64 database_id_; | |
156 std::vector<Transaction::WriteDescriptor> writes_; | |
157 std::vector<int64> removals_; | |
158 }; | |
159 | |
160 class TestIDBFactory : public IndexedDBFactory { | |
161 public: | |
162 TestIDBFactory(IndexedDBContextImpl* idb_context) | |
163 : IndexedDBFactory(idb_context) {} | |
164 | |
165 scoped_refptr<TestableIndexedDBBackingStore> OpenBackingStoreForTest( | |
166 const GURL& origin, | |
167 net::URLRequestContext* url_request_context) { | |
168 blink::WebIDBDataLoss data_loss; | |
169 std::string data_loss_reason; | |
170 bool disk_full; | |
171 scoped_refptr<IndexedDBBackingStore> backing_store = | |
172 OpenBackingStore(origin, | |
173 context()->data_path(), | |
174 url_request_context, | |
175 &data_loss, | |
176 &data_loss_reason, | |
177 &disk_full); | |
178 scoped_refptr<TestableIndexedDBBackingStore> testable_store = | |
179 static_cast<TestableIndexedDBBackingStore*>(backing_store.get()); | |
180 return testable_store; | |
181 } | |
182 | |
183 protected: | |
184 scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( | |
185 const GURL& origin_url, | |
186 const base::FilePath& data_directory, | |
187 net::URLRequestContext* request_context, | |
188 blink::WebIDBDataLoss* data_loss, | |
189 std::string* data_loss_message, | |
190 bool* disk_full, | |
191 bool first_time) { | |
192 DefaultLevelDBFactory leveldb_factory; | |
193 return TestableIndexedDBBackingStore::Open(this, | |
194 origin_url, | |
195 data_directory, | |
196 request_context, | |
197 &leveldb_factory, | |
198 context()->TaskRunner()); | |
199 } | |
200 }; | |
201 | |
21 class IndexedDBBackingStoreTest : public testing::Test { | 202 class IndexedDBBackingStoreTest : public testing::Test { |
22 public: | 203 public: |
23 IndexedDBBackingStoreTest() {} | 204 IndexedDBBackingStoreTest() {} |
24 virtual void SetUp() { | 205 virtual void SetUp() { |
25 const GURL origin("http://localhost:81"); | 206 const GURL origin("http://localhost:81"); |
207 task_runner_ = new base::TestSimpleTaskRunner(); | |
208 special_storage_policy_ = new MockSpecialStoragePolicy(); | |
209 special_storage_policy_->SetAllUnlimited(true); | |
210 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
211 idb_context_ = new IndexedDBContextImpl( | |
212 temp_dir_.path(), special_storage_policy_, NULL, task_runner_); | |
213 idb_factory_ = new TestIDBFactory(idb_context_); | |
26 backing_store_ = | 214 backing_store_ = |
27 IndexedDBBackingStore::OpenInMemory(origin, NULL /* task_runner */); | 215 idb_factory_->OpenBackingStoreForTest(origin, &url_request_context_); |
28 | 216 |
29 // useful keys and values during tests | 217 // useful keys and values during tests |
30 m_value1 = IndexedDBValue("value1", std::vector<IndexedDBBlobInfo>()); | 218 m_value1 = IndexedDBValue("value1", std::vector<IndexedDBBlobInfo>()); |
31 m_value2 = IndexedDBValue("value2", std::vector<IndexedDBBlobInfo>()); | 219 m_value2 = IndexedDBValue("value2", std::vector<IndexedDBBlobInfo>()); |
32 | 220 |
221 m_blobInfo.push_back( | |
222 IndexedDBBlobInfo("uuid 3", base::UTF8ToUTF16("blob type"), 1)); | |
223 m_blobInfo.push_back( | |
224 IndexedDBBlobInfo("uuid 4", | |
225 base::FilePath(FILE_PATH_LITERAL("path/to/file")), | |
226 base::UTF8ToUTF16("file name"), | |
227 base::UTF8ToUTF16("file type"))); | |
228 m_value3 = IndexedDBValue("value3", m_blobInfo); | |
229 | |
33 m_key1 = IndexedDBKey(99, blink::WebIDBKeyTypeNumber); | 230 m_key1 = IndexedDBKey(99, blink::WebIDBKeyTypeNumber); |
34 m_key2 = IndexedDBKey(ASCIIToUTF16("key2")); | 231 m_key2 = IndexedDBKey(ASCIIToUTF16("key2")); |
232 m_key3 = IndexedDBKey(ASCIIToUTF16("key3")); | |
233 } | |
234 | |
235 // This just checks the data that survive getting stored and recalled, e.g. | |
236 // the file path and UUID will change and thus aren't verified. | |
237 bool CheckBlobInfoMatches(const std::vector<IndexedDBBlobInfo>& reads) const { | |
238 if (m_blobInfo.size() != reads.size()) | |
239 return false; | |
240 for (size_t i = 0; i < m_blobInfo.size(); ++i) { | |
241 const IndexedDBBlobInfo& a = m_blobInfo[i]; | |
242 const IndexedDBBlobInfo& b = reads[i]; | |
243 if (a.is_file() != b.is_file()) | |
244 return false; | |
245 if (a.type() != b.type()) | |
246 return false; | |
247 if (a.is_file()) { | |
248 if (a.file_name() != b.file_name()) | |
249 return false; | |
250 } else { | |
251 if (a.size() != b.size()) | |
252 return false; | |
253 } | |
254 } | |
255 return true; | |
256 } | |
257 | |
258 bool CheckBlobReadsMatchWrites( | |
259 const std::vector<IndexedDBBlobInfo>& reads) const { | |
260 if (backing_store_->writes().size() != reads.size()) | |
261 return false; | |
262 std::set<int64> ids; | |
263 for (size_t i = 0; i < backing_store_->writes().size(); ++i) | |
264 ids.insert(backing_store_->writes()[i].key()); | |
265 if (ids.size() != backing_store_->writes().size()) | |
266 return false; | |
267 for (size_t i = 0; i < reads.size(); ++i) | |
jsbell
2014/05/20 22:02:19
Nit: should have braces since body is > 1 line
ericu
2014/05/21 18:14:47
Done.
| |
268 if (ids.count(reads[i].key()) != 1) | |
269 return false; | |
270 return true; | |
271 } | |
272 | |
273 bool CheckBlobWrites() const { | |
274 if (backing_store_->writes().size() != m_blobInfo.size()) | |
275 return false; | |
276 for (size_t i = 0; i < backing_store_->writes().size(); ++i) { | |
277 const IndexedDBBackingStore::Transaction::WriteDescriptor& desc = | |
278 backing_store_->writes()[i]; | |
279 const IndexedDBBlobInfo& info = m_blobInfo[i]; | |
280 if (desc.is_file() != info.is_file()) | |
281 return false; | |
282 if (desc.is_file()) { | |
283 if (desc.file_path() != info.file_path()) | |
284 return false; | |
285 } else { | |
286 if (desc.url() != GURL("blob:uuid/" + info.uuid())) | |
287 return false; | |
288 } | |
289 } | |
290 return true; | |
291 } | |
292 | |
293 bool CheckBlobRemovals() const { | |
294 if (backing_store_->removals().size() != backing_store_->writes().size()) | |
295 return false; | |
296 for (size_t i = 0; i < backing_store_->writes().size(); ++i) | |
297 if (backing_store_->writes()[i].key() != backing_store_->removals()[i]) | |
298 return false; | |
299 return true; | |
35 } | 300 } |
36 | 301 |
37 protected: | 302 protected: |
38 scoped_refptr<IndexedDBBackingStore> backing_store_; | 303 base::ScopedTempDir temp_dir_; |
304 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | |
305 scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_; | |
306 scoped_refptr<IndexedDBContextImpl> idb_context_; | |
307 scoped_refptr<TestIDBFactory> idb_factory_; | |
308 net::TestURLRequestContext url_request_context_; | |
309 | |
310 scoped_refptr<TestableIndexedDBBackingStore> backing_store_; | |
39 | 311 |
40 // Sample keys and values that are consistent. | 312 // Sample keys and values that are consistent. |
41 IndexedDBKey m_key1; | 313 IndexedDBKey m_key1; |
42 IndexedDBKey m_key2; | 314 IndexedDBKey m_key2; |
315 IndexedDBKey m_key3; | |
43 IndexedDBValue m_value1; | 316 IndexedDBValue m_value1; |
44 IndexedDBValue m_value2; | 317 IndexedDBValue m_value2; |
318 IndexedDBValue m_value3; | |
319 std::vector<IndexedDBBlobInfo> m_blobInfo; | |
45 | 320 |
46 private: | 321 private: |
47 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStoreTest); | 322 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStoreTest); |
48 }; | 323 }; |
49 | 324 |
325 class TestCallback : public IndexedDBBackingStore::BlobWriteCallback { | |
326 public: | |
327 TestCallback() : called(false), succeeded(false) {} | |
328 virtual ~TestCallback() {} | |
329 virtual void Run(bool succeeded_in) { | |
330 called = true; | |
331 succeeded = succeeded_in; | |
332 } | |
333 bool called; | |
334 bool succeeded; | |
335 }; | |
336 | |
50 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { | 337 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { |
51 { | 338 { |
52 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 339 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
53 transaction1.Begin(); | 340 transaction1.Begin(); |
54 ScopedVector<webkit_blob::BlobDataHandle> handles; | 341 ScopedVector<webkit_blob::BlobDataHandle> handles; |
55 IndexedDBBackingStore::RecordIdentifier record; | 342 IndexedDBBackingStore::RecordIdentifier record; |
56 leveldb::Status s = backing_store_->PutRecord( | 343 leveldb::Status s = backing_store_->PutRecord( |
57 &transaction1, 1, 1, m_key1, m_value1, &handles, &record); | 344 &transaction1, 1, 1, m_key1, m_value1, &handles, &record); |
58 EXPECT_TRUE(s.ok()); | 345 EXPECT_TRUE(s.ok()); |
59 transaction1.Commit(); | 346 scoped_refptr<TestCallback> callback(new TestCallback()); |
347 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | |
348 EXPECT_TRUE(callback->called); | |
349 EXPECT_TRUE(callback->succeeded); | |
350 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | |
60 } | 351 } |
61 | 352 |
62 { | 353 { |
63 IndexedDBBackingStore::Transaction transaction2(backing_store_); | 354 IndexedDBBackingStore::Transaction transaction2(backing_store_); |
64 transaction2.Begin(); | 355 transaction2.Begin(); |
65 IndexedDBValue result_value; | 356 IndexedDBValue result_value; |
66 leveldb::Status s = | 357 EXPECT_TRUE( |
67 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value); | 358 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value) |
68 transaction2.Commit(); | 359 .ok()); |
69 EXPECT_TRUE(s.ok()); | 360 scoped_refptr<TestCallback> callback(new TestCallback()); |
361 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); | |
362 EXPECT_TRUE(callback->called); | |
363 EXPECT_TRUE(callback->succeeded); | |
364 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | |
70 EXPECT_EQ(m_value1.bits, result_value.bits); | 365 EXPECT_EQ(m_value1.bits, result_value.bits); |
71 } | 366 } |
72 } | 367 } |
73 | 368 |
369 TEST_F(IndexedDBBackingStoreTest, PutGetConsistencyWithBlobs) { | |
370 { | |
371 IndexedDBBackingStore::Transaction transaction1(backing_store_); | |
372 transaction1.Begin(); | |
373 ScopedVector<webkit_blob::BlobDataHandle> handles; | |
374 IndexedDBBackingStore::RecordIdentifier record; | |
375 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | |
376 1, | |
377 1, | |
378 m_key3, | |
379 m_value3, | |
380 &handles, | |
381 &record).ok()); | |
382 scoped_refptr<TestCallback> callback(new TestCallback()); | |
383 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | |
384 task_runner_->RunUntilIdle(); | |
385 EXPECT_TRUE(CheckBlobWrites()); | |
386 EXPECT_TRUE(callback->called); | |
387 EXPECT_TRUE(callback->succeeded); | |
388 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | |
389 } | |
390 | |
391 { | |
392 IndexedDBBackingStore::Transaction transaction2(backing_store_); | |
393 transaction2.Begin(); | |
394 IndexedDBValue result_value; | |
395 EXPECT_TRUE( | |
396 backing_store_->GetRecord(&transaction2, 1, 1, m_key3, &result_value) | |
397 .ok()); | |
398 scoped_refptr<TestCallback> callback(new TestCallback()); | |
399 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); | |
400 EXPECT_TRUE(callback->called); | |
401 EXPECT_TRUE(callback->succeeded); | |
402 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | |
403 EXPECT_EQ(m_value3.bits, result_value.bits); | |
404 EXPECT_TRUE(CheckBlobInfoMatches(result_value.blob_info)); | |
405 EXPECT_TRUE(CheckBlobReadsMatchWrites(result_value.blob_info)); | |
406 } | |
407 | |
408 { | |
409 IndexedDBBackingStore::Transaction transaction3(backing_store_); | |
410 transaction3.Begin(); | |
411 IndexedDBValue result_value; | |
412 EXPECT_TRUE(backing_store_->DeleteRange(&transaction3, | |
413 1, | |
414 1, | |
415 IndexedDBKeyRange(m_key3)).ok()); | |
416 scoped_refptr<TestCallback> callback(new TestCallback()); | |
417 EXPECT_TRUE(transaction3.CommitPhaseOne(callback).ok()); | |
418 task_runner_->RunUntilIdle(); | |
419 EXPECT_TRUE(callback->called); | |
420 EXPECT_TRUE(callback->succeeded); | |
421 EXPECT_TRUE(transaction3.CommitPhaseTwo().ok()); | |
422 EXPECT_TRUE(CheckBlobRemovals()); | |
423 } | |
424 } | |
425 | |
426 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { | |
427 { | |
428 IndexedDBBackingStore::Transaction transaction1(backing_store_); | |
429 transaction1.Begin(); | |
430 ScopedVector<webkit_blob::BlobDataHandle> handles; | |
431 IndexedDBBackingStore::RecordIdentifier record; | |
432 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | |
433 1, | |
434 1, | |
435 m_key3, | |
436 m_value3, | |
437 &handles, | |
438 &record).ok()); | |
439 scoped_refptr<TestCallback> callback(new TestCallback()); | |
440 EXPECT_TRUE(transaction1.CommitPhaseOne(callback).ok()); | |
441 task_runner_->RunUntilIdle(); | |
442 EXPECT_TRUE(CheckBlobWrites()); | |
443 EXPECT_TRUE(callback->called); | |
444 EXPECT_TRUE(callback->succeeded); | |
445 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | |
446 } | |
447 | |
448 IndexedDBValue read_result_value; | |
449 { | |
450 IndexedDBBackingStore::Transaction transaction2(backing_store_); | |
451 transaction2.Begin(); | |
452 EXPECT_TRUE( | |
453 backing_store_->GetRecord( | |
454 &transaction2, 1, 1, m_key3, &read_result_value) | |
455 .ok()); | |
456 scoped_refptr<TestCallback> callback(new TestCallback()); | |
457 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); | |
458 EXPECT_TRUE(callback->called); | |
459 EXPECT_TRUE(callback->succeeded); | |
460 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | |
461 EXPECT_EQ(m_value3.bits, read_result_value.bits); | |
462 EXPECT_TRUE(CheckBlobInfoMatches(read_result_value.blob_info)); | |
463 EXPECT_TRUE(CheckBlobReadsMatchWrites(read_result_value.blob_info)); | |
464 for (size_t i = 0; i < read_result_value.blob_info.size(); ++i) { | |
465 read_result_value.blob_info[i].mark_used_callback().Run(); | |
466 } | |
467 } | |
468 | |
469 { | |
470 IndexedDBBackingStore::Transaction transaction3(backing_store_); | |
471 transaction3.Begin(); | |
472 EXPECT_TRUE(backing_store_->DeleteRange(&transaction3, | |
473 1, | |
474 1, | |
475 IndexedDBKeyRange(m_key3)).ok()); | |
476 scoped_refptr<TestCallback> callback(new TestCallback()); | |
477 EXPECT_TRUE(transaction3.CommitPhaseOne(callback).ok()); | |
478 task_runner_->RunUntilIdle(); | |
479 EXPECT_TRUE(callback->called); | |
480 EXPECT_TRUE(callback->succeeded); | |
481 EXPECT_TRUE(transaction3.CommitPhaseTwo().ok()); | |
482 EXPECT_EQ(0U, backing_store_->removals().size()); | |
483 for (size_t i = 0; i < read_result_value.blob_info.size(); ++i) { | |
484 read_result_value.blob_info[i].release_callback().Run( | |
485 read_result_value.blob_info[i].file_path()); | |
486 } | |
487 task_runner_->RunUntilIdle(); | |
488 EXPECT_NE(0U, backing_store_->removals().size()); | |
489 EXPECT_TRUE(CheckBlobRemovals()); | |
490 } | |
491 } | |
492 | |
74 // Make sure that using very high ( more than 32 bit ) values for database_id | 493 // Make sure that using very high ( more than 32 bit ) values for database_id |
75 // and object_store_id still work. | 494 // and object_store_id still work. |
76 TEST_F(IndexedDBBackingStoreTest, HighIds) { | 495 TEST_F(IndexedDBBackingStoreTest, HighIds) { |
77 const int64 high_database_id = 1ULL << 35; | 496 const int64 high_database_id = 1ULL << 35; |
78 const int64 high_object_store_id = 1ULL << 39; | 497 const int64 high_object_store_id = 1ULL << 39; |
79 // index_ids are capped at 32 bits for storage purposes. | 498 // index_ids are capped at 32 bits for storage purposes. |
80 const int64 high_index_id = 1ULL << 29; | 499 const int64 high_index_id = 1ULL << 29; |
81 | 500 |
82 const int64 invalid_high_index_id = 1ULL << 37; | 501 const int64 invalid_high_index_id = 1ULL << 37; |
83 | 502 |
(...skipping 23 matching lines...) Expand all Loading... | |
107 EXPECT_FALSE(s.ok()); | 526 EXPECT_FALSE(s.ok()); |
108 | 527 |
109 s = backing_store_->PutIndexDataForRecord(&transaction1, | 528 s = backing_store_->PutIndexDataForRecord(&transaction1, |
110 high_database_id, | 529 high_database_id, |
111 high_object_store_id, | 530 high_object_store_id, |
112 high_index_id, | 531 high_index_id, |
113 index_key, | 532 index_key, |
114 record); | 533 record); |
115 EXPECT_TRUE(s.ok()); | 534 EXPECT_TRUE(s.ok()); |
116 | 535 |
117 s = transaction1.Commit(); | 536 scoped_refptr<TestCallback> callback(new TestCallback()); |
537 s = transaction1.CommitPhaseOne(callback); | |
538 EXPECT_TRUE(s.ok()); | |
539 EXPECT_TRUE(callback->called); | |
540 EXPECT_TRUE(callback->succeeded); | |
541 s = transaction1.CommitPhaseTwo(); | |
118 EXPECT_TRUE(s.ok()); | 542 EXPECT_TRUE(s.ok()); |
119 } | 543 } |
120 | 544 |
121 { | 545 { |
122 IndexedDBBackingStore::Transaction transaction2(backing_store_); | 546 IndexedDBBackingStore::Transaction transaction2(backing_store_); |
123 transaction2.Begin(); | 547 transaction2.Begin(); |
124 IndexedDBValue result_value; | 548 IndexedDBValue result_value; |
125 leveldb::Status s = backing_store_->GetRecord(&transaction2, | 549 leveldb::Status s = backing_store_->GetRecord(&transaction2, |
126 high_database_id, | 550 high_database_id, |
127 high_object_store_id, | 551 high_object_store_id, |
(...skipping 13 matching lines...) Expand all Loading... | |
141 | 565 |
142 s = backing_store_->GetPrimaryKeyViaIndex(&transaction2, | 566 s = backing_store_->GetPrimaryKeyViaIndex(&transaction2, |
143 high_database_id, | 567 high_database_id, |
144 high_object_store_id, | 568 high_object_store_id, |
145 high_index_id, | 569 high_index_id, |
146 index_key, | 570 index_key, |
147 &new_primary_key); | 571 &new_primary_key); |
148 EXPECT_TRUE(s.ok()); | 572 EXPECT_TRUE(s.ok()); |
149 EXPECT_TRUE(new_primary_key->Equals(m_key1)); | 573 EXPECT_TRUE(new_primary_key->Equals(m_key1)); |
150 | 574 |
151 s = transaction2.Commit(); | 575 scoped_refptr<TestCallback> callback(new TestCallback()); |
576 s = transaction2.CommitPhaseOne(callback); | |
577 EXPECT_TRUE(s.ok()); | |
578 EXPECT_TRUE(callback->called); | |
579 EXPECT_TRUE(callback->succeeded); | |
580 s = transaction2.CommitPhaseTwo(); | |
152 EXPECT_TRUE(s.ok()); | 581 EXPECT_TRUE(s.ok()); |
153 } | 582 } |
154 } | 583 } |
155 | 584 |
156 // Make sure that other invalid ids do not crash. | 585 // Make sure that other invalid ids do not crash. |
157 TEST_F(IndexedDBBackingStoreTest, InvalidIds) { | 586 TEST_F(IndexedDBBackingStoreTest, InvalidIds) { |
158 // valid ids for use when testing invalid ids | 587 // valid ids for use when testing invalid ids |
159 const int64 database_id = 1; | 588 const int64 database_id = 1; |
160 const int64 object_store_id = 1; | 589 const int64 object_store_id = 1; |
161 const int64 index_id = kMinimumIndexId; | 590 const int64 index_id = kMinimumIndexId; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 s = backing_store_->CreateIndex(&transaction, | 709 s = backing_store_->CreateIndex(&transaction, |
281 database_id, | 710 database_id, |
282 object_store_id, | 711 object_store_id, |
283 index_id, | 712 index_id, |
284 index_name, | 713 index_name, |
285 index_key_path, | 714 index_key_path, |
286 unique, | 715 unique, |
287 multi_entry); | 716 multi_entry); |
288 EXPECT_TRUE(s.ok()); | 717 EXPECT_TRUE(s.ok()); |
289 | 718 |
290 s = transaction.Commit(); | 719 scoped_refptr<TestCallback> callback(new TestCallback()); |
720 s = transaction.CommitPhaseOne(callback); | |
721 EXPECT_TRUE(s.ok()); | |
722 EXPECT_TRUE(callback->called); | |
723 EXPECT_TRUE(callback->succeeded); | |
724 s = transaction.CommitPhaseTwo(); | |
291 EXPECT_TRUE(s.ok()); | 725 EXPECT_TRUE(s.ok()); |
292 } | 726 } |
293 | 727 |
294 { | 728 { |
295 IndexedDBDatabaseMetadata database; | 729 IndexedDBDatabaseMetadata database; |
296 bool found; | 730 bool found; |
297 leveldb::Status s = backing_store_->GetIDBDatabaseMetaData( | 731 leveldb::Status s = backing_store_->GetIDBDatabaseMetaData( |
298 database_name, &database, &found); | 732 database_name, &database, &found); |
299 EXPECT_TRUE(s.ok()); | 733 EXPECT_TRUE(s.ok()); |
300 EXPECT_TRUE(found); | 734 EXPECT_TRUE(found); |
(...skipping 18 matching lines...) Expand all Loading... | |
319 EXPECT_EQ(index_name, index.name); | 753 EXPECT_EQ(index_name, index.name); |
320 EXPECT_EQ(index_key_path, index.key_path); | 754 EXPECT_EQ(index_key_path, index.key_path); |
321 EXPECT_EQ(unique, index.unique); | 755 EXPECT_EQ(unique, index.unique); |
322 EXPECT_EQ(multi_entry, index.multi_entry); | 756 EXPECT_EQ(multi_entry, index.multi_entry); |
323 } | 757 } |
324 } | 758 } |
325 | 759 |
326 } // namespace | 760 } // namespace |
327 | 761 |
328 } // namespace content | 762 } // namespace content |
OLD | NEW |