| 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> | 7 #include <stdint.h> |
| 8 #include <memory> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "content/browser/indexed_db/indexed_db_connection.h" | 15 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 15 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" | 16 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
| 16 #include "content/browser/indexed_db/indexed_db_observer.h" | 17 #include "content/browser/indexed_db/indexed_db_observer.h" |
| 17 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 18 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
| 18 #include "content/browser/indexed_db/mock_indexed_db_factory.h" | 19 #include "content/browser/indexed_db/mock_indexed_db_factory.h" |
| 19 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 24 const int kFakeProcessId = 10; |
| 23 | 25 |
| 24 class AbortObserver { | 26 class AbortObserver { |
| 25 public: | 27 public: |
| 26 AbortObserver() : abort_task_called_(false) {} | 28 AbortObserver() : abort_task_called_(false) {} |
| 27 | 29 |
| 28 void AbortTask(IndexedDBTransaction* transaction) { | 30 void AbortTask(IndexedDBTransaction* transaction) { |
| 29 abort_task_called_ = true; | 31 abort_task_called_ = true; |
| 30 } | 32 } |
| 31 | 33 |
| 32 bool abort_task_called() const { return abort_task_called_; } | 34 bool abort_task_called() const { return abort_task_called_; } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 60 void DummyOperation(IndexedDBTransaction* transaction) {} | 62 void DummyOperation(IndexedDBTransaction* transaction) {} |
| 61 void AbortableOperation(AbortObserver* observer, | 63 void AbortableOperation(AbortObserver* observer, |
| 62 IndexedDBTransaction* transaction) { | 64 IndexedDBTransaction* transaction) { |
| 63 transaction->ScheduleAbortTask( | 65 transaction->ScheduleAbortTask( |
| 64 base::Bind(&AbortObserver::AbortTask, base::Unretained(observer))); | 66 base::Bind(&AbortObserver::AbortTask, base::Unretained(observer))); |
| 65 } | 67 } |
| 66 | 68 |
| 67 protected: | 69 protected: |
| 68 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; | 70 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; |
| 69 scoped_refptr<IndexedDBDatabase> db_; | 71 scoped_refptr<IndexedDBDatabase> db_; |
| 72 url::Origin fake_connection_origin_; |
| 70 | 73 |
| 71 private: | 74 private: |
| 72 scoped_refptr<MockIndexedDBFactory> factory_; | 75 scoped_refptr<MockIndexedDBFactory> factory_; |
| 73 TestBrowserThreadBundle thread_bundle_; | 76 TestBrowserThreadBundle thread_bundle_; |
| 74 | 77 |
| 75 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTest); | 78 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTest); |
| 76 }; | 79 }; |
| 77 | 80 |
| 78 class IndexedDBTransactionTestMode | 81 class IndexedDBTransactionTestMode |
| 79 : public IndexedDBTransactionTest, | 82 : public IndexedDBTransactionTest, |
| 80 public testing::WithParamInterface<blink::WebIDBTransactionMode> { | 83 public testing::WithParamInterface<blink::WebIDBTransactionMode> { |
| 81 public: | 84 public: |
| 82 IndexedDBTransactionTestMode() {} | 85 IndexedDBTransactionTestMode() {} |
| 83 private: | 86 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); | 87 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); |
| 85 }; | 88 }; |
| 86 | 89 |
| 87 TEST_F(IndexedDBTransactionTest, Timeout) { | 90 TEST_F(IndexedDBTransactionTest, Timeout) { |
| 88 const int64_t id = 0; | 91 const int64_t id = 0; |
| 89 const std::set<int64_t> scope; | 92 const std::set<int64_t> scope; |
| 90 const leveldb::Status commit_success = leveldb::Status::OK(); | 93 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 91 std::unique_ptr<IndexedDBConnection> connection( | 94 std::unique_ptr<IndexedDBConnection> connection( |
| 92 base::MakeUnique<IndexedDBConnection>( | 95 base::MakeUnique<IndexedDBConnection>( |
| 93 db_, new MockIndexedDBDatabaseCallbacks())); | 96 kFakeProcessId, fake_connection_origin_, db_, |
| 94 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 97 new MockIndexedDBDatabaseCallbacks())); |
| 95 id, connection->GetWeakPtr(), scope, | 98 std::unique_ptr<IndexedDBTransaction> transaction = |
| 96 blink::WebIDBTransactionModeReadWrite, | 99 std::unique_ptr<IndexedDBTransaction>(new IndexedDBTransaction( |
| 97 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 100 id, connection.get(), scope, blink::WebIDBTransactionModeReadWrite, |
| 101 new IndexedDBFakeBackingStore::FakeTransaction(commit_success))); |
| 98 db_->TransactionCreated(transaction.get()); | 102 db_->TransactionCreated(transaction.get()); |
| 99 | 103 |
| 100 // No conflicting transactions, so coordinator will start it immediately: | 104 // No conflicting transactions, so coordinator will start it immediately: |
| 101 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 105 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 102 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 106 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 103 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 107 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 104 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 108 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 105 | 109 |
| 106 // Schedule a task - timer won't be started until it's processed. | 110 // Schedule a task - timer won't be started until it's processed. |
| 107 transaction->ScheduleTask(base::Bind( | 111 transaction->ScheduleTask(base::Bind( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 127 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); | 131 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 128 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); | 132 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); |
| 129 } | 133 } |
| 130 | 134 |
| 131 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { | 135 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { |
| 132 const int64_t id = 0; | 136 const int64_t id = 0; |
| 133 const std::set<int64_t> scope; | 137 const std::set<int64_t> scope; |
| 134 const leveldb::Status commit_success = leveldb::Status::OK(); | 138 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 135 std::unique_ptr<IndexedDBConnection> connection( | 139 std::unique_ptr<IndexedDBConnection> connection( |
| 136 base::MakeUnique<IndexedDBConnection>( | 140 base::MakeUnique<IndexedDBConnection>( |
| 137 db_, new MockIndexedDBDatabaseCallbacks())); | 141 kFakeProcessId, fake_connection_origin_, db_, |
| 138 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 142 new MockIndexedDBDatabaseCallbacks())); |
| 139 id, connection->GetWeakPtr(), scope, blink::WebIDBTransactionModeReadOnly, | 143 std::unique_ptr<IndexedDBTransaction> transaction = |
| 140 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 144 std::unique_ptr<IndexedDBTransaction>(new IndexedDBTransaction( |
| 145 id, connection.get(), scope, blink::WebIDBTransactionModeReadOnly, |
| 146 new IndexedDBFakeBackingStore::FakeTransaction(commit_success))); |
| 141 db_->TransactionCreated(transaction.get()); | 147 db_->TransactionCreated(transaction.get()); |
| 142 | 148 |
| 143 // No conflicting transactions, so coordinator will start it immediately: | 149 // No conflicting transactions, so coordinator will start it immediately: |
| 144 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 150 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 145 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 151 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 146 | 152 |
| 147 // Schedule a task - timer won't be started until it's processed. | 153 // Schedule a task - timer won't be started until it's processed. |
| 148 transaction->ScheduleTask(base::Bind( | 154 transaction->ScheduleTask(base::Bind( |
| 149 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | 155 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); |
| 150 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 156 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 151 | 157 |
| 152 // Transaction is read-only, so no need to time it out. | 158 // Transaction is read-only, so no need to time it out. |
| 153 RunPostedTasks(); | 159 RunPostedTasks(); |
| 154 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 160 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 155 | 161 |
| 156 // Clean up to avoid leaks. | 162 // Clean up to avoid leaks. |
| 157 transaction->Abort(); | 163 transaction->Abort(); |
| 158 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 164 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 159 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 165 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 160 } | 166 } |
| 161 | 167 |
| 162 TEST_P(IndexedDBTransactionTestMode, ScheduleNormalTask) { | 168 TEST_P(IndexedDBTransactionTestMode, ScheduleNormalTask) { |
| 163 const int64_t id = 0; | 169 const int64_t id = 0; |
| 164 const std::set<int64_t> scope; | 170 const std::set<int64_t> scope; |
| 165 const leveldb::Status commit_success = leveldb::Status::OK(); | 171 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 166 std::unique_ptr<IndexedDBConnection> connection( | 172 std::unique_ptr<IndexedDBConnection> connection( |
| 167 base::MakeUnique<IndexedDBConnection>( | 173 base::MakeUnique<IndexedDBConnection>( |
| 168 db_, new MockIndexedDBDatabaseCallbacks())); | 174 kFakeProcessId, fake_connection_origin_, db_, |
| 169 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 175 new MockIndexedDBDatabaseCallbacks())); |
| 170 id, connection->GetWeakPtr(), scope, GetParam(), | 176 std::unique_ptr<IndexedDBTransaction> transaction = |
| 171 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 177 std::unique_ptr<IndexedDBTransaction>(new IndexedDBTransaction( |
| 178 id, connection.get(), scope, GetParam(), |
| 179 new IndexedDBFakeBackingStore::FakeTransaction(commit_success))); |
| 172 | 180 |
| 173 EXPECT_FALSE(transaction->HasPendingTasks()); | 181 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 174 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 182 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 175 EXPECT_TRUE(transaction->task_queue_.empty()); | 183 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 176 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 184 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 177 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 185 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 178 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 186 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 179 | 187 |
| 180 db_->TransactionCreated(transaction.get()); | 188 db_->TransactionCreated(transaction.get()); |
| 181 | 189 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); | 227 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); |
| 220 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); | 228 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); |
| 221 } | 229 } |
| 222 | 230 |
| 223 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { | 231 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { |
| 224 const int64_t id = 0; | 232 const int64_t id = 0; |
| 225 const std::set<int64_t> scope; | 233 const std::set<int64_t> scope; |
| 226 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); | 234 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); |
| 227 std::unique_ptr<IndexedDBConnection> connection( | 235 std::unique_ptr<IndexedDBConnection> connection( |
| 228 base::MakeUnique<IndexedDBConnection>( | 236 base::MakeUnique<IndexedDBConnection>( |
| 229 db_, new MockIndexedDBDatabaseCallbacks())); | 237 kFakeProcessId, fake_connection_origin_, db_, |
| 230 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 238 new MockIndexedDBDatabaseCallbacks())); |
| 231 id, connection->GetWeakPtr(), scope, | 239 std::unique_ptr<IndexedDBTransaction> transaction = |
| 232 blink::WebIDBTransactionModeVersionChange, | 240 std::unique_ptr<IndexedDBTransaction>(new IndexedDBTransaction( |
| 233 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); | 241 id, connection.get(), scope, |
| 242 blink::WebIDBTransactionModeVersionChange, |
| 243 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure))); |
| 234 | 244 |
| 235 EXPECT_FALSE(transaction->HasPendingTasks()); | 245 EXPECT_FALSE(transaction->HasPendingTasks()); |
| 236 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); | 246 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); |
| 237 EXPECT_TRUE(transaction->task_queue_.empty()); | 247 EXPECT_TRUE(transaction->task_queue_.empty()); |
| 238 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); | 248 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); |
| 239 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 249 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 240 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 250 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 241 | 251 |
| 242 db_->TransactionCreated(transaction.get()); | 252 db_->TransactionCreated(transaction.get()); |
| 243 | 253 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); | 290 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); |
| 281 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); | 291 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); |
| 282 } | 292 } |
| 283 | 293 |
| 284 TEST_P(IndexedDBTransactionTestMode, AbortTasks) { | 294 TEST_P(IndexedDBTransactionTestMode, AbortTasks) { |
| 285 const int64_t id = 0; | 295 const int64_t id = 0; |
| 286 const std::set<int64_t> scope; | 296 const std::set<int64_t> scope; |
| 287 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); | 297 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch."); |
| 288 std::unique_ptr<IndexedDBConnection> connection( | 298 std::unique_ptr<IndexedDBConnection> connection( |
| 289 base::MakeUnique<IndexedDBConnection>( | 299 base::MakeUnique<IndexedDBConnection>( |
| 290 db_, new MockIndexedDBDatabaseCallbacks())); | 300 kFakeProcessId, fake_connection_origin_, db_, |
| 291 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 301 new MockIndexedDBDatabaseCallbacks())); |
| 292 id, connection->GetWeakPtr(), scope, GetParam(), | 302 std::unique_ptr<IndexedDBTransaction> transaction = |
| 293 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); | 303 std::unique_ptr<IndexedDBTransaction>(new IndexedDBTransaction( |
| 304 id, connection.get(), scope, GetParam(), |
| 305 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure))); |
| 294 db_->TransactionCreated(transaction.get()); | 306 db_->TransactionCreated(transaction.get()); |
| 295 | 307 |
| 296 AbortObserver observer; | 308 AbortObserver observer; |
| 297 transaction->ScheduleTask( | 309 transaction->ScheduleTask( |
| 298 base::Bind(&IndexedDBTransactionTest::AbortableOperation, | 310 base::Bind(&IndexedDBTransactionTest::AbortableOperation, |
| 299 base::Unretained(this), | 311 base::Unretained(this), |
| 300 base::Unretained(&observer))); | 312 base::Unretained(&observer))); |
| 301 | 313 |
| 302 // Pump the message loop so that the transaction completes all pending tasks, | 314 // Pump the message loop so that the transaction completes all pending tasks, |
| 303 // otherwise it will defer the commit. | 315 // otherwise it will defer the commit. |
| 304 base::RunLoop().RunUntilIdle(); | 316 base::RunLoop().RunUntilIdle(); |
| 305 | 317 |
| 306 EXPECT_FALSE(observer.abort_task_called()); | 318 EXPECT_FALSE(observer.abort_task_called()); |
| 307 transaction->Commit(); | 319 transaction->Commit(); |
| 308 EXPECT_TRUE(observer.abort_task_called()); | 320 EXPECT_TRUE(observer.abort_task_called()); |
| 309 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 321 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
| 310 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 322 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 311 } | 323 } |
| 312 | 324 |
| 313 TEST_P(IndexedDBTransactionTestMode, AbortPreemptive) { | 325 TEST_P(IndexedDBTransactionTestMode, AbortPreemptive) { |
| 314 const int64_t id = 0; | 326 const int64_t id = 0; |
| 315 const std::set<int64_t> scope; | 327 const std::set<int64_t> scope; |
| 316 const leveldb::Status commit_success = leveldb::Status::OK(); | 328 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 317 std::unique_ptr<IndexedDBConnection> connection( | 329 std::unique_ptr<IndexedDBConnection> connection( |
| 318 base::MakeUnique<IndexedDBConnection>( | 330 base::MakeUnique<IndexedDBConnection>( |
| 319 db_, new MockIndexedDBDatabaseCallbacks())); | 331 kFakeProcessId, fake_connection_origin_, db_, |
| 320 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 332 new MockIndexedDBDatabaseCallbacks())); |
| 321 id, connection->GetWeakPtr(), scope, GetParam(), | 333 std::unique_ptr<IndexedDBTransaction> transaction = |
| 322 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 334 std::unique_ptr<IndexedDBTransaction>(new IndexedDBTransaction( |
| 335 id, connection.get(), scope, GetParam(), |
| 336 new IndexedDBFakeBackingStore::FakeTransaction(commit_success))); |
| 323 db_->TransactionCreated(transaction.get()); | 337 db_->TransactionCreated(transaction.get()); |
| 324 | 338 |
| 325 // No conflicting transactions, so coordinator will start it immediately: | 339 // No conflicting transactions, so coordinator will start it immediately: |
| 326 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 340 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 327 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 341 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
| 328 | 342 |
| 329 transaction->ScheduleTask( | 343 transaction->ScheduleTask( |
| 330 blink::WebIDBTaskTypePreemptive, | 344 blink::WebIDBTaskTypePreemptive, |
| 331 base::Bind(&IndexedDBTransactionTest::DummyOperation, | 345 base::Bind(&IndexedDBTransactionTest::DummyOperation, |
| 332 base::Unretained(this))); | 346 base::Unretained(this))); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 359 EXPECT_EQ(transaction->diagnostics().tasks_completed, | 373 EXPECT_EQ(transaction->diagnostics().tasks_completed, |
| 360 transaction->diagnostics().tasks_scheduled); | 374 transaction->diagnostics().tasks_scheduled); |
| 361 } | 375 } |
| 362 | 376 |
| 363 TEST_F(IndexedDBTransactionTest, IndexedDBObserver) { | 377 TEST_F(IndexedDBTransactionTest, IndexedDBObserver) { |
| 364 const int64_t id = 0; | 378 const int64_t id = 0; |
| 365 const std::set<int64_t> scope; | 379 const std::set<int64_t> scope; |
| 366 const leveldb::Status commit_success = leveldb::Status::OK(); | 380 const leveldb::Status commit_success = leveldb::Status::OK(); |
| 367 std::unique_ptr<IndexedDBConnection> connection( | 381 std::unique_ptr<IndexedDBConnection> connection( |
| 368 base::MakeUnique<IndexedDBConnection>( | 382 base::MakeUnique<IndexedDBConnection>( |
| 369 db_, new MockIndexedDBDatabaseCallbacks())); | 383 kFakeProcessId, fake_connection_origin_, db_, |
| 370 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 384 new MockIndexedDBDatabaseCallbacks())); |
| 371 id, connection->GetWeakPtr(), scope, | 385 |
| 372 blink::WebIDBTransactionModeReadWrite, | 386 IndexedDBTransaction* transaction = connection->StoreTransactionForTesting( |
| 373 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 387 std::unique_ptr<IndexedDBTransaction>(new IndexedDBTransaction( |
| 374 db_->TransactionCreated(transaction.get()); | 388 id, connection.get(), scope, blink::WebIDBTransactionModeReadWrite, |
| 389 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)))); |
| 390 db_->TransactionCreated(transaction); |
| 375 | 391 |
| 376 EXPECT_EQ(0UL, transaction->pending_observers_.size()); | 392 EXPECT_EQ(0UL, transaction->pending_observers_.size()); |
| 377 EXPECT_EQ(0UL, connection->active_observers().size()); | 393 EXPECT_EQ(0UL, connection->active_observers().size()); |
| 378 | 394 |
| 379 // Add observers to pending observer list. | 395 // Add observers to pending observer list. |
| 380 const int32_t observer_id1 = 1, observer_id2 = 2; | 396 const int32_t observer_id1 = 1, observer_id2 = 2; |
| 381 IndexedDBObserver::Options options(false, false, false, 0U); | 397 IndexedDBObserver::Options options(false, false, false, 0U); |
| 382 transaction->AddPendingObserver(observer_id1, options); | 398 transaction->AddPendingObserver(observer_id1, options); |
| 383 transaction->AddPendingObserver(observer_id2, options); | 399 transaction->AddPendingObserver(observer_id2, options); |
| 384 EXPECT_EQ(2UL, transaction->pending_observers_.size()); | 400 EXPECT_EQ(2UL, transaction->pending_observers_.size()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 407 | 423 |
| 408 static const blink::WebIDBTransactionMode kTestModes[] = { | 424 static const blink::WebIDBTransactionMode kTestModes[] = { |
| 409 blink::WebIDBTransactionModeReadOnly, blink::WebIDBTransactionModeReadWrite, | 425 blink::WebIDBTransactionModeReadOnly, blink::WebIDBTransactionModeReadWrite, |
| 410 blink::WebIDBTransactionModeVersionChange}; | 426 blink::WebIDBTransactionModeVersionChange}; |
| 411 | 427 |
| 412 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, | 428 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, |
| 413 IndexedDBTransactionTestMode, | 429 IndexedDBTransactionTestMode, |
| 414 ::testing::ValuesIn(kTestModes)); | 430 ::testing::ValuesIn(kTestModes)); |
| 415 | 431 |
| 416 } // namespace content | 432 } // namespace content |
| OLD | NEW |