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

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

Issue 2601163002: Remove indexed_db_messages.h. (Closed)
Patch Set: Addressed cmumford's feedback. Created 3 years, 11 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 class MockCallbacks : public IndexedDBCallbacks { 153 class MockCallbacks : public IndexedDBCallbacks {
154 public: 154 public:
155 MockCallbacks() : IndexedDBCallbacks(nullptr, url::Origin(), nullptr) {} 155 MockCallbacks() : IndexedDBCallbacks(nullptr, url::Origin(), nullptr) {}
156 156
157 void OnBlocked(int64_t existing_version) override { blocked_called_ = true; } 157 void OnBlocked(int64_t existing_version) override { blocked_called_ = true; }
158 void OnSuccess(int64_t result) override { success_called_ = true; } 158 void OnSuccess(int64_t result) override { success_called_ = true; }
159 void OnError(const IndexedDBDatabaseError& error) override { 159 void OnError(const IndexedDBDatabaseError& error) override {
160 error_called_ = true; 160 error_called_ = true;
161 } 161 }
162 bool IsValid() const override { return valid_; }
163 162
164 bool blocked_called() const { return blocked_called_; } 163 bool blocked_called() const { return blocked_called_; }
165 bool success_called() const { return success_called_; } 164 bool success_called() const { return success_called_; }
166 bool error_called() const { return error_called_; } 165 bool error_called() const { return error_called_; }
167 void set_valid(bool valid) { valid_ = valid; }
168 166
169 private: 167 private:
170 ~MockCallbacks() override {} 168 ~MockCallbacks() override {}
171 169
172 bool blocked_called_ = false; 170 bool blocked_called_ = false;
173 bool success_called_ = false; 171 bool success_called_ = false;
174 bool error_called_ = false; 172 bool error_called_ = false;
175 bool valid_ = true;
176 173
177 DISALLOW_COPY_AND_ASSIGN(MockCallbacks); 174 DISALLOW_COPY_AND_ASSIGN(MockCallbacks);
178 }; 175 };
179 176
180 TEST_F(IndexedDBDatabaseTest, PendingDelete) { 177 TEST_F(IndexedDBDatabaseTest, PendingDelete) {
181 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 178 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
182 new IndexedDBFakeBackingStore(); 179 new IndexedDBFakeBackingStore();
183 EXPECT_TRUE(backing_store->HasOneRef()); // local 180 EXPECT_TRUE(backing_store->HasOneRef()); // local
184 181
185 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); 182 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 db->Close(request1->connection(), true /* forced */); 221 db->Close(request1->connection(), true /* forced */);
225 EXPECT_EQ(db->ConnectionCount(), 0UL); 222 EXPECT_EQ(db->ConnectionCount(), 0UL);
226 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); 223 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
227 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); 224 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
228 225
229 EXPECT_FALSE(db->backing_store()); 226 EXPECT_FALSE(db->backing_store());
230 EXPECT_TRUE(backing_store->HasOneRef()); // local 227 EXPECT_TRUE(backing_store->HasOneRef()); // local
231 EXPECT_TRUE(request2->success_called()); 228 EXPECT_TRUE(request2->success_called());
232 } 229 }
233 230
234 TEST_F(IndexedDBDatabaseTest, ConnectionRequestsNoLongerValid) {
235 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
236 new IndexedDBFakeBackingStore();
237
238 const int64_t transaction_id1 = 1;
239 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
240 scoped_refptr<IndexedDBDatabase> db;
241 leveldb::Status s;
242 std::tie(db, s) =
243 IndexedDBDatabase::Create(ASCIIToUTF16("db"), backing_store.get(),
244 factory.get(), IndexedDBDatabase::Identifier());
245
246 // Make a connection request. This will be processed immediately.
247 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
248 {
249 std::unique_ptr<IndexedDBPendingConnection> connection(
250 base::MakeUnique<IndexedDBPendingConnection>(
251 request1, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()),
252 kFakeChildProcessId, transaction_id1,
253 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
254 db->OpenConnection(std::move(connection));
255 }
256
257 EXPECT_EQ(db->ConnectionCount(), 1UL);
258 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
259 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
260
261 // Make a delete request. This will be blocked by the open.
262 scoped_refptr<MockCallbacks> request2(new MockCallbacks());
263 db->DeleteDatabase(request2);
264
265 EXPECT_EQ(db->ConnectionCount(), 1UL);
266 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
267 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
268
269 db->VersionChangeIgnored();
270
271 EXPECT_TRUE(request2->blocked_called());
272
273 // Make another delete request. This will be waiting in the queue.
274 scoped_refptr<MockCallbacks> request3(new MockCallbacks());
275 db->DeleteDatabase(request3);
276 EXPECT_FALSE(request3->HasOneRef()); // local, db
277
278 EXPECT_EQ(db->ConnectionCount(), 1UL);
279 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
280 EXPECT_EQ(db->PendingOpenDeleteCount(), 1UL);
281
282 // Make another connection request. This will also be waiting in the queue.
283 scoped_refptr<MockCallbacks> request4(new MockCallbacks());
284 {
285 std::unique_ptr<IndexedDBPendingConnection> connection(
286 base::MakeUnique<IndexedDBPendingConnection>(
287 request4, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()),
288 kFakeChildProcessId, transaction_id1,
289 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
290 db->OpenConnection(std::move(connection));
291 }
292
293 EXPECT_EQ(db->ConnectionCount(), 1UL);
294 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
295 EXPECT_EQ(db->PendingOpenDeleteCount(), 2UL);
296
297 // Finally yet another delete request, also waiting in the queue.
298 scoped_refptr<MockCallbacks> request5(new MockCallbacks());
299 db->DeleteDatabase(request2);
300
301 EXPECT_EQ(db->ConnectionCount(), 1UL);
302 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
303 EXPECT_EQ(db->PendingOpenDeleteCount(), 3UL);
304
305 // Simulate renderer going away.
306 request3->set_valid(false);
307 request4->set_valid(false);
308
309 // Close the blocking connection. First delete request should succeed.
310 EXPECT_FALSE(request2->success_called());
311 db->Close(request1->connection(), true /* forced */);
312 EXPECT_TRUE(request2->success_called());
313
314 // Delete requests that have lost dispatcher should still be processed so
315 // that e.g. a delete followed by a window close is not ignored.
316 EXPECT_FALSE(request3->blocked_called());
317 EXPECT_TRUE(request3->success_called());
318 EXPECT_FALSE(request3->error_called());
319 EXPECT_TRUE(request3->HasOneRef()); // local
320
321 // Open requests that have lost dispatcher should not be processed.
322 EXPECT_FALSE(request4->blocked_called());
323 EXPECT_FALSE(request4->success_called());
324 EXPECT_FALSE(request4->error_called());
325 EXPECT_TRUE(request4->HasOneRef()); // local
326
327 // Final delete request should also run.
328 EXPECT_TRUE(request2->success_called());
329
330 // And everything else should be complete.
331 EXPECT_EQ(db->ConnectionCount(), 0UL);
332 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
333 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
334 }
335
336 leveldb::Status DummyOperation(IndexedDBTransaction* transaction) { 231 leveldb::Status DummyOperation(IndexedDBTransaction* transaction) {
337 return leveldb::Status::OK(); 232 return leveldb::Status::OK();
338 } 233 }
339 234
340 class IndexedDBDatabaseOperationTest : public testing::Test { 235 class IndexedDBDatabaseOperationTest : public testing::Test {
341 public: 236 public:
342 IndexedDBDatabaseOperationTest() 237 IndexedDBDatabaseOperationTest()
343 : commit_success_(leveldb::Status::OK()), 238 : commit_success_(leveldb::Status::OK()),
344 factory_(new MockIndexedDBFactory()) {} 239 factory_(new MockIndexedDBFactory()) {}
345 240
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 387 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
493 388
494 // This will execute the Put then Delete. 389 // This will execute the Put then Delete.
495 RunPostedTasks(); 390 RunPostedTasks();
496 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 391 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
497 392
498 transaction_->Commit(); // Cleans up the object hierarchy. 393 transaction_->Commit(); // Cleans up the object hierarchy.
499 } 394 }
500 395
501 } // namespace content 396 } // 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.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698