| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTest); | 68 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTest); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 class IndexedDBTransactionTestMode : public IndexedDBTransactionTest, | 71 class IndexedDBTransactionTestMode |
| 72 public testing::WithParamInterface<indexed_db::TransactionMode> { | 72 : public IndexedDBTransactionTest, |
| 73 public testing::WithParamInterface<blink::WebIDBTransactionMode> { |
| 73 public: | 74 public: |
| 74 IndexedDBTransactionTestMode() {} | 75 IndexedDBTransactionTestMode() {} |
| 75 private: | 76 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); | 77 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 TEST_F(IndexedDBTransactionTest, Timeout) { | 80 TEST_F(IndexedDBTransactionTest, Timeout) { |
| 80 const int64 id = 0; | 81 const int64 id = 0; |
| 81 const std::set<int64> scope; | 82 const std::set<int64> scope; |
| 82 const leveldb::Status commit_success = leveldb::Status::OK(); | 83 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 83 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 84 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 84 id, | 85 id, |
| 85 new MockIndexedDBDatabaseCallbacks(), | 86 new MockIndexedDBDatabaseCallbacks(), |
| 86 scope, | 87 scope, |
| 87 indexed_db::TRANSACTION_READ_WRITE, | 88 blink::WebIDBTransactionModeReadWrite, |
| 88 db_, | 89 db_, |
| 89 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 90 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 90 db_->TransactionCreated(transaction); | 91 db_->TransactionCreated(transaction); |
| 91 | 92 |
| 92 // No conflicting transactions, so coordinator will start it immediately: | 93 // No conflicting transactions, so coordinator will start it immediately: |
| 93 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 94 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 94 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 95 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 95 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 96 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 96 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 97 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 97 | 98 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 121 } | 122 } |
| 122 | 123 |
| 123 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { | 124 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { |
| 124 const int64 id = 0; | 125 const int64 id = 0; |
| 125 const std::set<int64> scope; | 126 const std::set<int64> scope; |
| 126 const leveldb::Status commit_success = leveldb::Status::OK(); | 127 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 127 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 128 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 128 id, | 129 id, |
| 129 new MockIndexedDBDatabaseCallbacks(), | 130 new MockIndexedDBDatabaseCallbacks(), |
| 130 scope, | 131 scope, |
| 131 indexed_db::TRANSACTION_READ_ONLY, | 132 blink::WebIDBTransactionModeReadOnly, |
| 132 db_, | 133 db_, |
| 133 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 134 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 134 db_->TransactionCreated(transaction); | 135 db_->TransactionCreated(transaction); |
| 135 | 136 |
| 136 // No conflicting transactions, so coordinator will start it immediately: | 137 // No conflicting transactions, so coordinator will start it immediately: |
| 137 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 138 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 138 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 139 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 139 | 140 |
| 140 // Schedule a task - timer won't be started until it's processed. | 141 // Schedule a task - timer won't be started until it's processed. |
| 141 transaction->ScheduleTask(base::Bind( | 142 transaction->ScheduleTask(base::Bind( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 172 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 173 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 173 | 174 |
| 174 db_->TransactionCreated(transaction); | 175 db_->TransactionCreated(transaction); |
| 175 | 176 |
| 176 EXPECT_FALSE(transaction->HasPendingTasks()); | 177 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 177 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 178 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 178 EXPECT_TRUE(transaction->task_queue_.empty()); | 179 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 179 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 180 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 180 | 181 |
| 181 transaction->ScheduleTask( | 182 transaction->ScheduleTask( |
| 182 IndexedDBDatabase::NORMAL_TASK, | 183 blink::WebIDBTaskTypeNormal, |
| 183 base::Bind(&IndexedDBTransactionTest::DummyOperation, | 184 base::Bind(&IndexedDBTransactionTest::DummyOperation, |
| 184 base::Unretained(this))); | 185 base::Unretained(this))); |
| 185 | 186 |
| 186 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); | 187 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 187 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 188 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 188 | 189 |
| 189 EXPECT_TRUE(transaction->HasPendingTasks()); | 190 EXPECT_TRUE(transaction->HasPendingTasks()); |
| 190 EXPECT_FALSE(transaction->IsTaskQueueEmpty()); | 191 EXPECT_FALSE(transaction->IsTaskQueueEmpty()); |
| 191 EXPECT_FALSE(transaction->task_queue_.empty()); | 192 EXPECT_FALSE(transaction->task_queue_.empty()); |
| 192 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 193 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 215 } | 216 } |
| 216 | 217 |
| 217 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { | 218 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { |
| 218 const int64 id = 0; | 219 const int64 id = 0; |
| 219 const std::set<int64> scope; | 220 const std::set<int64> scope; |
| 220 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); | 221 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); |
| 221 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 222 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
| 222 id, | 223 id, |
| 223 new MockIndexedDBDatabaseCallbacks(), | 224 new MockIndexedDBDatabaseCallbacks(), |
| 224 scope, | 225 scope, |
| 225 indexed_db::TRANSACTION_VERSION_CHANGE, | 226 blink::WebIDBTransactionModeVersionChange, |
| 226 db_, | 227 db_, |
| 227 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); | 228 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); |
| 228 | 229 |
| 229 EXPECT_FALSE(transaction->HasPendingTasks()); | 230 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 230 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 231 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 231 EXPECT_TRUE(transaction->task_queue_.empty()); | 232 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 232 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 233 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 233 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 234 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 234 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 235 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 235 | 236 |
| 236 db_->TransactionCreated(transaction); | 237 db_->TransactionCreated(transaction); |
| 237 | 238 |
| 238 EXPECT_FALSE(transaction->HasPendingTasks()); | 239 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 239 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 240 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 240 EXPECT_TRUE(transaction->task_queue_.empty()); | 241 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 241 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 242 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 242 | 243 |
| 243 transaction->ScheduleTask( | 244 transaction->ScheduleTask( |
| 244 IndexedDBDatabase::PREEMPTIVE_TASK, | 245 blink::WebIDBTaskTypePreemptive, |
| 245 base::Bind(&IndexedDBTransactionTest::DummyOperation, | 246 base::Bind(&IndexedDBTransactionTest::DummyOperation, |
| 246 base::Unretained(this))); | 247 base::Unretained(this))); |
| 247 transaction->AddPreemptiveEvent(); | 248 transaction->AddPreemptiveEvent(); |
| 248 | 249 |
| 249 EXPECT_TRUE(transaction->HasPendingTasks()); | 250 EXPECT_TRUE(transaction->HasPendingTasks()); |
| 250 EXPECT_FALSE(transaction->IsTaskQueueEmpty()); | 251 EXPECT_FALSE(transaction->IsTaskQueueEmpty()); |
| 251 EXPECT_TRUE(transaction->task_queue_.empty()); | 252 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 252 EXPECT_FALSE(transaction->preemptive_task_queue_.empty()); | 253 EXPECT_FALSE(transaction->preemptive_task_queue_.empty()); |
| 253 | 254 |
| 254 // Pump the message loop so that the transaction completes all pending tasks, | 255 // Pump the message loop so that the transaction completes all pending tasks, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 GetParam(), | 317 GetParam(), |
| 317 db_, | 318 db_, |
| 318 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 319 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
| 319 db_->TransactionCreated(transaction); | 320 db_->TransactionCreated(transaction); |
| 320 | 321 |
| 321 // No conflicting transactions, so coordinator will start it immediately: | 322 // No conflicting transactions, so coordinator will start it immediately: |
| 322 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 323 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 323 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 324 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 324 | 325 |
| 325 transaction->ScheduleTask( | 326 transaction->ScheduleTask( |
| 326 IndexedDBDatabase::PREEMPTIVE_TASK, | 327 blink::WebIDBTaskTypePreemptive, |
| 327 base::Bind(&IndexedDBTransactionTest::DummyOperation, | 328 base::Bind(&IndexedDBTransactionTest::DummyOperation, |
| 328 base::Unretained(this))); | 329 base::Unretained(this))); |
| 329 EXPECT_EQ(0, transaction->pending_preemptive_events_); | 330 EXPECT_EQ(0, transaction->pending_preemptive_events_); |
| 330 transaction->AddPreemptiveEvent(); | 331 transaction->AddPreemptiveEvent(); |
| 331 EXPECT_EQ(1, transaction->pending_preemptive_events_); | 332 EXPECT_EQ(1, transaction->pending_preemptive_events_); |
| 332 | 333 |
| 333 RunPostedTasks(); | 334 RunPostedTasks(); |
| 334 | 335 |
| 335 transaction->Abort(); | 336 transaction->Abort(); |
| 336 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 337 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 349 // This task will be ignored. | 350 // This task will be ignored. |
| 350 transaction->ScheduleTask(base::Bind( | 351 transaction->ScheduleTask(base::Bind( |
| 351 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | 352 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); |
| 352 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 353 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 353 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 354 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 354 EXPECT_FALSE(transaction->HasPendingTasks()); | 355 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 355 EXPECT_EQ(transaction->diagnostics().tasks_completed, | 356 EXPECT_EQ(transaction->diagnostics().tasks_completed, |
| 356 transaction->diagnostics().tasks_scheduled); | 357 transaction->diagnostics().tasks_scheduled); |
| 357 } | 358 } |
| 358 | 359 |
| 359 static const indexed_db::TransactionMode kTestModes[] = { | 360 static const blink::WebIDBTransactionMode kTestModes[] = { |
| 360 indexed_db::TRANSACTION_READ_ONLY, | 361 blink::WebIDBTransactionModeReadOnly, blink::WebIDBTransactionModeReadWrite, |
| 361 indexed_db::TRANSACTION_READ_WRITE, | 362 blink::WebIDBTransactionModeVersionChange}; |
| 362 indexed_db::TRANSACTION_VERSION_CHANGE | |
| 363 }; | |
| 364 | 363 |
| 365 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, | 364 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, |
| 366 IndexedDBTransactionTestMode, | 365 IndexedDBTransactionTestMode, |
| 367 ::testing::ValuesIn(kTestModes)); | 366 ::testing::ValuesIn(kTestModes)); |
| 368 | 367 |
| 369 } // namespace content | 368 } // namespace content |
| OLD | NEW |