diff options
author | jsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-09 20:50:17 +0000 |
---|---|---|
committer | jsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-09 20:50:17 +0000 |
commit | 1847c3ea3a8a43eed6957f03447eb3d275945f7b (patch) | |
tree | 09a290ba71e4a39b926bb0562c988b9e73b86ded /content/browser/indexed_db/indexed_db_transaction_unittest.cc | |
parent | a8573003348a043b80a62a28cbb8f67a37b092b3 (diff) | |
download | chromium_src-1847c3ea3a8a43eed6957f03447eb3d275945f7b.zip chromium_src-1847c3ea3a8a43eed6957f03447eb3d275945f7b.tar.gz chromium_src-1847c3ea3a8a43eed6957f03447eb3d275945f7b.tar.bz2 |
IndexedDB: Timeout transactions if front-end is unresponsive
Introduce a fixed time-out that limits how long a
transaction will wait after it handles the last request
before it gives up and aborts. This is to prevent "wedged"
renderers (not crashed but not turning the event loop, etc)
from holding up the transaction queue since they never
issue a another request or ask to commit.
(TBR for new file entry in gypi)
BUG=318992
R=dgrogam
TBR=jam
Review URL: https://codereview.chromium.org/67173010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239543 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/indexed_db/indexed_db_transaction_unittest.cc')
-rw-r--r-- | content/browser/indexed_db/indexed_db_transaction_unittest.cc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/content/browser/indexed_db/indexed_db_transaction_unittest.cc b/content/browser/indexed_db/indexed_db_transaction_unittest.cc new file mode 100644 index 0000000..3fc7271 --- /dev/null +++ b/content/browser/indexed_db/indexed_db_transaction_unittest.cc @@ -0,0 +1,82 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/indexed_db/indexed_db_transaction.h" + +#include "base/bind.h" +#include "base/logging.h" +#include "base/message_loop/message_loop.h" +#include "base/strings/utf_string_conversions.h" +#include "content/browser/indexed_db/indexed_db_fake_backing_store.h" +#include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace content { + +namespace { + +class IndexedDBTransactionTest : public testing::Test { + public: + IndexedDBTransactionTest() { + IndexedDBFactory* factory = NULL; + backing_store_ = new IndexedDBFakeBackingStore(); + db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"), + backing_store_, + factory, + IndexedDBDatabase::Identifier()); + } + + void RunPostedTasks() { message_loop_.RunUntilIdle(); } + void DummyOperation(IndexedDBTransaction* transaction) {} + + protected: + scoped_refptr<IndexedDBFakeBackingStore> backing_store_; + scoped_refptr<IndexedDBDatabase> db_; + + private: + base::MessageLoop message_loop_; + + DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTest); +}; + +TEST_F(IndexedDBTransactionTest, Timeout) { + const int64 id = 0; + const std::set<int64> scope; + const bool commit_success = true; + scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( + id, + new MockIndexedDBDatabaseCallbacks(), + scope, + indexed_db::TRANSACTION_READ_ONLY, + db_, + new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); + db_->TransactionCreated(transaction); + + // No conflicting transactions, so coordinator will start it immediately: + EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); + EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); + + // Schedule a task - timer won't be started until it's processed. + transaction->ScheduleTask(base::Bind( + &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); + EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); + + RunPostedTasks(); + EXPECT_TRUE(transaction->IsTimeoutTimerRunning()); + + // Abort should cancel the timer. + transaction->Abort(); + EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); + EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); + + // This task will be ignored. + transaction->ScheduleTask(base::Bind( + &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); + EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); + EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); +} + +} // namespace + +} // namespace content |