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

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

Issue 2519073003: IndexedDB: IndexedDBDatabase::Create() returning db/status tuple. (Closed)
Patch Set: Added std::tie. Created 4 years 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 TestBrowserThreadBundle thread_bundle_; 43 TestBrowserThreadBundle thread_bundle_;
44 }; 44 };
45 45
46 TEST_F(IndexedDBDatabaseTest, BackingStoreRetention) { 46 TEST_F(IndexedDBDatabaseTest, BackingStoreRetention) {
47 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 47 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
48 new IndexedDBFakeBackingStore(); 48 new IndexedDBFakeBackingStore();
49 EXPECT_TRUE(backing_store->HasOneRef()); 49 EXPECT_TRUE(backing_store->HasOneRef());
50 50
51 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); 51 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
52 leveldb::Status s; 52 leveldb::Status s;
53 scoped_refptr<IndexedDBDatabase> db = 53 scoped_refptr<IndexedDBDatabase> db;
54 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 54 std::tie(db, s) =
55 backing_store.get(), 55 IndexedDBDatabase::Create(ASCIIToUTF16("db"), backing_store.get(),
56 factory.get(), 56 factory.get(), IndexedDBDatabase::Identifier());
57 IndexedDBDatabase::Identifier(),
58 &s);
59 ASSERT_TRUE(s.ok()); 57 ASSERT_TRUE(s.ok());
60 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 58 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
61 db = NULL; 59 db = NULL;
62 EXPECT_TRUE(backing_store->HasOneRef()); // local 60 EXPECT_TRUE(backing_store->HasOneRef()); // local
63 } 61 }
64 62
65 TEST_F(IndexedDBDatabaseTest, ConnectionLifecycle) { 63 TEST_F(IndexedDBDatabaseTest, ConnectionLifecycle) {
66 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 64 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
67 new IndexedDBFakeBackingStore(); 65 new IndexedDBFakeBackingStore();
68 EXPECT_TRUE(backing_store->HasOneRef()); // local 66 EXPECT_TRUE(backing_store->HasOneRef()); // local
69 67
70 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); 68 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
71 leveldb::Status s; 69 leveldb::Status s;
jsbell 2016/11/21 20:07:20 nit: I'd flip the order here to match the tuple or
cmumford 2016/11/22 16:43:19 Done.
72 scoped_refptr<IndexedDBDatabase> db = 70 scoped_refptr<IndexedDBDatabase> db;
73 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 71 std::tie(db, s) =
74 backing_store.get(), 72 IndexedDBDatabase::Create(ASCIIToUTF16("db"), backing_store.get(),
75 factory.get(), 73 factory.get(), IndexedDBDatabase::Identifier());
76 IndexedDBDatabase::Identifier(),
77 &s);
78 ASSERT_TRUE(s.ok()); 74 ASSERT_TRUE(s.ok());
79 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 75 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
80 76
81 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 77 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
82 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( 78 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1(
83 new MockIndexedDBDatabaseCallbacks()); 79 new MockIndexedDBDatabaseCallbacks());
84 const int64_t transaction_id1 = 1; 80 const int64_t transaction_id1 = 1;
85 std::unique_ptr<IndexedDBPendingConnection> connection1( 81 std::unique_ptr<IndexedDBPendingConnection> connection1(
86 base::MakeUnique<IndexedDBPendingConnection>( 82 base::MakeUnique<IndexedDBPendingConnection>(
87 request1, callbacks1, kFakeChildProcessId, transaction_id1, 83 request1, callbacks1, kFakeChildProcessId, transaction_id1,
(...skipping 28 matching lines...) Expand all
116 db = NULL; 112 db = NULL;
117 } 113 }
118 114
119 TEST_F(IndexedDBDatabaseTest, ForcedClose) { 115 TEST_F(IndexedDBDatabaseTest, ForcedClose) {
120 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 116 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
121 new IndexedDBFakeBackingStore(); 117 new IndexedDBFakeBackingStore();
122 EXPECT_TRUE(backing_store->HasOneRef()); 118 EXPECT_TRUE(backing_store->HasOneRef());
123 119
124 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); 120 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
125 leveldb::Status s; 121 leveldb::Status s;
126 scoped_refptr<IndexedDBDatabase> database = 122 scoped_refptr<IndexedDBDatabase> database;
127 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 123 std::tie(database, s) =
128 backing_store.get(), 124 IndexedDBDatabase::Create(ASCIIToUTF16("db"), backing_store.get(),
129 factory.get(), 125 factory.get(), IndexedDBDatabase::Identifier());
130 IndexedDBDatabase::Identifier(),
131 &s);
132 ASSERT_TRUE(s.ok()); 126 ASSERT_TRUE(s.ok());
133 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 127 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
134 128
135 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( 129 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks(
136 new MockIndexedDBDatabaseCallbacks()); 130 new MockIndexedDBDatabaseCallbacks());
137 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); 131 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks());
138 const int64_t upgrade_transaction_id = 3; 132 const int64_t upgrade_transaction_id = 3;
139 std::unique_ptr<IndexedDBPendingConnection> connection( 133 std::unique_ptr<IndexedDBPendingConnection> connection(
140 base::MakeUnique<IndexedDBPendingConnection>( 134 base::MakeUnique<IndexedDBPendingConnection>(
141 request, callbacks, kFakeChildProcessId, upgrade_transaction_id, 135 request, callbacks, kFakeChildProcessId, upgrade_transaction_id,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 DISALLOW_COPY_AND_ASSIGN(MockCallbacks); 177 DISALLOW_COPY_AND_ASSIGN(MockCallbacks);
184 }; 178 };
185 179
186 TEST_F(IndexedDBDatabaseTest, PendingDelete) { 180 TEST_F(IndexedDBDatabaseTest, PendingDelete) {
187 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 181 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
188 new IndexedDBFakeBackingStore(); 182 new IndexedDBFakeBackingStore();
189 EXPECT_TRUE(backing_store->HasOneRef()); // local 183 EXPECT_TRUE(backing_store->HasOneRef()); // local
190 184
191 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); 185 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
192 leveldb::Status s; 186 leveldb::Status s;
193 scoped_refptr<IndexedDBDatabase> db = 187 scoped_refptr<IndexedDBDatabase> db;
194 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 188 std::tie(db, s) =
195 backing_store.get(), 189 IndexedDBDatabase::Create(ASCIIToUTF16("db"), backing_store.get(),
196 factory.get(), 190 factory.get(), IndexedDBDatabase::Identifier());
197 IndexedDBDatabase::Identifier(),
198 &s);
199 ASSERT_TRUE(s.ok()); 191 ASSERT_TRUE(s.ok());
200 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 192 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
201 193
202 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 194 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
203 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( 195 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1(
204 new MockIndexedDBDatabaseCallbacks()); 196 new MockIndexedDBDatabaseCallbacks());
205 const int64_t transaction_id1 = 1; 197 const int64_t transaction_id1 = 1;
206 std::unique_ptr<IndexedDBPendingConnection> connection( 198 std::unique_ptr<IndexedDBPendingConnection> connection(
207 base::MakeUnique<IndexedDBPendingConnection>( 199 base::MakeUnique<IndexedDBPendingConnection>(
208 request1, callbacks1, kFakeChildProcessId, transaction_id1, 200 request1, callbacks1, kFakeChildProcessId, transaction_id1,
(...skipping 30 matching lines...) Expand all
239 EXPECT_TRUE(request2->success_called()); 231 EXPECT_TRUE(request2->success_called());
240 } 232 }
241 233
242 TEST_F(IndexedDBDatabaseTest, ConnectionRequestsNoLongerValid) { 234 TEST_F(IndexedDBDatabaseTest, ConnectionRequestsNoLongerValid) {
243 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 235 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
244 new IndexedDBFakeBackingStore(); 236 new IndexedDBFakeBackingStore();
245 237
246 const int64_t transaction_id1 = 1; 238 const int64_t transaction_id1 = 1;
247 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); 239 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
248 leveldb::Status s; 240 leveldb::Status s;
249 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create( 241 scoped_refptr<IndexedDBDatabase> db;
250 ASCIIToUTF16("db"), backing_store.get(), factory.get(), 242 std::tie(db, s) =
251 IndexedDBDatabase::Identifier(), &s); 243 IndexedDBDatabase::Create(ASCIIToUTF16("db"), backing_store.get(),
244 factory.get(), IndexedDBDatabase::Identifier());
252 245
253 // Make a connection request. This will be processed immediately. 246 // Make a connection request. This will be processed immediately.
254 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 247 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
255 { 248 {
256 std::unique_ptr<IndexedDBPendingConnection> connection( 249 std::unique_ptr<IndexedDBPendingConnection> connection(
257 base::MakeUnique<IndexedDBPendingConnection>( 250 base::MakeUnique<IndexedDBPendingConnection>(
258 request1, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()), 251 request1, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()),
259 kFakeChildProcessId, transaction_id1, 252 kFakeChildProcessId, transaction_id1,
260 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 253 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
261 db->OpenConnection(std::move(connection)); 254 db->OpenConnection(std::move(connection));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 338
346 class IndexedDBDatabaseOperationTest : public testing::Test { 339 class IndexedDBDatabaseOperationTest : public testing::Test {
347 public: 340 public:
348 IndexedDBDatabaseOperationTest() 341 IndexedDBDatabaseOperationTest()
349 : commit_success_(leveldb::Status::OK()), 342 : commit_success_(leveldb::Status::OK()),
350 factory_(new MockIndexedDBFactory()) {} 343 factory_(new MockIndexedDBFactory()) {}
351 344
352 void SetUp() override { 345 void SetUp() override {
353 backing_store_ = new IndexedDBFakeBackingStore(); 346 backing_store_ = new IndexedDBFakeBackingStore();
354 leveldb::Status s; 347 leveldb::Status s;
355 db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"), 348 std::tie(db_, s) = IndexedDBDatabase::Create(
356 backing_store_.get(), 349 ASCIIToUTF16("db"), backing_store_.get(), factory_.get(),
357 factory_.get(), 350 IndexedDBDatabase::Identifier());
358 IndexedDBDatabase::Identifier(),
359 &s);
360 ASSERT_TRUE(s.ok()); 351 ASSERT_TRUE(s.ok());
361 352
362 request_ = new MockIndexedDBCallbacks(); 353 request_ = new MockIndexedDBCallbacks();
363 callbacks_ = new MockIndexedDBDatabaseCallbacks(); 354 callbacks_ = new MockIndexedDBDatabaseCallbacks();
364 const int64_t transaction_id = 1; 355 const int64_t transaction_id = 1;
365 std::unique_ptr<IndexedDBPendingConnection> connection( 356 std::unique_ptr<IndexedDBPendingConnection> connection(
366 base::MakeUnique<IndexedDBPendingConnection>( 357 base::MakeUnique<IndexedDBPendingConnection>(
367 request_, callbacks_, kFakeChildProcessId, transaction_id, 358 request_, callbacks_, kFakeChildProcessId, transaction_id,
368 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 359 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
369 db_->OpenConnection(std::move(connection)); 360 db_->OpenConnection(std::move(connection));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 514 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
524 515
525 // This will execute the Put then Delete. 516 // This will execute the Put then Delete.
526 RunPostedTasks(); 517 RunPostedTasks();
527 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 518 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
528 519
529 transaction_->Commit(); // Cleans up the object hierarchy. 520 transaction_->Commit(); // Cleans up the object hierarchy.
530 } 521 }
531 522
532 } // namespace content 523 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698