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