| OLD | NEW |
| 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 462 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 463 | 463 |
| 464 const base::string16 db_name(ASCIIToUTF16("db")); | 464 const base::string16 db_name(ASCIIToUTF16("db")); |
| 465 const int64_t db_version = 2; | 465 const int64_t db_version = 2; |
| 466 const int64_t transaction_id = 1; | 466 const int64_t transaction_id = 1; |
| 467 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( | 467 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( |
| 468 new MockIndexedDBDatabaseCallbacks()); | 468 new MockIndexedDBDatabaseCallbacks()); |
| 469 | 469 |
| 470 // Open at version 2, then close. | 470 // Open at version 2, then close. |
| 471 { | 471 { |
| 472 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 472 scoped_refptr<UpgradeNeededCallbacks> callbacks( |
| 473 new UpgradeNeededCallbacks()); | 473 new UpgradeNeededCallbacks()); |
| 474 std::unique_ptr<IndexedDBPendingConnection> connection( | 474 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 475 base::MakeUnique<IndexedDBPendingConnection>( | 475 base::MakeUnique<IndexedDBPendingConnection>( |
| 476 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 476 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 477 db_version)); | 477 db_version)); |
| 478 factory()->Open(db_name, std::move(connection), | 478 factory()->Open(db_name, std::move(connection), |
| 479 nullptr /* request_context */, origin, | 479 nullptr /* request_context */, origin, |
| 480 temp_directory.GetPath()); | 480 temp_directory.GetPath()); |
| 481 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); | 481 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); |
| 482 | 482 |
| 483 // Pump the message loop so the upgrade transaction can run. | 483 // Pump the message loop so the upgrade transaction can run. |
| 484 base::RunLoop().RunUntilIdle(); | 484 base::RunLoop().RunUntilIdle(); |
| 485 EXPECT_TRUE(callbacks->connection()); | 485 EXPECT_TRUE(callbacks->connection()); |
| 486 callbacks->connection()->database()->Commit(transaction_id); | 486 callbacks->connection()->database()->Commit( |
| 487 callbacks->connection()->GetTransaction(transaction_id)); |
| 487 | 488 |
| 488 callbacks->connection()->Close(); | 489 callbacks->connection()->Close(); |
| 489 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); | 490 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); |
| 490 } | 491 } |
| 491 | 492 |
| 492 // Open at version < 2, which will fail; ensure factory doesn't retain | 493 // Open at version < 2, which will fail; ensure factory doesn't retain |
| 493 // the database object. | 494 // the database object. |
| 494 { | 495 { |
| 495 scoped_refptr<ErrorCallbacks> callbacks(new ErrorCallbacks()); | 496 scoped_refptr<ErrorCallbacks> callbacks(new ErrorCallbacks()); |
| 496 std::unique_ptr<IndexedDBPendingConnection> connection( | 497 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 497 base::MakeUnique<IndexedDBPendingConnection>( | 498 base::MakeUnique<IndexedDBPendingConnection>( |
| 498 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 499 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 499 db_version - 1)); | 500 db_version - 1)); |
| 500 factory()->Open(db_name, std::move(connection), | 501 factory()->Open(db_name, std::move(connection), |
| 501 nullptr /* request_context */, origin, | 502 nullptr /* request_context */, origin, |
| 502 temp_directory.GetPath()); | 503 temp_directory.GetPath()); |
| 503 EXPECT_TRUE(callbacks->saw_error()); | 504 EXPECT_TRUE(callbacks->saw_error()); |
| 504 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); | 505 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); |
| 505 } | 506 } |
| 506 | 507 |
| 507 // Terminate all pending-close timers. | 508 // Terminate all pending-close timers. |
| 508 factory()->ForceClose(origin); | 509 factory()->ForceClose(origin); |
| 509 } | 510 } |
| 510 | 511 |
| 511 } // namespace content | 512 } // namespace content |
| OLD | NEW |