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_transaction.h" | 5 #include "content/browser/indexed_db/indexed_db_transaction.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "content/browser/indexed_db/indexed_db_factory.h" |
11 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" | 12 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
12 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 13 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
| 14 #include "content/browser/indexed_db/mock_indexed_db_factory.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
14 | 17 |
15 namespace content { | 18 namespace content { |
16 | 19 |
17 class AbortObserver { | 20 class AbortObserver { |
18 public: | 21 public: |
19 AbortObserver() : abort_task_called_(false) {} | 22 AbortObserver() : abort_task_called_(false) {} |
20 | 23 |
21 void AbortTask(IndexedDBTransaction* transaction) { | 24 void AbortTask(IndexedDBTransaction* transaction) { |
22 abort_task_called_ = true; | 25 abort_task_called_ = true; |
23 } | 26 } |
24 | 27 |
25 bool abort_task_called() const { return abort_task_called_; } | 28 bool abort_task_called() const { return abort_task_called_; } |
26 | 29 |
27 private: | 30 private: |
28 bool abort_task_called_; | 31 bool abort_task_called_; |
29 DISALLOW_COPY_AND_ASSIGN(AbortObserver); | 32 DISALLOW_COPY_AND_ASSIGN(AbortObserver); |
30 }; | 33 }; |
31 | 34 |
32 class IndexedDBTransactionTest : public testing::Test { | 35 class IndexedDBTransactionTest : public testing::Test { |
33 public: | 36 public: |
34 IndexedDBTransactionTest() { | 37 IndexedDBTransactionTest() : factory_(new MockIndexedDBFactory()) { |
35 backing_store_ = new IndexedDBFakeBackingStore(); | 38 backing_store_ = new IndexedDBFakeBackingStore(); |
36 CreateDB(); | 39 CreateDB(); |
37 } | 40 } |
38 | 41 |
39 void CreateDB() { | 42 void CreateDB() { |
40 // DB is created here instead of the constructor to workaround a | 43 // DB is created here instead of the constructor to workaround a |
41 // "peculiarity of C++". More info at | 44 // "peculiarity of C++". More info at |
42 // https://code.google.com/p/googletest/wiki/FAQ#My_compiler_complains_that_
a_constructor_(or_destructor)_cannot | 45 // https://code.google.com/p/googletest/wiki/FAQ#My_compiler_complains_that_
a_constructor_(or_destructor)_cannot |
43 IndexedDBFactory* factory = NULL; | |
44 leveldb::Status s; | 46 leveldb::Status s; |
45 db_ = IndexedDBDatabase::Create(base::ASCIIToUTF16("db"), | 47 db_ = IndexedDBDatabase::Create(base::ASCIIToUTF16("db"), |
46 backing_store_, | 48 backing_store_, |
47 factory, | 49 factory_, |
48 IndexedDBDatabase::Identifier(), | 50 IndexedDBDatabase::Identifier(), |
49 &s); | 51 &s); |
50 ASSERT_TRUE(s.ok()); | 52 ASSERT_TRUE(s.ok()); |
51 } | 53 } |
52 | 54 |
53 void RunPostedTasks() { message_loop_.RunUntilIdle(); } | 55 void RunPostedTasks() { message_loop_.RunUntilIdle(); } |
54 void DummyOperation(IndexedDBTransaction* transaction) {} | 56 void DummyOperation(IndexedDBTransaction* transaction) {} |
55 void AbortableOperation(AbortObserver* observer, | 57 void AbortableOperation(AbortObserver* observer, |
56 IndexedDBTransaction* transaction) { | 58 IndexedDBTransaction* transaction) { |
57 transaction->ScheduleAbortTask( | 59 transaction->ScheduleAbortTask( |
58 base::Bind(&AbortObserver::AbortTask, base::Unretained(observer))); | 60 base::Bind(&AbortObserver::AbortTask, base::Unretained(observer))); |
59 } | 61 } |
60 | 62 |
61 protected: | 63 protected: |
62 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; | 64 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; |
63 scoped_refptr<IndexedDBDatabase> db_; | 65 scoped_refptr<IndexedDBDatabase> db_; |
64 | 66 |
65 private: | 67 private: |
66 base::MessageLoop message_loop_; | 68 base::MessageLoop message_loop_; |
| 69 scoped_refptr<MockIndexedDBFactory> factory_; |
67 | 70 |
68 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTest); | 71 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTest); |
69 }; | 72 }; |
70 | 73 |
71 class IndexedDBTransactionTestMode : public IndexedDBTransactionTest, | 74 class IndexedDBTransactionTestMode : public IndexedDBTransactionTest, |
72 public testing::WithParamInterface<indexed_db::TransactionMode> { | 75 public testing::WithParamInterface<indexed_db::TransactionMode> { |
73 public: | 76 public: |
74 IndexedDBTransactionTestMode() {} | 77 IndexedDBTransactionTestMode() {} |
75 private: | 78 private: |
76 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); | 79 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 indexed_db::TRANSACTION_READ_ONLY, | 363 indexed_db::TRANSACTION_READ_ONLY, |
361 indexed_db::TRANSACTION_READ_WRITE, | 364 indexed_db::TRANSACTION_READ_WRITE, |
362 indexed_db::TRANSACTION_VERSION_CHANGE | 365 indexed_db::TRANSACTION_VERSION_CHANGE |
363 }; | 366 }; |
364 | 367 |
365 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, | 368 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, |
366 IndexedDBTransactionTestMode, | 369 IndexedDBTransactionTestMode, |
367 ::testing::ValuesIn(kTestModes)); | 370 ::testing::ValuesIn(kTestModes)); |
368 | 371 |
369 } // namespace content | 372 } // namespace content |
OLD | NEW |