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

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

Issue 1832553002: IndexedDB: Pass url::Origin rather than GURL over IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@origin-wdb
Patch Set: Rebased Created 4 years, 8 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = 256 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks =
257 new LookingForQuotaErrorMockCallbacks; 257 new LookingForQuotaErrorMockCallbacks;
258 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = 258 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks =
259 new IndexedDBDatabaseCallbacks(NULL, 0, 0); 259 new IndexedDBDatabaseCallbacks(NULL, 0, 0);
260 const base::string16 name(ASCIIToUTF16("name")); 260 const base::string16 name(ASCIIToUTF16("name"));
261 IndexedDBPendingConnection connection(callbacks, 261 IndexedDBPendingConnection connection(callbacks,
262 dummy_database_callbacks, 262 dummy_database_callbacks,
263 0, /* child_process_id */ 263 0, /* child_process_id */
264 2, /* transaction_id */ 264 2, /* transaction_id */
265 1 /* version */); 265 1 /* version */);
266 factory->Open(name, 266 factory->Open(name, connection, NULL /* request_context */,
267 connection, 267 url::Origin(origin), temp_directory.path());
268 NULL /* request_context */,
269 origin,
270 temp_directory.path());
271 EXPECT_TRUE(callbacks->error_called()); 268 EXPECT_TRUE(callbacks->error_called());
272 } 269 }
273 270
274 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { 271 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) {
275 GURL origin("http://localhost:81"); 272 GURL origin("http://localhost:81");
276 273
277 base::ScopedTempDir temp_directory; 274 base::ScopedTempDir temp_directory;
278 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 275 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
279 276
280 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 277 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
281 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 278 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
282 new MockIndexedDBDatabaseCallbacks()); 279 new MockIndexedDBDatabaseCallbacks());
283 const int64_t transaction_id = 1; 280 const int64_t transaction_id = 1;
284 IndexedDBPendingConnection connection( 281 IndexedDBPendingConnection connection(
285 callbacks, db_callbacks, 0, /* child_process_id */ 282 callbacks, db_callbacks, 0, /* child_process_id */
286 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION); 283 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION);
287 factory()->Open(ASCIIToUTF16("db"), 284 factory()->Open(ASCIIToUTF16("db"), connection, NULL /* request_context */,
288 connection, 285 url::Origin(origin), temp_directory.path());
289 NULL /* request_context */,
290 origin,
291 temp_directory.path());
292 286
293 EXPECT_TRUE(callbacks->connection()); 287 EXPECT_TRUE(callbacks->connection());
294 288
295 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); 289 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin));
296 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); 290 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin));
297 291
298 callbacks->connection()->ForceClose(); 292 callbacks->connection()->ForceClose();
299 293
300 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); 294 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin));
301 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); 295 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin));
302 } 296 }
303 297
304 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { 298 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) {
305 GURL origin("http://localhost:81"); 299 GURL origin("http://localhost:81");
306 300
307 base::ScopedTempDir temp_directory; 301 base::ScopedTempDir temp_directory;
308 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 302 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
309 303
310 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 304 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
311 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 305 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
312 new MockIndexedDBDatabaseCallbacks()); 306 new MockIndexedDBDatabaseCallbacks());
313 const int64_t transaction_id = 1; 307 const int64_t transaction_id = 1;
314 IndexedDBPendingConnection connection( 308 IndexedDBPendingConnection connection(
315 callbacks, db_callbacks, 0, /* child_process_id */ 309 callbacks, db_callbacks, 0, /* child_process_id */
316 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION); 310 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION);
317 factory()->Open(ASCIIToUTF16("db"), 311 factory()->Open(ASCIIToUTF16("db"), connection, NULL /* request_context */,
318 connection, 312 url::Origin(origin), temp_directory.path());
319 NULL /* request_context */,
320 origin,
321 temp_directory.path());
322 313
323 EXPECT_TRUE(callbacks->connection()); 314 EXPECT_TRUE(callbacks->connection());
324 IndexedDBBackingStore* store = 315 IndexedDBBackingStore* store =
325 callbacks->connection()->database()->backing_store(); 316 callbacks->connection()->database()->backing_store();
326 EXPECT_FALSE(store->HasOneRef()); // Factory and database. 317 EXPECT_FALSE(store->HasOneRef()); // Factory and database.
327 318
328 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); 319 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin));
329 callbacks->connection()->Close(); 320 callbacks->connection()->Close();
330 EXPECT_TRUE(store->HasOneRef()); // Factory. 321 EXPECT_TRUE(store->HasOneRef()); // Factory.
331 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); 322 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin));
(...skipping 14 matching lines...) Expand all
346 GURL origin("http://localhost:81"); 337 GURL origin("http://localhost:81");
347 338
348 base::ScopedTempDir temp_directory; 339 base::ScopedTempDir temp_directory;
349 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 340 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
350 341
351 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); 342 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin));
352 343
353 const bool expect_connection = false; 344 const bool expect_connection = false;
354 scoped_refptr<MockIndexedDBCallbacks> callbacks( 345 scoped_refptr<MockIndexedDBCallbacks> callbacks(
355 new MockIndexedDBCallbacks(expect_connection)); 346 new MockIndexedDBCallbacks(expect_connection));
356 factory()->DeleteDatabase(ASCIIToUTF16("db"), 347 factory()->DeleteDatabase(ASCIIToUTF16("db"), NULL /* request_context */,
357 NULL /* request_context */, 348 callbacks, url::Origin(origin),
358 callbacks,
359 origin,
360 temp_directory.path()); 349 temp_directory.path());
361 350
362 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); 351 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin));
363 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); 352 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin));
364 353
365 // Now simulate shutdown, which should stop the timer. 354 // Now simulate shutdown, which should stop the timer.
366 factory()->ContextDestroyed(); 355 factory()->ContextDestroyed();
367 356
368 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); 357 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin));
369 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); 358 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin));
370 } 359 }
371 360
372 TEST_F(IndexedDBFactoryTest, GetDatabaseNamesClosesBackingStore) { 361 TEST_F(IndexedDBFactoryTest, GetDatabaseNamesClosesBackingStore) {
373 GURL origin("http://localhost:81"); 362 GURL origin("http://localhost:81");
374 363
375 base::ScopedTempDir temp_directory; 364 base::ScopedTempDir temp_directory;
376 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 365 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
377 366
378 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); 367 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin));
379 368
380 const bool expect_connection = false; 369 const bool expect_connection = false;
381 scoped_refptr<MockIndexedDBCallbacks> callbacks( 370 scoped_refptr<MockIndexedDBCallbacks> callbacks(
382 new MockIndexedDBCallbacks(expect_connection)); 371 new MockIndexedDBCallbacks(expect_connection));
383 factory()->GetDatabaseNames( 372 factory()->GetDatabaseNames(callbacks, url::Origin(origin),
384 callbacks, origin, temp_directory.path(), NULL /* request_context */); 373 temp_directory.path(),
374 NULL /* request_context */);
385 375
386 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); 376 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin));
387 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); 377 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin));
388 378
389 // Now simulate shutdown, which should stop the timer. 379 // Now simulate shutdown, which should stop the timer.
390 factory()->ContextDestroyed(); 380 factory()->ContextDestroyed();
391 381
392 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); 382 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin));
393 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); 383 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin));
394 } 384 }
395 385
396 TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) { 386 TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) {
397 GURL origin("http://localhost:81"); 387 GURL origin("http://localhost:81");
398 388
399 base::ScopedTempDir temp_directory; 389 base::ScopedTempDir temp_directory;
400 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 390 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
401 391
402 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 392 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
403 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 393 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
404 new MockIndexedDBDatabaseCallbacks()); 394 new MockIndexedDBDatabaseCallbacks());
405 const int64_t transaction_id = 1; 395 const int64_t transaction_id = 1;
406 IndexedDBPendingConnection connection( 396 IndexedDBPendingConnection connection(
407 callbacks, db_callbacks, 0, /* child_process_id */ 397 callbacks, db_callbacks, 0, /* child_process_id */
408 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION); 398 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION);
409 factory()->Open(ASCIIToUTF16("db"), 399 factory()->Open(ASCIIToUTF16("db"), connection, NULL /* request_context */,
410 connection, 400 url::Origin(origin), temp_directory.path());
411 NULL /* request_context */,
412 origin,
413 temp_directory.path());
414 401
415 EXPECT_TRUE(callbacks->connection()); 402 EXPECT_TRUE(callbacks->connection());
416 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); 403 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin));
417 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); 404 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin));
418 405
419 callbacks->connection()->Close(); 406 callbacks->connection()->Close();
420 407
421 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); 408 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin));
422 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); 409 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin));
423 410
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 471
485 // Open at version 2, then close. 472 // Open at version 2, then close.
486 { 473 {
487 scoped_refptr<MockIndexedDBCallbacks> callbacks( 474 scoped_refptr<MockIndexedDBCallbacks> callbacks(
488 new UpgradeNeededCallbacks()); 475 new UpgradeNeededCallbacks());
489 IndexedDBPendingConnection connection(callbacks, 476 IndexedDBPendingConnection connection(callbacks,
490 db_callbacks, 477 db_callbacks,
491 0, /* child_process_id */ 478 0, /* child_process_id */
492 transaction_id, 479 transaction_id,
493 db_version); 480 db_version);
494 factory()->Open(db_name, 481 factory()->Open(db_name, connection, NULL /* request_context */,
495 connection, 482 url::Origin(origin), temp_directory.path());
496 NULL /* request_context */,
497 origin,
498 temp_directory.path());
499 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); 483 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name));
500 484
501 // Pump the message loop so the upgrade transaction can run. 485 // Pump the message loop so the upgrade transaction can run.
502 base::MessageLoop::current()->RunUntilIdle(); 486 base::MessageLoop::current()->RunUntilIdle();
503 EXPECT_TRUE(callbacks->connection()); 487 EXPECT_TRUE(callbacks->connection());
504 callbacks->connection()->database()->Commit(transaction_id); 488 callbacks->connection()->database()->Commit(transaction_id);
505 489
506 callbacks->connection()->Close(); 490 callbacks->connection()->Close();
507 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); 491 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name));
508 } 492 }
509 493
510 // Open at version < 2, which will fail; ensure factory doesn't retain 494 // Open at version < 2, which will fail; ensure factory doesn't retain
511 // the database object. 495 // the database object.
512 { 496 {
513 scoped_refptr<ErrorCallbacks> callbacks(new ErrorCallbacks()); 497 scoped_refptr<ErrorCallbacks> callbacks(new ErrorCallbacks());
514 IndexedDBPendingConnection connection(callbacks, 498 IndexedDBPendingConnection connection(callbacks,
515 db_callbacks, 499 db_callbacks,
516 0, /* child_process_id */ 500 0, /* child_process_id */
517 transaction_id, 501 transaction_id,
518 db_version - 1); 502 db_version - 1);
519 factory()->Open(db_name, 503 factory()->Open(db_name, connection, NULL /* request_context */,
520 connection, 504 url::Origin(origin), temp_directory.path());
521 NULL /* request_context */,
522 origin,
523 temp_directory.path());
524 EXPECT_TRUE(callbacks->saw_error()); 505 EXPECT_TRUE(callbacks->saw_error());
525 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); 506 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name));
526 } 507 }
527 508
528 // Terminate all pending-close timers. 509 // Terminate all pending-close timers.
529 factory()->ForceClose(origin); 510 factory()->ForceClose(origin);
530 } 511 }
531 512
532 } // namespace content 513 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698