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

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

Issue 2386683003: IndexedDB: Ignore open/delete requests from terminated renderers. (Closed)
Patch Set: Allow deletes to proceed Created 4 years, 2 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 request->connection(), 143 request->connection(),
144 scope, 144 scope,
145 blink::WebIDBTransactionModeReadOnly); 145 blink::WebIDBTransactionModeReadOnly);
146 146
147 request->connection()->ForceClose(); 147 request->connection()->ForceClose();
148 148
149 EXPECT_TRUE(backing_store->HasOneRef()); // local 149 EXPECT_TRUE(backing_store->HasOneRef()); // local
150 EXPECT_TRUE(callbacks->abort_called()); 150 EXPECT_TRUE(callbacks->abort_called());
151 } 151 }
152 152
153 class MockDeleteCallbacks : public IndexedDBCallbacks { 153 class MockCallbacks : public IndexedDBCallbacks {
154 public: 154 public:
155 MockDeleteCallbacks() 155 MockCallbacks() : IndexedDBCallbacks(NULL, 0, 0) {}
156 : IndexedDBCallbacks(NULL, 0, 0),
157 blocked_called_(false),
158 success_called_(false) {}
159 156
160 void OnBlocked(int64_t existing_version) override { blocked_called_ = true; } 157 void OnBlocked(int64_t existing_version) override { blocked_called_ = true; }
161 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 {
160 error_called_ = true;
161 }
162 bool IsValid() const override { return valid_; }
162 163
163 bool blocked_called() const { return blocked_called_; } 164 bool blocked_called() const { return blocked_called_; }
164 bool success_called() const { return success_called_; } 165 bool success_called() const { return success_called_; }
166 bool error_called() const { return error_called_; }
167 void set_valid(bool valid) { valid_ = valid; }
165 168
166 private: 169 private:
167 ~MockDeleteCallbacks() override {} 170 ~MockCallbacks() override {}
168 171
169 bool blocked_called_; 172 bool blocked_called_ = false;
170 bool success_called_; 173 bool success_called_ = false;
174 bool error_called_ = false;
175 bool valid_ = true;
171 176
172 DISALLOW_COPY_AND_ASSIGN(MockDeleteCallbacks); 177 DISALLOW_COPY_AND_ASSIGN(MockCallbacks);
173 }; 178 };
174 179
175 TEST(IndexedDBDatabaseTest, PendingDelete) { 180 TEST(IndexedDBDatabaseTest, PendingDelete) {
176 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 181 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
177 new IndexedDBFakeBackingStore(); 182 new IndexedDBFakeBackingStore();
178 EXPECT_TRUE(backing_store->HasOneRef()); // local 183 EXPECT_TRUE(backing_store->HasOneRef()); // local
179 184
180 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); 185 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
181 leveldb::Status s; 186 leveldb::Status s;
182 scoped_refptr<IndexedDBDatabase> db = 187 scoped_refptr<IndexedDBDatabase> db =
(...skipping 13 matching lines...) Expand all
196 base::MakeUnique<IndexedDBPendingConnection>( 201 base::MakeUnique<IndexedDBPendingConnection>(
197 request1, callbacks1, kFakeChildProcessId, transaction_id1, 202 request1, callbacks1, kFakeChildProcessId, transaction_id1,
198 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); 203 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
199 db->OpenConnection(std::move(connection)); 204 db->OpenConnection(std::move(connection));
200 205
201 EXPECT_EQ(db->ConnectionCount(), 1UL); 206 EXPECT_EQ(db->ConnectionCount(), 1UL);
202 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); 207 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
203 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); 208 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
204 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 209 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
205 210
206 scoped_refptr<MockDeleteCallbacks> request2(new MockDeleteCallbacks()); 211 scoped_refptr<MockCallbacks> request2(new MockCallbacks());
207 db->DeleteDatabase(request2); 212 db->DeleteDatabase(request2);
208 EXPECT_EQ(db->ConnectionCount(), 1UL); 213 EXPECT_EQ(db->ConnectionCount(), 1UL);
209 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); 214 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
210 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); 215 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
211 216
212 EXPECT_FALSE(request2->blocked_called()); 217 EXPECT_FALSE(request2->blocked_called());
213 db->VersionChangeIgnored(); 218 db->VersionChangeIgnored();
214 EXPECT_TRUE(request2->blocked_called()); 219 EXPECT_TRUE(request2->blocked_called());
215 EXPECT_EQ(db->ConnectionCount(), 1UL); 220 EXPECT_EQ(db->ConnectionCount(), 1UL);
216 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); 221 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
217 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); 222 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
218 223
219 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 224 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
220 225
221 db->Close(request1->connection(), true /* forced */); 226 db->Close(request1->connection(), true /* forced */);
222 EXPECT_EQ(db->ConnectionCount(), 0UL); 227 EXPECT_EQ(db->ConnectionCount(), 0UL);
223 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); 228 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
224 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); 229 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
225 230
226 EXPECT_FALSE(db->backing_store()); 231 EXPECT_FALSE(db->backing_store());
227 EXPECT_TRUE(backing_store->HasOneRef()); // local 232 EXPECT_TRUE(backing_store->HasOneRef()); // local
228 EXPECT_TRUE(request2->success_called()); 233 EXPECT_TRUE(request2->success_called());
229 } 234 }
230 235
236 TEST(IndexedDBDatabaseTest, ConnectionRequestsNoLongerValid) {
237 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
238 new IndexedDBFakeBackingStore();
239
240 const int64_t transaction_id1 = 1;
241 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory();
242 leveldb::Status s;
243 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create(
244 ASCIIToUTF16("db"), backing_store.get(), factory.get(),
245 IndexedDBDatabase::Identifier(), &s);
246
247 // Make a connection request. This will be processed immediately.
248 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
249 {
250 std::unique_ptr<IndexedDBPendingConnection> connection(
251 base::MakeUnique<IndexedDBPendingConnection>(
252 request1, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()),
253 kFakeChildProcessId, transaction_id1,
254 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
255 db->OpenConnection(std::move(connection));
256 }
257
258 EXPECT_EQ(db->ConnectionCount(), 1UL);
259 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
260 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
261
262 // Make a delete request. This will be blocked by the open.
263 scoped_refptr<MockCallbacks> request2(new MockCallbacks());
264 db->DeleteDatabase(request2);
265
266 EXPECT_EQ(db->ConnectionCount(), 1UL);
267 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
268 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
269
270 db->VersionChangeIgnored();
271
272 EXPECT_TRUE(request2->blocked_called());
273
274 // Make another delete request. This will be waiting in the queue.
275 scoped_refptr<MockCallbacks> request3(new MockCallbacks());
276 db->DeleteDatabase(request3);
277 EXPECT_FALSE(request3->HasOneRef()); // local, db
278
279 EXPECT_EQ(db->ConnectionCount(), 1UL);
280 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
281 EXPECT_EQ(db->PendingOpenDeleteCount(), 1UL);
282
283 // Make another connection request. This will also be waiting in the queue.
284 scoped_refptr<MockCallbacks> request4(new MockCallbacks());
285 {
286 std::unique_ptr<IndexedDBPendingConnection> connection(
287 base::MakeUnique<IndexedDBPendingConnection>(
288 request4, make_scoped_refptr(new MockIndexedDBDatabaseCallbacks()),
289 kFakeChildProcessId, transaction_id1,
290 IndexedDBDatabaseMetadata::DEFAULT_VERSION));
291 db->OpenConnection(std::move(connection));
292 }
293
294 EXPECT_EQ(db->ConnectionCount(), 1UL);
295 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
296 EXPECT_EQ(db->PendingOpenDeleteCount(), 2UL);
297
298 // Finally yet another delete request, also waiting in the queue.
299 scoped_refptr<MockCallbacks> request5(new MockCallbacks());
300 db->DeleteDatabase(request2);
301
302 EXPECT_EQ(db->ConnectionCount(), 1UL);
303 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL);
304 EXPECT_EQ(db->PendingOpenDeleteCount(), 3UL);
305
306 // Simulate renderer going away.
307 request3->set_valid(false);
308 request4->set_valid(false);
309
310 // Close the blocking connection. First delete request should succeed.
311 EXPECT_FALSE(request2->success_called());
312 db->Close(request1->connection(), true /* forced */);
313 EXPECT_TRUE(request2->success_called());
314
315 // Delete requests that have lost dispatcher should still be processed so
316 // that e.g. a delete followed by a window close is not ignored.
317 EXPECT_FALSE(request3->blocked_called());
318 EXPECT_TRUE(request3->success_called());
319 EXPECT_FALSE(request3->error_called());
320 EXPECT_TRUE(request3->HasOneRef()); // local
321
322 // Open requests that have lost dispatcher should not be processed.
323 EXPECT_FALSE(request4->blocked_called());
324 EXPECT_FALSE(request4->success_called());
325 EXPECT_FALSE(request4->error_called());
326 EXPECT_TRUE(request4->HasOneRef()); // local
327
328 // Final delete request should also run.
329 EXPECT_TRUE(request2->success_called());
330
331 // And everything else should be complete.
332 EXPECT_EQ(db->ConnectionCount(), 0UL);
333 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL);
334 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL);
335 }
336
231 void DummyOperation(IndexedDBTransaction* transaction) { 337 void DummyOperation(IndexedDBTransaction* transaction) {
232 } 338 }
233 339
234 class IndexedDBDatabaseOperationTest : public testing::Test { 340 class IndexedDBDatabaseOperationTest : public testing::Test {
235 public: 341 public:
236 IndexedDBDatabaseOperationTest() 342 IndexedDBDatabaseOperationTest()
237 : commit_success_(leveldb::Status::OK()), 343 : commit_success_(leveldb::Status::OK()),
238 factory_(new MockIndexedDBFactory()) {} 344 factory_(new MockIndexedDBFactory()) {}
239 345
240 void SetUp() override { 346 void SetUp() override {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); 517 EXPECT_EQ(1ULL, db_->metadata().object_stores.size());
412 518
413 // This will execute the Put then Delete. 519 // This will execute the Put then Delete.
414 RunPostedTasks(); 520 RunPostedTasks();
415 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); 521 EXPECT_EQ(0ULL, db_->metadata().object_stores.size());
416 522
417 transaction_->Commit(); // Cleans up the object hierarchy. 523 transaction_->Commit(); // Cleans up the object hierarchy.
418 } 524 }
419 525
420 } // namespace content 526 } // 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