| 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 <stdint.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 11 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" | 14 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
| 12 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 15 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
| 13 #include "content/browser/indexed_db/mock_indexed_db_factory.h" | 16 #include "content/browser/indexed_db/mock_indexed_db_factory.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 18 |
| 16 namespace content { | 19 namespace content { |
| 17 | 20 |
| 18 class AbortObserver { | 21 class AbortObserver { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 class IndexedDBTransactionTestMode | 75 class IndexedDBTransactionTestMode |
| 73 : public IndexedDBTransactionTest, | 76 : public IndexedDBTransactionTest, |
| 74 public testing::WithParamInterface<blink::WebIDBTransactionMode> { | 77 public testing::WithParamInterface<blink::WebIDBTransactionMode> { |
| 75 public: | 78 public: |
| 76 IndexedDBTransactionTestMode() {} | 79 IndexedDBTransactionTestMode() {} |
| 77 private: | 80 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); | 81 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 TEST_F(IndexedDBTransactionTest, Timeout) { | 84 TEST_F(IndexedDBTransactionTest, Timeout) { |
| 82 const int64 id = 0; | 85 const int64_t id = 0; |
| 83 const std::set<int64> scope; | 86 const std::set<int64_t> scope; |
| 84 const leveldb::Status commit_success = leveldb::Status::OK(); | 87 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 85 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 88 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 86 id, | 89 id, |
| 87 new MockIndexedDBDatabaseCallbacks(), | 90 new MockIndexedDBDatabaseCallbacks(), |
| 88 scope, | 91 scope, |
| 89 blink::WebIDBTransactionModeReadWrite, | 92 blink::WebIDBTransactionModeReadWrite, |
| 90 db_.get(), | 93 db_.get(), |
| 91 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 94 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 92 db_->TransactionCreated(transaction.get()); | 95 db_->TransactionCreated(transaction.get()); |
| 93 | 96 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 116 // This task will be ignored. | 119 // This task will be ignored. |
| 117 transaction->ScheduleTask(base::Bind( | 120 transaction->ScheduleTask(base::Bind( |
| 118 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | 121 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); |
| 119 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 122 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 120 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 123 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 121 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); | 124 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 122 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); | 125 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); |
| 123 } | 126 } |
| 124 | 127 |
| 125 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { | 128 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { |
| 126 const int64 id = 0; | 129 const int64_t id = 0; |
| 127 const std::set<int64> scope; | 130 const std::set<int64_t> scope; |
| 128 const leveldb::Status commit_success = leveldb::Status::OK(); | 131 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 129 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 132 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 130 id, | 133 id, |
| 131 new MockIndexedDBDatabaseCallbacks(), | 134 new MockIndexedDBDatabaseCallbacks(), |
| 132 scope, | 135 scope, |
| 133 blink::WebIDBTransactionModeReadOnly, | 136 blink::WebIDBTransactionModeReadOnly, |
| 134 db_.get(), | 137 db_.get(), |
| 135 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 138 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 136 db_->TransactionCreated(transaction.get()); | 139 db_->TransactionCreated(transaction.get()); |
| 137 | 140 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 148 RunPostedTasks(); | 151 RunPostedTasks(); |
| 149 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 152 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 150 | 153 |
| 151 // Clean up to avoid leaks. | 154 // Clean up to avoid leaks. |
| 152 transaction->Abort(); | 155 transaction->Abort(); |
| 153 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 156 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 154 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 157 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 155 } | 158 } |
| 156 | 159 |
| 157 TEST_P(IndexedDBTransactionTestMode, ScheduleNormalTask) { | 160 TEST_P(IndexedDBTransactionTestMode, ScheduleNormalTask) { |
| 158 const int64 id = 0; | 161 const int64_t id = 0; |
| 159 const std::set<int64> scope; | 162 const std::set<int64_t> scope; |
| 160 const leveldb::Status commit_success = leveldb::Status::OK(); | 163 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 161 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 164 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 162 id, | 165 id, |
| 163 new MockIndexedDBDatabaseCallbacks(), | 166 new MockIndexedDBDatabaseCallbacks(), |
| 164 scope, | 167 scope, |
| 165 GetParam(), | 168 GetParam(), |
| 166 db_.get(), | 169 db_.get(), |
| 167 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 170 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 168 | 171 |
| 169 EXPECT_FALSE(transaction->HasPendingTasks()); | 172 EXPECT_FALSE(transaction->HasPendingTasks()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 EXPECT_FALSE(transaction->HasPendingTasks()); | 213 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 211 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 214 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 212 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 215 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 213 EXPECT_TRUE(transaction->task_queue_.empty()); | 216 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 214 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 217 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 215 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); | 218 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 216 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); | 219 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); |
| 217 } | 220 } |
| 218 | 221 |
| 219 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { | 222 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { |
| 220 const int64 id = 0; | 223 const int64_t id = 0; |
| 221 const std::set<int64> scope; | 224 const std::set<int64_t> scope; |
| 222 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); | 225 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); |
| 223 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 226 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 224 id, | 227 id, |
| 225 new MockIndexedDBDatabaseCallbacks(), | 228 new MockIndexedDBDatabaseCallbacks(), |
| 226 scope, | 229 scope, |
| 227 blink::WebIDBTransactionModeVersionChange, | 230 blink::WebIDBTransactionModeVersionChange, |
| 228 db_.get(), | 231 db_.get(), |
| 229 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); | 232 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); |
| 230 | 233 |
| 231 EXPECT_FALSE(transaction->HasPendingTasks()); | 234 EXPECT_FALSE(transaction->HasPendingTasks()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 EXPECT_FALSE(transaction->HasPendingTasks()); | 274 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 272 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 275 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 273 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 276 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 274 EXPECT_TRUE(transaction->task_queue_.empty()); | 277 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 275 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 278 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 276 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 279 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 277 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 280 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 278 } | 281 } |
| 279 | 282 |
| 280 TEST_P(IndexedDBTransactionTestMode, AbortTasks) { | 283 TEST_P(IndexedDBTransactionTestMode, AbortTasks) { |
| 281 const int64 id = 0; | 284 const int64_t id = 0; |
| 282 const std::set<int64> scope; | 285 const std::set<int64_t> scope; |
| 283 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); | 286 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); |
| 284 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 287 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 285 id, | 288 id, |
| 286 new MockIndexedDBDatabaseCallbacks(), | 289 new MockIndexedDBDatabaseCallbacks(), |
| 287 scope, | 290 scope, |
| 288 GetParam(), | 291 GetParam(), |
| 289 db_.get(), | 292 db_.get(), |
| 290 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); | 293 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); |
| 291 db_->TransactionCreated(transaction.get()); | 294 db_->TransactionCreated(transaction.get()); |
| 292 | 295 |
| 293 AbortObserver observer; | 296 AbortObserver observer; |
| 294 transaction->ScheduleTask( | 297 transaction->ScheduleTask( |
| 295 base::Bind(&IndexedDBTransactionTest::AbortableOperation, | 298 base::Bind(&IndexedDBTransactionTest::AbortableOperation, |
| 296 base::Unretained(this), | 299 base::Unretained(this), |
| 297 base::Unretained(&observer))); | 300 base::Unretained(&observer))); |
| 298 | 301 |
| 299 // Pump the message loop so that the transaction completes all pending tasks, | 302 // Pump the message loop so that the transaction completes all pending tasks, |
| 300 // otherwise it will defer the commit. | 303 // otherwise it will defer the commit. |
| 301 base::MessageLoop::current()->RunUntilIdle(); | 304 base::MessageLoop::current()->RunUntilIdle(); |
| 302 | 305 |
| 303 EXPECT_FALSE(observer.abort_task_called()); | 306 EXPECT_FALSE(observer.abort_task_called()); |
| 304 transaction->Commit(); | 307 transaction->Commit(); |
| 305 EXPECT_TRUE(observer.abort_task_called()); | 308 EXPECT_TRUE(observer.abort_task_called()); |
| 306 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 309 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 307 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 310 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 308 } | 311 } |
| 309 | 312 |
| 310 TEST_P(IndexedDBTransactionTestMode, AbortPreemptive) { | 313 TEST_P(IndexedDBTransactionTestMode, AbortPreemptive) { |
| 311 const int64 id = 0; | 314 const int64_t id = 0; |
| 312 const std::set<int64> scope; | 315 const std::set<int64_t> scope; |
| 313 const leveldb::Status commit_success = leveldb::Status::OK(); | 316 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 314 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 317 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 315 id, | 318 id, |
| 316 new MockIndexedDBDatabaseCallbacks(), | 319 new MockIndexedDBDatabaseCallbacks(), |
| 317 scope, | 320 scope, |
| 318 GetParam(), | 321 GetParam(), |
| 319 db_.get(), | 322 db_.get(), |
| 320 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 323 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 321 db_->TransactionCreated(transaction.get()); | 324 db_->TransactionCreated(transaction.get()); |
| 322 | 325 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 363 |
| 361 static const blink::WebIDBTransactionMode kTestModes[] = { | 364 static const blink::WebIDBTransactionMode kTestModes[] = { |
| 362 blink::WebIDBTransactionModeReadOnly, blink::WebIDBTransactionModeReadWrite, | 365 blink::WebIDBTransactionModeReadOnly, blink::WebIDBTransactionModeReadWrite, |
| 363 blink::WebIDBTransactionModeVersionChange}; | 366 blink::WebIDBTransactionModeVersionChange}; |
| 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 |