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

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

Issue 203833003: Add the IndexedDBActiveBlobRegistry, currently unused, to enable future blob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang fixes Created 6 years, 9 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 | Annotate | Revision Log
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_factory.h" 5 #include "content/browser/indexed_db/indexed_db_factory.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const base::FilePath& data_directory) { 42 const base::FilePath& data_directory) {
43 blink::WebIDBDataLoss data_loss = 43 blink::WebIDBDataLoss data_loss =
44 blink::WebIDBDataLossNone; 44 blink::WebIDBDataLossNone;
45 std::string data_loss_message; 45 std::string data_loss_message;
46 bool disk_full; 46 bool disk_full;
47 scoped_refptr<IndexedDBBackingStore> backing_store = 47 scoped_refptr<IndexedDBBackingStore> backing_store =
48 OpenBackingStore(origin, 48 OpenBackingStore(origin,
49 data_directory, 49 data_directory,
50 &data_loss, 50 &data_loss,
51 &data_loss_message, 51 &data_loss_message,
52 &disk_full); 52 &disk_full,
53 NULL /* task_runner */);
53 EXPECT_EQ(blink::WebIDBDataLossNone, data_loss); 54 EXPECT_EQ(blink::WebIDBDataLossNone, data_loss);
54 return backing_store; 55 return backing_store;
55 } 56 }
56 57
57 void TestCloseBackingStore(IndexedDBBackingStore* backing_store) { 58 void TestCloseBackingStore(IndexedDBBackingStore* backing_store) {
58 CloseBackingStore(backing_store->origin_url()); 59 CloseBackingStore(backing_store->origin_url());
59 } 60 }
60 61
61 void TestReleaseBackingStore(IndexedDBBackingStore* backing_store, 62 void TestReleaseBackingStore(IndexedDBBackingStore* backing_store,
62 bool immediate) { 63 bool immediate) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 public: 183 public:
183 DiskFullFactory() : IndexedDBFactory(NULL) {} 184 DiskFullFactory() : IndexedDBFactory(NULL) {}
184 185
185 private: 186 private:
186 virtual ~DiskFullFactory() {} 187 virtual ~DiskFullFactory() {}
187 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( 188 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
188 const GURL& origin_url, 189 const GURL& origin_url,
189 const base::FilePath& data_directory, 190 const base::FilePath& data_directory,
190 blink::WebIDBDataLoss* data_loss, 191 blink::WebIDBDataLoss* data_loss,
191 std::string* data_loss_message, 192 std::string* data_loss_message,
192 bool* disk_full) OVERRIDE { 193 bool* disk_full,
194 base::TaskRunner* task_runner) OVERRIDE {
193 *disk_full = true; 195 *disk_full = true;
194 return scoped_refptr<IndexedDBBackingStore>(); 196 return scoped_refptr<IndexedDBBackingStore>();
195 } 197 }
196 }; 198 };
197 199
198 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { 200 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks {
199 public: 201 public:
200 LookingForQuotaErrorMockCallbacks() 202 LookingForQuotaErrorMockCallbacks()
201 : IndexedDBCallbacks(NULL, 0, 0), error_called_(false) {} 203 : IndexedDBCallbacks(NULL, 0, 0), error_called_(false) {}
202 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE { 204 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE {
203 error_called_ = true; 205 error_called_ = true;
204 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code()); 206 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code());
205 } 207 }
206 208
207 private: 209 private:
208 virtual ~LookingForQuotaErrorMockCallbacks() { EXPECT_TRUE(error_called_); } 210 virtual ~LookingForQuotaErrorMockCallbacks() { EXPECT_TRUE(error_called_); }
209 bool error_called_; 211 bool error_called_;
210 }; 212 };
211 213
212 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { 214 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) {
213 const GURL origin("http://localhost:81"); 215 const GURL origin("http://localhost:81");
216 base::ScopedTempDir temp_directory;
217 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
214 218
215 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory; 219 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory;
216 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = 220 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks =
217 new LookingForQuotaErrorMockCallbacks; 221 new LookingForQuotaErrorMockCallbacks;
218 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = 222 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks =
219 new IndexedDBDatabaseCallbacks(NULL, 0, 0); 223 new IndexedDBDatabaseCallbacks(NULL, 0, 0);
220 const base::string16 name(ASCIIToUTF16("name")); 224 const base::string16 name(ASCIIToUTF16("name"));
221 IndexedDBPendingConnection connection(callbacks, 225 IndexedDBPendingConnection connection(callbacks,
222 dummy_database_callbacks, 226 dummy_database_callbacks,
223 0, /* child_process_id */ 227 0, /* child_process_id */
224 2, /* transaction_id */ 228 2, /* transaction_id */
225 1 /* version */); 229 1 /* version */);
226 factory->Open( 230 factory->Open(
227 name, connection, origin, base::FilePath(FILE_PATH_LITERAL("/dummy"))); 231 name, connection, origin, temp_directory.path(), NULL /* task_runner */);
228 } 232 }
229 233
230 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { 234 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) {
231 GURL origin("http://localhost:81"); 235 GURL origin("http://localhost:81");
232 236
233 base::ScopedTempDir temp_directory; 237 base::ScopedTempDir temp_directory;
234 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 238 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
235 239
236 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); 240 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL);
237 241
238 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 242 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
239 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 243 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
240 new MockIndexedDBDatabaseCallbacks()); 244 new MockIndexedDBDatabaseCallbacks());
241 const int64 transaction_id = 1; 245 const int64 transaction_id = 1;
242 IndexedDBPendingConnection connection( 246 IndexedDBPendingConnection connection(
243 callbacks, 247 callbacks,
244 db_callbacks, 248 db_callbacks,
245 0, /* child_process_id */ 249 0, /* child_process_id */
246 transaction_id, 250 transaction_id,
247 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 251 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
248 factory->Open(ASCIIToUTF16("db"), connection, origin, temp_directory.path()); 252 factory->Open(ASCIIToUTF16("db"),
253 connection,
254 origin,
255 temp_directory.path(),
256 NULL /* task_runner */);
249 257
250 EXPECT_TRUE(callbacks->connection()); 258 EXPECT_TRUE(callbacks->connection());
251 259
252 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); 260 EXPECT_TRUE(factory->IsBackingStoreOpen(origin));
253 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); 261 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin));
254 262
255 callbacks->connection()->ForceClose(); 263 callbacks->connection()->ForceClose();
256 264
257 EXPECT_FALSE(factory->IsBackingStoreOpen(origin)); 265 EXPECT_FALSE(factory->IsBackingStoreOpen(origin));
258 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); 266 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin));
(...skipping 10 matching lines...) Expand all
269 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 277 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
270 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 278 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
271 new MockIndexedDBDatabaseCallbacks()); 279 new MockIndexedDBDatabaseCallbacks());
272 const int64 transaction_id = 1; 280 const int64 transaction_id = 1;
273 IndexedDBPendingConnection connection( 281 IndexedDBPendingConnection connection(
274 callbacks, 282 callbacks,
275 db_callbacks, 283 db_callbacks,
276 0, /* child_process_id */ 284 0, /* child_process_id */
277 transaction_id, 285 transaction_id,
278 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 286 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
279 factory->Open(ASCIIToUTF16("db"), connection, origin, temp_directory.path()); 287 factory->Open(ASCIIToUTF16("db"),
288 connection,
289 origin,
290 temp_directory.path(),
291 NULL /* task_runner */);
280 292
281 EXPECT_TRUE(callbacks->connection()); 293 EXPECT_TRUE(callbacks->connection());
282 IndexedDBBackingStore* store = 294 IndexedDBBackingStore* store =
283 callbacks->connection()->database()->backing_store(); 295 callbacks->connection()->database()->backing_store();
284 EXPECT_FALSE(store->HasOneRef()); // Factory and database. 296 EXPECT_FALSE(store->HasOneRef()); // Factory and database.
285 297
286 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); 298 EXPECT_TRUE(factory->IsBackingStoreOpen(origin));
287 callbacks->connection()->Close(); 299 callbacks->connection()->Close();
288 EXPECT_TRUE(store->HasOneRef()); // Factory. 300 EXPECT_TRUE(store->HasOneRef()); // Factory.
289 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); 301 EXPECT_TRUE(factory->IsBackingStoreOpen(origin));
(...skipping 18 matching lines...) Expand all
308 320
309 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); 321 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL);
310 EXPECT_FALSE(factory->IsBackingStoreOpen(origin)); 322 EXPECT_FALSE(factory->IsBackingStoreOpen(origin));
311 323
312 const bool expect_connection = false; 324 const bool expect_connection = false;
313 scoped_refptr<MockIndexedDBCallbacks> callbacks( 325 scoped_refptr<MockIndexedDBCallbacks> callbacks(
314 new MockIndexedDBCallbacks(expect_connection)); 326 new MockIndexedDBCallbacks(expect_connection));
315 factory->DeleteDatabase(ASCIIToUTF16("db"), 327 factory->DeleteDatabase(ASCIIToUTF16("db"),
316 callbacks, 328 callbacks,
317 origin, 329 origin,
318 temp_directory.path()); 330 temp_directory.path(),
331 NULL /* task_runner */);
319 332
320 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); 333 EXPECT_TRUE(factory->IsBackingStoreOpen(origin));
321 EXPECT_TRUE(factory->IsBackingStorePendingClose(origin)); 334 EXPECT_TRUE(factory->IsBackingStorePendingClose(origin));
322 335
323 // Now simulate shutdown, which should stop the timer. 336 // Now simulate shutdown, which should stop the timer.
324 factory->ContextDestroyed(); 337 factory->ContextDestroyed();
325 338
326 EXPECT_FALSE(factory->IsBackingStoreOpen(origin)); 339 EXPECT_FALSE(factory->IsBackingStoreOpen(origin));
327 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); 340 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin));
328 } 341 }
329 342
330 TEST_F(IndexedDBFactoryTest, GetDatabaseNamesClosesBackingStore) { 343 TEST_F(IndexedDBFactoryTest, GetDatabaseNamesClosesBackingStore) {
331 GURL origin("http://localhost:81"); 344 GURL origin("http://localhost:81");
332 345
333 base::ScopedTempDir temp_directory; 346 base::ScopedTempDir temp_directory;
334 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 347 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
335 348
336 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); 349 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL);
337 EXPECT_FALSE(factory->IsBackingStoreOpen(origin)); 350 EXPECT_FALSE(factory->IsBackingStoreOpen(origin));
338 351
339 const bool expect_connection = false; 352 const bool expect_connection = false;
340 scoped_refptr<MockIndexedDBCallbacks> callbacks( 353 scoped_refptr<MockIndexedDBCallbacks> callbacks(
341 new MockIndexedDBCallbacks(expect_connection)); 354 new MockIndexedDBCallbacks(expect_connection));
342 factory->GetDatabaseNames(callbacks, 355 factory->GetDatabaseNames(
343 origin, 356 callbacks, origin, temp_directory.path(), NULL /* task_runner */);
344 temp_directory.path());
345 357
346 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); 358 EXPECT_TRUE(factory->IsBackingStoreOpen(origin));
347 EXPECT_TRUE(factory->IsBackingStorePendingClose(origin)); 359 EXPECT_TRUE(factory->IsBackingStorePendingClose(origin));
348 360
349 // Now simulate shutdown, which should stop the timer. 361 // Now simulate shutdown, which should stop the timer.
350 factory->ContextDestroyed(); 362 factory->ContextDestroyed();
351 363
352 EXPECT_FALSE(factory->IsBackingStoreOpen(origin)); 364 EXPECT_FALSE(factory->IsBackingStoreOpen(origin));
353 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); 365 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin));
354 } 366 }
355 367
356 TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) { 368 TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) {
357 GURL origin("http://localhost:81"); 369 GURL origin("http://localhost:81");
358 370
359 base::ScopedTempDir temp_directory; 371 base::ScopedTempDir temp_directory;
360 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 372 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
361 373
362 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); 374 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL);
363 375
364 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 376 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
365 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 377 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
366 new MockIndexedDBDatabaseCallbacks()); 378 new MockIndexedDBDatabaseCallbacks());
367 const int64 transaction_id = 1; 379 const int64 transaction_id = 1;
368 IndexedDBPendingConnection connection( 380 IndexedDBPendingConnection connection(
369 callbacks, 381 callbacks,
370 db_callbacks, 382 db_callbacks,
371 0, /* child_process_id */ 383 0, /* child_process_id */
372 transaction_id, 384 transaction_id,
373 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 385 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
374 factory->Open(ASCIIToUTF16("db"), connection, origin, temp_directory.path()); 386 factory->Open(ASCIIToUTF16("db"),
387 connection,
388 origin,
389 temp_directory.path(),
390 NULL /* task_runner */);
375 391
376 EXPECT_TRUE(callbacks->connection()); 392 EXPECT_TRUE(callbacks->connection());
377 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); 393 EXPECT_TRUE(factory->IsBackingStoreOpen(origin));
378 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); 394 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin));
379 395
380 callbacks->connection()->Close(); 396 callbacks->connection()->Close();
381 397
382 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); 398 EXPECT_TRUE(factory->IsBackingStoreOpen(origin));
383 EXPECT_TRUE(factory->IsBackingStorePendingClose(origin)); 399 EXPECT_TRUE(factory->IsBackingStorePendingClose(origin));
384 400
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 456
441 // Open at version 2, then close. 457 // Open at version 2, then close.
442 { 458 {
443 scoped_refptr<MockIndexedDBCallbacks> callbacks( 459 scoped_refptr<MockIndexedDBCallbacks> callbacks(
444 new UpgradeNeededCallbacks()); 460 new UpgradeNeededCallbacks());
445 IndexedDBPendingConnection connection(callbacks, 461 IndexedDBPendingConnection connection(callbacks,
446 db_callbacks, 462 db_callbacks,
447 0, /* child_process_id */ 463 0, /* child_process_id */
448 transaction_id, 464 transaction_id,
449 db_version); 465 db_version);
450 factory->Open(db_name, connection, origin, temp_directory.path()); 466 factory->Open(db_name,
467 connection,
468 origin,
469 temp_directory.path(),
470 NULL /* task_runner */);
451 EXPECT_TRUE(factory->IsDatabaseOpen(origin, db_name)); 471 EXPECT_TRUE(factory->IsDatabaseOpen(origin, db_name));
452 472
453 // Pump the message loop so the upgrade transaction can run. 473 // Pump the message loop so the upgrade transaction can run.
454 base::MessageLoop::current()->RunUntilIdle(); 474 base::MessageLoop::current()->RunUntilIdle();
455 EXPECT_TRUE(callbacks->connection()); 475 EXPECT_TRUE(callbacks->connection());
456 callbacks->connection()->database()->Commit(transaction_id); 476 callbacks->connection()->database()->Commit(transaction_id);
457 477
458 callbacks->connection()->Close(); 478 callbacks->connection()->Close();
459 EXPECT_FALSE(factory->IsDatabaseOpen(origin, db_name)); 479 EXPECT_FALSE(factory->IsDatabaseOpen(origin, db_name));
460 } 480 }
461 481
462 // Open at version < 2, which will fail; ensure factory doesn't retain 482 // Open at version < 2, which will fail; ensure factory doesn't retain
463 // the database object. 483 // the database object.
464 { 484 {
465 scoped_refptr<IndexedDBCallbacks> callbacks(new ErrorCallbacks()); 485 scoped_refptr<IndexedDBCallbacks> callbacks(new ErrorCallbacks());
466 IndexedDBPendingConnection connection(callbacks, 486 IndexedDBPendingConnection connection(callbacks,
467 db_callbacks, 487 db_callbacks,
468 0, /* child_process_id */ 488 0, /* child_process_id */
469 transaction_id, 489 transaction_id,
470 db_version - 1); 490 db_version - 1);
471 factory->Open(db_name, connection, origin, temp_directory.path()); 491 factory->Open(db_name,
492 connection,
493 origin,
494 temp_directory.path(),
495 NULL /* task_runner */);
472 EXPECT_FALSE(factory->IsDatabaseOpen(origin, db_name)); 496 EXPECT_FALSE(factory->IsDatabaseOpen(origin, db_name));
473 } 497 }
474 498
475 // Terminate all pending-close timers. 499 // Terminate all pending-close timers.
476 factory->ForceClose(origin); 500 factory->ForceClose(origin);
477 } 501 }
478 502
479 } // namespace content 503 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698