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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 new MockIndexedDBDatabaseCallbacks(), | 55 new MockIndexedDBDatabaseCallbacks(), |
56 scope, | 56 scope, |
57 indexed_db::TRANSACTION_READ_WRITE, | 57 indexed_db::TRANSACTION_READ_WRITE, |
58 db_, | 58 db_, |
59 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 59 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
60 db_->TransactionCreated(transaction); | 60 db_->TransactionCreated(transaction); |
61 | 61 |
62 // No conflicting transactions, so coordinator will start it immediately: | 62 // No conflicting transactions, so coordinator will start it immediately: |
63 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 63 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
64 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 64 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 65 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 66 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
65 | 67 |
66 // Schedule a task - timer won't be started until it's processed. | 68 // Schedule a task - timer won't be started until it's processed. |
67 transaction->ScheduleTask(base::Bind( | 69 transaction->ScheduleTask(base::Bind( |
68 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | 70 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); |
69 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 71 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 72 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 73 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
70 | 74 |
71 RunPostedTasks(); | 75 RunPostedTasks(); |
72 EXPECT_TRUE(transaction->IsTimeoutTimerRunning()); | 76 EXPECT_TRUE(transaction->IsTimeoutTimerRunning()); |
73 | 77 |
74 // Abort should cancel the timer. | 78 transaction->Timeout(); |
75 transaction->Abort(); | |
76 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 79 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
77 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 80 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 81 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 82 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); |
78 | 83 |
79 // This task will be ignored. | 84 // This task will be ignored. |
80 transaction->ScheduleTask(base::Bind( | 85 transaction->ScheduleTask(base::Bind( |
81 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | 86 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); |
82 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 87 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
83 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 88 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 89 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 90 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); |
84 } | 91 } |
85 | 92 |
86 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { | 93 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { |
87 const int64 id = 0; | 94 const int64 id = 0; |
88 const std::set<int64> scope; | 95 const std::set<int64> scope; |
89 const bool commit_success = true; | 96 const bool commit_success = true; |
90 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 97 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
91 id, | 98 id, |
92 new MockIndexedDBDatabaseCallbacks(), | 99 new MockIndexedDBDatabaseCallbacks(), |
93 scope, | 100 scope, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 indexed_db::TRANSACTION_READ_ONLY, | 222 indexed_db::TRANSACTION_READ_ONLY, |
216 indexed_db::TRANSACTION_READ_WRITE, | 223 indexed_db::TRANSACTION_READ_WRITE, |
217 indexed_db::TRANSACTION_VERSION_CHANGE | 224 indexed_db::TRANSACTION_VERSION_CHANGE |
218 }; | 225 }; |
219 | 226 |
220 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, | 227 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, |
221 IndexedDBTransactionTestMode, | 228 IndexedDBTransactionTestMode, |
222 ::testing::ValuesIn(kTestModes)); | 229 ::testing::ValuesIn(kTestModes)); |
223 | 230 |
224 } // namespace content | 231 } // namespace content |
OLD | NEW |