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 30 matching lines...) Expand all Loading... |
41 }; | 41 }; |
42 | 42 |
43 TEST_F(IndexedDBTransactionTest, Timeout) { | 43 TEST_F(IndexedDBTransactionTest, Timeout) { |
44 const int64 id = 0; | 44 const int64 id = 0; |
45 const std::set<int64> scope; | 45 const std::set<int64> scope; |
46 const bool commit_success = true; | 46 const bool commit_success = true; |
47 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | 47 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
48 id, | 48 id, |
49 new MockIndexedDBDatabaseCallbacks(), | 49 new MockIndexedDBDatabaseCallbacks(), |
50 scope, | 50 scope, |
51 indexed_db::TRANSACTION_READ_WRITE, | 51 indexed_db::TRANSACTION_READ_ONLY, |
52 db_, | 52 db_, |
53 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | 53 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); |
54 db_->TransactionCreated(transaction); | 54 db_->TransactionCreated(transaction); |
55 | 55 |
56 // No conflicting transactions, so coordinator will start it immediately: | 56 // No conflicting transactions, so coordinator will start it immediately: |
57 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 57 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
58 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 58 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
59 | 59 |
60 // Schedule a task - timer won't be started until it's processed. | 60 // Schedule a task - timer won't be started until it's processed. |
61 transaction->ScheduleTask(base::Bind( | 61 transaction->ScheduleTask(base::Bind( |
62 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | 62 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); |
63 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 63 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
64 | 64 |
65 RunPostedTasks(); | 65 RunPostedTasks(); |
66 EXPECT_TRUE(transaction->IsTimeoutTimerRunning()); | 66 EXPECT_TRUE(transaction->IsTimeoutTimerRunning()); |
67 | 67 |
68 // Abort should cancel the timer. | 68 // Abort should cancel the timer. |
69 transaction->Abort(); | 69 transaction->Abort(); |
70 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 70 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
71 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 71 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
72 | 72 |
73 // This task will be ignored. | 73 // This task will be ignored. |
74 transaction->ScheduleTask(base::Bind( | 74 transaction->ScheduleTask(base::Bind( |
75 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | 75 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); |
76 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); | 76 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); |
77 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | 77 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); |
78 } | 78 } |
79 | 79 |
80 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { | |
81 const int64 id = 0; | |
82 const std::set<int64> scope; | |
83 const bool commit_success = true; | |
84 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( | |
85 id, | |
86 new MockIndexedDBDatabaseCallbacks(), | |
87 scope, | |
88 indexed_db::TRANSACTION_READ_ONLY, | |
89 db_, | |
90 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); | |
91 db_->TransactionCreated(transaction); | |
92 | |
93 // No conflicting transactions, so coordinator will start it immediately: | |
94 EXPECT_EQ(IndexedDBTransaction::STARTED, transaction->state()); | |
95 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | |
96 | |
97 // Schedule a task - timer won't be started until it's processed. | |
98 transaction->ScheduleTask(base::Bind( | |
99 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); | |
100 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | |
101 | |
102 // Transaction is read-only, so no need to time it out | |
103 RunPostedTasks(); | |
104 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); | |
105 } | |
106 | |
107 class AbortObserver { | 80 class AbortObserver { |
108 public: | 81 public: |
109 AbortObserver() : abort_task_called_(false) {} | 82 AbortObserver() : abort_task_called_(false) {} |
110 | 83 |
111 void AbortTask(IndexedDBTransaction* transaction) { | 84 void AbortTask(IndexedDBTransaction* transaction) { |
112 abort_task_called_ = true; | 85 abort_task_called_ = true; |
113 } | 86 } |
114 | 87 |
115 bool abort_task_called() const { return abort_task_called_; } | 88 bool abort_task_called() const { return abort_task_called_; } |
116 | 89 |
(...skipping 26 matching lines...) Expand all Loading... |
143 base::MessageLoop::current()->RunUntilIdle(); | 116 base::MessageLoop::current()->RunUntilIdle(); |
144 | 117 |
145 EXPECT_FALSE(observer.abort_task_called()); | 118 EXPECT_FALSE(observer.abort_task_called()); |
146 transaction->Commit(); | 119 transaction->Commit(); |
147 EXPECT_TRUE(observer.abort_task_called()); | 120 EXPECT_TRUE(observer.abort_task_called()); |
148 } | 121 } |
149 | 122 |
150 } // namespace | 123 } // namespace |
151 | 124 |
152 } // namespace content | 125 } // namespace content |
OLD | NEW |