Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: content/browser/indexed_db/indexed_db_transaction_unittest.cc

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DeleteRange now seems to work. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 public testing::WithParamInterface<indexed_db::TransactionMode> { 52 public testing::WithParamInterface<indexed_db::TransactionMode> {
53 public: 53 public:
54 IndexedDBTransactionTestMode() {} 54 IndexedDBTransactionTestMode() {}
55 private: 55 private:
56 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode); 56 DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionTestMode);
57 }; 57 };
58 58
59 TEST_F(IndexedDBTransactionTest, Timeout) { 59 TEST_F(IndexedDBTransactionTest, Timeout) {
60 const int64 id = 0; 60 const int64 id = 0;
61 const std::set<int64> scope; 61 const std::set<int64> scope;
62 const bool commit_success = true; 62 const leveldb::Status commit_success = leveldb::Status::OK();
63 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( 63 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction(
64 id, 64 id,
65 new MockIndexedDBDatabaseCallbacks(), 65 new MockIndexedDBDatabaseCallbacks(),
66 scope, 66 scope,
67 indexed_db::TRANSACTION_READ_WRITE, 67 indexed_db::TRANSACTION_READ_WRITE,
68 db_, 68 db_,
69 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); 69 new IndexedDBFakeBackingStore::FakeTransaction(commit_success));
70 db_->TransactionCreated(transaction); 70 db_->TransactionCreated(transaction);
71 71
72 // No conflicting transactions, so coordinator will start it immediately: 72 // No conflicting transactions, so coordinator will start it immediately:
(...skipping 23 matching lines...) Expand all
96 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this))); 96 &IndexedDBTransactionTest::DummyOperation, base::Unretained(this)));
97 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); 97 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state());
98 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); 98 EXPECT_FALSE(transaction->IsTimeoutTimerRunning());
99 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); 99 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled);
100 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); 100 EXPECT_EQ(1, transaction->diagnostics().tasks_completed);
101 } 101 }
102 102
103 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) { 103 TEST_F(IndexedDBTransactionTest, NoTimeoutReadOnly) {
104 const int64 id = 0; 104 const int64 id = 0;
105 const std::set<int64> scope; 105 const std::set<int64> scope;
106 const bool commit_success = true; 106 const leveldb::Status commit_success = leveldb::Status::OK();
107 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( 107 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction(
108 id, 108 id,
109 new MockIndexedDBDatabaseCallbacks(), 109 new MockIndexedDBDatabaseCallbacks(),
110 scope, 110 scope,
111 indexed_db::TRANSACTION_READ_ONLY, 111 indexed_db::TRANSACTION_READ_ONLY,
112 db_, 112 db_,
113 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); 113 new IndexedDBFakeBackingStore::FakeTransaction(commit_success));
114 db_->TransactionCreated(transaction); 114 db_->TransactionCreated(transaction);
115 115
116 // No conflicting transactions, so coordinator will start it immediately: 116 // No conflicting transactions, so coordinator will start it immediately:
(...skipping 26 matching lines...) Expand all
143 bool abort_task_called() const { return abort_task_called_; } 143 bool abort_task_called() const { return abort_task_called_; }
144 144
145 private: 145 private:
146 bool abort_task_called_; 146 bool abort_task_called_;
147 DISALLOW_COPY_AND_ASSIGN(AbortObserver); 147 DISALLOW_COPY_AND_ASSIGN(AbortObserver);
148 }; 148 };
149 149
150 TEST_P(IndexedDBTransactionTestMode, ScheduleNormalTask) { 150 TEST_P(IndexedDBTransactionTestMode, ScheduleNormalTask) {
151 const int64 id = 0; 151 const int64 id = 0;
152 const std::set<int64> scope; 152 const std::set<int64> scope;
153 const bool commit_failure = false; 153 const leveldb::Status commit_success = leveldb::Status::OK();
154 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( 154 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction(
155 id, 155 id,
156 new MockIndexedDBDatabaseCallbacks(), 156 new MockIndexedDBDatabaseCallbacks(),
157 scope, 157 scope,
158 GetParam(), 158 GetParam(),
159 db_, 159 db_,
160 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); 160 new IndexedDBFakeBackingStore::FakeTransaction(commit_success));
161 161
162 EXPECT_FALSE(transaction->HasPendingTasks()); 162 EXPECT_FALSE(transaction->HasPendingTasks());
163 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); 163 EXPECT_TRUE(transaction->IsTaskQueueEmpty());
164 EXPECT_TRUE(transaction->task_queue_.empty()); 164 EXPECT_TRUE(transaction->task_queue_.empty());
165 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); 165 EXPECT_TRUE(transaction->preemptive_task_queue_.empty());
166 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); 166 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled);
167 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); 167 EXPECT_EQ(0, transaction->diagnostics().tasks_completed);
168 168
169 db_->TransactionCreated(transaction); 169 db_->TransactionCreated(transaction);
170 170
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); 205 EXPECT_TRUE(transaction->IsTaskQueueEmpty());
206 EXPECT_TRUE(transaction->task_queue_.empty()); 206 EXPECT_TRUE(transaction->task_queue_.empty());
207 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); 207 EXPECT_TRUE(transaction->preemptive_task_queue_.empty());
208 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled); 208 EXPECT_EQ(1, transaction->diagnostics().tasks_scheduled);
209 EXPECT_EQ(1, transaction->diagnostics().tasks_completed); 209 EXPECT_EQ(1, transaction->diagnostics().tasks_completed);
210 } 210 }
211 211
212 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) { 212 TEST_F(IndexedDBTransactionTest, SchedulePreemptiveTask) {
213 const int64 id = 0; 213 const int64 id = 0;
214 const std::set<int64> scope; 214 const std::set<int64> scope;
215 const bool commit_failure = false; 215 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch.");
216 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( 216 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction(
217 id, 217 id,
218 new MockIndexedDBDatabaseCallbacks(), 218 new MockIndexedDBDatabaseCallbacks(),
219 scope, 219 scope,
220 indexed_db::TRANSACTION_VERSION_CHANGE, 220 indexed_db::TRANSACTION_VERSION_CHANGE,
221 db_, 221 db_,
222 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); 222 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure));
223 223
224 EXPECT_FALSE(transaction->HasPendingTasks()); 224 EXPECT_FALSE(transaction->HasPendingTasks());
225 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); 225 EXPECT_TRUE(transaction->IsTaskQueueEmpty());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 EXPECT_TRUE(transaction->IsTaskQueueEmpty()); 266 EXPECT_TRUE(transaction->IsTaskQueueEmpty());
267 EXPECT_TRUE(transaction->task_queue_.empty()); 267 EXPECT_TRUE(transaction->task_queue_.empty());
268 EXPECT_TRUE(transaction->preemptive_task_queue_.empty()); 268 EXPECT_TRUE(transaction->preemptive_task_queue_.empty());
269 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled); 269 EXPECT_EQ(0, transaction->diagnostics().tasks_scheduled);
270 EXPECT_EQ(0, transaction->diagnostics().tasks_completed); 270 EXPECT_EQ(0, transaction->diagnostics().tasks_completed);
271 } 271 }
272 272
273 TEST_P(IndexedDBTransactionTestMode, AbortTasks) { 273 TEST_P(IndexedDBTransactionTestMode, AbortTasks) {
274 const int64 id = 0; 274 const int64 id = 0;
275 const std::set<int64> scope; 275 const std::set<int64> scope;
276 const bool commit_failure = false; 276 const leveldb::Status commit_failure = leveldb::Status::Corruption("Ouch.");
277 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( 277 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction(
278 id, 278 id,
279 new MockIndexedDBDatabaseCallbacks(), 279 new MockIndexedDBDatabaseCallbacks(),
280 scope, 280 scope,
281 GetParam(), 281 GetParam(),
282 db_, 282 db_,
283 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure)); 283 new IndexedDBFakeBackingStore::FakeTransaction(commit_failure));
284 db_->TransactionCreated(transaction); 284 db_->TransactionCreated(transaction);
285 285
286 AbortObserver observer; 286 AbortObserver observer;
287 transaction->ScheduleTask( 287 transaction->ScheduleTask(
288 base::Bind(&IndexedDBTransactionTest::DummyOperation, 288 base::Bind(&IndexedDBTransactionTest::DummyOperation,
289 base::Unretained(this)), 289 base::Unretained(this)),
290 base::Bind(&AbortObserver::AbortTask, base::Unretained(&observer))); 290 base::Bind(&AbortObserver::AbortTask, base::Unretained(&observer)));
291 291
292 // Pump the message loop so that the transaction completes all pending tasks, 292 // Pump the message loop so that the transaction completes all pending tasks,
293 // otherwise it will defer the commit. 293 // otherwise it will defer the commit.
294 base::MessageLoop::current()->RunUntilIdle(); 294 base::MessageLoop::current()->RunUntilIdle();
295 295
296 EXPECT_FALSE(observer.abort_task_called()); 296 EXPECT_FALSE(observer.abort_task_called());
297 transaction->Commit(); 297 transaction->Commit();
298 EXPECT_TRUE(observer.abort_task_called()); 298 EXPECT_TRUE(observer.abort_task_called());
299 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state()); 299 EXPECT_EQ(IndexedDBTransaction::FINISHED, transaction->state());
300 EXPECT_FALSE(transaction->IsTimeoutTimerRunning()); 300 EXPECT_FALSE(transaction->IsTimeoutTimerRunning());
301 } 301 }
302 302
303 TEST_P(IndexedDBTransactionTestMode, AbortPreemptive) { 303 TEST_P(IndexedDBTransactionTestMode, AbortPreemptive) {
304 const int64 id = 0; 304 const int64 id = 0;
305 const std::set<int64> scope; 305 const std::set<int64> scope;
306 const bool commit_success = true; 306 const leveldb::Status commit_success = leveldb::Status::OK();
307 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( 307 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction(
308 id, 308 id,
309 new MockIndexedDBDatabaseCallbacks(), 309 new MockIndexedDBDatabaseCallbacks(),
310 scope, 310 scope,
311 GetParam(), 311 GetParam(),
312 db_, 312 db_,
313 new IndexedDBFakeBackingStore::FakeTransaction(commit_success)); 313 new IndexedDBFakeBackingStore::FakeTransaction(commit_success));
314 db_->TransactionCreated(transaction); 314 db_->TransactionCreated(transaction);
315 315
316 // No conflicting transactions, so coordinator will start it immediately: 316 // No conflicting transactions, so coordinator will start it immediately:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 indexed_db::TRANSACTION_READ_ONLY, 355 indexed_db::TRANSACTION_READ_ONLY,
356 indexed_db::TRANSACTION_READ_WRITE, 356 indexed_db::TRANSACTION_READ_WRITE,
357 indexed_db::TRANSACTION_VERSION_CHANGE 357 indexed_db::TRANSACTION_VERSION_CHANGE
358 }; 358 };
359 359
360 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions, 360 INSTANTIATE_TEST_CASE_P(IndexedDBTransactions,
361 IndexedDBTransactionTestMode, 361 IndexedDBTransactionTestMode,
362 ::testing::ValuesIn(kTestModes)); 362 ::testing::ValuesIn(kTestModes));
363 363
364 } // namespace content 364 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698