OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 EXPECT_FALSE(db->backing_store()); | 213 EXPECT_FALSE(db->backing_store()); |
214 EXPECT_TRUE(backing_store->HasOneRef()); // local | 214 EXPECT_TRUE(backing_store->HasOneRef()); // local |
215 EXPECT_TRUE(request2->success_called()); | 215 EXPECT_TRUE(request2->success_called()); |
216 } | 216 } |
217 | 217 |
218 void DummyOperation(IndexedDBTransaction* transaction) { | 218 void DummyOperation(IndexedDBTransaction* transaction) { |
219 } | 219 } |
220 | 220 |
221 class IndexedDBDatabaseOperationTest : public testing::Test { | 221 class IndexedDBDatabaseOperationTest : public testing::Test { |
222 public: | 222 public: |
223 IndexedDBDatabaseOperationTest() : commit_success_(true) {} | 223 IndexedDBDatabaseOperationTest() : commit_success_(leveldb::Status::OK()) {} |
224 | 224 |
225 virtual void SetUp() { | 225 virtual void SetUp() { |
226 backing_store_ = new IndexedDBFakeBackingStore(); | 226 backing_store_ = new IndexedDBFakeBackingStore(); |
227 leveldb::Status s; | 227 leveldb::Status s; |
228 db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 228 db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
229 backing_store_, | 229 backing_store_, |
230 NULL /*factory*/, | 230 NULL /*factory*/, |
231 IndexedDBDatabase::Identifier(), | 231 IndexedDBDatabase::Identifier(), |
232 &s); | 232 &s); |
233 ASSERT_TRUE(s.ok()); | 233 ASSERT_TRUE(s.ok()); |
(...skipping 27 matching lines...) Expand all Loading... |
261 | 261 |
262 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } | 262 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } |
263 | 263 |
264 protected: | 264 protected: |
265 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; | 265 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; |
266 scoped_refptr<IndexedDBDatabase> db_; | 266 scoped_refptr<IndexedDBDatabase> db_; |
267 scoped_refptr<MockIndexedDBCallbacks> request_; | 267 scoped_refptr<MockIndexedDBCallbacks> request_; |
268 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; | 268 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; |
269 scoped_refptr<IndexedDBTransaction> transaction_; | 269 scoped_refptr<IndexedDBTransaction> transaction_; |
270 | 270 |
271 bool commit_success_; | 271 leveldb::Status commit_success_; |
272 | 272 |
273 private: | 273 private: |
274 base::MessageLoop message_loop_; | 274 base::MessageLoop message_loop_; |
275 | 275 |
276 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); | 276 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); |
277 }; | 277 }; |
278 | 278 |
279 TEST_F(IndexedDBDatabaseOperationTest, CreateObjectStore) { | 279 TEST_F(IndexedDBDatabaseOperationTest, CreateObjectStore) { |
280 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 280 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
281 const int64 store_id = 1001; | 281 const int64 store_id = 1001; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 transaction_->Commit(); | 314 transaction_->Commit(); |
315 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); | 315 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); |
316 EXPECT_EQ( | 316 EXPECT_EQ( |
317 1ULL, | 317 1ULL, |
318 db_->metadata().object_stores.find(store_id)->second.indexes.size()); | 318 db_->metadata().object_stores.find(store_id)->second.indexes.size()); |
319 } | 319 } |
320 | 320 |
321 class IndexedDBDatabaseOperationAbortTest | 321 class IndexedDBDatabaseOperationAbortTest |
322 : public IndexedDBDatabaseOperationTest { | 322 : public IndexedDBDatabaseOperationTest { |
323 public: | 323 public: |
324 IndexedDBDatabaseOperationAbortTest() { commit_success_ = false; } | 324 IndexedDBDatabaseOperationAbortTest() { |
| 325 commit_success_ = leveldb::Status::NotFound("Bummer."); |
| 326 } |
325 }; | 327 }; |
326 | 328 |
327 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateObjectStore) { | 329 TEST_F(IndexedDBDatabaseOperationAbortTest, CreateObjectStore) { |
328 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 330 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
329 const int64 store_id = 1001; | 331 const int64 store_id = 1001; |
330 db_->CreateObjectStore(transaction_->id(), | 332 db_->CreateObjectStore(transaction_->id(), |
331 store_id, | 333 store_id, |
332 ASCIIToUTF16("store"), | 334 ASCIIToUTF16("store"), |
333 IndexedDBKeyPath(), | 335 IndexedDBKeyPath(), |
334 false /*auto_increment*/); | 336 false /*auto_increment*/); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 db_->DeleteObjectStore(transaction_->id(), | 398 db_->DeleteObjectStore(transaction_->id(), |
397 store_id); | 399 store_id); |
398 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); | 400 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); |
399 | 401 |
400 // This will execute the Put then Delete. | 402 // This will execute the Put then Delete. |
401 RunPostedTasks(); | 403 RunPostedTasks(); |
402 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 404 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
403 } | 405 } |
404 | 406 |
405 } // namespace content | 407 } // namespace content |
OLD | NEW |