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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { | 35 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { |
36 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 36 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
37 new IndexedDBFakeBackingStore(); | 37 new IndexedDBFakeBackingStore(); |
38 EXPECT_TRUE(backing_store->HasOneRef()); | 38 EXPECT_TRUE(backing_store->HasOneRef()); |
39 | 39 |
40 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 40 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
41 leveldb::Status s; | 41 leveldb::Status s; |
42 scoped_refptr<IndexedDBDatabase> db = | 42 scoped_refptr<IndexedDBDatabase> db = |
43 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 43 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
44 backing_store, | 44 backing_store.get(), |
45 factory, | 45 factory.get(), |
46 IndexedDBDatabase::Identifier(), | 46 IndexedDBDatabase::Identifier(), |
47 &s); | 47 &s); |
48 ASSERT_TRUE(s.ok()); | 48 ASSERT_TRUE(s.ok()); |
49 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 49 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
50 db = NULL; | 50 db = NULL; |
51 EXPECT_TRUE(backing_store->HasOneRef()); // local | 51 EXPECT_TRUE(backing_store->HasOneRef()); // local |
52 } | 52 } |
53 | 53 |
54 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { | 54 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { |
55 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 55 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
56 new IndexedDBFakeBackingStore(); | 56 new IndexedDBFakeBackingStore(); |
57 EXPECT_TRUE(backing_store->HasOneRef()); // local | 57 EXPECT_TRUE(backing_store->HasOneRef()); // local |
58 | 58 |
59 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 59 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
60 leveldb::Status s; | 60 leveldb::Status s; |
61 scoped_refptr<IndexedDBDatabase> db = | 61 scoped_refptr<IndexedDBDatabase> db = |
62 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 62 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
63 backing_store, | 63 backing_store.get(), |
64 factory, | 64 factory.get(), |
65 IndexedDBDatabase::Identifier(), | 65 IndexedDBDatabase::Identifier(), |
66 &s); | 66 &s); |
67 ASSERT_TRUE(s.ok()); | 67 ASSERT_TRUE(s.ok()); |
68 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 68 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
69 | 69 |
70 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); | 70 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); |
71 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( | 71 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( |
72 new MockIndexedDBDatabaseCallbacks()); | 72 new MockIndexedDBDatabaseCallbacks()); |
73 const int64 transaction_id1 = 1; | 73 const int64 transaction_id1 = 1; |
74 IndexedDBPendingConnection connection1( | 74 IndexedDBPendingConnection connection1( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 TEST(IndexedDBDatabaseTest, ForcedClose) { | 112 TEST(IndexedDBDatabaseTest, ForcedClose) { |
113 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 113 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
114 new IndexedDBFakeBackingStore(); | 114 new IndexedDBFakeBackingStore(); |
115 EXPECT_TRUE(backing_store->HasOneRef()); | 115 EXPECT_TRUE(backing_store->HasOneRef()); |
116 | 116 |
117 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 117 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
118 leveldb::Status s; | 118 leveldb::Status s; |
119 scoped_refptr<IndexedDBDatabase> database = | 119 scoped_refptr<IndexedDBDatabase> database = |
120 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 120 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
121 backing_store, | 121 backing_store.get(), |
122 factory, | 122 factory.get(), |
123 IndexedDBDatabase::Identifier(), | 123 IndexedDBDatabase::Identifier(), |
124 &s); | 124 &s); |
125 ASSERT_TRUE(s.ok()); | 125 ASSERT_TRUE(s.ok()); |
126 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 126 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
127 | 127 |
128 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( | 128 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( |
129 new MockIndexedDBDatabaseCallbacks()); | 129 new MockIndexedDBDatabaseCallbacks()); |
130 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); | 130 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); |
131 const int64 upgrade_transaction_id = 3; | 131 const int64 upgrade_transaction_id = 3; |
132 IndexedDBPendingConnection connection( | 132 IndexedDBPendingConnection connection( |
133 request, | 133 request, |
134 callbacks, | 134 callbacks, |
135 kFakeChildProcessId, | 135 kFakeChildProcessId, |
136 upgrade_transaction_id, | 136 upgrade_transaction_id, |
137 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); | 137 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); |
138 database->OpenConnection(connection); | 138 database->OpenConnection(connection); |
139 EXPECT_EQ(database, request->connection()->database()); | 139 EXPECT_EQ(database.get(), request->connection()->database()); |
140 | 140 |
141 const int64 transaction_id = 123; | 141 const int64 transaction_id = 123; |
142 const std::vector<int64> scope; | 142 const std::vector<int64> scope; |
143 database->CreateTransaction(transaction_id, | 143 database->CreateTransaction(transaction_id, |
144 request->connection(), | 144 request->connection(), |
145 scope, | 145 scope, |
146 blink::WebIDBTransactionModeReadOnly); | 146 blink::WebIDBTransactionModeReadOnly); |
147 | 147 |
148 request->connection()->ForceClose(); | 148 request->connection()->ForceClose(); |
149 | 149 |
(...skipping 27 matching lines...) Expand all Loading... |
177 | 177 |
178 TEST(IndexedDBDatabaseTest, PendingDelete) { | 178 TEST(IndexedDBDatabaseTest, PendingDelete) { |
179 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 179 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
180 new IndexedDBFakeBackingStore(); | 180 new IndexedDBFakeBackingStore(); |
181 EXPECT_TRUE(backing_store->HasOneRef()); // local | 181 EXPECT_TRUE(backing_store->HasOneRef()); // local |
182 | 182 |
183 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 183 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
184 leveldb::Status s; | 184 leveldb::Status s; |
185 scoped_refptr<IndexedDBDatabase> db = | 185 scoped_refptr<IndexedDBDatabase> db = |
186 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 186 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
187 backing_store, | 187 backing_store.get(), |
188 factory, | 188 factory.get(), |
189 IndexedDBDatabase::Identifier(), | 189 IndexedDBDatabase::Identifier(), |
190 &s); | 190 &s); |
191 ASSERT_TRUE(s.ok()); | 191 ASSERT_TRUE(s.ok()); |
192 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 192 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
193 | 193 |
194 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); | 194 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); |
195 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( | 195 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( |
196 new MockIndexedDBDatabaseCallbacks()); | 196 new MockIndexedDBDatabaseCallbacks()); |
197 const int64 transaction_id1 = 1; | 197 const int64 transaction_id1 = 1; |
198 IndexedDBPendingConnection connection( | 198 IndexedDBPendingConnection connection( |
(...skipping 28 matching lines...) Expand all Loading... |
227 class IndexedDBDatabaseOperationTest : public testing::Test { | 227 class IndexedDBDatabaseOperationTest : public testing::Test { |
228 public: | 228 public: |
229 IndexedDBDatabaseOperationTest() | 229 IndexedDBDatabaseOperationTest() |
230 : commit_success_(leveldb::Status::OK()), | 230 : commit_success_(leveldb::Status::OK()), |
231 factory_(new MockIndexedDBFactory()) {} | 231 factory_(new MockIndexedDBFactory()) {} |
232 | 232 |
233 virtual void SetUp() { | 233 virtual void SetUp() { |
234 backing_store_ = new IndexedDBFakeBackingStore(); | 234 backing_store_ = new IndexedDBFakeBackingStore(); |
235 leveldb::Status s; | 235 leveldb::Status s; |
236 db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 236 db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
237 backing_store_, | 237 backing_store_.get(), |
238 factory_, | 238 factory_.get(), |
239 IndexedDBDatabase::Identifier(), | 239 IndexedDBDatabase::Identifier(), |
240 &s); | 240 &s); |
241 ASSERT_TRUE(s.ok()); | 241 ASSERT_TRUE(s.ok()); |
242 | 242 |
243 request_ = new MockIndexedDBCallbacks(); | 243 request_ = new MockIndexedDBCallbacks(); |
244 callbacks_ = new MockIndexedDBDatabaseCallbacks(); | 244 callbacks_ = new MockIndexedDBDatabaseCallbacks(); |
245 const int64 transaction_id = 1; | 245 const int64 transaction_id = 1; |
246 db_->OpenConnection(IndexedDBPendingConnection( | 246 db_->OpenConnection(IndexedDBPendingConnection( |
247 request_, | 247 request_, |
248 callbacks_, | 248 callbacks_, |
249 kFakeChildProcessId, | 249 kFakeChildProcessId, |
250 transaction_id, | 250 transaction_id, |
251 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION)); | 251 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION)); |
252 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION, | 252 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION, |
253 db_->metadata().int_version); | 253 db_->metadata().int_version); |
254 | 254 |
255 transaction_ = new IndexedDBTransaction( | 255 transaction_ = new IndexedDBTransaction( |
256 transaction_id, | 256 transaction_id, |
257 callbacks_, | 257 callbacks_, |
258 std::set<int64>() /*scope*/, | 258 std::set<int64>() /*scope*/, |
259 blink::WebIDBTransactionModeVersionChange, | 259 blink::WebIDBTransactionModeVersionChange, |
260 db_, | 260 db_.get(), |
261 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); | 261 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); |
262 db_->TransactionCreated(transaction_); | 262 db_->TransactionCreated(transaction_.get()); |
263 | 263 |
264 // Add a dummy task which takes the place of the VersionChangeOperation | 264 // Add a dummy task which takes the place of the VersionChangeOperation |
265 // which kicks off the upgrade. This ensures that the transaction has | 265 // which kicks off the upgrade. This ensures that the transaction has |
266 // processed at least one task before the CreateObjectStore call. | 266 // processed at least one task before the CreateObjectStore call. |
267 transaction_->ScheduleTask(base::Bind(&DummyOperation)); | 267 transaction_->ScheduleTask(base::Bind(&DummyOperation)); |
268 } | 268 } |
269 | 269 |
270 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } | 270 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } |
271 | 271 |
272 protected: | 272 protected: |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); | 412 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); |
413 | 413 |
414 // This will execute the Put then Delete. | 414 // This will execute the Put then Delete. |
415 RunPostedTasks(); | 415 RunPostedTasks(); |
416 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 416 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
417 | 417 |
418 transaction_->Commit(); // Cleans up the object hierarchy. | 418 transaction_->Commit(); // Cleans up the object hierarchy. |
419 } | 419 } |
420 | 420 |
421 } // namespace content | 421 } // namespace content |
OLD | NEW |