| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 request1, callbacks1, kFakeChildProcessId, transaction_id1, | 197 request1, callbacks1, kFakeChildProcessId, transaction_id1, |
| 198 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 198 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 199 db->OpenConnection(std::move(connection)); | 199 db->OpenConnection(std::move(connection)); |
| 200 | 200 |
| 201 EXPECT_EQ(db->ConnectionCount(), 1UL); | 201 EXPECT_EQ(db->ConnectionCount(), 1UL); |
| 202 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); | 202 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); |
| 203 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 203 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
| 204 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 204 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 205 | 205 |
| 206 scoped_refptr<MockCallbacks> request2(new MockCallbacks()); | 206 scoped_refptr<MockCallbacks> request2(new MockCallbacks()); |
| 207 db->DeleteDatabase(request2); | 207 db->DeleteDatabase(request2, false /* force_delete */); |
| 208 EXPECT_EQ(db->ConnectionCount(), 1UL); | 208 EXPECT_EQ(db->ConnectionCount(), 1UL); |
| 209 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); | 209 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); |
| 210 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 210 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
| 211 | 211 |
| 212 EXPECT_FALSE(request2->blocked_called()); | 212 EXPECT_FALSE(request2->blocked_called()); |
| 213 db->VersionChangeIgnored(); | 213 db->VersionChangeIgnored(); |
| 214 EXPECT_TRUE(request2->blocked_called()); | 214 EXPECT_TRUE(request2->blocked_called()); |
| 215 EXPECT_EQ(db->ConnectionCount(), 1UL); | 215 EXPECT_EQ(db->ConnectionCount(), 1UL); |
| 216 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); | 216 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); |
| 217 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 217 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
| 218 | 218 |
| 219 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 219 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 220 | 220 |
| 221 db->Close(request1->connection(), true /* forced */); | 221 db->Close(request1->connection(), true /* forced */); |
| 222 EXPECT_EQ(db->ConnectionCount(), 0UL); | 222 EXPECT_EQ(db->ConnectionCount(), 0UL); |
| 223 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); | 223 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); |
| 224 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 224 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
| 225 | 225 |
| 226 EXPECT_FALSE(db->backing_store()); | 226 EXPECT_FALSE(db->backing_store()); |
| 227 EXPECT_TRUE(backing_store->HasOneRef()); // local | 227 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 228 EXPECT_TRUE(request2->success_called()); | 228 EXPECT_TRUE(request2->success_called()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 TEST_F(IndexedDBDatabaseTest, ForceDelete) { |
| 232 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 233 new IndexedDBFakeBackingStore(); |
| 234 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 235 |
| 236 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
| 237 scoped_refptr<IndexedDBDatabase> db; |
| 238 leveldb::Status s; |
| 239 std::tie(db, s) = |
| 240 IndexedDBDatabase::Create(ASCIIToUTF16("db"), backing_store.get(), |
| 241 factory.get(), IndexedDBDatabase::Identifier()); |
| 242 ASSERT_TRUE(s.ok()); |
| 243 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 244 |
| 245 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); |
| 246 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( |
| 247 new MockIndexedDBDatabaseCallbacks()); |
| 248 const int64_t transaction_id1 = 1; |
| 249 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 250 base::MakeUnique<IndexedDBPendingConnection>( |
| 251 request1, callbacks1, kFakeChildProcessId, transaction_id1, |
| 252 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 253 db->OpenConnection(std::move(connection)); |
| 254 |
| 255 EXPECT_EQ(db->ConnectionCount(), 1UL); |
| 256 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); |
| 257 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
| 258 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 259 |
| 260 scoped_refptr<MockCallbacks> request2(new MockCallbacks()); |
| 261 db->DeleteDatabase(request2, true /* force_delete */); |
| 262 EXPECT_EQ(db->ConnectionCount(), 0UL); |
| 263 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); |
| 264 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
| 265 EXPECT_FALSE(request2->blocked_called()); |
| 266 |
| 267 EXPECT_FALSE(db->backing_store()); |
| 268 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 269 EXPECT_TRUE(request2->success_called()); |
| 270 } |
| 271 |
| 231 leveldb::Status DummyOperation(IndexedDBTransaction* transaction) { | 272 leveldb::Status DummyOperation(IndexedDBTransaction* transaction) { |
| 232 return leveldb::Status::OK(); | 273 return leveldb::Status::OK(); |
| 233 } | 274 } |
| 234 | 275 |
| 235 class IndexedDBDatabaseOperationTest : public testing::Test { | 276 class IndexedDBDatabaseOperationTest : public testing::Test { |
| 236 public: | 277 public: |
| 237 IndexedDBDatabaseOperationTest() | 278 IndexedDBDatabaseOperationTest() |
| 238 : commit_success_(leveldb::Status::OK()), | 279 : commit_success_(leveldb::Status::OK()), |
| 239 factory_(new MockIndexedDBFactory()) {} | 280 factory_(new MockIndexedDBFactory()) {} |
| 240 | 281 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); | 428 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); |
| 388 | 429 |
| 389 // This will execute the Put then Delete. | 430 // This will execute the Put then Delete. |
| 390 RunPostedTasks(); | 431 RunPostedTasks(); |
| 391 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 432 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
| 392 | 433 |
| 393 transaction_->Commit(); // Cleans up the object hierarchy. | 434 transaction_->Commit(); // Cleans up the object hierarchy. |
| 394 } | 435 } |
| 395 | 436 |
| 396 } // namespace content | 437 } // namespace content |
| OLD | NEW |