| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 public testing::WithParamInterface<indexed_db::TransactionMode> { | 72 public testing::WithParamInterface<indexed_db::TransactionMode> { |
| 73 public: | 73 public: |
| 74 IndexedDBTransactionTestMode() {} | 74 IndexedDBTransactionTestMode() {} |
| 75 private: | 75 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); | 76 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 TEST_F(IndexedDBTransactionTest, Timeout) { | 79 TEST_F(IndexedDBTransactionTest, Timeout) { |
| 80 const int64 id = 0; | 80 const int64 id = 0; |
| 81 const std::set<int64> scope; | 81 const std::set<int64> scope; |
| 82 const bool commit_success = true; | 82 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 83 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 83 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 84 id, | 84 id, |
| 85 new MockIndexedDBDatabaseCallbacks(), | 85 new MockIndexedDBDatabaseCallbacks(), |
| 86 scope, | 86 scope, |
| 87 indexed_db::TRANSACTION_READ_WRITE, | 87 indexed_db::TRANSACTION_READ_WRITE, |
| 88 db_, | 88 db_, |
| 89 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 89 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 90 db_->TransactionCreated(transaction); | 90 db_->TransactionCreated(transaction); |
| 91 | 91 |
| 92 // No conflicting transactions, so coordinator will start it immediately: | 92 // No conflicting transactions, so coordinator will start it immediately: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 116 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | 116 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); |
| 117 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 117 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 118 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 118 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 119 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); | 119 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 120 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); | 120 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { | 123 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { |
| 124 const int64 id = 0; | 124 const int64 id = 0; |
| 125 const std::set<int64> scope; | 125 const std::set<int64> scope; |
| 126 const bool commit_success = true; | 126 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 127 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 127 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 128 id, | 128 id, |
| 129 new MockIndexedDBDatabaseCallbacks(), | 129 new MockIndexedDBDatabaseCallbacks(), |
| 130 scope, | 130 scope, |
| 131 indexed_db::TRANSACTION_READ_ONLY, | 131 indexed_db::TRANSACTION_READ_ONLY, |
| 132 db_, | 132 db_, |
| 133 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 133 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 134 db_->TransactionCreated(transaction); | 134 db_->TransactionCreated(transaction); |
| 135 | 135 |
| 136 // No conflicting transactions, so coordinator will start it immediately: | 136 // No conflicting transactions, so coordinator will start it immediately: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 148 | 148 |
| 149 // Clean up to avoid leaks. | 149 // Clean up to avoid leaks. |
| 150 transaction->Abort(); | 150 transaction->Abort(); |
| 151 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 151 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 152 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 152 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST_P(IndexedDBTransactionTestMode, ScheduleNormalTask) { | 155 TEST_P(IndexedDBTransactionTestMode, ScheduleNormalTask) { |
| 156 const int64 id = 0; | 156 const int64 id = 0; |
| 157 const std::set<int64> scope; | 157 const std::set<int64> scope; |
| 158 const bool commit_failure = false; | 158 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 159 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 159 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 160 id, | 160 id, |
| 161 new MockIndexedDBDatabaseCallbacks(), | 161 new MockIndexedDBDatabaseCallbacks(), |
| 162 scope, | 162 scope, |
| 163 GetParam(), | 163 GetParam(), |
| 164 db_, | 164 db_, |
| 165 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); | 165 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 166 | 166 |
| 167 EXPECT_FALSE(transaction->HasPendingTasks()); | 167 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 168 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 168 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 169 EXPECT_TRUE(transaction->task_queue_.empty()); | 169 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 170 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 170 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 171 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 171 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 172 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 172 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 173 | 173 |
| 174 db_->TransactionCreated(transaction); | 174 db_->TransactionCreated(transaction); |
| 175 | 175 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 210 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 211 EXPECT_TRUE(transaction->task_queue_.empty()); | 211 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 212 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 212 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 213 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); | 213 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 214 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); | 214 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); |
| 215 } | 215 } |
| 216 | 216 |
| 217 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { | 217 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { |
| 218 const int64 id = 0; | 218 const int64 id = 0; |
| 219 const std::set<int64> scope; | 219 const std::set<int64> scope; |
| 220 const bool commit_failure = false; | 220 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); |
| 221 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 221 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 222 id, | 222 id, |
| 223 new MockIndexedDBDatabaseCallbacks(), | 223 new MockIndexedDBDatabaseCallbacks(), |
| 224 scope, | 224 scope, |
| 225 indexed_db::TRANSACTION_VERSION_CHANGE, | 225 indexed_db::TRANSACTION_VERSION_CHANGE, |
| 226 db_, | 226 db_, |
| 227 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); | 227 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); |
| 228 | 228 |
| 229 EXPECT_FALSE(transaction->HasPendingTasks()); | 229 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 230 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 230 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 271 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 272 EXPECT_TRUE(transaction->task_queue_.empty()); | 272 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 273 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 273 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 274 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 274 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 275 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 275 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_P(IndexedDBTransactionTestMode, AbortTasks) { | 278 TEST_P(IndexedDBTransactionTestMode, AbortTasks) { |
| 279 const int64 id = 0; | 279 const int64 id = 0; |
| 280 const std::set<int64> scope; | 280 const std::set<int64> scope; |
| 281 const bool commit_failure = false; | 281 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); |
| 282 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 282 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 283 id, | 283 id, |
| 284 new MockIndexedDBDatabaseCallbacks(), | 284 new MockIndexedDBDatabaseCallbacks(), |
| 285 scope, | 285 scope, |
| 286 GetParam(), | 286 GetParam(), |
| 287 db_, | 287 db_, |
| 288 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); | 288 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); |
| 289 db_->TransactionCreated(transaction); | 289 db_->TransactionCreated(transaction); |
| 290 | 290 |
| 291 AbortObserver observer; | 291 AbortObserver observer; |
| 292 transaction->ScheduleTask( | 292 transaction->ScheduleTask( |
| 293 base::Bind(&IndexedDBTransactionTest::AbortableOperation, | 293 base::Bind(&IndexedDBTransactionTest::AbortableOperation, |
| 294 base::Unretained(this), | 294 base::Unretained(this), |
| 295 base::Unretained(&observer))); | 295 base::Unretained(&observer))); |
| 296 | 296 |
| 297 // Pump the message loop so that the transaction completes all pending tasks, | 297 // Pump the message loop so that the transaction completes all pending tasks, |
| 298 // otherwise it will defer the commit. | 298 // otherwise it will defer the commit. |
| 299 base::MessageLoop::current()->RunUntilIdle(); | 299 base::MessageLoop::current()->RunUntilIdle(); |
| 300 | 300 |
| 301 EXPECT_FALSE(observer.abort_task_called()); | 301 EXPECT_FALSE(observer.abort_task_called()); |
| 302 transaction->Commit(); | 302 transaction->Commit(); |
| 303 EXPECT_TRUE(observer.abort_task_called()); | 303 EXPECT_TRUE(observer.abort_task_called()); |
| 304 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 304 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 305 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 305 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 TEST_P(IndexedDBTransactionTestMode, AbortPreemptive) { | 308 TEST_P(IndexedDBTransactionTestMode, AbortPreemptive) { |
| 309 const int64 id = 0; | 309 const int64 id = 0; |
| 310 const std::set<int64> scope; | 310 const std::set<int64> scope; |
| 311 const bool commit_success = true; | 311 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 312 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 312 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 313 id, | 313 id, |
| 314 new MockIndexedDBDatabaseCallbacks(), | 314 new MockIndexedDBDatabaseCallbacks(), |
| 315 scope, | 315 scope, |
| 316 GetParam(), | 316 GetParam(), |
| 317 db_, | 317 db_, |
| 318 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 318 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 319 db_->TransactionCreated(transaction); | 319 db_->TransactionCreated(transaction); |
| 320 | 320 |
| 321 // No conflicting transactions, so coordinator will start it immediately: | 321 // No conflicting transactions, so coordinator will start it immediately: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 indexed_db::TRANSACTION_READ_ONLY, | 360 indexed_db::TRANSACTION_READ_ONLY, |
| 361 indexed_db::TRANSACTION_READ_WRITE, | 361 indexed_db::TRANSACTION_READ_WRITE, |
| 362 indexed_db::TRANSACTION_VERSION_CHANGE | 362 indexed_db::TRANSACTION_VERSION_CHANGE |
| 363 }; | 363 }; |
| 364 | 364 |
| 365 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, | 365 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, |
| 366 IndexedDBTransactionTestMode, | 366 IndexedDBTransactionTestMode, |
| 367 ::testing::ValuesIn(kTestModes)); | 367 ::testing::ValuesIn(kTestModes)); |
| 368 | 368 |
| 369 } // namespace content | 369 } // namespace content |
| OLD | NEW |