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

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

Issue 2233153002: IndexedDB: WrapUnique(new T(args..)) -> MakeUnique<T>(args...) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 4 years, 4 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
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_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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 IndexedDBDatabase::Identifier(), 70 IndexedDBDatabase::Identifier(),
71 &s); 71 &s);
72 ASSERT_TRUE(s.ok()); 72 ASSERT_TRUE(s.ok());
73 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 73 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
74 74
75 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 75 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
76 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( 76 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1(
77 new MockIndexedDBDatabaseCallbacks()); 77 new MockIndexedDBDatabaseCallbacks());
78 const int64_t transaction_id1 = 1; 78 const int64_t transaction_id1 = 1;
79 std::unique_ptr<IndexedDBPendingConnection> connection1( 79 std::unique_ptr<IndexedDBPendingConnection> connection1(
80 new IndexedDBPendingConnection( 80 base::MakeUnique<IndexedDBPendingConnection>(
81 request1, callbacks1, kFakeChildProcessId, transaction_id1, 81 request1, callbacks1, kFakeChildProcessId, transaction_id1,
82 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 82 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
83 db->OpenConnection(std::move(connection1)); 83 db->OpenConnection(std::move(connection1));
84 84
85 EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0 85 EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0
86 86
87 scoped_refptr<MockIndexedDBCallbacks> request2(new MockIndexedDBCallbacks()); 87 scoped_refptr<MockIndexedDBCallbacks> request2(new MockIndexedDBCallbacks());
88 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks2( 88 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks2(
89 new MockIndexedDBDatabaseCallbacks()); 89 new MockIndexedDBDatabaseCallbacks());
90 const int64_t transaction_id2 = 2; 90 const int64_t transaction_id2 = 2;
91 std::unique_ptr<IndexedDBPendingConnection> connection2( 91 std::unique_ptr<IndexedDBPendingConnection> connection2(
92 new IndexedDBPendingConnection( 92 base::MakeUnique<IndexedDBPendingConnection>(
93 request2, callbacks2, kFakeChildProcessId, transaction_id2, 93 request2, callbacks2, kFakeChildProcessId, transaction_id2,
94 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 94 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
95 db->OpenConnection(std::move(connection2)); 95 db->OpenConnection(std::move(connection2));
96 96
97 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 97 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
98 98
99 request1->connection()->ForceClose(); 99 request1->connection()->ForceClose();
100 EXPECT_FALSE(request1->connection()->IsConnected()); 100 EXPECT_FALSE(request1->connection()->IsConnected());
101 101
102 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 102 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
(...skipping 21 matching lines...) Expand all
124 IndexedDBDatabase::Identifier(), 124 IndexedDBDatabase::Identifier(),
125 &s); 125 &s);
126 ASSERT_TRUE(s.ok()); 126 ASSERT_TRUE(s.ok());
127 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 127 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
128 128
129 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( 129 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks(
130 new MockIndexedDBDatabaseCallbacks()); 130 new MockIndexedDBDatabaseCallbacks());
131 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); 131 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks());
132 const int64_t upgrade_transaction_id = 3; 132 const int64_t upgrade_transaction_id = 3;
133 std::unique_ptr<IndexedDBPendingConnection> connection( 133 std::unique_ptr<IndexedDBPendingConnection> connection(
134 new IndexedDBPendingConnection( 134 base::MakeUnique<IndexedDBPendingConnection>(
135 request, callbacks, kFakeChildProcessId, upgrade_transaction_id, 135 request, callbacks, kFakeChildProcessId, upgrade_transaction_id,
136 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 136 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
137 database->OpenConnection(std::move(connection)); 137 database->OpenConnection(std::move(connection));
138 EXPECT_EQ(database.get(), request->connection()->database()); 138 EXPECT_EQ(database.get(), request->connection()->database());
139 139
140 const int64_t transaction_id = 123; 140 const int64_t transaction_id = 123;
141 const std::vector<int64_t> scope; 141 const std::vector<int64_t> scope;
142 database->CreateTransaction(transaction_id, 142 database->CreateTransaction(transaction_id,
143 request->connection(), 143 request->connection(),
144 scope, 144 scope,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 IndexedDBDatabase::Identifier(), 186 IndexedDBDatabase::Identifier(),
187 &s); 187 &s);
188 ASSERT_TRUE(s.ok()); 188 ASSERT_TRUE(s.ok());
189 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 189 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
190 190
191 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 191 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
192 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( 192 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1(
193 new MockIndexedDBDatabaseCallbacks()); 193 new MockIndexedDBDatabaseCallbacks());
194 const int64_t transaction_id1 = 1; 194 const int64_t transaction_id1 = 1;
195 std::unique_ptr<IndexedDBPendingConnection> connection( 195 std::unique_ptr<IndexedDBPendingConnection> connection(
196 new IndexedDBPendingConnection( 196 base::MakeUnique<IndexedDBPendingConnection>(
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<MockDeleteCallbacks> request2(new MockDeleteCallbacks()); 206 scoped_refptr<MockDeleteCallbacks> request2(new MockDeleteCallbacks());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 backing_store_.get(), 244 backing_store_.get(),
245 factory_.get(), 245 factory_.get(),
246 IndexedDBDatabase::Identifier(), 246 IndexedDBDatabase::Identifier(),
247 &s); 247 &s);
248 ASSERT_TRUE(s.ok()); 248 ASSERT_TRUE(s.ok());
249 249
250 request_ = new MockIndexedDBCallbacks(); 250 request_ = new MockIndexedDBCallbacks();
251 callbacks_ = new MockIndexedDBDatabaseCallbacks(); 251 callbacks_ = new MockIndexedDBDatabaseCallbacks();
252 const int64_t transaction_id = 1; 252 const int64_t transaction_id = 1;
253 std::unique_ptr<IndexedDBPendingConnection> connection( 253 std::unique_ptr<IndexedDBPendingConnection> connection(
254 new IndexedDBPendingConnection( 254 base::MakeUnique<IndexedDBPendingConnection>(
255 request_, callbacks_, kFakeChildProcessId, transaction_id, 255 request_, callbacks_, kFakeChildProcessId, transaction_id,
256 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 256 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
257 db_->OpenConnection(std::move(connection)); 257 db_->OpenConnection(std::move(connection));
258 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version); 258 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version);
259 259
260 connection_ = base::WrapUnique(new IndexedDBConnection(db_, callbacks_)); 260 connection_ = base::MakeUnique<IndexedDBConnection>(db_, callbacks_);
261 transaction_ = IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( 261 transaction_ = IndexedDBClassFactory::Get()->CreateIndexedDBTransaction(
262 transaction_id, connection_->GetWeakPtr(), 262 transaction_id, connection_->GetWeakPtr(),
263 std::set<int64_t>() /*scope*/, 263 std::set<int64_t>() /*scope*/,
264 blink::WebIDBTransactionModeVersionChange, 264 blink::WebIDBTransactionModeVersionChange,
265 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); 265 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_));
266 db_->TransactionCreated(transaction_.get()); 266 db_->TransactionCreated(transaction_.get());
267 267
268 // Add a dummy task which takes the place of the VersionChangeOperation 268 // Add a dummy task which takes the place of the VersionChangeOperation
269 // which kicks off the upgrade. This ensures that the transaction has 269 // which kicks off the upgrade. This ensures that the transaction has
270 // processed at least one task before the CreateObjectStore call. 270 // processed at least one task before the CreateObjectStore call.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 store_id, 391 store_id,
392 ASCIIToUTF16("store"), 392 ASCIIToUTF16("store"),
393 IndexedDBKeyPath(), 393 IndexedDBKeyPath(),
394 false /*auto_increment*/); 394 false /*auto_increment*/);
395 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 395 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
396 396
397 397
398 // Put is asynchronous 398 // Put is asynchronous
399 IndexedDBValue value("value1", std::vector<IndexedDBBlobInfo>()); 399 IndexedDBValue value("value1", std::vector<IndexedDBBlobInfo>());
400 ScopedVector<storage::BlobDataHandle> handles; 400 ScopedVector<storage::BlobDataHandle> handles;
401 std::unique_ptr<IndexedDBKey> key(new IndexedDBKey("key")); 401 std::unique_ptr<IndexedDBKey> key(base::MakeUnique<IndexedDBKey>("key"));
402 std::vector<IndexedDBDatabase::IndexKeys> index_keys; 402 std::vector<IndexedDBDatabase::IndexKeys> index_keys;
403 scoped_refptr<MockIndexedDBCallbacks> request( 403 scoped_refptr<MockIndexedDBCallbacks> request(
404 new MockIndexedDBCallbacks(false)); 404 new MockIndexedDBCallbacks(false));
405 db_->Put(transaction_->id(), store_id, &value, &handles, std::move(key), 405 db_->Put(transaction_->id(), store_id, &value, &handles, std::move(key),
406 blink::WebIDBPutModeAddOnly, request, index_keys); 406 blink::WebIDBPutModeAddOnly, request, index_keys);
407 407
408 // Deletion is asynchronous. 408 // Deletion is asynchronous.
409 db_->DeleteObjectStore(transaction_->id(), 409 db_->DeleteObjectStore(transaction_->id(),
410 store_id); 410 store_id);
411 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 411 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
412 412
413 // This will execute the Put then Delete. 413 // This will execute the Put then Delete.
414 RunPostedTasks(); 414 RunPostedTasks();
415 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 415 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
416 416
417 transaction_->Commit(); // Cleans up the object hierarchy. 417 transaction_->Commit(); // Cleans up the object hierarchy.
418 } 418 }
419 419
420 } // namespace content 420 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database.cc ('k') | content/browser/indexed_db/indexed_db_dispatcher_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698